Do not include :code in the storage proof if not required (#480)

This is basically a hack that prevents the inclusion of `:code` in the
storage proof. A proper fix requires some changes to the trie crate to
not include nodes that aren't read.
This commit is contained in:
Bastian Köcher
2021-06-07 16:17:19 +02:00
committed by GitHub
parent 33908c1414
commit 794bc23de4
10 changed files with 59 additions and 8 deletions
+17 -2
View File
@@ -333,6 +333,8 @@ mod tests {
use polkadot_overseer::{AllSubsystems, HeadSupportsParachains, Overseer};
use sp_consensus::BlockOrigin;
use sp_core::{testing::TaskExecutor, Pair};
use sp_runtime::traits::BlakeTwo256;
use sp_state_machine::Backend;
struct AlwaysSupportsParachains;
impl HeadSupportsParachains for AlwaysSupportsParachains {
@@ -376,7 +378,7 @@ mod tests {
}
#[test]
fn collates_produces_a_block() {
fn collates_produces_a_block_and_storage_proof_does_not_contains_code() {
let _ = env_logger::try_init();
let spawner = TaskExecutor::new();
@@ -432,8 +434,21 @@ mod tests {
let block_data = collation.proof_of_validity.block_data;
let block = Block::decode(&mut &block_data.0[..]).expect("Is a valid block");
let block =
ParachainBlockData::<Block>::decode(&mut &block_data.0[..]).expect("Is a valid block");
assert_eq!(1, *block.header().number());
// Ensure that we did not include `:code` in the proof.
let db = block.storage_proof().clone().into_memory_db();
let backend =
sp_state_machine::new_in_mem::<BlakeTwo256>().update_backend(*header.state_root(), db);
// Should return an error, as it was not included while building the proof.
assert!(backend
.storage(sp_core::storage::well_known_keys::CODE)
.unwrap_err()
.contains("Trie lookup error: Database missing expected key"));
}
}