aboutsummaryrefslogtreecommitdiffstats
path: root/core/agreement.go
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2019-04-15 18:50:35 +0800
committerGitHub <noreply@github.com>2019-04-15 18:50:35 +0800
commitccba7be9105c01eba0617e5ec0a791436200a132 (patch)
tree4c88741f37be02d4bdd46695ecd3e2e52a9fbcee /core/agreement.go
parentd554efde81d4385158c039f906e213bcdfd0313b (diff)
downloaddexon-consensus-ccba7be9105c01eba0617e5ec0a791436200a132.tar
dexon-consensus-ccba7be9105c01eba0617e5ec0a791436200a132.tar.gz
dexon-consensus-ccba7be9105c01eba0617e5ec0a791436200a132.tar.bz2
dexon-consensus-ccba7be9105c01eba0617e5ec0a791436200a132.tar.lz
dexon-consensus-ccba7be9105c01eba0617e5ec0a791436200a132.tar.xz
dexon-consensus-ccba7be9105c01eba0617e5ec0a791436200a132.tar.zst
dexon-consensus-ccba7be9105c01eba0617e5ec0a791436200a132.zip
core: optimize handling for bad block (#574)
* core: optimize handling for bad block * fix test
Diffstat (limited to 'core/agreement.go')
-rw-r--r--core/agreement.go31
1 files changed, 23 insertions, 8 deletions
diff --git a/core/agreement.go b/core/agreement.go
index 7830af0..2215394 100644
--- a/core/agreement.go
+++ b/core/agreement.go
@@ -640,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(),