diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2018-10-26 13:22:29 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-26 13:22:29 +0800 |
commit | 721d36f2720b0cbf648cbffe40fd05c9a60061e4 (patch) | |
tree | 05d643695b20cc9f430869cf2105c177856625bc /core/agreement.go | |
parent | ef0df0e6e27acd3852f2e0efdccf0798d5fc63ad (diff) | |
download | tangerine-consensus-721d36f2720b0cbf648cbffe40fd05c9a60061e4.tar tangerine-consensus-721d36f2720b0cbf648cbffe40fd05c9a60061e4.tar.gz tangerine-consensus-721d36f2720b0cbf648cbffe40fd05c9a60061e4.tar.bz2 tangerine-consensus-721d36f2720b0cbf648cbffe40fd05c9a60061e4.tar.lz tangerine-consensus-721d36f2720b0cbf648cbffe40fd05c9a60061e4.tar.xz tangerine-consensus-721d36f2720b0cbf648cbffe40fd05c9a60061e4.tar.zst tangerine-consensus-721d36f2720b0cbf648cbffe40fd05c9a60061e4.zip |
core: Pull block (#263)
Diffstat (limited to 'core/agreement.go')
-rw-r--r-- | core/agreement.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/core/agreement.go b/core/agreement.go index 8618b5f..cc7af4f 100644 --- a/core/agreement.go +++ b/core/agreement.go @@ -69,6 +69,7 @@ type agreementReceiver interface { ProposeVote(vote *types.Vote) ProposeBlock() common.Hash ConfirmBlock(common.Hash, map[types.NodeID]*types.Vote) + PullBlocks(common.Hashes) } type pendingBlock struct { @@ -327,6 +328,21 @@ func (a *agreement) processVote(vote *types.Vote) error { // Condition 3. if vote.Type == types.VoteCom && vote.Period >= a.data.period && len(a.data.votes[vote.Period][types.VoteCom]) >= a.data.requiredVote { + hashes := common.Hashes{} + addPullBlocks := func(voteType types.VoteType) { + for _, vote := range a.data.votes[vote.Period][voteType] { + if vote.BlockHash == nullBlockHash || vote.BlockHash == skipBlockHash { + continue + } + if _, found := a.findCandidateBlock(vote.BlockHash); !found { + hashes = append(hashes, vote.BlockHash) + } + } + } + addPullBlocks(types.VoteInit) + addPullBlocks(types.VotePreCom) + addPullBlocks(types.VoteCom) + a.data.recv.PullBlocks(hashes) a.fastForward <- vote.Period + 1 return nil } |