From 3b025b21fe02c1398e30397a30424f2a4d759c52 Mon Sep 17 00:00:00 2001 From: avalonche Date: Tue, 4 Jul 2023 16:46:08 +1000 Subject: [PATCH] remove signed beacon block wrapper types --- beaconclient/mock_beacon_instance.go | 4 +- beaconclient/mock_multi_beacon_client.go | 4 +- beaconclient/multi_beacon_client.go | 22 ++++-- beaconclient/prod_beacon_instance.go | 4 +- common/types.go | 90 ------------------------ common/types_spec.go | 4 +- database/database.go | 5 +- database/database_test.go | 3 +- database/mockdb.go | 3 +- go.mod | 2 +- go.sum | 4 +- 11 files changed, 34 insertions(+), 111 deletions(-) diff --git a/beaconclient/mock_beacon_instance.go b/beaconclient/mock_beacon_instance.go index 1b36faf8..d5804879 100644 --- a/beaconclient/mock_beacon_instance.go +++ b/beaconclient/mock_beacon_instance.go @@ -4,8 +4,8 @@ import ( "sync" "time" + "github.com/attestantio/go-eth2-client/spec" "github.com/flashbots/go-boost-utils/types" - "github.com/flashbots/mev-boost-relay/common" ) type MockBeaconInstance struct { @@ -107,7 +107,7 @@ func (c *MockBeaconInstance) addDelay() { } } -func (c *MockBeaconInstance) PublishBlock(block *common.SignedBeaconBlock) (code int, err error) { +func (c *MockBeaconInstance) PublishBlock(block *spec.VersionedSignedBeaconBlock) (code int, err error) { return 0, nil } diff --git a/beaconclient/mock_multi_beacon_client.go b/beaconclient/mock_multi_beacon_client.go index db8e7b36..4efacf14 100644 --- a/beaconclient/mock_multi_beacon_client.go +++ b/beaconclient/mock_multi_beacon_client.go @@ -1,8 +1,8 @@ package beaconclient import ( + "github.com/attestantio/go-eth2-client/spec" "github.com/attestantio/go-eth2-client/spec/capella" - "github.com/flashbots/mev-boost-relay/common" ) type MockMultiBeaconClient struct{} @@ -32,7 +32,7 @@ func (*MockMultiBeaconClient) GetProposerDuties(epoch uint64) (*ProposerDutiesRe return nil, nil } -func (*MockMultiBeaconClient) PublishBlock(block *common.SignedBeaconBlock) (code int, err error) { +func (*MockMultiBeaconClient) PublishBlock(block *spec.VersionedSignedBeaconBlock) (code int, err error) { return 0, nil } diff --git a/beaconclient/multi_beacon_client.go b/beaconclient/multi_beacon_client.go index 5ae80969..36a6f3a1 100644 --- a/beaconclient/multi_beacon_client.go +++ b/beaconclient/multi_beacon_client.go @@ -8,7 +8,7 @@ import ( "strings" "sync" - "github.com/flashbots/mev-boost-relay/common" + "github.com/attestantio/go-eth2-client/spec" "github.com/sirupsen/logrus" uberatomic "go.uber.org/atomic" ) @@ -30,7 +30,7 @@ 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 *spec.VersionedSignedBeaconBlock) (code int, err error) GetGenesis() (*GetGenesisResponse, error) GetSpec() (spec *GetSpecResponse, err error) GetForkSchedule() (spec *GetForkScheduleResponse, err error) @@ -48,7 +48,7 @@ type IBeaconInstance interface { GetStateValidators(stateID string) (*GetStateValidatorsResponse, error) GetProposerDuties(epoch uint64) (*ProposerDutiesResponse, error) GetURI() string - PublishBlock(block *common.SignedBeaconBlock) (code int, err error) + PublishBlock(block *spec.VersionedSignedBeaconBlock) (code int, err error) GetGenesis() (*GetGenesisResponse, error) GetSpec() (spec *GetSpecResponse, err error) GetForkSchedule() (spec *GetForkScheduleResponse, err error) @@ -228,10 +228,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 *spec.VersionedSignedBeaconBlock) (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.BlockHash() + 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() diff --git a/beaconclient/prod_beacon_instance.go b/beaconclient/prod_beacon_instance.go index f491d4da..db1a4aea 100644 --- a/beaconclient/prod_beacon_instance.go +++ b/beaconclient/prod_beacon_instance.go @@ -6,9 +6,9 @@ import ( "net/http" "time" + "github.com/attestantio/go-eth2-client/spec" "github.com/attestantio/go-eth2-client/spec/capella" "github.com/flashbots/go-boost-utils/types" - "github.com/flashbots/mev-boost-relay/common" "github.com/r3labs/sse/v2" "github.com/sirupsen/logrus" ) @@ -256,7 +256,7 @@ func (c *ProdBeaconInstance) GetURI() string { return c.beaconURI } -func (c *ProdBeaconInstance) PublishBlock(block *common.SignedBeaconBlock) (code int, err error) { +func (c *ProdBeaconInstance) PublishBlock(block *spec.VersionedSignedBeaconBlock) (code int, err error) { uri := fmt.Sprintf("%s/eth/v1/beacon/blocks", c.beaconURI) return fetchBeacon(http.MethodPost, uri, block, nil, nil) } diff --git a/common/types.go b/common/types.go index d3757bfa..344f901b 100644 --- a/common/types.go +++ b/common/types.go @@ -10,7 +10,6 @@ import ( "github.com/attestantio/go-builder-client/api" "github.com/attestantio/go-builder-client/api/capella" apiv1 "github.com/attestantio/go-builder-client/api/v1" - "github.com/attestantio/go-builder-client/spec" 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" @@ -272,31 +271,6 @@ func (b *BidTraceV2WithTimestampJSON) ToCSVRecord() []string { } } -type SignedBeaconBlock struct { - Capella *consensuscapella.SignedBeaconBlock -} - -func (s *SignedBeaconBlock) MarshalJSON() ([]byte, error) { - if s.Capella != nil { - return json.Marshal(s.Capella) - } - return nil, ErrEmptyPayload -} - -func (s *SignedBeaconBlock) Slot() uint64 { - if s.Capella != nil { - return uint64(s.Capella.Message.Slot) - } - return 0 -} - -func (s *SignedBeaconBlock) BlockHash() string { - if s.Capella != nil { - return s.Capella.Message.Body.ExecutionPayload.BlockHash.String() - } - return "" -} - type BuilderSubmitBlockRequest struct { Capella *capella.SubmitBlockRequest } @@ -455,70 +429,6 @@ func (b *BuilderSubmitBlockRequest) Message() *apiv1.BidTrace { return nil } -type GetHeaderResponse struct { - Bellatrix *boostTypes.GetHeaderResponse - Capella *spec.VersionedSignedBuilderBid -} - -func (p *GetHeaderResponse) UnmarshalJSON(data []byte) error { - capella := new(spec.VersionedSignedBuilderBid) - err := json.Unmarshal(data, capella) - if err == nil && capella.Capella != nil { - p.Capella = capella - return nil - } - bellatrix := new(boostTypes.GetHeaderResponse) - err = json.Unmarshal(data, bellatrix) - if err != nil { - return err - } - p.Bellatrix = bellatrix - return nil -} - -func (p *GetHeaderResponse) MarshalJSON() ([]byte, error) { - if p.Capella != nil { - return json.Marshal(p.Capella) - } - if p.Bellatrix != nil { - return json.Marshal(p.Bellatrix) - } - return nil, ErrEmptyPayload -} - -func (p *GetHeaderResponse) Value() *big.Int { - if p.Capella != nil { - return p.Capella.Capella.Message.Value.ToBig() - } - if p.Bellatrix != nil { - return p.Bellatrix.Data.Message.Value.BigInt() - } - return nil -} - -func (p *GetHeaderResponse) BlockHash() phase0.Hash32 { - if p.Capella != nil { - return p.Capella.Capella.Message.Header.BlockHash - } - if p.Bellatrix != nil { - return phase0.Hash32(p.Bellatrix.Data.Message.Header.BlockHash) - } - return phase0.Hash32{} -} - -func (p *GetHeaderResponse) Empty() bool { - if p == nil { - return true - } - if p.Capella != nil { - return p.Capella.Capella == nil || p.Capella.Capella.Message == nil - } - if p.Bellatrix != nil { - return p.Bellatrix.Data == nil || p.Bellatrix.Data.Message == nil - } - return true -} - func (b *BuilderSubmitBlockRequest) Withdrawals() []*consensuscapella.Withdrawal { if b.Capella != nil { return b.Capella.ExecutionPayload.Withdrawals diff --git a/common/types_spec.go b/common/types_spec.go index 8a6248d9..e37cb955 100644 --- a/common/types_spec.go +++ b/common/types_spec.go @@ -148,8 +148,8 @@ func CapellaPayloadToPayloadHeader(p *consensuscapella.ExecutionPayload) (*conse }, nil } -func SignedBlindedBeaconBlockToBeaconBlock(signedBlindedBeaconBlock *consensusapi.VersionedSignedBlindedBeaconBlock, executionPayload *api.VersionedExecutionPayload) *SignedBeaconBlock { - var signedBeaconBlock SignedBeaconBlock +func SignedBlindedBeaconBlockToBeaconBlock(signedBlindedBeaconBlock *consensusapi.VersionedSignedBlindedBeaconBlock, executionPayload *api.VersionedExecutionPayload) *consensusspec.VersionedSignedBeaconBlock { + var signedBeaconBlock consensusspec.VersionedSignedBeaconBlock capellaBlindedBlock := signedBlindedBeaconBlock.Capella if capellaBlindedBlock != nil { signedBeaconBlock.Capella = &consensuscapella.SignedBeaconBlock{ diff --git a/database/database.go b/database/database.go index 95e48ed4..afdac7b6 100644 --- a/database/database.go +++ b/database/database.go @@ -10,6 +10,7 @@ import ( "time" consensusapi "github.com/attestantio/go-eth2-client/api" + "github.com/attestantio/go-eth2-client/spec" "github.com/flashbots/go-boost-utils/types" "github.com/flashbots/mev-boost-relay/common" "github.com/flashbots/mev-boost-relay/database/migrations" @@ -49,7 +50,7 @@ type IDatabaseService interface { IncBlockBuilderStatsAfterGetPayload(builderPubkey string) error InsertBuilderDemotion(submitBlockRequest *common.BuilderSubmitBlockRequest, simError error) error - UpdateBuilderDemotion(trace *common.BidTraceV2, signedBlock *common.SignedBeaconBlock, signedRegistration *types.SignedValidatorRegistration) error + UpdateBuilderDemotion(trace *common.BidTraceV2, signedBlock *spec.VersionedSignedBeaconBlock, signedRegistration *types.SignedValidatorRegistration) error GetBuilderDemotion(trace *common.BidTraceV2) (*BuilderDemotionEntry, error) GetTooLateGetPayload(slot uint64) (entries []*TooLateGetPayloadEntry, err error) @@ -566,7 +567,7 @@ func (s *DatabaseService) InsertBuilderDemotion(submitBlockRequest *common.Build return err } -func (s *DatabaseService) UpdateBuilderDemotion(trace *common.BidTraceV2, signedBlock *common.SignedBeaconBlock, signedRegistration *types.SignedValidatorRegistration) error { +func (s *DatabaseService) UpdateBuilderDemotion(trace *common.BidTraceV2, signedBlock *spec.VersionedSignedBeaconBlock, signedRegistration *types.SignedValidatorRegistration) error { _signedBeaconBlock, err := json.Marshal(signedBlock) if err != nil { return err diff --git a/database/database_test.go b/database/database_test.go index 3679a3a1..3381d4e5 100644 --- a/database/database_test.go +++ b/database/database_test.go @@ -8,6 +8,7 @@ import ( "time" v1 "github.com/attestantio/go-builder-client/api/v1" + "github.com/attestantio/go-eth2-client/spec" "github.com/attestantio/go-eth2-client/spec/bellatrix" consensuscapella "github.com/attestantio/go-eth2-client/spec/capella" "github.com/attestantio/go-eth2-client/spec/phase0" @@ -354,7 +355,7 @@ func TestUpdateBuilderDemotion(t *testing.T) { require.Empty(t, demotion.SignedValidatorRegistration.String) // Update demotion with the signedBlock and signedRegistration. - bb := &common.SignedBeaconBlock{ + bb := &spec.VersionedSignedBeaconBlock{ Capella: &consensuscapella.SignedBeaconBlock{}, } err = db.UpdateBuilderDemotion(bt, bb, &types.SignedValidatorRegistration{}) diff --git a/database/mockdb.go b/database/mockdb.go index 0708e7f8..5679b242 100644 --- a/database/mockdb.go +++ b/database/mockdb.go @@ -6,6 +6,7 @@ import ( "time" consensusapi "github.com/attestantio/go-eth2-client/api" + "github.com/attestantio/go-eth2-client/spec" "github.com/flashbots/go-boost-utils/types" "github.com/flashbots/mev-boost-relay/common" ) @@ -160,7 +161,7 @@ func (db MockDB) InsertBuilderDemotion(submitBlockRequest *common.BuilderSubmitB return nil } -func (db MockDB) UpdateBuilderDemotion(trace *common.BidTraceV2, signedBlock *common.SignedBeaconBlock, signedRegistration *types.SignedValidatorRegistration) error { +func (db MockDB) UpdateBuilderDemotion(trace *common.BidTraceV2, signedBlock *spec.VersionedSignedBeaconBlock, signedRegistration *types.SignedValidatorRegistration) error { pubkey := trace.BuilderPubkey.String() _, ok := db.Builders[pubkey] if !ok { diff --git a/go.mod b/go.mod index ffce0b8c..29f86f30 100644 --- a/go.mod +++ b/go.mod @@ -115,4 +115,4 @@ retract ( v1.0.0-alpha1 ) -replace github.com/attestantio/go-eth2-client => github.com/avalonche/go-eth2-client v0.0.0-20230720050755-dfcc05c7f873 +replace github.com/attestantio/go-eth2-client => github.com/avalonche/go-eth2-client v0.0.0-20230720061256-82081347600e diff --git a/go.sum b/go.sum index d23fd27c..103908bc 100644 --- a/go.sum +++ b/go.sum @@ -24,8 +24,8 @@ github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= 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/avalonche/go-eth2-client v0.0.0-20230720061256-82081347600e h1:WhEhbE/udrh+M8MltkFhXy4BCTB+Q3ubinTdTidt10I= +github.com/avalonche/go-eth2-client v0.0.0-20230720061256-82081347600e/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=