Skip to content

Commit

Permalink
Merge pull request #22 from karalabe/merge-interop-spec-sync3
Browse files Browse the repository at this point in the history
eth: minor sync polishes
  • Loading branch information
MariusVanDerWijden authored Oct 4, 2021
2 parents a094be5 + b1ff642 commit 716ff95
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 89 deletions.
4 changes: 4 additions & 0 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,10 @@ func (s *Ethereum) SetSynced() { atomic.StoreUint32(&s.h
func (s *Ethereum) ArchiveMode() bool { return s.config.NoPruning }
func (s *Ethereum) BloomIndexer() *core.ChainIndexer { return s.bloomIndexer }
func (s *Ethereum) Merger() *core.Merger { return s.merger }
func (s *Ethereum) SyncMode() downloader.SyncMode {
mode, _ := s.handler.chainSync.modeAndLocalHead()
return mode
}

// Protocols returns all the currently configured
// network protocols to start.
Expand Down
25 changes: 10 additions & 15 deletions eth/catalyst/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ type ConsensusAPI struct {
eth *eth.Ethereum
les *les.LightEthereum
engine consensus.Engine // engine is the post-merge consensus engine, only for block creation
syncer *syncer // syncer is responsible for triggering chain sync
preparedBlocks map[int]*ExecutableData
}

Expand Down Expand Up @@ -114,7 +113,6 @@ func NewConsensusAPI(eth *eth.Ethereum, les *les.LightEthereum) *ConsensusAPI {
eth: eth,
les: les,
engine: engine,
syncer: newSyncer(),
preparedBlocks: make(map[int]*ExecutableData),
}
}
Expand Down Expand Up @@ -217,11 +215,11 @@ func (api *ConsensusAPI) ConsensusValidated(params ConsensusValidatedParams) err

func (api *ConsensusAPI) ForkchoiceUpdated(params ForkChoiceParams) error {
var emptyHash = common.Hash{}
if !bytes.Equal(params.FinalizedBlockHash[:], emptyHash[:]) {
if err := api.checkTerminalTotalDifficulty(params.FinalizedBlockHash); err != nil {
if !bytes.Equal(params.HeadBlockHash[:], emptyHash[:]) {
if err := api.checkTerminalTotalDifficulty(params.HeadBlockHash); err != nil {
return err
}
return api.setHead(params.FinalizedBlockHash)
return api.setHead(params.HeadBlockHash)
}
return nil
}
Expand Down Expand Up @@ -249,22 +247,19 @@ func (api *ConsensusAPI) ExecutePayload(params ExecutableData) (GenericStringRes

td := api.eth.BlockChain().GetTdByHash(parent.Hash())
ttd := api.eth.BlockChain().Config().TerminalTotalDifficulty
if !api.eth.Synced() {
if td.Cmp(ttd) > 0 {
// first pos block
api.eth.SetSynced()
} else {
// TODO (MariusVanDerWijden) if the node is not synced and we received a finalized block
// we should trigger the reverse header sync here.
return SYNCING, errors.New("node is not synced yet")
}
} else if td.Cmp(ttd) < 0 {
if td.Cmp(ttd) < 0 {
return INVALID, fmt.Errorf("can not execute payload on top of block with low td got: %v threshold %v", td, ttd)
}
block, err := ExecutableDataToBlock(api.eth.BlockChain().Config(), parent.Header(), params)
if err != nil {
return INVALID, err
}
if !api.eth.BlockChain().HasBlock(block.ParentHash(), block.NumberU64()-1) {
if err := api.eth.Downloader().BeaconSync(api.eth.SyncMode(), block.Header()); err != nil {
return SYNCING, err
}
return SYNCING, nil
}
if err := api.eth.BlockChain().InsertBlock(block); err != nil {
return INVALID, err
}
Expand Down
74 changes: 0 additions & 74 deletions eth/catalyst/sync.go

This file was deleted.

0 comments on commit 716ff95

Please sign in to comment.