Skip to content

Reduce booting time by using is_empty method #1526

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/scheme/scheme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
3 changes: 3 additions & 0 deletions util/hashdb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions util/journaldb/src/archivedb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -114,10 +118,6 @@ impl JournalDB for ArchiveDB {
})
}

fn is_empty(&self) -> bool {
self.latest_era.is_none()
}

fn latest_era(&self) -> Option<u64> {
self.latest_era
}
Expand Down
3 changes: 0 additions & 3 deletions util/journaldb/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u64> {
None
Expand Down
4 changes: 4 additions & 0 deletions util/memorydb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ impl HashDB for MemoryDB {
}
}
}

fn is_empty(&self) -> bool {
self.data.is_empty()
}
}

#[cfg(test)]
Expand Down