Skip to content

Commit 0317e87

Browse files
authored
add initial function during load latest block from db (ethereum#96)
1 parent 7effc71 commit 0317e87

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

consensus/XDPoS/XDPoS.go

+9
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,15 @@ func NewFaker(db ethdb.Database, chainConfig *params.ChainConfig) *XDPoS {
130130
return fakeEngine
131131
}
132132

133+
func (x *XDPoS) Initial(chain consensus.ChainReader, header *types.Header) error {
134+
switch x.config.BlockConsensusVersion(header.Number) {
135+
case params.ConsensusEngineVersion2:
136+
return x.EngineV2.Initial(chain, header)
137+
default: // Default "v1"
138+
return nil
139+
}
140+
}
141+
133142
/*
134143
Eth Consensus engine interface implementation
135144
*/

core/blockchain.go

+7
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,13 @@ func (bc *BlockChain) loadLastState() error {
352352
}
353353
bc.hc.SetCurrentHeader(currentHeader)
354354

355+
if engine, ok := bc.Engine().(*XDPoS.XDPoS); ok {
356+
err := engine.Initial(bc, currentHeader)
357+
if err != nil {
358+
return err
359+
}
360+
}
361+
355362
// Restore the last known head fast block
356363
bc.currentFastBlock.Store(currentBlock)
357364
if head := GetHeadFastBlockHash(bc.db); head != (common.Hash{}) {

0 commit comments

Comments
 (0)