aboutsummaryrefslogtreecommitdiffstats
path: root/core/agreement.go
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2018-10-26 15:38:43 +0800
committerGitHub <noreply@github.com>2018-10-26 15:38:43 +0800
commit12f7924d4e2496bb336131c4917d45c5bd6b414b (patch)
tree690cf95993ea68ee1b18075a3e03bda0d2b41aa7 /core/agreement.go
parentef9575062f5ec6a36b30efb5064c0e3a442075fe (diff)
downloaddexon-consensus-12f7924d4e2496bb336131c4917d45c5bd6b414b.tar
dexon-consensus-12f7924d4e2496bb336131c4917d45c5bd6b414b.tar.gz
dexon-consensus-12f7924d4e2496bb336131c4917d45c5bd6b414b.tar.bz2
dexon-consensus-12f7924d4e2496bb336131c4917d45c5bd6b414b.tar.lz
dexon-consensus-12f7924d4e2496bb336131c4917d45c5bd6b414b.tar.xz
dexon-consensus-12f7924d4e2496bb336131c4917d45c5bd6b414b.tar.zst
dexon-consensus-12f7924d4e2496bb336131c4917d45c5bd6b414b.zip
core: sync BA (#264)
Diffstat (limited to 'core/agreement.go')
-rw-r--r--core/agreement.go21
1 files changed, 17 insertions, 4 deletions
diff --git a/core/agreement.go b/core/agreement.go
index cc7af4f..13f39ce 100644
--- a/core/agreement.go
+++ b/core/agreement.go
@@ -169,7 +169,9 @@ func (a *agreement) restart(
defer a.lock.Unlock()
newPendingBlock := make([]pendingBlock, 0)
for _, pending := range a.pendingBlock {
- if pending.block.Position == aID {
+ if aID.Newer(&pending.block.Position) {
+ continue
+ } else if pending.block.Position == aID {
replayBlock = append(replayBlock, pending.block)
} else if pending.receivedTime.After(expireTime) {
newPendingBlock = append(newPendingBlock, pending)
@@ -184,7 +186,9 @@ func (a *agreement) restart(
defer a.lock.Unlock()
newPendingVote := make([]pendingVote, 0)
for _, pending := range a.pendingVote {
- if pending.vote.Position == aID {
+ if aID.Newer(&pending.vote.Position) {
+ continue
+ } else if pending.vote.Position == aID {
replayVote = append(replayVote, pending.vote)
} else if pending.receivedTime.After(expireTime) {
newPendingVote = append(newPendingVote, pending)
@@ -273,7 +277,11 @@ func (a *agreement) processVote(vote *types.Vote) error {
if err := a.sanityCheck(vote); err != nil {
return err
}
- if vote.Position != a.agreementID() {
+ aID := a.agreementID()
+ if vote.Position != aID {
+ if aID.Newer(&vote.Position) {
+ return nil
+ }
a.lock.Lock()
defer a.lock.Unlock()
a.pendingVote = append(a.pendingVote, pendingVote{
@@ -372,7 +380,12 @@ func (a *agreement) done() <-chan struct{} {
func (a *agreement) processBlock(block *types.Block) error {
a.data.blocksLock.Lock()
defer a.data.blocksLock.Unlock()
- if block.Position != a.agreementID() {
+
+ aID := a.agreementID()
+ if block.Position != aID {
+ if aID.Newer(&block.Position) {
+ return nil
+ }
a.pendingBlock = append(a.pendingBlock, pendingBlock{
block: block,
receivedTime: time.Now().UTC(),