diff --git a/substrate/core/state-db/src/pruning.rs b/substrate/core/state-db/src/pruning.rs index 59ced33cc28040e8579114a6c07086e46e77eaff..83cd51b70b4d2f2ce01295243d7ca80ea9aa2dee 100644 --- a/substrate/core/state-db/src/pruning.rs +++ b/substrate/core/state-db/src/pruning.rs @@ -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]); diff --git a/substrate/node/runtime/src/lib.rs b/substrate/node/runtime/src/lib.rs index 179012db39369ad41662afbb4dc50a39b97587ed..56ac26b4e8e00ae26ad41bcf9ea4280c54a26c53 100644 --- a/substrate/node/runtime/src/lib.rs +++ b/substrate/node/runtime/src/lib.rs @@ -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, };