aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMission Liao <mission.liao@dexon.org>2019-03-28 14:03:12 +0800
committerGitHub <noreply@github.com>2019-03-28 14:03:12 +0800
commite3e7f4fbd840819b1ef44ae2c345f64e0bb2c161 (patch)
treeb753090b8ee723b17ca8afb30106dc9229304397
parenta8b01422da4a66cf2844012c89d46a7d22ac1664 (diff)
downloaddexon-consensus-e3e7f4fbd840819b1ef44ae2c345f64e0bb2c161.tar
dexon-consensus-e3e7f4fbd840819b1ef44ae2c345f64e0bb2c161.tar.gz
dexon-consensus-e3e7f4fbd840819b1ef44ae2c345f64e0bb2c161.tar.bz2
dexon-consensus-e3e7f4fbd840819b1ef44ae2c345f64e0bb2c161.tar.lz
dexon-consensus-e3e7f4fbd840819b1ef44ae2c345f64e0bb2c161.tar.xz
dexon-consensus-e3e7f4fbd840819b1ef44ae2c345f64e0bb2c161.tar.zst
dexon-consensus-e3e7f4fbd840819b1ef44ae2c345f64e0bb2c161.zip
core: fix issues (#525)
* Refine the logic to append config * Potential fix for round not increase when fast syncing
-rw-r--r--core/agreement-mgr.go5
-rw-r--r--core/consensus.go25
-rw-r--r--core/utils/round-event.go5
3 files changed, 20 insertions, 15 deletions
diff --git a/core/agreement-mgr.go b/core/agreement-mgr.go
index 9790452..7006242 100644
--- a/core/agreement-mgr.go
+++ b/core/agreement-mgr.go
@@ -199,6 +199,11 @@ func (mgr *agreementMgr) notifyRoundEvents(evts []utils.RoundEventParam) error {
if len(mgr.configs) > 0 {
lastCfg := mgr.configs[len(mgr.configs)-1]
if e.BeginHeight != lastCfg.RoundEndHeight() {
+ // the init config of BA part is provided when constructing.
+ if len(mgr.configs) == 1 &&
+ e.BeginHeight == lastCfg.LastPeriodBeginHeight() {
+ return nil
+ }
return ErrInvalidBlockHeight
}
if lastCfg.RoundID() == e.Round {
diff --git a/core/consensus.go b/core/consensus.go
index 4e01860..6d0f683 100644
--- a/core/consensus.go
+++ b/core/consensus.go
@@ -390,15 +390,17 @@ CleanChannelLoop:
}
}
newPos := block.Position
- if block.Position.Height+1 == recv.changeNotaryHeight() {
- recv.consensus.logger.Info("Round will change", "block", block)
+ changeNotaryHeight := recv.changeNotaryHeight()
+ if block.Position.Height+1 >= changeNotaryHeight {
+ recv.consensus.logger.Info("Round will change",
+ "block", block,
+ "change-height", changeNotaryHeight)
newPos.Round++
recv.updateRound(newPos.Round)
}
currentRound := recv.round()
- changeNotaryHeight := recv.changeNotaryHeight()
if block.Position.Height > changeNotaryHeight &&
- block.Position.Round <= currentRound {
+ block.Position.Round < currentRound {
panic(fmt.Errorf(
"round not switch when confirming: %s, %d, should switch at %d, %s",
block, currentRound, changeNotaryHeight, newPos))
@@ -810,20 +812,13 @@ func (con *Consensus) prepare(initBlock *types.Block) (err error) {
// Register round event handler to update BA and BC modules.
con.roundEvent.Register(func(evts []utils.RoundEventParam) {
defer elapse("append-config", evts[len(evts)-1])()
- // Always updates newer configs to the later modules first in the flow.
+ // Always updates newer configs to the later modules first in the data
+ // flow.
if err := con.bcModule.notifyRoundEvents(evts); err != nil {
panic(err)
}
- // The init config is provided to baModule when construction.
- // TODO(jimmy): remove -1 after we match the height with fullnode.
- roundHeight := con.gov.GetRoundHeight(initRound)
- if initRound > 0 {
- roundHeight--
- }
- if evts[len(evts)-1].BeginHeight != roundHeight {
- if err := con.baMgr.notifyRoundEvents(evts); err != nil {
- panic(err)
- }
+ if err := con.baMgr.notifyRoundEvents(evts); err != nil {
+ panic(err)
}
})
// Register round event handler to reset DKG if the DKG set for next round
diff --git a/core/utils/round-event.go b/core/utils/round-event.go
index 2642bfd..0e70cf2 100644
--- a/core/utils/round-event.go
+++ b/core/utils/round-event.go
@@ -92,6 +92,11 @@ func (e RoundEventParam) NextDKGRegisterHeight() uint64 {
return e.BeginHeight + e.Config.RoundLength/2
}
+// RoundEndHeight returns the round ending height of this round event.
+func (e RoundEventParam) RoundEndHeight() uint64 {
+ return e.BeginHeight + e.Config.RoundLength
+}
+
func (e RoundEventParam) String() string {
return fmt.Sprintf("roundEvtParam{Round:%d Reset:%d Height:%d}",
e.Round,