From 721d36f2720b0cbf648cbffe40fd05c9a60061e4 Mon Sep 17 00:00:00 2001 From: Jimmy Hu Date: Fri, 26 Oct 2018 13:22:29 +0800 Subject: core: Pull block (#263) --- core/agreement.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'core/agreement.go') 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 } -- cgit v1.2.3