diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2019-03-28 13:34:30 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-28 13:34:30 +0800 |
commit | a8b01422da4a66cf2844012c89d46a7d22ac1664 (patch) | |
tree | 22f79b20b580bac05774cf1284f6a76e7bdda815 | |
parent | c0995cb576b840432114011791b39aa904602570 (diff) | |
download | dexon-consensus-a8b01422da4a66cf2844012c89d46a7d22ac1664.tar.gz dexon-consensus-a8b01422da4a66cf2844012c89d46a7d22ac1664.tar.zst dexon-consensus-a8b01422da4a66cf2844012c89d46a7d22ac1664.zip |
core: workaround for GetRoundHeight (#526)
-rw-r--r-- | core/consensus.go | 12 | ||||
-rw-r--r-- | core/test/governance.go | 3 | ||||
-rw-r--r-- | core/utils/round-event.go | 6 |
3 files changed, 18 insertions, 3 deletions
diff --git a/core/consensus.go b/core/consensus.go index 19ba74c..4e01860 100644 --- a/core/consensus.go +++ b/core/consensus.go @@ -735,7 +735,11 @@ func newConsensusForRound( baConfig := agreementMgrConfig{} baConfig.from(initRound, initConfig, initCRS) // TODO(jimmy): remove -1 after we match the height with fullnode. - baConfig.SetRoundBeginHeight(gov.GetRoundHeight(initRound) - 1) + roundHeight := gov.GetRoundHeight(initRound) + if initRound > 0 { + roundHeight-- + } + baConfig.SetRoundBeginHeight(roundHeight) con.baMgr, err = newAgreementMgr(con, baConfig) if err != nil { panic(err) @@ -812,7 +816,11 @@ func (con *Consensus) prepare(initBlock *types.Block) (err error) { } // The init config is provided to baModule when construction. // TODO(jimmy): remove -1 after we match the height with fullnode. - if evts[len(evts)-1].BeginHeight != con.gov.GetRoundHeight(initRound)-1 { + 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) } diff --git a/core/test/governance.go b/core/test/governance.go index 4970420..4ee20d8 100644 --- a/core/test/governance.go +++ b/core/test/governance.go @@ -94,6 +94,9 @@ func (g *Governance) Configuration(round uint64) *types.Config { // GetRoundHeight returns the begin height of a round. func (g *Governance) GetRoundHeight(round uint64) uint64 { + if round == 0 { + return 0 + } g.lock.RLock() defer g.lock.RUnlock() if round >= uint64(len(g.roundBeginHeights)) { diff --git a/core/utils/round-event.go b/core/utils/round-event.go index c03a2fd..2642bfd 100644 --- a/core/utils/round-event.go +++ b/core/utils/round-event.go @@ -180,7 +180,11 @@ func NewRoundEvent(parentCtx context.Context, gov governanceAccessor, e.config = RoundBasedConfig{} e.config.SetupRoundBasedFields(initRound, initConfig) // TODO(jimmy): remove -1 after we match the height with fullnode. - e.config.SetRoundBeginHeight(gov.GetRoundHeight(initRound) - 1) + roundHeight := gov.GetRoundHeight(initRound) + if initRound != 0 { + roundHeight-- + } + e.config.SetRoundBeginHeight(roundHeight) // Make sure the DKG reset count in current governance can cover the initial // block height. resetCount := gov.DKGResetCount(initRound + 1) |