Added client function to delete a recent block (#8533)

* Implemented recent block removal

* Apply suggestions from code review

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Arkadiy Paronyan
2021-05-05 19:16:34 +03:00
committed by GitHub
parent 7c3a3f79ba
commit d11e60510e
7 changed files with 295 additions and 49 deletions
+17
View File
@@ -364,6 +364,17 @@ impl<BlockHash: Hash + MallocSizeOf, Key: Hash + MallocSizeOf> StateDbSync<Block
}
}
fn remove(&mut self, hash: &BlockHash) -> Option<CommitSet<Key>> {
match self.mode {
PruningMode::ArchiveAll => {
Some(CommitSet::default())
},
PruningMode::ArchiveCanonical | PruningMode::Constrained(_) => {
self.non_canonical.remove(hash)
},
}
}
fn pin(&mut self, hash: &BlockHash) -> Result<(), PinError> {
match self.mode {
PruningMode::ArchiveAll => Ok(()),
@@ -509,6 +520,12 @@ impl<BlockHash: Hash + MallocSizeOf, Key: Hash + MallocSizeOf> StateDb<BlockHash
self.db.write().revert_one()
}
/// Remove specified non-canonical block.
/// Returns a database commit or `None` if not possible.
pub fn remove(&self, hash: &BlockHash) -> Option<CommitSet<Key>> {
self.db.write().remove(hash)
}
/// Returns last finalized block number.
pub fn best_canonical(&self) -> Option<u64> {
return self.db.read().best_canonical()