diff options
author | BJ4 <bojie@dexon.org> | 2018-11-02 18:09:57 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-04-09 21:32:52 +0800 |
commit | f2c37d5acc88d01ca4f786cfbfc8b32697ee620e (patch) | |
tree | b04a6a8418fba809f19a01a0ad3f7adcc8344751 /vendor/github.com/dexon-foundation/dexon-consensus | |
parent | 47910a53cbd851deb6f77d4f16f9f68d56d013d0 (diff) | |
download | dexon-f2c37d5acc88d01ca4f786cfbfc8b32697ee620e.tar dexon-f2c37d5acc88d01ca4f786cfbfc8b32697ee620e.tar.gz dexon-f2c37d5acc88d01ca4f786cfbfc8b32697ee620e.tar.bz2 dexon-f2c37d5acc88d01ca4f786cfbfc8b32697ee620e.tar.lz dexon-f2c37d5acc88d01ca4f786cfbfc8b32697ee620e.tar.xz dexon-f2c37d5acc88d01ca4f786cfbfc8b32697ee620e.tar.zst dexon-f2c37d5acc88d01ca4f786cfbfc8b32697ee620e.zip |
app: lock by chain correctly and remove old core in vendor
Diffstat (limited to 'vendor/github.com/dexon-foundation/dexon-consensus')
5 files changed, 31 insertions, 34 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 8741baf10..d6875bc45 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus/core/agreement.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/agreement.go @@ -118,7 +118,6 @@ type agreement struct { func newAgreement( ID types.NodeID, recv agreementReceiver, - notarySet map[types.NodeID]struct{}, leader *leaderSelector, authModule *Authenticator) *agreement { agreement := &agreement{ @@ -137,7 +136,7 @@ func newAgreement( // restart the agreement func (a *agreement) restart( - notarySet map[types.NodeID]struct{}, aID types.Position) { + notarySet map[types.NodeID]struct{}, aID types.Position, crs common.Hash) { func() { a.lock.Lock() @@ -151,7 +150,7 @@ func (a *agreement) restart( a.data.period = 1 a.data.blocks = make(map[types.NodeID]*types.Block) a.data.requiredVote = len(notarySet)/3*2 + 1 - a.data.leader.restart() + a.data.leader.restart(crs) a.data.lockValue = nullBlockHash a.data.lockRound = 1 a.fastForward = make(chan uint64, 1) @@ -213,7 +212,7 @@ func (a *agreement) restart( func (a *agreement) stop() { a.restart(make(map[types.NodeID]struct{}), types.Position{ ChainID: math.MaxUint32, - }) + }, common.Hash{}) } func isStop(aID types.Position) bool { 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 cec3c4f64..29d4aa2c8 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go @@ -315,12 +315,6 @@ func NewConsensus( config := gov.Configuration(round) nodeSetCache := NewNodeSetCache(gov) logger.Debug("Calling Governance.CRS", "round", round) - crs := gov.CRS(round) - // Setup acking by information returned from Governace. - nodes, err := nodeSetCache.GetNodeSet(round) - if err != nil { - panic(err) - } // Setup auth module. authModule := NewAuthenticator(prv) // Check if the application implement Debug interface. @@ -385,8 +379,7 @@ func NewConsensus( agreementModule := newAgreement( con.ID, recv, - nodes.IDs, - newLeaderSelector(crs, validLeader), + newLeaderSelector(validLeader), con.authModule, ) // Hacky way to make agreement module self contained. @@ -448,6 +441,7 @@ func (con *Consensus) runBA(chainID uint32, tick <-chan struct{}) { recv := con.receivers[chainID] recv.restartNotary <- true nIDs := make(map[types.NodeID]struct{}) + crs := common.Hash{} // Reset ticker <-tick BALoop: @@ -466,16 +460,17 @@ BALoop: if err != nil { panic(err) } + con.logger.Debug("Calling Governance.CRS", "round", recv.round) + crs = con.gov.CRS(recv.round) con.logger.Debug("Calling Governance.Configuration", "round", recv.round) - con.logger.Debug("Calling Governance.CRS", "round", recv.round) nIDs = nodes.GetSubSet( int(con.gov.Configuration(recv.round).NotarySetSize), - types.NewNotarySetTarget(con.gov.CRS(recv.round), chainID)) + types.NewNotarySetTarget(crs, chainID)) } nextPos := con.lattice.NextPosition(chainID) nextPos.Round = recv.round - agreement.restart(nIDs, nextPos) + agreement.restart(nIDs, nextPos, crs) default: } if agreement.pullVotes() { @@ -809,14 +804,15 @@ func (con *Consensus) ProcessAgreementResult( con.logger.Debug("Calling Network.PullBlocks for syncing BA", "hash", rand.BlockHash) con.network.PullBlocks(common.Hashes{rand.BlockHash}) + con.logger.Debug("Calling Governance.CRS", "round", rand.Position.Round) + crs := con.gov.CRS(rand.Position.Round) nIDs := nodes.GetSubSet( int(con.gov.Configuration(rand.Position.Round).NotarySetSize), - types.NewNotarySetTarget( - con.gov.CRS(rand.Position.Round), rand.Position.ChainID)) + types.NewNotarySetTarget(crs, rand.Position.ChainID)) for _, vote := range rand.Votes { agreement.processVote(&vote) } - agreement.restart(nIDs, rand.Position) + agreement.restart(nIDs, rand.Position, crs) } // Calculating randomness. if rand.Position.Round == 0 { @@ -929,7 +925,7 @@ func (con *Consensus) preProcessBlock(b *types.Block) (err error) { func (con *Consensus) deliverBlock(b *types.Block) { // TODO(mission): clone types.FinalizationResult con.logger.Debug("Calling Application.BlockDelivered", "block", b) - con.app.BlockDelivered(b.Hash, b.Finalization) + con.app.BlockDelivered(b.Hash, b.Position, b.Finalization) if b.Position.Round+2 == con.roundToNotify { // Only the first block delivered of that round would // trigger this noitification. diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/interfaces.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/interfaces.go index 75a2fdfcf..3a9c0752a 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus/core/interfaces.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/interfaces.go @@ -42,7 +42,8 @@ type Application interface { BlockConfirmed(block types.Block) // BlockDelivered is called when a block is add to the compaction chain. - BlockDelivered(blockHash common.Hash, result types.FinalizationResult) + BlockDelivered(blockHash common.Hash, + blockPosition types.Position, result types.FinalizationResult) } // Debug describes the application interface that requires 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 2be596abc..08006dbfb 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 @@ -59,13 +59,8 @@ type leaderSelector struct { lock sync.Mutex } -func newLeaderSelector( - crs common.Hash, validLeader validLeaderFn) *leaderSelector { - numCRS := big.NewInt(0) - numCRS.SetBytes(crs[:]) +func newLeaderSelector(validLeader validLeaderFn) *leaderSelector { return &leaderSelector{ - numCRS: numCRS, - hashCRS: crs, minCRSBlock: maxHash, validLeader: validLeader, } @@ -86,9 +81,13 @@ func (l *leaderSelector) probability(sig crypto.Signature) float64 { return p } -func (l *leaderSelector) restart() { +func (l *leaderSelector) restart(crs common.Hash) { + numCRS := big.NewInt(0) + numCRS.SetBytes(crs[:]) l.lock.Lock() defer l.lock.Unlock() + l.numCRS = numCRS + l.hashCRS = crs l.minCRSBlock = maxHash l.minBlockHash = common.Hash{} l.pendingBlocks = []*types.Block{} diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/nonblocking.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/nonblocking.go index fafbd10bb..a73331fae 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus/core/nonblocking.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/nonblocking.go @@ -39,8 +39,9 @@ type totalOrderingDeliveredEvent struct { } type blockDeliveredEvent struct { - blockHash common.Hash - result *types.FinalizationResult + blockHash common.Hash + blockPosition types.Position + result *types.FinalizationResult } // nonBlocking implements these interfaces and is a decorator for @@ -99,7 +100,7 @@ func (nb *nonBlocking) run() { case totalOrderingDeliveredEvent: nb.debug.TotalOrderingDelivered(e.blockHashes, e.mode) case blockDeliveredEvent: - nb.app.BlockDelivered(e.blockHash, *e.result) + nb.app.BlockDelivered(e.blockHash, e.blockPosition, *e.result) default: fmt.Printf("Unknown event %v.", e) } @@ -155,10 +156,11 @@ func (nb *nonBlocking) TotalOrderingDelivered( } // BlockDelivered is called when a block is add to the compaction chain. -func (nb *nonBlocking) BlockDelivered( - blockHash common.Hash, result types.FinalizationResult) { +func (nb *nonBlocking) BlockDelivered(blockHash common.Hash, + blockPosition types.Position, result types.FinalizationResult) { nb.addEvent(blockDeliveredEvent{ - blockHash: blockHash, - result: &result, + blockHash: blockHash, + blockPosition: blockPosition, + result: &result, }) } |