Skip to content

Commit

Permalink
Merge branch 'tomas/fix-non-persisted-diffs' (#2964)
Browse files Browse the repository at this point in the history
* origin/tomas/fix-non-persisted-diffs:
  changelog: add #2964
  test/DB: update rocksdb diffs and rollback tests
  DB: prune non-persisted diffs from prev block on every new block commit
  rocksdb: separate non-persisted diffs into new "rollback" column family
  core/storage: add `BlockHeight::checked_prev`
  • Loading branch information
tzemanovic committed Apr 10, 2024
2 parents b46ee0d + 58883a3 commit 370e18e
Show file tree
Hide file tree
Showing 7 changed files with 357 additions and 253 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- Replaced DB key-val diffs pruning of non-persisted keys that searched for the
last diffs and was degrading throughput with a separate DB column family that
is pruned on every block.
([\#2964](https://github.com/anoma/namada/pull/2964))
19 changes: 8 additions & 11 deletions crates/apps/src/lib/node/ledger/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,10 +777,6 @@ mod tests {
Key::parse("testing2").unwrap()
}

fn merkle_tree_key_filter(key: &Key) -> bool {
key == &test_key_1()
}

#[test]
fn test_persistent_storage_writing_without_merklizing_or_diffs() {
let db_path =
Expand All @@ -791,7 +787,8 @@ mod tests {
ChainId::default(),
address::testing::nam(),
None,
merkle_tree_key_filter,
// Only merkelize and persist diffs for `test_key_1`
|key: &Key| -> bool { key == &test_key_1() },
);
// Start the first block
let first_height = BlockHeight::first();
Expand Down Expand Up @@ -867,12 +864,12 @@ mod tests {
// need to have diffs for at least 1 block for rollback purposes
let res2 = state
.db()
.read_diffs_val(&key2, first_height, true)
.read_rollback_val(&key2, first_height, true)
.unwrap();
assert!(res2.is_none());
let res2 = state
.db()
.read_diffs_val(&key2, first_height, false)
.read_rollback_val(&key2, first_height, false)
.unwrap()
.unwrap();
let res2 = u64::try_from_slice(&res2).unwrap();
Expand Down Expand Up @@ -930,27 +927,27 @@ mod tests {
// Check that key-val-2 diffs don't exist for block 0 anymore
let res2 = state
.db()
.read_diffs_val(&key2, first_height, true)
.read_rollback_val(&key2, first_height, true)
.unwrap();
assert!(res2.is_none());
let res2 = state
.db()
.read_diffs_val(&key2, first_height, false)
.read_rollback_val(&key2, first_height, false)
.unwrap();
assert!(res2.is_none());

// Check that the block 1 diffs for key-val-2 include an "old" value of
// val2 and no "new" value
let res2 = state
.db()
.read_diffs_val(&key2, second_height, true)
.read_rollback_val(&key2, second_height, true)
.unwrap()
.unwrap();
let res2 = u64::try_from_slice(&res2).unwrap();
assert_eq!(res2, val2);
let res2 = state
.db()
.read_diffs_val(&key2, second_height, false)
.read_rollback_val(&key2, second_height, false)
.unwrap();
assert!(res2.is_none());
}
Expand Down

0 comments on commit 370e18e

Please sign in to comment.