diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2019-04-15 22:24:30 +0800 |
---|---|---|
committer | Jimmy Hu <jimmy.hu@dexon.org> | 2019-04-15 22:24:30 +0800 |
commit | 6b281056b53dc8289146af605c81dd4465a1f797 (patch) | |
tree | da7ba21907a33db3f9fa0ec2697f9083e83dc35f /vendor/github.com/dexon-foundation/dexon-consensus | |
parent | 1aca2eff39c55afd5e56123bd6a5b92e6e628b2b (diff) | |
download | dexon-6b281056b53dc8289146af605c81dd4465a1f797.tar dexon-6b281056b53dc8289146af605c81dd4465a1f797.tar.gz dexon-6b281056b53dc8289146af605c81dd4465a1f797.tar.bz2 dexon-6b281056b53dc8289146af605c81dd4465a1f797.tar.lz dexon-6b281056b53dc8289146af605c81dd4465a1f797.tar.xz dexon-6b281056b53dc8289146af605c81dd4465a1f797.tar.zst dexon-6b281056b53dc8289146af605c81dd4465a1f797.zip |
vendor: sync to latest core
Diffstat (limited to 'vendor/github.com/dexon-foundation/dexon-consensus')
3 files changed, 63 insertions, 30 deletions
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/agreement-mgr.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/agreement-mgr.go index f65903d25..17def6747 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus/core/agreement-mgr.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/agreement-mgr.go @@ -271,34 +271,48 @@ func (mgr *agreementMgr) notifyRoundEvents(evts []utils.RoundEventParam) error { return nil } -func (mgr *agreementMgr) processVote(v *types.Vote) (err error) { - if !mgr.recv.isNotary { - return nil - } - if mgr.voteFilter.Filter(v) { - return nil - } - if v.Position.Round == mgr.curRoundSetting.round { - if _, exist := mgr.curRoundSetting.dkgSet[v.ProposerID]; !exist { +func (mgr *agreementMgr) checkProposer( + round uint64, proposerID types.NodeID) error { + if round == mgr.curRoundSetting.round { + if _, exist := mgr.curRoundSetting.dkgSet[proposerID]; !exist { return ErrNotInNotarySet } - } else if v.Position.Round == mgr.curRoundSetting.round+1 { - setting := mgr.generateSetting(v.Position.Round) + } else if round == mgr.curRoundSetting.round+1 { + setting := mgr.generateSetting(round) if setting == nil { return ErrConfigurationNotReady } - if _, exist := setting.dkgSet[v.ProposerID]; !exist { + if _, exist := setting.dkgSet[proposerID]; !exist { return ErrNotInNotarySet } } + return nil +} + +func (mgr *agreementMgr) processVote(v *types.Vote) (err error) { + if !mgr.recv.isNotary { + return nil + } + if mgr.voteFilter.Filter(v) { + return nil + } + if err := mgr.checkProposer(v.Position.Round, v.ProposerID); err != nil { + return err + } if err = mgr.baModule.processVote(v); err == nil { mgr.baModule.updateFilter(mgr.voteFilter) mgr.voteFilter.AddVote(v) } + if err == ErrSkipButNoError { + err = nil + } return } func (mgr *agreementMgr) processBlock(b *types.Block) error { + if err := mgr.checkProposer(b.Position.Round, b.ProposerID); err != nil { + return err + } return mgr.baModule.processBlock(b) } diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/agreement.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/agreement.go index cb467719d..22153948d 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus/core/agreement.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/agreement.go @@ -85,7 +85,7 @@ type agreementReceiver interface { PullBlocks(common.Hashes) ReportForkVote(v1, v2 *types.Vote) ReportForkBlock(b1, b2 *types.Block) - VerifyPartialSignature(vote *types.Vote) bool + VerifyPartialSignature(vote *types.Vote) (bool, bool) } type pendingBlock struct { @@ -372,8 +372,11 @@ func (a *agreement) sanityCheck(vote *types.Vote) error { // TODO(jimmy): maybe we can verify partial signature at agreement-mgr. return nil } - if !a.data.recv.VerifyPartialSignature(vote) { - return ErrIncorrectVotePartialSignature + if ok, report := a.data.recv.VerifyPartialSignature(vote); !ok { + if report { + return ErrIncorrectVotePartialSignature + } + return ErrSkipButNoError } return nil } @@ -637,19 +640,34 @@ func (a *agreement) confirmedNoLock() bool { // processBlock is the entry point for processing Block. func (a *agreement) processBlock(block *types.Block) error { + checkSkip := func() bool { + aID := a.agreementID() + if block.Position != aID { + // Agreement module has stopped. + if !isStop(aID) { + if aID.Newer(block.Position) { + return true + } + } + } + return false + } + if checkSkip() { + return nil + } + if err := utils.VerifyBlockSignature(block); err != nil { + return err + } + a.lock.Lock() defer a.lock.Unlock() a.data.blocksLock.Lock() defer a.data.blocksLock.Unlock() - aID := a.agreementID() - if block.Position != aID { - // Agreement module has stopped. - if !isStop(aID) { - if aID.Newer(block.Position) { - return nil - } - } + // a.agreementID might change during lock, so we need to checkSkip again. + if checkSkip() { + return nil + } else if aID != block.Position { a.pendingBlock = append(a.pendingBlock, pendingBlock{ block: block, receivedTime: time.Now().UTC(), diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go index ba7d8fd60..e7449c222 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go @@ -89,28 +89,29 @@ func (recv *consensusBAReceiver) emptyBlockHash(pos types.Position) ( return hash, nil } -func (recv *consensusBAReceiver) VerifyPartialSignature(vote *types.Vote) bool { +func (recv *consensusBAReceiver) VerifyPartialSignature(vote *types.Vote) ( + bool, bool) { if vote.Position.Round >= DKGDelayRound && vote.BlockHash != types.SkipBlockHash { if vote.Type == types.VoteCom || vote.Type == types.VoteFastCom { if recv.npks == nil { recv.consensus.logger.Debug( "Unable to verify psig, npks is nil", "vote", vote) - return false + return false, false } if vote.Position.Round != recv.npks.Round { recv.consensus.logger.Debug( "Unable to verify psig, round of npks mismatch", "vote", vote, "npksRound", recv.npks.Round) - return false + return false, false } pubKey, exist := recv.npks.PublicKeys[vote.ProposerID] if !exist { recv.consensus.logger.Debug( "Unable to verify psig, proposer is not qualified", "vote", vote) - return false + return false, true } blockHash := vote.BlockHash if blockHash == types.NullBlockHash { @@ -121,14 +122,14 @@ func (recv *consensusBAReceiver) VerifyPartialSignature(vote *types.Vote) bool { "Failed to verify vote for empty block", "position", vote.Position, "error", err) - return false + return false, true } } return pubKey.VerifySignature( - vote.BlockHash, crypto.Signature(vote.PartialSignature)) + blockHash, crypto.Signature(vote.PartialSignature)), true } } - return len(vote.PartialSignature.Signature) == 0 + return len(vote.PartialSignature.Signature) == 0, true } func (recv *consensusBAReceiver) ProposeVote(vote *types.Vote) { |