Skip to content
Snippets Groups Projects
Commit 1fc2db58 authored by Arkadiy Paronyan's avatar Arkadiy Paronyan Committed by Gav Wood
Browse files

Fixed finalizing multiple blocks at once (#1837)

* Fixed finalizing multiple blocks at once

* Added a test

* Added a comment
parent 93c19326
No related merge requests found
......@@ -166,7 +166,9 @@ impl<BlockHash: Hash, Key: Hash> RefWindow<BlockHash, Key> {
inserted,
deleted,
};
let block = self.pending_number + self.window_size() as u64;
// Calculate pending block number taking pending canonicalizations into account, but not pending prunings
// as these are always applied last.
let block = self.pending_number + (self.death_rows.len() + self.pending_records.len()) as u64;
let journal_key = to_journal_key(block);
commit.meta.inserted.push((journal_key.clone(), journal_record.encode()));
self.pending_records.push((block, journal_record));
......@@ -290,6 +292,29 @@ mod tests {
assert_eq!(pruning.pending_number, 2);
}
#[test]
fn prune_two_pending() {
let mut db = make_db(&[1, 2, 3]);
let mut pruning: RefWindow<H256, H256> = RefWindow::new(&db).unwrap();
let mut commit = make_commit(&[4], &[1]);
pruning.note_canonical(&H256::random(), &mut commit);
db.commit(&commit);
let mut commit = make_commit(&[5], &[2]);
pruning.note_canonical(&H256::random(), &mut commit);
db.commit(&commit);
assert!(db.data_eq(&make_db(&[1, 2, 3, 4, 5])));
let mut commit = CommitSet::default();
pruning.prune_one(&mut commit);
db.commit(&commit);
assert!(db.data_eq(&make_db(&[2, 3, 4, 5])));
let mut commit = CommitSet::default();
pruning.prune_one(&mut commit);
db.commit(&commit);
pruning.apply_pending();
assert!(db.data_eq(&make_db(&[3, 4, 5])));
assert_eq!(pruning.pending_number, 2);
}
#[test]
fn reinserted_survives() {
let mut db = make_db(&[1, 2, 3]);
......
......@@ -60,7 +60,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("node"),
impl_name: create_runtime_str!("substrate-node"),
authoring_version: 10,
spec_version: 29,
spec_version: 30,
impl_version: 32,
apis: RUNTIME_API_VERSIONS,
};
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment