aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/dexon-foundation/dexon-consensus/core/agreement.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/dexon-foundation/dexon-consensus/core/agreement.go')
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/agreement.go40
1 files changed, 29 insertions, 11 deletions
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(),