[dpos] support single block verification
@@ -103,17 +103,19 @@ func New(cfg *config.Config, hub *component.ComponentHub, cdb consensus.ChainDB,
return nil, err
}
+ vprInitBlockNo := func(blockNo types.BlockNo) types.BlockNo {
+ if blockNo == 0 {
+ return blockNo
+ }
+ return blockNo - 1
+ }
+
// Initialize the voting power ranking.
- if !cfg.Blockchain.VerifyOnly {
- err = InitVPR(sdb.GetStateDB())
- } else {
- var block *types.Block
- if block, err = cdb.GetBlockByNo(0); err != nil {
+ if block, err := cdb.GetBlockByNo(vprInitBlockNo(cfg.Blockchain.VerifyBlock)); err != nil {
return nil, err
} else {
err = InitVprWithRoot(sdb, block.GetHeader().GetBlocksRootHash())
}
- }
if err != nil {
return nil, err
