aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go
diff options
context:
space:
mode:
authorWei-Ning Huang <w@dexon.org>2019-03-22 17:16:17 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-06-13 18:11:44 +0800
commit6f2a06197463ad2aefb2b053b2d784b9b3ff184f (patch)
tree9c0b7aa6976d6ebceecee10fa0767d4a4376d662 /vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go
parent9ae4bba0bb7ddf004f54e7e7e2a18f021f4a7cd6 (diff)
downloadgo-tangerine-6f2a06197463ad2aefb2b053b2d784b9b3ff184f.tar
go-tangerine-6f2a06197463ad2aefb2b053b2d784b9b3ff184f.tar.gz
go-tangerine-6f2a06197463ad2aefb2b053b2d784b9b3ff184f.tar.bz2
go-tangerine-6f2a06197463ad2aefb2b053b2d784b9b3ff184f.tar.lz
go-tangerine-6f2a06197463ad2aefb2b053b2d784b9b3ff184f.tar.xz
go-tangerine-6f2a06197463ad2aefb2b053b2d784b9b3ff184f.tar.zst
go-tangerine-6f2a06197463ad2aefb2b053b2d784b9b3ff184f.zip
vendor: sync to latest core (#295)
Diffstat (limited to 'vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go')
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go101
1 files changed, 54 insertions, 47 deletions
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 8f8002b67..83727ec58 100644
--- a/vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go
+++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go
@@ -658,8 +658,10 @@ func (con *Consensus) prepare(
// Register round event handler to abort previous running DKG if any.
con.roundEvent.Register(func(evts []utils.RoundEventParam) {
e := evts[len(evts)-1]
- defer elapse("abort DKG", e)()
- con.cfgModule.abortDKG(e.Round+1, e.Reset)
+ go func() {
+ defer elapse("abort DKG", e)()
+ con.cfgModule.abortDKG(e.Round+1, e.Reset)
+ }()
})
// Register round event handler to update BA and BC modules.
con.roundEvent.Register(func(evts []utils.RoundEventParam) {
@@ -721,8 +723,10 @@ func (con *Consensus) prepare(
return
}
// Aborting all previous running DKG protocol instance if any.
- con.cfgModule.abortDKG(nextRound, e.Reset)
- con.runCRS(e.Round, utils.Rehash(e.CRS, uint(e.Reset+1)), true)
+ go func() {
+ con.cfgModule.abortDKG(nextRound, e.Reset)
+ con.runCRS(e.Round, utils.Rehash(e.CRS, uint(e.Reset+1)), true)
+ }()
})
})
// Register round event handler to propose new CRS.
@@ -750,7 +754,7 @@ func (con *Consensus) prepare(
con.logger.Debug("CRS already proposed", "round", e.Round+1)
return
}
- con.runCRS(e.Round, e.CRS, false)
+ go con.runCRS(e.Round, e.CRS, false)
})
}
})
@@ -788,10 +792,8 @@ func (con *Consensus) prepare(
e := evts[len(evts)-1]
defer elapse("next round", e)()
// Register a routine to trigger round events.
- con.event.RegisterHeight(e.NextRoundValidationHeight(), func(
- blockHeight uint64) {
- con.roundEvent.ValidateNextRound(blockHeight)
- })
+ con.event.RegisterHeight(e.NextRoundValidationHeight(),
+ utils.RoundEventRetryHandlerGenerator(con.roundEvent, con.event))
// Register a routine to register next DKG.
con.event.RegisterHeight(e.NextDKGRegisterHeight(), func(uint64) {
nextRound := e.Round + 1
@@ -801,48 +803,53 @@ func (con *Consensus) prepare(
"reset", e.Reset)
return
}
- // Normally, gov.CRS would return non-nil. Use this for in case of
- // unexpected network fluctuation and ensure the robustness.
- if !checkWithCancel(
- con.ctx, 500*time.Millisecond, checkCRS(nextRound)) {
- con.logger.Debug("unable to prepare CRS for DKG set",
- "round", nextRound,
- "reset", e.Reset)
- return
- }
- nextDkgSet, err := con.nodeSetCache.GetDKGSet(nextRound)
- if err != nil {
- con.logger.Error("Error getting DKG set for next round",
- "round", nextRound,
- "reset", e.Reset,
- "error", err)
- return
- }
- if _, exist := nextDkgSet[con.ID]; !exist {
- con.logger.Info("Not selected as DKG set",
+ go func() {
+ // Normally, gov.CRS would return non-nil. Use this for in case
+ // of unexpected network fluctuation and ensure the robustness.
+ if !checkWithCancel(
+ con.ctx, 500*time.Millisecond, checkCRS(nextRound)) {
+ con.logger.Debug("unable to prepare CRS for DKG set",
+ "round", nextRound,
+ "reset", e.Reset)
+ return
+ }
+ nextDkgSet, err := con.nodeSetCache.GetDKGSet(nextRound)
+ if err != nil {
+ con.logger.Error("Error getting DKG set for next round",
+ "round", nextRound,
+ "reset", e.Reset,
+ "error", err)
+ return
+ }
+ if _, exist := nextDkgSet[con.ID]; !exist {
+ con.logger.Info("Not selected as DKG set",
+ "round", nextRound,
+ "reset", e.Reset)
+ return
+ }
+ con.logger.Info("Selected as DKG set",
"round", nextRound,
"reset", e.Reset)
- return
- }
- con.logger.Info("Selected as DKG set",
- "round", nextRound,
- "reset", e.Reset)
- nextConfig := utils.GetConfigWithPanic(con.gov, nextRound,
- con.logger)
- con.cfgModule.registerDKG(nextRound, e.Reset, utils.GetDKGThreshold(
- nextConfig))
- con.event.RegisterHeight(e.NextDKGPreparationHeight(),
- func(uint64) {
- func() {
- con.dkgReady.L.Lock()
- defer con.dkgReady.L.Unlock()
- con.dkgRunning = 0
- }()
- con.runDKG(nextRound, e.Reset, nextConfig)
- })
+ nextConfig := utils.GetConfigWithPanic(con.gov, nextRound,
+ con.logger)
+ con.cfgModule.registerDKG(nextRound, e.Reset,
+ utils.GetDKGThreshold(nextConfig))
+ con.event.RegisterHeight(e.NextDKGPreparationHeight(),
+ func(uint64) {
+ func() {
+ con.dkgReady.L.Lock()
+ defer con.dkgReady.L.Unlock()
+ con.dkgRunning = 0
+ }()
+ con.runDKG(nextRound, e.Reset, nextConfig)
+ })
+ }()
})
})
con.roundEvent.TriggerInitEvent()
+ if initBlock != nil {
+ con.event.NotifyHeight(initBlock.Finalization.Height)
+ }
return
}
@@ -1289,7 +1296,7 @@ func (con *Consensus) deliverFinalizedBlocksWithoutLock() (err error) {
"pending", con.bcModule.lastPendingBlock())
for _, b := range deliveredBlocks {
con.deliverBlock(b)
- go con.event.NotifyHeight(b.Finalization.Height)
+ con.event.NotifyHeight(b.Finalization.Height)
}
return
}