diff options
-rw-r--r-- | core/agreement-mgr.go | 5 | ||||
-rw-r--r-- | core/consensus.go | 25 | ||||
-rw-r--r-- | core/utils/round-event.go | 5 |
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, |