Skip to content

Commit b1ff642

Browse files
committed
eth: minor sync polishes
1 parent 54a5b2f commit b1ff642

File tree

3 files changed

+14
-89
lines changed

3 files changed

+14
-89
lines changed

eth/backend.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,10 @@ func (s *Ethereum) SetSynced() { atomic.StoreUint32(&s.h
529529
func (s *Ethereum) ArchiveMode() bool { return s.config.NoPruning }
530530
func (s *Ethereum) BloomIndexer() *core.ChainIndexer { return s.bloomIndexer }
531531
func (s *Ethereum) Merger() *core.Merger { return s.merger }
532+
func (s *Ethereum) SyncMode() downloader.SyncMode {
533+
mode, _ := s.handler.chainSync.modeAndLocalHead()
534+
return mode
535+
}
532536

533537
// Protocols returns all the currently configured
534538
// network protocols to start.

eth/catalyst/api.go

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

218216
func (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
}

eth/catalyst/sync.go

Lines changed: 0 additions & 74 deletions
This file was deleted.

0 commit comments

Comments
 (0)