seqHeight = bestHeight
}
- preSeq := (seqHeight - 1) / consensus.RoundVoteBlockNums
+ preSeq := state.CalcVoteSeq(seqHeight) - 1
voteResult, err := c.store.GetVoteResult(preSeq)
if err != nil {
return nil, err
func (c *consensusNodeManager) getBestVoteResult() (*state.VoteResult, error) {
blockNode := c.blockIndex.BestNode()
- if blockNode.Height == 0 {
- return c.store.GetVoteResult(0)
- }
-
- seq := (blockNode.Height-1)/consensus.RoundVoteBlockNums + 1
+ seq := state.CalcVoteSeq(blockNode.Height)
voteResult, err := c.store.GetVoteResult(seq)
if err != nil {
return nil, err
// seq 1 is the the block height 1, to block height RoundVoteBlockNums
// seq 2 is the block height RoundVoteBlockNums + 1 to block height 2 * RoundVoteBlockNums
// consensus node of the current round is the final result of previous round
+func CalcVoteSeq(blockHeight uint64) uint64 {
+ if blockHeight == 0 {
+ return 0
+ }
+ return (blockHeight-1)/consensus.RoundVoteBlockNums + 1
+}
// VoteResult represents a snapshot of each round of DPOS voting
// Seq indicates the sequence of current votes, which start from zero
v.BlockHash = block.Hash()
v.BlockHeight = block.Height
- v.Seq = (block.Height-1)/consensus.RoundVoteBlockNums + 1
+ v.Seq = CalcVoteSeq(block.Height)
return nil
}
v.BlockHash = block.PreviousBlockHash
v.BlockHeight = block.Height - 1
- v.Seq = (block.Height-2)/consensus.RoundVoteBlockNums + 1
+ v.Seq = CalcVoteSeq(block.Height - 1)
return nil
}