pallet-mmr: fix offchain db for sync from zero (#12498)

* pallet-mmr: cosmetic improvements

* pallet-mmr: fix offchain storage for initial sync

* address review comments

* pallet-mmr: change offchain fork-resistant key to `(prefix, pos, parent_hash)`

Do this so that both canon and fork-resitant keys have the same
`(prefix, pos).encode()` prefix. Might be useful in the future if we'd
be able to to "get" offchain db entries using key prefixes as well.

Signed-off-by: acatangiu <adrian@parity.io>

Signed-off-by: acatangiu <adrian@parity.io>
This commit is contained in:
Adrian Catangiu
2022-10-17 12:09:47 +03:00
committed by GitHub
parent 37538f0429
commit 4ae0d9a8e3
4 changed files with 163 additions and 108 deletions
+4 -4
View File
@@ -100,8 +100,8 @@ fn should_contain_mmr_digest() {
#[test]
fn should_contain_valid_leaf_data() {
fn node_offchain_key(parent_hash: H256, pos: usize) -> Vec<u8> {
(<Test as pallet_mmr::Config>::INDEXING_PREFIX, parent_hash, pos as u64).encode()
fn node_offchain_key(pos: usize, parent_hash: H256) -> Vec<u8> {
(<Test as pallet_mmr::Config>::INDEXING_PREFIX, pos as u64, parent_hash).encode()
}
let mut ext = new_test_ext(vec![1, 2, 3, 4]);
@@ -110,7 +110,7 @@ fn should_contain_valid_leaf_data() {
<frame_system::Pallet<Test>>::parent_hash()
});
let mmr_leaf = read_mmr_leaf(&mut ext, node_offchain_key(parent_hash, 0));
let mmr_leaf = read_mmr_leaf(&mut ext, node_offchain_key(0, parent_hash));
assert_eq!(
mmr_leaf,
MmrLeaf {
@@ -135,7 +135,7 @@ fn should_contain_valid_leaf_data() {
<frame_system::Pallet<Test>>::parent_hash()
});
let mmr_leaf = read_mmr_leaf(&mut ext, node_offchain_key(parent_hash, 1));
let mmr_leaf = read_mmr_leaf(&mut ext, node_offchain_key(1, parent_hash));
assert_eq!(
mmr_leaf,
MmrLeaf {