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/test/block-revealer.go | |
parent | 46f00c345dc0993cf888523e482ae0ff385c4391 (diff) | |
download | dexon-consensus-ecc5e12b1ac4826e302607769f5b831ab4c27046.tar dexon-consensus-ecc5e12b1ac4826e302607769f5b831ab4c27046.tar.gz dexon-consensus-ecc5e12b1ac4826e302607769f5b831ab4c27046.tar.bz2 dexon-consensus-ecc5e12b1ac4826e302607769f5b831ab4c27046.tar.lz dexon-consensus-ecc5e12b1ac4826e302607769f5b831ab4c27046.tar.xz 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/test/block-revealer.go')
-rw-r--r-- | core/test/block-revealer.go | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/core/test/block-revealer.go b/core/test/block-revealer.go index 7516e6c..e104f04 100644 --- a/core/test/block-revealer.go +++ b/core/test/block-revealer.go @@ -50,53 +50,48 @@ func loadAllBlocks(iter db.BlockIterator) ( return } -// CompactionChainBlockRevealer implements BlockRevealer interface, which would +// BlockRevealerByPosition implements BlockRevealer interface, which would // load all blocks from db, reveal them in the order of compaction chain, // from the genesis block to the latest one. -type CompactionChainBlockRevealer struct { - blocks types.BlocksByFinalizationHeight +type BlockRevealerByPosition struct { + blocks types.BlocksByPosition nextRevealIndex int } -// NewCompactionChainBlockRevealer constructs a block revealer in the order of +// NewBlockRevealerByPosition constructs a block revealer in the order of // compaction chain. -func NewCompactionChainBlockRevealer(iter db.BlockIterator, - startHeight uint64) (r *CompactionChainBlockRevealer, err error) { +func NewBlockRevealerByPosition(iter db.BlockIterator, startHeight uint64) ( + r *BlockRevealerByPosition, err error) { blocksByHash, err := loadAllBlocks(iter) if err != nil { return } - if startHeight == 0 { - startHeight = 1 - } - blocks := types.BlocksByFinalizationHeight{} + blocks := types.BlocksByPosition{} for _, b := range blocksByHash { - if b.Finalization.Height < startHeight { + if b.Position.Height < startHeight { continue } blocks = append(blocks, b) } - sort.Sort(types.BlocksByFinalizationHeight(blocks)) - // Make sure the finalization height of blocks are incremental with step 1. + sort.Sort(types.BlocksByPosition(blocks)) + // Make sure the height of blocks are incremental with step 1. for idx, b := range blocks { if idx == 0 { continue } - if b.Finalization.Height != blocks[idx-1].Finalization.Height+1 { + if b.Position.Height != blocks[idx-1].Position.Height+1 { err = ErrNotValidCompactionChain return } } - r = &CompactionChainBlockRevealer{ - blocks: blocks, - } + r = &BlockRevealerByPosition{blocks: blocks} r.Reset() return } // NextBlock implements Revealer.Next method, which would reveal blocks in the // order of compaction chain. -func (r *CompactionChainBlockRevealer) NextBlock() (types.Block, error) { +func (r *BlockRevealerByPosition) NextBlock() (types.Block, error) { if r.nextRevealIndex == len(r.blocks) { return types.Block{}, db.ErrIterationFinished } @@ -106,6 +101,6 @@ func (r *CompactionChainBlockRevealer) NextBlock() (types.Block, error) { } // Reset implement Revealer.Reset method, which would reset revealing. -func (r *CompactionChainBlockRevealer) Reset() { +func (r *BlockRevealerByPosition) Reset() { r.nextRevealIndex = 0 } |