aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/dexon-foundation/dexon-consensus
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/dexon-foundation/dexon-consensus')
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/agreement-mgr.go19
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/agreement.go17
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go2
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/leader-selector.go18
4 files changed, 36 insertions, 20 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 e468e9c2e..d3cf533c6 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
@@ -258,13 +258,20 @@ func (mgr *agreementMgr) processAgreementResult(
if isStop(aID) {
return nil
}
- if result.Position.Newer(&aID) {
+ if result.Position == aID {
mgr.logger.Info("Syncing BA", "position", &result.Position)
+ for key := range result.Votes {
+ if err := agreement.processVote(&result.Votes[key]); err != nil {
+ return err
+ }
+ }
+ } else if result.Position.Newer(&aID) {
+ mgr.logger.Info("Fast syncing BA", "position", &result.Position)
nodes, err := mgr.cache.GetNodeSet(result.Position.Round)
if err != nil {
return err
}
- mgr.logger.Debug("Calling Network.PullBlocks for syncing BA",
+ mgr.logger.Debug("Calling Network.PullBlocks for fast syncing BA",
"hash", result.BlockHash)
mgr.network.PullBlocks(common.Hashes{result.BlockHash})
mgr.logger.Debug("Calling Governance.CRS", "round", result.Position.Round)
@@ -459,16 +466,16 @@ Loop:
"round", recv.round(),
"chainID", setting.chainID)
err = nil
- nextHeight = oldPos.Height
+ nextHeight = restartPos.Height
}
- if isStop(oldPos) || nextHeight == 0 {
+ if isStop(restartPos) || nextHeight == 0 {
break
}
- if nextHeight > oldPos.Height {
+ if nextHeight > restartPos.Height {
break
}
mgr.logger.Debug("Lattice not ready!!!",
- "old", &oldPos, "next", nextHeight)
+ "old", &restartPos, "next", nextHeight)
time.Sleep(100 * time.Millisecond)
}
nextPos := types.Position{
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 62bbe250f..c17c59f8a 100644
--- a/vendor/github.com/dexon-foundation/dexon-consensus/core/agreement.go
+++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/agreement.go
@@ -545,17 +545,22 @@ func (a *agreement) addCandidateBlockNoLock(block *types.Block) {
a.candidateBlock[block.Hash] = block
}
-func (a *agreement) findCandidateBlock(hash common.Hash) (*types.Block, bool) {
- a.lock.RLock()
- defer a.lock.RUnlock()
- return a.findCandidateBlockNoLock(hash)
-}
-
func (a *agreement) findCandidateBlockNoLock(
hash common.Hash) (*types.Block, bool) {
b, e := a.candidateBlock[hash]
return b, e
}
+
+// find a block in both candidate blocks and pending blocks in leader-selector.
+// A block might be confirmed by others while we can't verify its validity.
+func (a *agreement) findBlockNoLock(hash common.Hash) (*types.Block, bool) {
+ b, e := a.findCandidateBlockNoLock(hash)
+ if !e {
+ b, e = a.data.leader.findPendingBlock(hash)
+ }
+ return b, e
+}
+
func (a *agreementData) countVote(period uint64, voteType types.VoteType) (
blockHash common.Hash, ok bool) {
a.lock.RLock()
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 0754e800f..b84947a86 100644
--- a/vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go
+++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go
@@ -137,7 +137,7 @@ func (recv *consensusBAReceiver) ConfirmBlock(
}
} else {
var exist bool
- block, exist = recv.agreementModule.findCandidateBlockNoLock(hash)
+ block, exist = recv.agreementModule.findBlockNoLock(hash)
if !exist {
recv.consensus.logger.Error("Unknown block confirmed",
"hash", hash.String()[:6],
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/leader-selector.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/leader-selector.go
index bcfa57fe6..214b4cb6e 100644
--- a/vendor/github.com/dexon-foundation/dexon-consensus/core/leader-selector.go
+++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/leader-selector.go
@@ -55,7 +55,7 @@ type leaderSelector struct {
numCRS *big.Int
minCRSBlock *big.Int
minBlockHash common.Hash
- pendingBlocks []*types.Block
+ pendingBlocks map[common.Hash]*types.Block
validLeader validLeaderFn
lock sync.Mutex
logger common.Logger
@@ -94,13 +94,12 @@ func (l *leaderSelector) restart(crs common.Hash) {
l.hashCRS = crs
l.minCRSBlock = maxHash
l.minBlockHash = common.Hash{}
- l.pendingBlocks = []*types.Block{}
+ l.pendingBlocks = make(map[common.Hash]*types.Block)
}
func (l *leaderSelector) leaderBlockHash() common.Hash {
l.lock.Lock()
defer l.lock.Unlock()
- newPendingBlocks := []*types.Block{}
for _, b := range l.pendingBlocks {
ok, dist := l.potentialLeader(b)
if !ok {
@@ -109,15 +108,14 @@ func (l *leaderSelector) leaderBlockHash() common.Hash {
ok, err := l.validLeader(b)
if err != nil {
l.logger.Error("Error checking validLeader", "error", err, "block", b)
+ delete(l.pendingBlocks, b.Hash)
continue
}
if ok {
l.updateLeader(b, dist)
- } else {
- newPendingBlocks = append(newPendingBlocks, b)
+ delete(l.pendingBlocks, b.Hash)
}
}
- l.pendingBlocks = newPendingBlocks
return l.minBlockHash
}
@@ -140,7 +138,7 @@ func (l *leaderSelector) processBlock(block *types.Block) error {
return err
}
if !ok {
- l.pendingBlocks = append(l.pendingBlocks, block)
+ l.pendingBlocks[block.Hash] = block
return nil
}
l.updateLeader(block, dist)
@@ -157,3 +155,9 @@ func (l *leaderSelector) updateLeader(block *types.Block, dist *big.Int) {
l.minCRSBlock = dist
l.minBlockHash = block.Hash
}
+
+func (l *leaderSelector) findPendingBlock(
+ hash common.Hash) (*types.Block, bool) {
+ b, e := l.pendingBlocks[hash]
+ return b, e
+}