mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 03:27:58 +00:00
Don't include :code by default in storage proofs (#5060)
* Adds test to verify that the runtime currently is always contained in the proof * Start passing the runtime wasm code from the outside * Fix compilation * More build fixes * Make the test work as expected now :) * Last fixes * Fixes benchmarks * Review feedback * Apply suggestions from code review Co-Authored-By: Sergei Pepyakin <sergei@parity.io> * Review feedback * Fix compilation Co-authored-by: Sergei Pepyakin <s.pepyakin@gmail.com>
This commit is contained in:
committed by
GitHub
parent
67837c6233
commit
6ee39261c8
@@ -18,9 +18,9 @@
|
||||
|
||||
use log::warn;
|
||||
use hash_db::Hasher;
|
||||
use codec::Encode;
|
||||
use codec::{Decode, Encode};
|
||||
|
||||
use sp_core::storage::{ChildInfo, OwnedChildInfo};
|
||||
use sp_core::{traits::RuntimeCode, storage::{ChildInfo, OwnedChildInfo, well_known_keys}};
|
||||
use sp_trie::{TrieMut, MemoryDB, trie_types::TrieDBMut};
|
||||
|
||||
use crate::{
|
||||
@@ -359,3 +359,22 @@ pub(crate) fn insert_into_memory_db<H, I>(mdb: &mut MemoryDB<H>, input: I) -> Op
|
||||
|
||||
Some(root)
|
||||
}
|
||||
|
||||
/// Get the runtime code from the given `backend`.
|
||||
///
|
||||
/// Returns an error if the `:code` could not be found.
|
||||
pub fn get_runtime_code<H: Hasher, B: Backend<H>>(backend: &B) -> Result<RuntimeCode, &'static str>
|
||||
where H::Out: Encode,
|
||||
{
|
||||
let code = backend.storage(well_known_keys::CODE)
|
||||
.ok()
|
||||
.flatten()
|
||||
.ok_or("`:code` not found")?;
|
||||
let hash = H::hash(&code).encode();
|
||||
let heap_pages = backend.storage(well_known_keys::HEAP_PAGES)
|
||||
.ok()
|
||||
.flatten()
|
||||
.and_then(|d| Decode::decode(&mut &d[..]).ok());
|
||||
|
||||
Ok(RuntimeCode { code, hash, heap_pages })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user