From bdd8c3a9afc94bc27c3e64cbd7aa5acc5701ff5a Mon Sep 17 00:00:00 2001 From: Jimmy Hu Date: Mon, 15 Apr 2019 22:24:30 +0800 Subject: vendor: sync to latest core --- .../dexon-consensus/core/agreement-mgr.go | 38 +++++++++++++------- .../dexon-consensus/core/agreement.go | 40 +++++++++++++++------ .../dexon-consensus/core/consensus.go | 15 ++++---- vendor/vendor.json | 42 +++++++++++----------- 4 files changed, 84 insertions(+), 51 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) { diff --git a/vendor/vendor.json b/vendor/vendor.json index 3480eec30..3f5d3792e 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -141,16 +141,16 @@ { "checksumSHA1": "In6vBHYUsX7DUIGiFN2hQggBgvI=", "path": "github.com/dexon-foundation/dexon-consensus/common", - "revision": "e9a1d3bca8353ee206d262ab1fad2d7e3e0b24a5", - "revisionTime": "2019-04-15T04:12:22Z", + "revision": "ccba7be9105c01eba0617e5ec0a791436200a132", + "revisionTime": "2019-04-15T10:50:35Z", "version": "master", "versionExact": "master" }, { - "checksumSHA1": "1RGs5z/8Kq82E69C8aRUAZT3U24=", + "checksumSHA1": "Uc+4k6fJSR3wZ4R4gZBnoBrZHq8=", "path": "github.com/dexon-foundation/dexon-consensus/core", - "revision": "e9a1d3bca8353ee206d262ab1fad2d7e3e0b24a5", - "revisionTime": "2019-04-15T04:12:22Z", + "revision": "ccba7be9105c01eba0617e5ec0a791436200a132", + "revisionTime": "2019-04-15T10:50:35Z", "version": "master", "versionExact": "master" }, @@ -165,64 +165,64 @@ { "checksumSHA1": "tQSbYCu5P00lUhKsx3IbBZCuSLY=", "path": "github.com/dexon-foundation/dexon-consensus/core/crypto", - "revision": "e9a1d3bca8353ee206d262ab1fad2d7e3e0b24a5", - "revisionTime": "2019-04-15T04:12:22Z", + "revision": "ccba7be9105c01eba0617e5ec0a791436200a132", + "revisionTime": "2019-04-15T10:50:35Z", "version": "master", "versionExact": "master" }, { "checksumSHA1": "4besQaa0rm8jRUAJjpEaLZ/ZOYs=", "path": "github.com/dexon-foundation/dexon-consensus/core/crypto/dkg", - "revision": "e9a1d3bca8353ee206d262ab1fad2d7e3e0b24a5", - "revisionTime": "2019-04-15T04:12:22Z", + "revision": "ccba7be9105c01eba0617e5ec0a791436200a132", + "revisionTime": "2019-04-15T10:50:35Z", "version": "master", "versionExact": "master" }, { "checksumSHA1": "BhLKK8RveoLaeXc9UyUKMwQqchU=", "path": "github.com/dexon-foundation/dexon-consensus/core/crypto/ecdsa", - "revision": "e9a1d3bca8353ee206d262ab1fad2d7e3e0b24a5", - "revisionTime": "2019-04-15T04:12:22Z", + "revision": "ccba7be9105c01eba0617e5ec0a791436200a132", + "revisionTime": "2019-04-15T10:50:35Z", "version": "master", "versionExact": "master" }, { "checksumSHA1": "3Ludp/1V4dMBZH/c1oIVjHj0CqY=", "path": "github.com/dexon-foundation/dexon-consensus/core/db", - "revision": "e9a1d3bca8353ee206d262ab1fad2d7e3e0b24a5", - "revisionTime": "2019-04-15T04:12:22Z", + "revision": "ccba7be9105c01eba0617e5ec0a791436200a132", + "revisionTime": "2019-04-15T10:50:35Z", "version": "master", "versionExact": "master" }, { "checksumSHA1": "sO5twEFTdLvkMuQo+I3vyzm9T3o=", "path": "github.com/dexon-foundation/dexon-consensus/core/syncer", - "revision": "e9a1d3bca8353ee206d262ab1fad2d7e3e0b24a5", - "revisionTime": "2019-04-15T04:12:22Z", + "revision": "ccba7be9105c01eba0617e5ec0a791436200a132", + "revisionTime": "2019-04-15T10:50:35Z", "version": "master", "versionExact": "master" }, { "checksumSHA1": "0BY+E0E2cM7IHIMqunXwoolDS5Y=", "path": "github.com/dexon-foundation/dexon-consensus/core/types", - "revision": "e9a1d3bca8353ee206d262ab1fad2d7e3e0b24a5", - "revisionTime": "2019-04-15T04:12:22Z", + "revision": "ccba7be9105c01eba0617e5ec0a791436200a132", + "revisionTime": "2019-04-15T10:50:35Z", "version": "master", "versionExact": "master" }, { "checksumSHA1": "yEPSfn48GaJmDbd2OFY+QRhjJ0w=", "path": "github.com/dexon-foundation/dexon-consensus/core/types/dkg", - "revision": "e9a1d3bca8353ee206d262ab1fad2d7e3e0b24a5", - "revisionTime": "2019-04-15T04:12:22Z", + "revision": "ccba7be9105c01eba0617e5ec0a791436200a132", + "revisionTime": "2019-04-15T10:50:35Z", "version": "master", "versionExact": "master" }, { "checksumSHA1": "7Ib134BAyLF1M/kREou4Zm7UUS4=", "path": "github.com/dexon-foundation/dexon-consensus/core/utils", - "revision": "e9a1d3bca8353ee206d262ab1fad2d7e3e0b24a5", - "revisionTime": "2019-04-15T04:12:22Z", + "revision": "ccba7be9105c01eba0617e5ec0a791436200a132", + "revisionTime": "2019-04-15T10:50:35Z", "version": "master", "versionExact": "master" }, -- cgit