diff options
author | Mission Liao <mission.liao@dexon.org> | 2019-04-01 12:25:09 +0800 |
---|---|---|
committer | Jimmy Hu <jimmy.hu@dexon.org> | 2019-04-01 12:25:09 +0800 |
commit | ecc5e12b1ac4826e302607769f5b831ab4c27046 (patch) | |
tree | e01fbf5d796c555f1d343e14023c282ad83bcba8 /core/utils/round-event.go | |
parent | 46f00c345dc0993cf888523e482ae0ff385c4391 (diff) | |
download | dexon-consensus-ecc5e12b1ac4826e302607769f5b831ab4c27046.tar.gz dexon-consensus-ecc5e12b1ac4826e302607769f5b831ab4c27046.tar.zst dexon-consensus-ecc5e12b1ac4826e302607769f5b831ab4c27046.zip |
core: clean TODOs (#539)
* core: fix block timestamp (#529)
* Remove TODO
dMoment is still required when the block timestamp of
the genesis block is still need to be verified.
* Refine timestamp when preparing blocks
* Add timestamp checking in sanity check
* Revert code to patch position when preparing
* Remove TODOs that seems meaningless now
* Remove TODOs related to refactoring
* core: remove finalization (#531)
- Remove types.FinalizationResult, randomness
field would be moved to `types.Block` directly.
- Add a placeholder for types.Block.Randomness
field for blocks proposed from
round < DKGDelayRound. (refer to core.NoRand)
- Make the height of the genesis block starts
from 1. (refer to types.GenesisHeight)
- The fullnode's behavior of
core.Governance.GetRoundHeight is (assume
round-length is 100):
- round: 0 -> 0 (we need to workaround this)
- round: 1 -> 101
- round: 2 -> 201
- test.Governance already simulate this
behavior, and the workaround is wrapped at
utils.GetRoundHeight.
* core: fix issues (#536)
fixing code in these condition:
- assigning position without initializing them
and expected it's for genesis
- compare height with 0
Diffstat (limited to 'core/utils/round-event.go')
-rw-r--r-- | core/utils/round-event.go | 43 |
1 files changed, 20 insertions, 23 deletions
diff --git a/core/utils/round-event.go b/core/utils/round-event.go index 0e70cf2..472c724 100644 --- a/core/utils/round-event.go +++ b/core/utils/round-event.go @@ -169,42 +169,39 @@ type RoundEvent struct { // NewRoundEvent creates an RoundEvent instance. func NewRoundEvent(parentCtx context.Context, gov governanceAccessor, - logger common.Logger, initRound uint64, - initBlockHeight uint64, - roundShift uint64) (*RoundEvent, error) { + logger common.Logger, initPos types.Position, roundShift uint64) ( + *RoundEvent, error) { // We need to generate valid ending block height of this round (taken // DKG reset count into consideration). - initConfig := GetConfigWithPanic(gov, initRound, logger) + logger.Info("new RoundEvent", "position", initPos, "shift", roundShift) + initConfig := GetConfigWithPanic(gov, initPos.Round, logger) e := &RoundEvent{ gov: gov, logger: logger, - lastTriggeredRound: initRound, + lastTriggeredRound: initPos.Round, roundShift: roundShift, } e.ctx, e.ctxCancel = context.WithCancel(parentCtx) e.config = RoundBasedConfig{} - e.config.SetupRoundBasedFields(initRound, initConfig) - // TODO(jimmy): remove -1 after we match the height with fullnode. - roundHeight := gov.GetRoundHeight(initRound) - if initRound != 0 { - roundHeight-- - } - e.config.SetRoundBeginHeight(roundHeight) + e.config.SetupRoundBasedFields(initPos.Round, initConfig) + e.config.SetRoundBeginHeight(GetRoundHeight(gov, initPos.Round)) // Make sure the DKG reset count in current governance can cover the initial // block height. - resetCount := gov.DKGResetCount(initRound + 1) - remains := resetCount - for ; remains > 0 && !e.config.Contains(initBlockHeight); remains-- { - e.config.ExtendLength() - } - if !e.config.Contains(initBlockHeight) { - return nil, ErrUnmatchedBlockHeightWithConfig{ - round: initRound, - reset: resetCount, - blockHeight: initBlockHeight, + if initPos.Height >= types.GenesisHeight { + resetCount := gov.DKGResetCount(initPos.Round + 1) + remains := resetCount + for ; remains > 0 && !e.config.Contains(initPos.Height); remains-- { + e.config.ExtendLength() + } + if !e.config.Contains(initPos.Height) { + return nil, ErrUnmatchedBlockHeightWithConfig{ + round: initPos.Round, + reset: resetCount, + blockHeight: initPos.Height, + } } + e.lastTriggeredResetCount = resetCount - remains } - e.lastTriggeredResetCount = resetCount - remains return e, nil } |