@@ -84,7 +84,6 @@ type ConsensusAPI struct {
8484 eth * eth.Ethereum
8585 les * les.LightEthereum
8686 engine consensus.Engine // engine is the post-merge consensus engine, only for block creation
87- syncer * syncer // syncer is responsible for triggering chain sync
8887 preparedBlocks map [int ]* ExecutableData
8988}
9089
@@ -114,7 +113,6 @@ func NewConsensusAPI(eth *eth.Ethereum, les *les.LightEthereum) *ConsensusAPI {
114113 eth : eth ,
115114 les : les ,
116115 engine : engine ,
117- syncer : newSyncer (),
118116 preparedBlocks : make (map [int ]* ExecutableData ),
119117 }
120118}
@@ -217,11 +215,11 @@ func (api *ConsensusAPI) ConsensusValidated(params ConsensusValidatedParams) err
217215
218216func (api * ConsensusAPI ) ForkchoiceUpdated (params ForkChoiceParams ) error {
219217 var emptyHash = common.Hash {}
220- if ! bytes .Equal (params .FinalizedBlockHash [:], emptyHash [:]) {
221- if err := api .checkTerminalTotalDifficulty (params .FinalizedBlockHash ); err != nil {
218+ if ! bytes .Equal (params .HeadBlockHash [:], emptyHash [:]) {
219+ if err := api .checkTerminalTotalDifficulty (params .HeadBlockHash ); err != nil {
222220 return err
223221 }
224- return api .setHead (params .FinalizedBlockHash )
222+ return api .setHead (params .HeadBlockHash )
225223 }
226224 return nil
227225}
@@ -249,22 +247,19 @@ func (api *ConsensusAPI) ExecutePayload(params ExecutableData) (GenericStringRes
249247
250248 td := api .eth .BlockChain ().GetTdByHash (parent .Hash ())
251249 ttd := api .eth .BlockChain ().Config ().TerminalTotalDifficulty
252- if ! api .eth .Synced () {
253- if td .Cmp (ttd ) > 0 {
254- // first pos block
255- api .eth .SetSynced ()
256- } else {
257- // TODO (MariusVanDerWijden) if the node is not synced and we received a finalized block
258- // we should trigger the reverse header sync here.
259- return SYNCING , errors .New ("node is not synced yet" )
260- }
261- } else if td .Cmp (ttd ) < 0 {
250+ if td .Cmp (ttd ) < 0 {
262251 return INVALID , fmt .Errorf ("can not execute payload on top of block with low td got: %v threshold %v" , td , ttd )
263252 }
264253 block , err := ExecutableDataToBlock (api .eth .BlockChain ().Config (), parent .Header (), params )
265254 if err != nil {
266255 return INVALID , err
267256 }
257+ if ! api .eth .BlockChain ().HasBlock (block .ParentHash (), block .NumberU64 ()- 1 ) {
258+ if err := api .eth .Downloader ().BeaconSync (api .eth .SyncMode (), block .Header ()); err != nil {
259+ return SYNCING , err
260+ }
261+ return SYNCING , nil
262+ }
268263 if err := api .eth .BlockChain ().InsertBlock (block ); err != nil {
269264 return INVALID , err
270265 }
0 commit comments