@@ -20,18 +20,14 @@ var (
2020 ErrBeaconBlock202 = errors .New ("beacon block failed validation but was still broadcast (202)" )
2121)
2222
23- type BroadcastMode int
23+ type BroadcastMode string
2424
2525const (
26- Gossip BroadcastMode = iota // lightweight gossip checks only
27- Consensus // full consensus checks, including validation of all signatures and blocks fields
28- ConsensusAndEquivocation // the same as `consensus`, with an extra equivocation check
26+ Gossip BroadcastMode = "gossip" // lightweight gossip checks only
27+ Consensus BroadcastMode = "consensus" // full consensus checks, including validation of all signatures and blocks fields
28+ ConsensusAndEquivocation BroadcastMode = "consensus_and_equivocation" // the same as `consensus`, with an extra equivocation check
2929)
3030
31- func (b BroadcastMode ) String () string {
32- return [... ]string {"gossip" , "consensus" , "consensus_and_equivocation" }[b ]
33- }
34-
3531// IMultiBeaconClient is the interface for the MultiBeaconClient, which can manage several beacon client instances under the hood
3632type IMultiBeaconClient interface {
3733 BestSyncStatus () (* SyncStatusPayloadData , error )
@@ -42,11 +38,10 @@ type IMultiBeaconClient interface {
4238 // GetStateValidators returns all active and pending validators from the beacon node
4339 GetStateValidators (stateID string ) (* GetStateValidatorsResponse , error )
4440 GetProposerDuties (epoch uint64 ) (* ProposerDutiesResponse , error )
45- PublishBlock (block * common.SignedBeaconBlock ) (code int , err error )
41+ PublishBlock (block * common.VersionedSignedProposal ) (code int , err error )
4642 GetGenesis () (* GetGenesisResponse , error )
4743 GetSpec () (spec * GetSpecResponse , err error )
4844 GetForkSchedule () (spec * GetForkScheduleResponse , err error )
49- GetBlock (blockID string ) (block * GetBlockResponse , err error )
5045 GetRandao (slot uint64 ) (spec * GetRandaoResponse , err error )
5146 GetWithdrawals (slot uint64 ) (spec * GetWithdrawalsResponse , err error )
5247}
@@ -60,11 +55,10 @@ type IBeaconInstance interface {
6055 GetStateValidators (stateID string ) (* GetStateValidatorsResponse , error )
6156 GetProposerDuties (epoch uint64 ) (* ProposerDutiesResponse , error )
6257 GetURI () string
63- PublishBlock (block * common.SignedBeaconBlock , broadcastMode BroadcastMode ) (code int , err error )
58+ PublishBlock (block * common.VersionedSignedProposal , broadcastMode BroadcastMode ) (code int , err error )
6459 GetGenesis () (* GetGenesisResponse , error )
6560 GetSpec () (spec * GetSpecResponse , err error )
6661 GetForkSchedule () (spec * GetForkScheduleResponse , err error )
67- GetBlock (blockID string ) (* GetBlockResponse , error )
6862 GetRandao (slot uint64 ) (spec * GetRandaoResponse , err error )
6963 GetWithdrawals (slot uint64 ) (spec * GetWithdrawalsResponse , err error )
7064}
@@ -99,10 +93,10 @@ func NewMultiBeaconClient(log *logrus.Entry, beaconInstances []IBeaconInstance)
9993 if broadcastModeStr != "" {
10094 broadcastMode , ok := parseBroadcastModeString (broadcastModeStr )
10195 if ! ok {
102- msg := fmt .Sprintf ("env: BROADCAST_MODE: invalid value %s, leaving to default value %s" , broadcastModeStr , client .broadcastMode . String () )
96+ msg := fmt .Sprintf ("env: BROADCAST_MODE: invalid value %s, leaving to default value %s" , broadcastModeStr , client .broadcastMode )
10397 client .log .Warn (msg )
10498 } else {
105- client .log .Info (fmt .Sprintf ("env: BROADCAST_MODE: setting mode to %s" , broadcastMode . String () ))
99+ client .log .Info (fmt .Sprintf ("env: BROADCAST_MODE: setting mode to %s" , broadcastMode ))
106100 client .broadcastMode = broadcastMode
107101 }
108102 }
@@ -255,10 +249,20 @@ type publishResp struct {
255249}
256250
257251// PublishBlock publishes the signed beacon block via https://ethereum.github.io/beacon-APIs/#/ValidatorRequiredApi/publishBlock
258- func (c * MultiBeaconClient ) PublishBlock (block * common.SignedBeaconBlock ) (code int , err error ) {
252+ func (c * MultiBeaconClient ) PublishBlock (block * common.VersionedSignedProposal ) (code int , err error ) {
253+ slot , err := block .Slot ()
254+ if err != nil {
255+ c .log .WithError (err ).Warn ("failed to publish block as block slot is missing" )
256+ return 0 , err
257+ }
258+ blockHash , err := block .ExecutionBlockHash ()
259+ if err != nil {
260+ c .log .WithError (err ).Warn ("failed to publish block as block hash is missing" )
261+ return 0 , err
262+ }
259263 log := c .log .WithFields (logrus.Fields {
260- "slot" : block . Slot () ,
261- "blockHash" : block . BlockHash (),
264+ "slot" : slot ,
265+ "blockHash" : blockHash . String (),
262266 })
263267
264268 clients := c .beaconInstancesByLastResponse ()
@@ -360,23 +364,6 @@ func (c *MultiBeaconClient) GetForkSchedule() (spec *GetForkScheduleResponse, er
360364 return nil , err
361365}
362366
363- // GetBlock returns a block - https://ethereum.github.io/beacon-APIs/#/Beacon/getBlockV2
364- func (c * MultiBeaconClient ) GetBlock (blockID string ) (block * GetBlockResponse , err error ) {
365- clients := c .beaconInstancesByLastResponse ()
366- for _ , client := range clients {
367- log := c .log .WithField ("uri" , client .GetURI ())
368- if block , err = client .GetBlock (blockID ); err != nil {
369- log .WithField ("blockID" , blockID ).WithError (err ).Warn ("failed to get block" )
370- continue
371- }
372-
373- return block , nil
374- }
375-
376- c .log .WithField ("blockID" , blockID ).WithError (err ).Error ("failed to get block from any CL node" )
377- return nil , err
378- }
379-
380367// GetRandao - 3500/eth/v1/beacon/states/<slot>/randao
381368func (c * MultiBeaconClient ) GetRandao (slot uint64 ) (randaoResp * GetRandaoResponse , err error ) {
382369 clients := c .beaconInstancesByLastResponse ()
0 commit comments