aboutsummaryrefslogtreecommitdiffstats
path: root/core/lattice-data.go
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2018-10-23 09:43:24 +0800
committerGitHub <noreply@github.com>2018-10-23 09:43:24 +0800
commit56cbbbaf4c638264cbf3ceb5cf16161b6adf2bc3 (patch)
treed52155ea22e6bcfae6ac062893c32186005c362f /core/lattice-data.go
parent6fbd0cd47fd70cfad707e95bc9fb948e7b44d4cf (diff)
downloadtangerine-consensus-56cbbbaf4c638264cbf3ceb5cf16161b6adf2bc3.tar
tangerine-consensus-56cbbbaf4c638264cbf3ceb5cf16161b6adf2bc3.tar.gz
tangerine-consensus-56cbbbaf4c638264cbf3ceb5cf16161b6adf2bc3.tar.bz2
tangerine-consensus-56cbbbaf4c638264cbf3ceb5cf16161b6adf2bc3.tar.lz
tangerine-consensus-56cbbbaf4c638264cbf3ceb5cf16161b6adf2bc3.tar.xz
tangerine-consensus-56cbbbaf4c638264cbf3ceb5cf16161b6adf2bc3.tar.zst
tangerine-consensus-56cbbbaf4c638264cbf3ceb5cf16161b6adf2bc3.zip
core: prepare empty block if null block is confirmed by BA. (#231)
Diffstat (limited to 'core/lattice-data.go')
-rw-r--r--core/lattice-data.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/core/lattice-data.go b/core/lattice-data.go
index 50fa1d3..31604a6 100644
--- a/core/lattice-data.go
+++ b/core/lattice-data.go
@@ -412,6 +412,40 @@ func (data *latticeData) prepareBlock(b *types.Block) error {
return nil
}
+// prepareEmptyBlock helps to setup fields of block based on its ChainID.
+// including:
+// - Acks only acking its parent
+// - Timestamp with parent.Timestamp + minBlockProposeInterval
+// - ParentHash and Height from parent block. If there is no valid parent block
+// (ex. Newly added chain or bootstrap ), these fields would be setup as
+// genesis block.
+func (data *latticeData) prepareEmptyBlock(b *types.Block) {
+ // emptyBlock has no proposer.
+ b.ProposerID = types.NodeID{}
+ var acks common.Hashes
+ // Reset fields to make sure we got these information from parent block.
+ b.Position.Height = 0
+ b.Position.Round = 0
+ b.ParentHash = common.Hash{}
+ b.Timestamp = time.Time{}
+ // Decide valid timestamp range.
+ homeChain := data.chains[b.Position.ChainID]
+ if homeChain.tip != nil {
+ chainTip := homeChain.tip
+ b.ParentHash = chainTip.Hash
+ chainTipConfig := data.getConfig(chainTip.Position.Round)
+ if chainTip.Timestamp.After(chainTipConfig.roundEndTime) {
+ b.Position.Round = chainTip.Position.Round + 1
+ } else {
+ b.Position.Round = chainTip.Position.Round
+ }
+ b.Position.Height = chainTip.Position.Height + 1
+ b.Timestamp = chainTip.Timestamp.Add(chainTipConfig.minBlockTimeInterval)
+ acks = append(acks, chainTip.Hash)
+ }
+ b.Acks = common.NewSortedHashes(acks)
+}
+
// TODO(mission): make more abstraction for this method.
// nextHeight returns the next height for the chain.
func (data *latticeData) nextPosition(chainID uint32) types.Position {