aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2018-10-16 23:27:54 +0800
committerWei-Ning Huang <aitjcize@gmail.com>2018-10-16 23:27:54 +0800
commit3c642a37675e29f82a169c0d406295608bed7abc (patch)
treedbb79fa3aabf97b3f4efe2fe2d4db76cb86be643
parent5a49482543f9d5d5641fd7b3b41a1598f5f83fd8 (diff)
downloaddexon-consensus-3c642a37675e29f82a169c0d406295608bed7abc.tar
dexon-consensus-3c642a37675e29f82a169c0d406295608bed7abc.tar.gz
dexon-consensus-3c642a37675e29f82a169c0d406295608bed7abc.tar.bz2
dexon-consensus-3c642a37675e29f82a169c0d406295608bed7abc.tar.lz
dexon-consensus-3c642a37675e29f82a169c0d406295608bed7abc.tar.xz
dexon-consensus-3c642a37675e29f82a169c0d406295608bed7abc.tar.zst
dexon-consensus-3c642a37675e29f82a169c0d406295608bed7abc.zip
Finalization Height starts from 1 (#215)
-rw-r--r--core/compaction-chain.go2
-rw-r--r--core/compaction-chain_test.go5
2 files changed, 7 insertions, 0 deletions
diff --git a/core/compaction-chain.go b/core/compaction-chain.go
index 6803661..3bf87f1 100644
--- a/core/compaction-chain.go
+++ b/core/compaction-chain.go
@@ -65,6 +65,8 @@ func (cc *compactionChain) processBlock(block *types.Block) error {
prevBlock := cc.lastBlock()
if prevBlock != nil {
block.Finalization.Height = prevBlock.Finalization.Height + 1
+ } else {
+ block.Finalization.Height = 1
}
cc.prevBlockLock.Lock()
defer cc.prevBlockLock.Unlock()
diff --git a/core/compaction-chain_test.go b/core/compaction-chain_test.go
index f91f1a1..0da0924 100644
--- a/core/compaction-chain_test.go
+++ b/core/compaction-chain_test.go
@@ -74,6 +74,11 @@ func (s *CompactionChainTestSuite) TestProcessBlock() {
for _, block := range blocks {
s.Equal(cc.prevBlock, prevBlock)
s.Require().NoError(cc.processBlock(block))
+ if prevBlock != nil {
+ s.Equal(prevBlock.Finalization.Height+1, block.Finalization.Height)
+ } else {
+ s.Equal(uint64(1), block.Finalization.Height)
+ }
prevBlock = block
}
}