diff --git a/core/src/scheme/scheme.rs b/core/src/scheme/scheme.rs index eacd3c2356..a0b1b2cec1 100644 --- a/core/src/scheme/scheme.rs +++ b/core/src/scheme/scheme.rs @@ -249,7 +249,7 @@ impl Scheme { } pub fn check_genesis_root(&self, db: &HashDB) -> bool { - if db.keys().is_empty() { + if db.is_empty() { return true } db.contains(&self.state_root()) diff --git a/util/hashdb/src/lib.rs b/util/hashdb/src/lib.rs index d7945e0fa0..801928b4e7 100644 --- a/util/hashdb/src/lib.rs +++ b/util/hashdb/src/lib.rs @@ -48,6 +48,9 @@ pub trait HashDB: AsHashDB + Send + Sync { /// Remove a datum previously inserted. Insertions can be "owed" such that the same number of `insert()`s may /// happen without the data being eventually being inserted into the DB. It can be "owed" more than once. fn remove(&mut self, key: &H256); + + /// check if the db has no commits + fn is_empty(&self) -> bool; } /// Upcast trait. diff --git a/util/journaldb/src/archivedb.rs b/util/journaldb/src/archivedb.rs index 8997de19eb..3859e5e9c4 100644 --- a/util/journaldb/src/archivedb.rs +++ b/util/journaldb/src/archivedb.rs @@ -102,6 +102,10 @@ impl HashDB for ArchiveDB { fn remove(&mut self, key: &H256) { self.overlay.remove(key); } + + fn is_empty(&self) -> bool { + self.latest_era.is_none() + } } impl JournalDB for ArchiveDB { @@ -114,10 +118,6 @@ impl JournalDB for ArchiveDB { }) } - fn is_empty(&self) -> bool { - self.latest_era.is_none() - } - fn latest_era(&self) -> Option { self.latest_era } diff --git a/util/journaldb/src/traits.rs b/util/journaldb/src/traits.rs index cd50c969cc..5bb39486c0 100644 --- a/util/journaldb/src/traits.rs +++ b/util/journaldb/src/traits.rs @@ -35,9 +35,6 @@ pub trait JournalDB: HashDB { 0 } - /// Check if this database has any commits - fn is_empty(&self) -> bool; - /// Get the earliest era in the DB. None if there isn't yet any data in there. fn earliest_era(&self) -> Option { None diff --git a/util/memorydb/src/lib.rs b/util/memorydb/src/lib.rs index ba6c68e825..0699fb3995 100644 --- a/util/memorydb/src/lib.rs +++ b/util/memorydb/src/lib.rs @@ -262,6 +262,10 @@ impl HashDB for MemoryDB { } } } + + fn is_empty(&self) -> bool { + self.data.is_empty() + } } #[cfg(test)]