Skip to content

Commit

Permalink
Deneb Support (#564)
Browse files Browse the repository at this point in the history
* Remove bellatrix from wrapper types (#475)

* Remove bellatrix from wrapper types

* remove test logs

* Remove get header wrapper types (#477)

* Remove signed blinded beacon block wrapper (#482)

* remove signed blinded beacon block wrapper type

* linting

* remove signed beacon block wrapper types (#483)

* Remove submit block request wrapper (#485)

* remove submit block request wrapper types

* fix tests

* fix lint

* Upgrade go-boost-utils (#488)

* Upgrade go-boost-utils

* pr comments

* remove commented out code

* Add custom json marshalling for versioned structs (#493)

* Add deneb signature checking for block contents

* Add deneb support for type conversions

* Add redis and database tests to store deneb payloads

* Block submission to v3 validation endpoint

* Update signed block conversions

* Replace some expectCont with expectOk (#509)

* Allow fork epochs to be 0

* Make attestantio import names consistent (#510)

* Make attestantio import names consistent

* Fix linter errors & two comments

* Fix mistake in redis prefix name (#517)

* Fix mistake in redis prefix for deneb

* Fix typo in prefix

* rebase conflicts from main

* update submit block request

* bug fixes

* fix blob sidecar signature

* ssz encode request to publish block

* use v2 publish endpoint by default

* go mod tidy

* update relay to latest builder-specs

* update go mod

* fix lint and tests

* switch to json encoding instead of ssz for block publishing v2

* add blob logging

* address pr comments

* Handle no deneb fork schedule from beacon client (#572)

* backwards compatibility if no deneb schedule

* Update services/api/service.go

Co-authored-by: Chris Hager <[email protected]>

---------

Co-authored-by: Chris Hager <[email protected]>

* change specific error log to info because it's expected nowadays (#574)

* Add json and ssz marshalling tests (#573)

* add test vectors

* linting

---------

Co-authored-by: Justin Traglia <[email protected]>
Co-authored-by: Chris Hager <[email protected]>
  • Loading branch information
3 people authored Jan 30, 2024
1 parent 930f084 commit 72fab1a
Show file tree
Hide file tree
Showing 52 changed files with 3,223 additions and 2,228 deletions.
8 changes: 8 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ linters:
enable-all: true
disable:
- cyclop
- depguard
- forbidigo
- funlen
- gochecknoglobals
Expand Down Expand Up @@ -69,6 +70,7 @@ linters-settings:

gomoddirectives:
replace-allow-list:
- github.com/attestantio/go-builder-client
- github.com/attestantio/go-eth2-client

maintidx:
Expand All @@ -88,6 +90,12 @@ linters-settings:
# Because it's easier to read without the other fields.
#
- 'GetPayloadsFilters'
#
# Easier to read with only one of the versioned payloads.
#
- 'VersionedSubmitBlindedBlockResponse'
- 'VersionedExecutionPayload'
- 'VersionedSignedBuilderBid'

#
# Structures outside our control that have a ton of settings. It doesn't
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ redis-cli DEL boost-relay/sepolia:validators-registration boost-relay/sepolia:va
* `DISABLE_LOWPRIO_BUILDERS` - reject block submissions by low-prio builders
* `FORCE_GET_HEADER_204` - force 204 as getHeader response
* `ENABLE_IGNORABLE_VALIDATION_ERRORS` - enable ignorable validation errors
* `USE_V2_PUBLISH_BLOCK_ENDPOINT` - uses the v2 publish block endpoint on the beacon node
* `USE_V1_PUBLISH_BLOCK_ENDPOINT` - uses the v1 publish block endpoint on the beacon node

#### Development Environment Variables

Expand Down
4 changes: 1 addition & 3 deletions beaconclient/beacon_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"testing"
"time"

"github.com/flashbots/go-boost-utils/types"
"github.com/flashbots/mev-boost-relay/common"
"github.com/gorilla/mux"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -194,11 +193,10 @@ func TestFetchValidators(t *testing.T) {

// only beacon 2 should have a validator, and should be used by default
backend.beaconInstances[0].MockFetchValidatorsErr = nil
backend.beaconInstances[1].SetValidators(make(map[types.PubkeyHex]ValidatorResponseEntry))
backend.beaconInstances[1].SetValidators(make(map[common.PubkeyHex]ValidatorResponseEntry))
backend.beaconInstances[2].MockFetchValidatorsErr = nil
backend.beaconInstances[2].AddValidator(entry)

// t.Log("beacon0/1/2 validators:", backend.beaconInstances[0].NumValidators(), backend.beaconInstances[1].NumValidators(), backend.beaconInstances[2].NumValidators())
validators, err = backend.beaconClient.GetStateValidators("1")
require.NoError(t, err)
require.Equal(t, 1, len(validators.Data))
Expand Down
17 changes: 6 additions & 11 deletions beaconclient/mock_beacon_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import (
"sync"
"time"

"github.com/flashbots/go-boost-utils/types"
"github.com/flashbots/mev-boost-relay/common"
)

type MockBeaconInstance struct {
mu sync.RWMutex
validatorSet map[types.PubkeyHex]ValidatorResponseEntry
validatorSet map[common.PubkeyHex]ValidatorResponseEntry

MockSyncStatus *SyncStatusPayloadData
MockSyncStatusErr error
Expand All @@ -23,7 +22,7 @@ type MockBeaconInstance struct {

func NewMockBeaconInstance() *MockBeaconInstance {
return &MockBeaconInstance{
validatorSet: make(map[types.PubkeyHex]ValidatorResponseEntry),
validatorSet: make(map[common.PubkeyHex]ValidatorResponseEntry),

MockSyncStatus: &SyncStatusPayloadData{
HeadSlot: 1,
Expand All @@ -44,17 +43,17 @@ func NewMockBeaconInstance() *MockBeaconInstance {

func (c *MockBeaconInstance) AddValidator(entry ValidatorResponseEntry) {
c.mu.Lock()
c.validatorSet[types.NewPubkeyHex(entry.Validator.Pubkey)] = entry
c.validatorSet[common.NewPubkeyHex(entry.Validator.Pubkey)] = entry
c.mu.Unlock()
}

func (c *MockBeaconInstance) SetValidators(validatorSet map[types.PubkeyHex]ValidatorResponseEntry) {
func (c *MockBeaconInstance) SetValidators(validatorSet map[common.PubkeyHex]ValidatorResponseEntry) {
c.mu.Lock()
c.validatorSet = validatorSet
c.mu.Unlock()
}

func (c *MockBeaconInstance) IsValidator(pubkey types.PubkeyHex) bool {
func (c *MockBeaconInstance) IsValidator(pubkey common.PubkeyHex) bool {
c.mu.RLock()
_, found := c.validatorSet[pubkey]
c.mu.RUnlock()
Expand Down Expand Up @@ -107,18 +106,14 @@ func (c *MockBeaconInstance) addDelay() {
}
}

func (c *MockBeaconInstance) PublishBlock(block *common.SignedBeaconBlock, broadcaseMode BroadcastMode) (code int, err error) {
func (c *MockBeaconInstance) PublishBlock(block *common.VersionedSignedProposal, broadcaseMode BroadcastMode) (code int, err error) {
return 0, nil
}

func (c *MockBeaconInstance) GetGenesis() (*GetGenesisResponse, error) {
return nil, nil
}

func (c *MockBeaconInstance) GetBlock(blockID string) (block *GetBlockResponse, err error) {
return nil, nil
}

func (c *MockBeaconInstance) GetSpec() (spec *GetSpecResponse, err error) {
return nil, nil
}
Expand Down
10 changes: 1 addition & 9 deletions beaconclient/mock_multi_beacon_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ func (*MockMultiBeaconClient) SubscribeToHeadEvents(slotC chan HeadEventData) {}
func (*MockMultiBeaconClient) SubscribeToPayloadAttributesEvents(payloadAttrC chan PayloadAttributesEvent) {
}

// func (*MockMultiBeaconClient) FetchValidators(headSlot uint64) (map[types.PubkeyHex]ValidatorResponseEntry, error) {
// return nil, nil
// }

func (*MockMultiBeaconClient) GetStateValidators(stateID string) (*GetStateValidatorsResponse, error) {
return nil, nil
}
Expand All @@ -32,7 +28,7 @@ func (*MockMultiBeaconClient) GetProposerDuties(epoch uint64) (*ProposerDutiesRe
return nil, nil
}

func (*MockMultiBeaconClient) PublishBlock(block *common.SignedBeaconBlock) (code int, err error) {
func (*MockMultiBeaconClient) PublishBlock(block *common.VersionedSignedProposal) (code int, err error) {
return 0, nil
}

Expand Down Expand Up @@ -62,10 +58,6 @@ func (*MockMultiBeaconClient) GetForkSchedule() (spec *GetForkScheduleResponse,
return resp, nil
}

func (*MockMultiBeaconClient) GetBlock(blockID string) (block *GetBlockResponse, err error) {
return nil, nil
}

func (*MockMultiBeaconClient) GetRandao(slot uint64) (spec *GetRandaoResponse, err error) {
return nil, nil
}
Expand Down
55 changes: 21 additions & 34 deletions beaconclient/multi_beacon_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,14 @@ var (
ErrBeaconBlock202 = errors.New("beacon block failed validation but was still broadcast (202)")
)

type BroadcastMode int
type BroadcastMode string

const (
Gossip BroadcastMode = iota // lightweight gossip checks only
Consensus // full consensus checks, including validation of all signatures and blocks fields
ConsensusAndEquivocation // the same as `consensus`, with an extra equivocation check
Gossip BroadcastMode = "gossip" // lightweight gossip checks only
Consensus BroadcastMode = "consensus" // full consensus checks, including validation of all signatures and blocks fields
ConsensusAndEquivocation BroadcastMode = "consensus_and_equivocation" // the same as `consensus`, with an extra equivocation check
)

func (b BroadcastMode) String() string {
return [...]string{"gossip", "consensus", "consensus_and_equivocation"}[b]
}

// IMultiBeaconClient is the interface for the MultiBeaconClient, which can manage several beacon client instances under the hood
type IMultiBeaconClient interface {
BestSyncStatus() (*SyncStatusPayloadData, error)
Expand All @@ -42,11 +38,10 @@ type IMultiBeaconClient interface {
// GetStateValidators returns all active and pending validators from the beacon node
GetStateValidators(stateID string) (*GetStateValidatorsResponse, error)
GetProposerDuties(epoch uint64) (*ProposerDutiesResponse, error)
PublishBlock(block *common.SignedBeaconBlock) (code int, err error)
PublishBlock(block *common.VersionedSignedProposal) (code int, err error)
GetGenesis() (*GetGenesisResponse, error)
GetSpec() (spec *GetSpecResponse, err error)
GetForkSchedule() (spec *GetForkScheduleResponse, err error)
GetBlock(blockID string) (block *GetBlockResponse, err error)
GetRandao(slot uint64) (spec *GetRandaoResponse, err error)
GetWithdrawals(slot uint64) (spec *GetWithdrawalsResponse, err error)
}
Expand All @@ -60,11 +55,10 @@ type IBeaconInstance interface {
GetStateValidators(stateID string) (*GetStateValidatorsResponse, error)
GetProposerDuties(epoch uint64) (*ProposerDutiesResponse, error)
GetURI() string
PublishBlock(block *common.SignedBeaconBlock, broadcastMode BroadcastMode) (code int, err error)
PublishBlock(block *common.VersionedSignedProposal, broadcastMode BroadcastMode) (code int, err error)
GetGenesis() (*GetGenesisResponse, error)
GetSpec() (spec *GetSpecResponse, err error)
GetForkSchedule() (spec *GetForkScheduleResponse, err error)
GetBlock(blockID string) (*GetBlockResponse, error)
GetRandao(slot uint64) (spec *GetRandaoResponse, err error)
GetWithdrawals(slot uint64) (spec *GetWithdrawalsResponse, err error)
}
Expand Down Expand Up @@ -99,10 +93,10 @@ func NewMultiBeaconClient(log *logrus.Entry, beaconInstances []IBeaconInstance)
if broadcastModeStr != "" {
broadcastMode, ok := parseBroadcastModeString(broadcastModeStr)
if !ok {
msg := fmt.Sprintf("env: BROADCAST_MODE: invalid value %s, leaving to default value %s", broadcastModeStr, client.broadcastMode.String())
msg := fmt.Sprintf("env: BROADCAST_MODE: invalid value %s, leaving to default value %s", broadcastModeStr, client.broadcastMode)
client.log.Warn(msg)
} else {
client.log.Info(fmt.Sprintf("env: BROADCAST_MODE: setting mode to %s", broadcastMode.String()))
client.log.Info(fmt.Sprintf("env: BROADCAST_MODE: setting mode to %s", broadcastMode))
client.broadcastMode = broadcastMode
}
}
Expand Down Expand Up @@ -255,10 +249,20 @@ type publishResp struct {
}

// PublishBlock publishes the signed beacon block via https://ethereum.github.io/beacon-APIs/#/ValidatorRequiredApi/publishBlock
func (c *MultiBeaconClient) PublishBlock(block *common.SignedBeaconBlock) (code int, err error) {
func (c *MultiBeaconClient) PublishBlock(block *common.VersionedSignedProposal) (code int, err error) {
slot, err := block.Slot()
if err != nil {
c.log.WithError(err).Warn("failed to publish block as block slot is missing")
return 0, err
}
blockHash, err := block.ExecutionBlockHash()
if err != nil {
c.log.WithError(err).Warn("failed to publish block as block hash is missing")
return 0, err
}
log := c.log.WithFields(logrus.Fields{
"slot": block.Slot(),
"blockHash": block.BlockHash(),
"slot": slot,
"blockHash": blockHash.String(),
})

clients := c.beaconInstancesByLastResponse()
Expand Down Expand Up @@ -360,23 +364,6 @@ func (c *MultiBeaconClient) GetForkSchedule() (spec *GetForkScheduleResponse, er
return nil, err
}

// GetBlock returns a block - https://ethereum.github.io/beacon-APIs/#/Beacon/getBlockV2
func (c *MultiBeaconClient) GetBlock(blockID string) (block *GetBlockResponse, err error) {
clients := c.beaconInstancesByLastResponse()
for _, client := range clients {
log := c.log.WithField("uri", client.GetURI())
if block, err = client.GetBlock(blockID); err != nil {
log.WithField("blockID", blockID).WithError(err).Warn("failed to get block")
continue
}

return block, nil
}

c.log.WithField("blockID", blockID).WithError(err).Error("failed to get block from any CL node")
return nil, err
}

// GetRandao - 3500/eth/v1/beacon/states/<slot>/randao
func (c *MultiBeaconClient) GetRandao(slot uint64) (randaoResp *GetRandaoResponse, err error) {
clients := c.beaconInstancesByLastResponse()
Expand Down
Loading

0 comments on commit 72fab1a

Please sign in to comment.