aboutsummaryrefslogtreecommitdiffstats
path: root/core/db
diff options
context:
space:
mode:
authorMission Liao <mission.liao@dexon.org>2018-12-20 14:19:55 +0800
committerGitHub <noreply@github.com>2018-12-20 14:19:55 +0800
commit45609b1dbfba5d7083826e27f2c5862fcca24106 (patch)
tree91fd80dc89ab3044e153f91c1a7d347b2da8911f /core/db
parentc7b4045802450df361216d9e7da3ec318e67cc34 (diff)
downloaddexon-consensus-45609b1dbfba5d7083826e27f2c5862fcca24106.tar
dexon-consensus-45609b1dbfba5d7083826e27f2c5862fcca24106.tar.gz
dexon-consensus-45609b1dbfba5d7083826e27f2c5862fcca24106.tar.bz2
dexon-consensus-45609b1dbfba5d7083826e27f2c5862fcca24106.tar.lz
dexon-consensus-45609b1dbfba5d7083826e27f2c5862fcca24106.tar.xz
dexon-consensus-45609b1dbfba5d7083826e27f2c5862fcca24106.tar.zst
dexon-consensus-45609b1dbfba5d7083826e27f2c5862fcca24106.zip
core: deliver finalized blocks upon receiving randomness results. (#376)
Diffstat (limited to 'core/db')
-rw-r--r--core/db/level-db.go2
-rw-r--r--core/db/level-db_test.go11
-rw-r--r--core/db/memory.go2
-rw-r--r--core/db/memory_test.go11
4 files changed, 18 insertions, 8 deletions
diff --git a/core/db/level-db.go b/core/db/level-db.go
index 3b5994b..75c3037 100644
--- a/core/db/level-db.go
+++ b/core/db/level-db.go
@@ -163,7 +163,7 @@ func (lvl *LevelDBBackedDB) PutCompactionChainTipInfo(
if err != nil {
return err
}
- if info.Height >= height {
+ if info.Height+1 != height {
return ErrInvalidCompactionChainTipHeight
}
if err = lvl.db.Put(compactionChainTipInfoKey, marshaled, nil); err != nil {
diff --git a/core/db/level-db_test.go b/core/db/level-db_test.go
index cf56b87..df971ee 100644
--- a/core/db/level-db_test.go
+++ b/core/db/level-db_test.go
@@ -141,14 +141,19 @@ func (s *LevelDBTestSuite) TestCompactionChainTipInfo() {
}(dbName)
// Save some tip info.
hash := common.NewRandomHash()
- s.Require().NoError(dbInst.PutCompactionChainTipInfo(hash, 123))
+ s.Require().NoError(dbInst.PutCompactionChainTipInfo(hash, 1))
// Get it back to check.
hashBack, height := dbInst.GetCompactionChainTipInfo()
s.Require().Equal(hash, hashBack)
- s.Require().Equal(height, uint64(123))
+ s.Require().Equal(height, uint64(1))
// Unable to put compaction chain tip info with lower height.
- err = dbInst.PutCompactionChainTipInfo(hash, 122)
+ err = dbInst.PutCompactionChainTipInfo(hash, 0)
s.Require().IsType(err, ErrInvalidCompactionChainTipHeight)
+ // Unable to put compaction chain tip info with height not incremental by 1.
+ err = dbInst.PutCompactionChainTipInfo(hash, 3)
+ s.Require().IsType(err, ErrInvalidCompactionChainTipHeight)
+ // It's OK to put compaction chain tip info with height incremental by 1.
+ s.Require().NoError(dbInst.PutCompactionChainTipInfo(hash, 2))
}
func (s *LevelDBTestSuite) TestDKGPrivateKey() {
diff --git a/core/db/memory.go b/core/db/memory.go
index 7393de9..4bc08e7 100644
--- a/core/db/memory.go
+++ b/core/db/memory.go
@@ -149,7 +149,7 @@ func (m *MemBackedDB) PutCompactionChainTipInfo(
blockHash common.Hash, height uint64) error {
m.compactionChainTipLock.Lock()
defer m.compactionChainTipLock.Unlock()
- if m.compactionChainTipHeight >= height {
+ if m.compactionChainTipHeight+1 != height {
return ErrInvalidCompactionChainTipHeight
}
m.compactionChainTipHeight = height
diff --git a/core/db/memory_test.go b/core/db/memory_test.go
index 09f74bb..a1b5165 100644
--- a/core/db/memory_test.go
+++ b/core/db/memory_test.go
@@ -137,14 +137,19 @@ func (s *MemBackedDBTestSuite) TestCompactionChainTipInfo() {
s.Require().NotNil(dbInst)
// Save some tip info.
hash := common.NewRandomHash()
- s.Require().NoError(dbInst.PutCompactionChainTipInfo(hash, 123))
+ s.Require().NoError(dbInst.PutCompactionChainTipInfo(hash, 1))
// Get it back to check.
hashBack, height := dbInst.GetCompactionChainTipInfo()
s.Require().Equal(hash, hashBack)
- s.Require().Equal(height, uint64(123))
+ s.Require().Equal(height, uint64(1))
// Unable to put compaction chain tip info with lower height.
- err = dbInst.PutCompactionChainTipInfo(hash, 122)
+ err = dbInst.PutCompactionChainTipInfo(hash, 0)
s.Require().IsType(err, ErrInvalidCompactionChainTipHeight)
+ // Unable to put compaction chain tip info with height not incremental by 1.
+ err = dbInst.PutCompactionChainTipInfo(hash, 3)
+ s.Require().IsType(err, ErrInvalidCompactionChainTipHeight)
+ // It's OK to put compaction chain tip info with height incremental by 1.
+ s.Require().NoError(dbInst.PutCompactionChainTipInfo(hash, 2))
}
func (s *MemBackedDBTestSuite) TestDKGPrivateKey() {