aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorhaoping-ku <haoping.ku@cobinhood.com>2018-11-07 13:41:24 +0800
committerMission Liao <mission.liao@dexon.org>2018-11-07 13:41:24 +0800
commitbcdc444319ca9fe219f27e818ab9ec863d6757ea (patch)
tree30d3f3dcb5b49afadb51f45788f0bf7c0022197f /core
parent3714ebf2f1054d9984d37b89cf17e885a5856532 (diff)
downloaddexon-consensus-bcdc444319ca9fe219f27e818ab9ec863d6757ea.tar
dexon-consensus-bcdc444319ca9fe219f27e818ab9ec863d6757ea.tar.gz
dexon-consensus-bcdc444319ca9fe219f27e818ab9ec863d6757ea.tar.bz2
dexon-consensus-bcdc444319ca9fe219f27e818ab9ec863d6757ea.tar.lz
dexon-consensus-bcdc444319ca9fe219f27e818ab9ec863d6757ea.tar.xz
dexon-consensus-bcdc444319ca9fe219f27e818ab9ec863d6757ea.tar.zst
dexon-consensus-bcdc444319ca9fe219f27e818ab9ec863d6757ea.zip
core: lattice: add round in NewLattice() (#303)
Diffstat (limited to 'core')
-rw-r--r--core/blockpool.go6
-rw-r--r--core/consensus-timestamp.go7
-rw-r--r--core/lattice.go6
3 files changed, 10 insertions, 9 deletions
diff --git a/core/blockpool.go b/core/blockpool.go
index 7861a73..fbd84f2 100644
--- a/core/blockpool.go
+++ b/core/blockpool.go
@@ -23,8 +23,8 @@ import (
"github.com/dexon-foundation/dexon-consensus/core/types"
)
-// blockPool is a heaped slice of blocks, indexed by chainID, and each in it is
-// sorted by block's height.
+// blockPool is a heaped slice of blocks ([][]*types.Block), indexed by chainID,
+// and blocks in each is sorted by block's height.
type blockPool []types.ByPosition
func newBlockPool(chainNum uint32) (pool blockPool) {
@@ -56,7 +56,7 @@ func (p blockPool) addBlock(b *types.Block) {
}
// purgeBlocks purges blocks of a specified chain with less-or-equal heights.
-// NOTE: "chainID" is not checked here, this should be ensured by the called.
+// NOTE: "chainID" is not checked here, this should be ensured by the caller.
func (p blockPool) purgeBlocks(chainID uint32, height uint64) {
for len(p[chainID]) > 0 && p[chainID][0].Position.Height <= height {
heap.Pop(&p[chainID])
diff --git a/core/consensus-timestamp.go b/core/consensus-timestamp.go
index 9750a74..833194b 100644
--- a/core/consensus-timestamp.go
+++ b/core/consensus-timestamp.go
@@ -52,9 +52,10 @@ var (
// newConsensusTimestamp creates timestamper object.
func newConsensusTimestamp(
dMoment time.Time, round uint64, numChains uint32) *consensusTimestamp {
- ts := make([]time.Time, 0, numChains)
- for i := uint32(0); i < numChains; i++ {
- ts = append(ts, dMoment)
+
+ ts := make([]time.Time, numChains)
+ for i := range ts {
+ ts[i] = dMoment
}
return &consensusTimestamp{
numChainsOfRounds: []uint32{numChains},
diff --git a/core/lattice.go b/core/lattice.go
index db13e7e..11412be 100644
--- a/core/lattice.go
+++ b/core/lattice.go
@@ -67,7 +67,7 @@ func NewLattice(
pool: newBlockPool(cfg.NumChains),
data: newLatticeData(db, dataConfig),
toModule: newTotalOrdering(toConfig),
- ctModule: newConsensusTimestamp(dMoment, 0, cfg.NumChains),
+ ctModule: newConsensusTimestamp(dMoment, round, cfg.NumChains),
logger: logger,
}
}
@@ -111,8 +111,8 @@ func (l *Lattice) PrepareEmptyBlock(b *types.Block) (err error) {
// SanityCheck checks the validity of a block.
//
-// If any acking blocks of this block does not exist, Lattice helps caching this
-// block and retries when Lattice.ProcessBlock is called.
+// If any acking block of this block does not exist, Lattice caches this block
+// and retries when Lattice.ProcessBlock is called.
func (l *Lattice) SanityCheck(b *types.Block) (err error) {
if b.IsEmpty() {
// Only need to verify block's hash.