diff --git a/.golangci.yaml b/.golangci.yaml index dd0b6a92..7ef8310d 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -3,6 +3,7 @@ linters: enable-all: true disable: - cyclop + - depguard - forbidigo - funlen - gochecknoglobals @@ -88,6 +89,10 @@ linters-settings: # Because it's easier to read without the other fields. # - 'GetPayloadsFilters' + # + # Easier to read with only one of the versioned payloads. + # + - 'api.VersionedExecutionPayload' # # Structures outside our control that have a ton of settings. It doesn't diff --git a/common/types.go b/common/types.go index 5e60311e..d3757bfa 100644 --- a/common/types.go +++ b/common/types.go @@ -11,7 +11,6 @@ import ( "github.com/attestantio/go-builder-client/api/capella" apiv1 "github.com/attestantio/go-builder-client/api/v1" "github.com/attestantio/go-builder-client/spec" - apiv1capella "github.com/attestantio/go-eth2-client/api/v1/capella" consensusspec "github.com/attestantio/go-eth2-client/spec" consensuscapella "github.com/attestantio/go-eth2-client/spec/capella" "github.com/attestantio/go-eth2-client/spec/phase0" @@ -141,8 +140,8 @@ type BuilderGetValidatorsResponseEntry struct { type BidTraceV2 struct { apiv1.BidTrace - BlockNumber uint64 `json:"block_number,string" db:"block_number"` - NumTx uint64 `json:"num_tx,string" db:"num_tx"` + BlockNumber uint64 `db:"block_number" json:"block_number,string"` + NumTx uint64 `db:"num_tx" json:"num_tx,string"` } type BidTraceV2JSON struct { @@ -273,82 +272,6 @@ func (b *BidTraceV2WithTimestampJSON) ToCSVRecord() []string { } } -type SignedBlindedBeaconBlock struct { - Bellatrix *boostTypes.SignedBlindedBeaconBlock - Capella *apiv1capella.SignedBlindedBeaconBlock -} - -func (s *SignedBlindedBeaconBlock) MarshalJSON() ([]byte, error) { - if s.Capella != nil { - return json.Marshal(s.Capella) - } - if s.Bellatrix != nil { - return json.Marshal(s.Bellatrix) - } - return nil, ErrEmptyPayload -} - -func (s *SignedBlindedBeaconBlock) Slot() uint64 { - if s.Capella != nil { - return uint64(s.Capella.Message.Slot) - } - if s.Bellatrix != nil { - return s.Bellatrix.Message.Slot - } - return 0 -} - -func (s *SignedBlindedBeaconBlock) BlockHash() string { - if s.Capella != nil { - return s.Capella.Message.Body.ExecutionPayloadHeader.BlockHash.String() - } - if s.Bellatrix != nil { - return s.Bellatrix.Message.Body.ExecutionPayloadHeader.BlockHash.String() - } - return "" -} - -func (s *SignedBlindedBeaconBlock) BlockNumber() uint64 { - if s.Capella != nil { - return s.Capella.Message.Body.ExecutionPayloadHeader.BlockNumber - } - if s.Bellatrix != nil { - return s.Bellatrix.Message.Body.ExecutionPayloadHeader.BlockNumber - } - return 0 -} - -func (s *SignedBlindedBeaconBlock) ProposerIndex() uint64 { - if s.Capella != nil { - return uint64(s.Capella.Message.ProposerIndex) - } - if s.Bellatrix != nil { - return s.Bellatrix.Message.ProposerIndex - } - return 0 -} - -func (s *SignedBlindedBeaconBlock) Signature() []byte { - if s.Capella != nil { - return s.Capella.Signature[:] - } - if s.Bellatrix != nil { - return s.Bellatrix.Signature[:] - } - return nil -} - -//nolint:nolintlint,ireturn -func (s *SignedBlindedBeaconBlock) Message() boostTypes.HashTreeRoot { - if s.Capella != nil { - return s.Capella.Message - } - if s.Bellatrix != nil { - return s.Bellatrix.Message - } - return nil -} - type SignedBeaconBlock struct { Capella *consensuscapella.SignedBeaconBlock } @@ -404,7 +327,7 @@ func (b *BuilderSubmitBlockRequest) HasExecutionPayload() bool { func (b *BuilderSubmitBlockRequest) ExecutionPayloadResponse() (*api.VersionedExecutionPayload, error) { if b.Capella != nil { - return &api.VersionedExecutionPayload{ //nolint:exhaustruct + return &api.VersionedExecutionPayload{ Version: consensusspec.DataVersionCapella, Capella: b.Capella.ExecutionPayload, }, nil diff --git a/common/types_spec.go b/common/types_spec.go index d4b8a235..8a6248d9 100644 --- a/common/types_spec.go +++ b/common/types_spec.go @@ -7,6 +7,7 @@ import ( "github.com/attestantio/go-builder-client/api" "github.com/attestantio/go-builder-client/api/capella" "github.com/attestantio/go-builder-client/spec" + consensusapi "github.com/attestantio/go-eth2-client/api" consensusspec "github.com/attestantio/go-eth2-client/spec" consensuscapella "github.com/attestantio/go-eth2-client/spec/capella" "github.com/attestantio/go-eth2-client/spec/phase0" @@ -56,7 +57,7 @@ func BuildGetHeaderResponse(payload *BuilderSubmitBlockRequest, sk *bls.SecretKe func BuildGetPayloadResponse(payload *BuilderSubmitBlockRequest) (*api.VersionedExecutionPayload, error) { if payload.Capella != nil { - return &api.VersionedExecutionPayload{ //nolint:exhaustruct + return &api.VersionedExecutionPayload{ Version: consensusspec.DataVersionCapella, Capella: payload.Capella.ExecutionPayload, }, nil @@ -147,7 +148,7 @@ func CapellaPayloadToPayloadHeader(p *consensuscapella.ExecutionPayload) (*conse }, nil } -func SignedBlindedBeaconBlockToBeaconBlock(signedBlindedBeaconBlock *SignedBlindedBeaconBlock, executionPayload *api.VersionedExecutionPayload) *SignedBeaconBlock { +func SignedBlindedBeaconBlockToBeaconBlock(signedBlindedBeaconBlock *consensusapi.VersionedSignedBlindedBeaconBlock, executionPayload *api.VersionedExecutionPayload) *SignedBeaconBlock { var signedBeaconBlock SignedBeaconBlock capellaBlindedBlock := signedBlindedBeaconBlock.Capella if capellaBlindedBlock != nil { diff --git a/database/database.go b/database/database.go index 939161a2..95e48ed4 100644 --- a/database/database.go +++ b/database/database.go @@ -9,6 +9,7 @@ import ( "strings" "time" + consensusapi "github.com/attestantio/go-eth2-client/api" "github.com/flashbots/go-boost-utils/types" "github.com/flashbots/mev-boost-relay/common" "github.com/flashbots/mev-boost-relay/database/migrations" @@ -34,7 +35,7 @@ type IDatabaseService interface { GetExecutionPayloads(idFirst, idLast uint64) (entries []*ExecutionPayloadEntry, err error) DeleteExecutionPayloads(idFirst, idLast uint64) error - SaveDeliveredPayload(bidTrace *common.BidTraceV2, signedBlindedBeaconBlock *common.SignedBlindedBeaconBlock, signedAt time.Time, publishMs uint64) error + SaveDeliveredPayload(bidTrace *common.BidTraceV2, signedBlindedBeaconBlock *consensusapi.VersionedSignedBlindedBeaconBlock, signedAt time.Time, publishMs uint64) error GetNumDeliveredPayloads() (uint64, error) GetRecentDeliveredPayloads(filters GetPayloadsFilters) ([]*DeliveredPayloadEntry, error) GetDeliveredPayloads(idFirst, idLast uint64) (entries []*DeliveredPayloadEntry, err error) @@ -267,7 +268,7 @@ func (s *DatabaseService) GetExecutionPayloadEntryBySlotPkHash(slot uint64, prop return entry, err } -func (s *DatabaseService) SaveDeliveredPayload(bidTrace *common.BidTraceV2, signedBlindedBeaconBlock *common.SignedBlindedBeaconBlock, signedAt time.Time, publishMs uint64) error { +func (s *DatabaseService) SaveDeliveredPayload(bidTrace *common.BidTraceV2, signedBlindedBeaconBlock *consensusapi.VersionedSignedBlindedBeaconBlock, signedAt time.Time, publishMs uint64) error { _signedBlindedBeaconBlock, err := json.Marshal(signedBlindedBeaconBlock) if err != nil { return err diff --git a/database/mockdb.go b/database/mockdb.go index 79138f64..0708e7f8 100644 --- a/database/mockdb.go +++ b/database/mockdb.go @@ -5,6 +5,7 @@ import ( "fmt" "time" + consensusapi "github.com/attestantio/go-eth2-client/api" "github.com/flashbots/go-boost-utils/types" "github.com/flashbots/mev-boost-relay/common" ) @@ -85,7 +86,7 @@ func (db MockDB) GetBuilderSubmissionsBySlots(slotFrom, slotTo uint64) (entries return nil, nil } -func (db MockDB) SaveDeliveredPayload(bidTrace *common.BidTraceV2, signedBlindedBeaconBlock *common.SignedBlindedBeaconBlock, signedAt time.Time, publishMs uint64) error { +func (db MockDB) SaveDeliveredPayload(bidTrace *common.BidTraceV2, signedBlindedBeaconBlock *consensusapi.VersionedSignedBlindedBeaconBlock, signedAt time.Time, publishMs uint64) error { return nil } diff --git a/database/typesconv.go b/database/typesconv.go index 8f291ffe..1df7abc2 100644 --- a/database/typesconv.go +++ b/database/typesconv.go @@ -85,7 +85,7 @@ func ExecutionPayloadEntryToExecutionPayload(executionPayloadEntry *ExecutionPay if err != nil { return nil, err } - return &api.VersionedExecutionPayload{ //nolint:exhaustruct + return &api.VersionedExecutionPayload{ Version: consensusspec.DataVersionCapella, Capella: executionPayload, }, nil diff --git a/datastore/memcached_test.go b/datastore/memcached_test.go index 3f19fefc..4ec0fbda 100644 --- a/datastore/memcached_test.go +++ b/datastore/memcached_test.go @@ -68,7 +68,7 @@ func testBuilderSubmitBlockRequest(pubkey phase0.BLSPubKey, signature phase0.BLS } case consensusspec.DataVersionDeneb: fallthrough - case consensusspec.DataVersionPhase0, consensusspec.DataVersionAltair, consensusspec.DataVersionBellatrix: + case consensusspec.DataVersionUnknown, consensusspec.DataVersionPhase0, consensusspec.DataVersionAltair, consensusspec.DataVersionBellatrix: fallthrough default: return common.BuilderSubmitBlockRequest{ diff --git a/datastore/redis.go b/datastore/redis.go index f37eb660..37cfd563 100644 --- a/datastore/redis.go +++ b/datastore/redis.go @@ -382,7 +382,7 @@ func (r *RedisCache) GetExecutionPayloadCapella(slot uint64, proposerPubkey, blo return nil, err } - return &api.VersionedExecutionPayload{ //nolint:exhaustruct + return &api.VersionedExecutionPayload{ Version: consensusspec.DataVersionCapella, Capella: capellaPayload, }, nil diff --git a/go.mod b/go.mod index cc90bec7..ffce0b8c 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.20 require ( github.com/NYTimes/gziphandler v1.1.1 github.com/alicebob/miniredis/v2 v2.30.4 - github.com/attestantio/go-builder-client v0.3.1 + github.com/attestantio/go-builder-client v0.3.2-0.20230701110827-d0ecfee1ab62 github.com/attestantio/go-eth2-client v0.16.4 github.com/bradfitz/gomemcache v0.0.0-20230124162541-5f7a7d875746 github.com/btcsuite/btcd/btcutil v1.1.2 @@ -19,7 +19,7 @@ require ( github.com/jmoiron/sqlx v1.3.5 github.com/lib/pq v1.10.8 github.com/pkg/errors v0.9.1 - github.com/r3labs/sse/v2 v2.8.1 + github.com/r3labs/sse/v2 v2.10.0 github.com/sirupsen/logrus v1.9.3 github.com/spf13/cobra v1.6.1 github.com/stretchr/testify v1.8.4 @@ -45,7 +45,7 @@ require ( github.com/goccy/go-yaml v1.11.0 // indirect github.com/gofrs/flock v0.8.1 // indirect github.com/gogo/protobuf v1.3.2 // indirect - github.com/golang/protobuf v1.5.2 // indirect + github.com/golang/protobuf v1.5.3 // indirect github.com/klauspost/compress v1.15.15 // indirect github.com/kr/pretty v0.3.1 // indirect github.com/kr/text v0.2.0 // indirect @@ -53,14 +53,14 @@ require ( github.com/mattn/go-isatty v0.0.18 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect github.com/mmcloughlin/addchain v0.4.0 // indirect - github.com/prometheus/client_golang v1.14.0 // indirect + github.com/prometheus/client_golang v1.16.0 // indirect github.com/prometheus/client_model v0.3.0 // indirect - github.com/prometheus/common v0.39.0 // indirect - github.com/prometheus/procfs v0.9.0 // indirect + github.com/prometheus/common v0.42.0 // indirect + github.com/prometheus/procfs v0.10.1 // indirect github.com/prysmaticlabs/go-bitfield v0.0.0-20210809151128-385d8c5e3fb7 // indirect - github.com/rogpeppe/go-internal v1.9.0 // indirect + github.com/rogpeppe/go-internal v1.11.0 // indirect golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect - google.golang.org/protobuf v1.28.1 // indirect + google.golang.org/protobuf v1.30.0 // indirect rsc.io/tmplfunc v0.0.3 // indirect ) @@ -97,9 +97,9 @@ require ( github.com/yuin/gopher-lua v1.1.0 // indirect go.uber.org/multierr v1.6.0 // indirect go.uber.org/zap v1.23.0 // indirect - golang.org/x/crypto v0.8.0 // indirect - golang.org/x/net v0.9.0 // indirect - golang.org/x/sys v0.8.0 // indirect + golang.org/x/crypto v0.10.0 // indirect + golang.org/x/net v0.10.0 // indirect + golang.org/x/sys v0.9.0 // indirect gopkg.in/cenkalti/backoff.v1 v1.1.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect @@ -114,3 +114,5 @@ retract ( v1.0.0-alpha2 v1.0.0-alpha1 ) + +replace github.com/attestantio/go-eth2-client => github.com/avalonche/go-eth2-client v0.0.0-20230720050755-dfcc05c7f873 diff --git a/go.sum b/go.sum index 4ed59bca..d23fd27c 100644 --- a/go.sum +++ b/go.sum @@ -22,10 +22,10 @@ github.com/alicebob/miniredis/v2 v2.30.4/go.mod h1:b25qWj4fCEsBeAAR2mlb0ufImGC6u github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah4HI848JfFxHt+iPb26b4zyfspmqY0/8= github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= -github.com/attestantio/go-builder-client v0.3.1 h1:yKULPmv9IymY2eJ0VzdRfqjUUz/8yRO66Ym6Wn8RJM0= -github.com/attestantio/go-builder-client v0.3.1/go.mod h1:DwesMTOqnCp4u+n3uZ+fWL8wwnSBZVD9VMIVPDR+AZE= -github.com/attestantio/go-eth2-client v0.16.4 h1:utfGx49JZN4W7IT6/txdwE9qobP3b/eTa3Ge1PJFRJg= -github.com/attestantio/go-eth2-client v0.16.4/go.mod h1:lgxKsjRSxQnHSWxSbtZLGYlFkE3vFM4L+DK4bXqAxAU= +github.com/attestantio/go-builder-client v0.3.2-0.20230701110827-d0ecfee1ab62 h1:jtNd8modhHUKfgLcQBv6ajgBNldwkIXT4U2iqWtbyA0= +github.com/attestantio/go-builder-client v0.3.2-0.20230701110827-d0ecfee1ab62/go.mod h1:DwesMTOqnCp4u+n3uZ+fWL8wwnSBZVD9VMIVPDR+AZE= +github.com/avalonche/go-eth2-client v0.0.0-20230720050755-dfcc05c7f873 h1:IIDWbWmoIW6WuZLYFNDuyeoGGYIAvZ5oH3XuZa47hQs= +github.com/avalonche/go-eth2-client v0.0.0-20230720050755-dfcc05c7f873/go.mod h1:KSVlZSW1A3jUg5H8O89DLtqxgJprRfTtI7k89fLdhu0= github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g= github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= @@ -181,8 +181,9 @@ github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvq github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= +github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb h1:PBC98N2aIaM3XXiurYmW7fx4GZkL8feAMVq7nEjURHk= @@ -331,23 +332,24 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/poy/onpar v1.1.2 h1:QaNrNiZx0+Nar5dLgTVp5mXkyoVFIbepjyEoGSnhbAY= -github.com/prometheus/client_golang v1.14.0 h1:nJdhIvne2eSX/XRAFV9PcvFFRbrjbcTUj0VP62TMhnw= -github.com/prometheus/client_golang v1.14.0/go.mod h1:8vpkKitgIVNcqrRBWh1C4TIUQgYNtG/XQE4E/Zae36Y= +github.com/prometheus/client_golang v1.16.0 h1:yk/hx9hDbrGHovbci4BY+pRMfSuuat626eFsHb7tmT8= +github.com/prometheus/client_golang v1.16.0/go.mod h1:Zsulrv/L9oM40tJ7T815tM89lFEugiJ9HzIqaAx4LKc= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.3.0 h1:UBgGFHqYdG/TPFD1B1ogZywDqEkwp3fBMvqdiQ7Xew4= github.com/prometheus/client_model v0.3.0/go.mod h1:LDGWKZIo7rky3hgvBe+caln+Dr3dPggB5dvjtD7w9+w= -github.com/prometheus/common v0.39.0 h1:oOyhkDq05hPZKItWVBkJ6g6AtGxi+fy7F4JvUV8uhsI= -github.com/prometheus/common v0.39.0/go.mod h1:6XBZ7lYdLCbkAVhwRsWTZn+IN5AB9F/NXd5w0BbEX0Y= -github.com/prometheus/procfs v0.9.0 h1:wzCHvIvM5SxWqYvwgVL7yJY8Lz3PKn49KQtpgMYJfhI= -github.com/prometheus/procfs v0.9.0/go.mod h1:+pB4zwohETzFnmlpe6yd2lSc+0/46IYZRB/chUwxUZY= +github.com/prometheus/common v0.42.0 h1:EKsfXEYo4JpWMHH5cg+KOUWeuJSov1Id8zGR8eeI1YM= +github.com/prometheus/common v0.42.0/go.mod h1:xBwqVerjNdUDjgODMpudtOMwlOwf2SaTr1yjz4b7Zbc= +github.com/prometheus/procfs v0.10.1 h1:kYK1Va/YMlutzCGazswoHKo//tZVlFpKYh+PymziUAg= +github.com/prometheus/procfs v0.10.1/go.mod h1:nwNm2aOCAYw8uTR/9bWRREkZFxAUcWzPHWJq+XBB/FM= github.com/prysmaticlabs/go-bitfield v0.0.0-20210809151128-385d8c5e3fb7 h1:0tVE4tdWQK9ZpYygoV7+vS6QkDvQVySboMVEIxBJmXw= github.com/prysmaticlabs/go-bitfield v0.0.0-20210809151128-385d8c5e3fb7/go.mod h1:wmuf/mdK4VMD+jA9ThwcUKjg3a2XWM9cVfFYjDyY4j4= -github.com/r3labs/sse/v2 v2.8.1 h1:lZH+W4XOLIq88U5MIHOsLec7+R62uhz3bIi2yn0Sg8o= -github.com/r3labs/sse/v2 v2.8.1/go.mod h1:Igau6Whc+F17QUgML1fYe1VPZzTV6EMCnYktEmkNJ7I= +github.com/r3labs/sse/v2 v2.10.0 h1:hFEkLLFY4LDifoHdiCN/LlGBAdVJYsANaLqNYa1l/v0= +github.com/r3labs/sse/v2 v2.10.0/go.mod h1:Igau6Whc+F17QUgML1fYe1VPZzTV6EMCnYktEmkNJ7I= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o= -github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= +github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= +github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= github.com/rubenv/sql-migrate v1.5.1 h1:WsZo4jPQfjmddDTh/suANP2aKPA7/ekN0LzuuajgQEo= github.com/rubenv/sql-migrate v1.5.1/go.mod h1:H38GW8Vqf8F0Su5XignRyaRcbXbJunSWxs+kmzlg0Is= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= @@ -434,8 +436,8 @@ golang.org/x/crypto v0.0.0-20191227163750-53104e6ec876/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.8.0 h1:pd9TJtTueMTVQXzk8E2XESSMQDj/U7OUu0PqJqPXQjQ= -golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE= +golang.org/x/crypto v0.10.0 h1:LKqV2xt9+kDzSTfOhx4FrkEBcMrAgHSYgzywV9zcGmM= +golang.org/x/crypto v0.10.0/go.mod h1:o4eNf7Ede1fv+hwOwZsTHl9EsPFO6q6ZvYR8vYfY45I= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20230206171751-46f607a40771 h1:xP7rWLUr1e1n2xkK5YB4LI0hPEy3LJC6Wk+D4pGlOJg= golang.org/x/exp v0.0.0-20230206171751-46f607a40771/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= @@ -468,8 +470,8 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20211008194852-3b03d305991f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.9.0 h1:aWJ/m6xSmxWBx+V0XRHTlrYrPG56jKsLdTFmsSsCzOM= -golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= +golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= +golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -479,7 +481,7 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= +golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -514,10 +516,10 @@ golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= -golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s= +golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.7.0 h1:BEvjmm5fURWqcfbSKTdpkDXYBrUS1c0m8agp14W48vQ= +golang.org/x/term v0.9.0 h1:GRRCnKYhdQrD8kfRAdQ6Zcw1P0OcELxGLKJvtjVMZ28= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= @@ -570,8 +572,8 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= -google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= +google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/cenkalti/backoff.v1 v1.1.0 h1:Arh75ttbsvlpVA7WtVpH4u9h6Zl46xuptxqLxPiSo4Y= gopkg.in/cenkalti/backoff.v1 v1.1.0/go.mod h1:J6Vskwqd+OMVJl8C33mmtxTBs2gyzfv7UDAkHu8BrjI= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/services/api/service.go b/services/api/service.go index d1974d13..5581830e 100644 --- a/services/api/service.go +++ b/services/api/service.go @@ -22,6 +22,7 @@ import ( "github.com/NYTimes/gziphandler" builderCapella "github.com/attestantio/go-builder-client/api/capella" + consensusapi "github.com/attestantio/go-eth2-client/api" "github.com/attestantio/go-eth2-client/api/v1/capella" "github.com/attestantio/go-eth2-client/spec/phase0" "github.com/buger/jsonparser" @@ -1218,7 +1219,7 @@ func (api *RelayAPI) handleGetPayload(w http.ResponseWriter, req *http.Request) } // Decode payload - payload := new(common.SignedBlindedBeaconBlock) + payload := new(consensusapi.VersionedSignedBlindedBeaconBlock) // TODO: add deneb support. payload.Capella = new(capella.SignedBlindedBeaconBlock) if err := json.NewDecoder(bytes.NewReader(body)).Decode(payload.Capella); err != nil { @@ -1229,27 +1230,42 @@ func (api *RelayAPI) handleGetPayload(w http.ResponseWriter, req *http.Request) // Take time after the decoding, and add to logging decodeTime := time.Now().UTC() - slotStartTimestamp := api.genesisInfo.Data.GenesisTime + (payload.Slot() * common.SecondsPerSlot) + slot, err := payload.Slot() + if err != nil { + log.WithError(err).Warn("failed to get payload slot") + api.RespondError(w, http.StatusBadRequest, "failed to get payload slot") + } + blockHash, err := payload.BlockHash() + if err != nil { + log.WithError(err).Warn("failed to get payload block hash") + api.RespondError(w, http.StatusBadRequest, "failed to get payload block hash") + } + proposerIndex, err := payload.ProposerIndex() + if err != nil { + log.WithError(err).Warn("failed to get payload proposer index") + api.RespondError(w, http.StatusBadRequest, "failed to get payload proposer index") + } + slotStartTimestamp := api.genesisInfo.Data.GenesisTime + (uint64(slot) * common.SecondsPerSlot) msIntoSlot := decodeTime.UnixMilli() - int64((slotStartTimestamp * 1000)) log = log.WithFields(logrus.Fields{ - "slot": payload.Slot(), - "slotEpochPos": (payload.Slot() % common.SlotsPerEpoch) + 1, - "blockHash": payload.BlockHash(), + "slot": slot, + "slotEpochPos": (uint64(slot) % common.SlotsPerEpoch) + 1, + "blockHash": blockHash.String(), "slotStartSec": slotStartTimestamp, "msIntoSlot": msIntoSlot, "timestampAfterDecode": decodeTime.UnixMilli(), - "proposerIndex": payload.ProposerIndex(), + "proposerIndex": proposerIndex, }) // Ensure the proposer index is expected api.proposerDutiesLock.RLock() - slotDuty := api.proposerDutiesMap[payload.Slot()] + slotDuty := api.proposerDutiesMap[uint64(slot)] api.proposerDutiesLock.RUnlock() if slotDuty == nil { log.Warn("could not find slot duty") } else { log = log.WithField("feeRecipient", slotDuty.Entry.Message.FeeRecipient) - if slotDuty.ValidatorIndex != payload.ProposerIndex() { + if slotDuty.ValidatorIndex != uint64(proposerIndex) { log.WithField("expectedProposerIndex", slotDuty.ValidatorIndex).Warn("not the expected proposer index") api.RespondError(w, http.StatusBadRequest, "not the expected proposer index") return @@ -1257,9 +1273,9 @@ func (api *RelayAPI) handleGetPayload(w http.ResponseWriter, req *http.Request) } // Get the proposer pubkey based on the validator index from the payload - proposerPubkey, found := api.datastore.GetKnownValidatorPubkeyByIndex(payload.ProposerIndex()) + proposerPubkey, found := api.datastore.GetKnownValidatorPubkeyByIndex(uint64(proposerIndex)) if !found { - log.Errorf("could not find proposer pubkey for index %d", payload.ProposerIndex()) + log.Errorf("could not find proposer pubkey for index %d", proposerIndex) api.RespondError(w, http.StatusBadRequest, "could not match proposer index to pubkey") return } @@ -1275,9 +1291,9 @@ func (api *RelayAPI) handleGetPayload(w http.ResponseWriter, req *http.Request) return } - // Validate proposer signature (first attempt verifying the Capella signature) + // Validate proposer signature // TODO: add deneb support. - ok, err := boostTypes.VerifySignature(payload.Message(), api.opts.EthNetDetails.DomainBeaconProposerCapella, pk[:], payload.Signature()) + ok, err := checkProposerSignature(payload, api.opts.EthNetDetails.DomainBeaconProposerCapella, pk[:]) if !ok || err != nil { if api.ffLogInvalidSignaturePayload { txt, _ := json.Marshal(payload) //nolint:errchkjson @@ -1296,18 +1312,18 @@ func (api *RelayAPI) handleGetPayload(w http.ResponseWriter, req *http.Request) // Get the response - from Redis, Memcache or DB // note that recent mev-boost versions only send getPayload to relays that provided the bid - getPayloadResp, err := api.datastore.GetGetPayloadResponse(log, payload.Slot(), proposerPubkey.String(), payload.BlockHash()) + getPayloadResp, err := api.datastore.GetGetPayloadResponse(log, uint64(slot), proposerPubkey.String(), blockHash.String()) if err != nil || getPayloadResp == nil { log.WithError(err).Warn("failed getting execution payload (1/2)") time.Sleep(time.Duration(timeoutGetPayloadRetryMs) * time.Millisecond) // Try again - getPayloadResp, err = api.datastore.GetGetPayloadResponse(log, payload.Slot(), proposerPubkey.String(), payload.BlockHash()) + getPayloadResp, err = api.datastore.GetGetPayloadResponse(log, uint64(slot), proposerPubkey.String(), blockHash.String()) if err != nil || getPayloadResp == nil { // Still not found! Error out now. if errors.Is(err, datastore.ErrExecutionPayloadNotFound) { // Couldn't find the execution payload, maybe it never was submitted to our relay! Check that now - _, err := api.db.GetBlockSubmissionEntry(payload.Slot(), proposerPubkey.String(), payload.BlockHash()) + _, err := api.db.GetBlockSubmissionEntry(uint64(slot), proposerPubkey.String(), blockHash.String()) if errors.Is(err, sql.ErrNoRows) { log.Warn("failed getting execution payload (2/2) - payload not found, block was never submitted to this relay") api.RespondError(w, http.StatusBadRequest, "no execution payload for this request - block was never seen by this relay") @@ -1328,7 +1344,7 @@ func (api *RelayAPI) handleGetPayload(w http.ResponseWriter, req *http.Request) log = log.WithField("timestampAfterLoadResponse", time.Now().UTC().UnixMilli()) // Check whether getPayload has already been called -- TODO: do we need to allow multiple submissions of one blinded block? - err = api.redis.CheckAndSetLastSlotAndHashDelivered(payload.Slot(), payload.BlockHash()) + err = api.redis.CheckAndSetLastSlotAndHashDelivered(uint64(slot), blockHash.String()) log = log.WithField("timestampAfterAlreadyDeliveredCheck", time.Now().UTC().UnixMilli()) if err != nil { if errors.Is(err, datastore.ErrAnotherPayloadAlreadyDeliveredForSlot) { @@ -1366,7 +1382,7 @@ func (api *RelayAPI) handleGetPayload(w http.ResponseWriter, req *http.Request) api.RespondError(w, http.StatusBadRequest, fmt.Sprintf("sent too late - %d ms into slot", msIntoSlot)) go func() { - err := api.db.InsertTooLateGetPayload(payload.Slot(), proposerPubkey.String(), payload.BlockHash(), slotStartTimestamp, uint64(receivedAt.UnixMilli()), uint64(decodeTime.UnixMilli()), uint64(msIntoSlot)) + err := api.db.InsertTooLateGetPayload(uint64(slot), proposerPubkey.String(), blockHash.String(), slotStartTimestamp, uint64(receivedAt.UnixMilli()), uint64(decodeTime.UnixMilli()), uint64(msIntoSlot)) if err != nil { log.WithError(err).Error("failed to insert payload too late into db") } @@ -1402,16 +1418,23 @@ func (api *RelayAPI) handleGetPayload(w http.ResponseWriter, req *http.Request) // respond to the HTTP request api.RespondOK(w, getPayloadResp) + blockNumber, err := payload.BlockNumber() + if err != nil { + log.WithError(err).Info("failed to get block number") + } + txs, err := getPayloadResp.Transactions() + if err != nil { + log.WithError(err).Info("failed to get transactions") + } log = log.WithFields(logrus.Fields{ - // TODO: get tx field when https://github.com/attestantio/go-builder-client/pull/14 is merged - // "numTx": getPayloadResp.NumTx(), - "blockNumber": payload.BlockNumber(), + "numTx": len(txs), + "blockNumber": blockNumber, }) log.Info("execution payload delivered") // Save information about delivered payload go func() { - bidTrace, err := api.redis.GetBidTrace(payload.Slot(), proposerPubkey.String(), payload.BlockHash()) + bidTrace, err := api.redis.GetBidTrace(uint64(slot), proposerPubkey.String(), blockHash.String()) if err != nil { log.WithError(err).Error("failed to get bidTrace for delivered payload from redis") return diff --git a/services/api/utils.go b/services/api/utils.go index 100fc015..acdd4ad4 100644 --- a/services/api/utils.go +++ b/services/api/utils.go @@ -4,9 +4,11 @@ import ( "errors" "github.com/attestantio/go-builder-client/api" + consensusapi "github.com/attestantio/go-eth2-client/api" "github.com/attestantio/go-eth2-client/spec/capella" "github.com/attestantio/go-eth2-client/spec/phase0" utilcapella "github.com/attestantio/go-eth2-client/util/capella" + "github.com/flashbots/go-boost-utils/bls" boostTypes "github.com/flashbots/go-boost-utils/types" "github.com/flashbots/mev-boost-relay/common" ) @@ -47,7 +49,7 @@ func ComputeWithdrawalsRoot(w []*capella.Withdrawal) (phase0.Root, error) { return withdrawals.HashTreeRoot() } -func EqExecutionPayloadToHeader(bb *common.SignedBlindedBeaconBlock, payload *api.VersionedExecutionPayload) error { +func EqExecutionPayloadToHeader(bb *consensusapi.VersionedSignedBlindedBeaconBlock, payload *api.VersionedExecutionPayload) error { if bb.Capella != nil { // process Capella beacon block if payload.Capella == nil { return ErrPayloadMismatchCapella @@ -77,3 +79,21 @@ func EqExecutionPayloadToHeader(bb *common.SignedBlindedBeaconBlock, payload *ap return ErrNoPayloads } + +func checkProposerSignature(block *consensusapi.VersionedSignedBlindedBeaconBlock, domain boostTypes.Domain, pubKey []byte) (bool, error) { + root, err := block.Root() + if err != nil { + return false, err + } + sig, err := block.Signature() + if err != nil { + return false, err + } + signingData := boostTypes.SigningData{Root: boostTypes.Root(root), Domain: domain} + msg, err := signingData.HashTreeRoot() + if err != nil { + return false, err + } + + return bls.VerifySignatureBytes(msg[:], sig[:], pubKey[:]) +}