From 0317e871d4cacd74c8dfea142c52ec6ae91f2d84 Mon Sep 17 00:00:00 2001 From: Liam Date: Sun, 29 May 2022 11:28:08 +0200 Subject: [PATCH] add initial function during load latest block from db (#96) --- consensus/XDPoS/XDPoS.go | 9 +++++++++ core/blockchain.go | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/consensus/XDPoS/XDPoS.go b/consensus/XDPoS/XDPoS.go index c86a4d4957..342e754399 100644 --- a/consensus/XDPoS/XDPoS.go +++ b/consensus/XDPoS/XDPoS.go @@ -130,6 +130,15 @@ func NewFaker(db ethdb.Database, chainConfig *params.ChainConfig) *XDPoS { return fakeEngine } +func (x *XDPoS) Initial(chain consensus.ChainReader, header *types.Header) error { + switch x.config.BlockConsensusVersion(header.Number) { + case params.ConsensusEngineVersion2: + return x.EngineV2.Initial(chain, header) + default: // Default "v1" + return nil + } +} + /* Eth Consensus engine interface implementation */ diff --git a/core/blockchain.go b/core/blockchain.go index bb597cbb6b..c9f83bf72b 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -352,6 +352,13 @@ func (bc *BlockChain) loadLastState() error { } bc.hc.SetCurrentHeader(currentHeader) + if engine, ok := bc.Engine().(*XDPoS.XDPoS); ok { + err := engine.Initial(bc, currentHeader) + if err != nil { + return err + } + } + // Restore the last known head fast block bc.currentFastBlock.Store(currentBlock) if head := GetHeadFastBlockHash(bc.db); head != (common.Hash{}) {