Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove signed beacon block wrapper types #483

Merged
merged 1 commit into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions beaconclient/mock_beacon_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions beaconclient/mock_multi_beacon_client.go
Original file line number Diff line number Diff line change
@@ -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{}
Expand Down Expand Up @@ -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
}

Expand Down
22 changes: 16 additions & 6 deletions beaconclient/multi_beacon_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions beaconclient/prod_beacon_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
}
Expand Down
90 changes: 0 additions & 90 deletions common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions common/types_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
5 changes: 3 additions & 2 deletions database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion database/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{})
Expand Down
3 changes: 2 additions & 1 deletion database/mockdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
Loading