• R/O
  • HTTP
  • SSH
  • HTTPS

vapor: コミット

Golang implemented sidechain for Bytom


コミットメタ情報

リビジョンb6fae706ce8a41f2c805566e076a69894d805a20 (tree)
日時2019-06-05 12:27:02
作者paladz <453256728@qq.c...>
コミッターpaladz

ログメッセージ

edit for code review

変更サマリ

差分

--- a/protocol/consensus_node_manager.go
+++ b/protocol/consensus_node_manager.go
@@ -92,7 +92,7 @@ func (c *consensusNodeManager) getConsensusNodes(prevBlockHash *bc.Hash) (map[st
9292 seqHeight = bestHeight
9393 }
9494
95- preSeq := (seqHeight - 1) / consensus.RoundVoteBlockNums
95+ preSeq := state.CalcVoteSeq(seqHeight) - 1
9696 voteResult, err := c.store.GetVoteResult(preSeq)
9797 if err != nil {
9898 return nil, err
@@ -115,11 +115,7 @@ func (c *consensusNodeManager) getConsensusNodes(prevBlockHash *bc.Hash) (map[st
115115
116116 func (c *consensusNodeManager) getBestVoteResult() (*state.VoteResult, error) {
117117 blockNode := c.blockIndex.BestNode()
118- if blockNode.Height == 0 {
119- return c.store.GetVoteResult(0)
120- }
121-
122- seq := (blockNode.Height-1)/consensus.RoundVoteBlockNums + 1
118+ seq := state.CalcVoteSeq(blockNode.Height)
123119 voteResult, err := c.store.GetVoteResult(seq)
124120 if err != nil {
125121 return nil, err
--- a/protocol/state/vote_result.go
+++ b/protocol/state/vote_result.go
@@ -32,6 +32,12 @@ func (c byVote) Swap(i, j int) { c[i], c[j] = c[j], c[i] }
3232 // seq 1 is the the block height 1, to block height RoundVoteBlockNums
3333 // seq 2 is the block height RoundVoteBlockNums + 1 to block height 2 * RoundVoteBlockNums
3434 // consensus node of the current round is the final result of previous round
35+func CalcVoteSeq(blockHeight uint64) uint64 {
36+ if blockHeight == 0 {
37+ return 0
38+ }
39+ return (blockHeight-1)/consensus.RoundVoteBlockNums + 1
40+}
3541
3642 // VoteResult represents a snapshot of each round of DPOS voting
3743 // Seq indicates the sequence of current votes, which start from zero
@@ -82,7 +88,7 @@ func (v *VoteResult) ApplyBlock(block *types.Block) error {
8288
8389 v.BlockHash = block.Hash()
8490 v.BlockHeight = block.Height
85- v.Seq = (block.Height-1)/consensus.RoundVoteBlockNums + 1
91+ v.Seq = CalcVoteSeq(block.Height)
8692 return nil
8793 }
8894
@@ -147,7 +153,7 @@ func (v *VoteResult) DetachBlock(block *types.Block) error {
147153
148154 v.BlockHash = block.PreviousBlockHash
149155 v.BlockHeight = block.Height - 1
150- v.Seq = (block.Height-2)/consensus.RoundVoteBlockNums + 1
156+ v.Seq = CalcVoteSeq(block.Height - 1)
151157 return nil
152158 }
153159
旧リポジトリブラウザで表示