difftreelog
feat retrieve key values from proof trie
in: master
4 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -12847,6 +12847,8 @@
"sp-rpc",
"sp-runtime",
"sp-state-machine",
+ "sp-trie",
+ "trie-db",
"unique-runtime",
"up-common",
"up-data-structs",
client/rpc/Cargo.tomldiffbeforeafterboth--- a/client/rpc/Cargo.toml
+++ b/client/rpc/Cargo.toml
@@ -16,6 +16,7 @@
jsonrpsee = { version = "0.16.2", features = ["server", "macros"] }
anyhow = "1.0.57"
zstd = { version = "0.11.2", default-features = false }
+trie-db = { version = "0.24.0", default-features = false }
sc-rpc-api = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
sc-service = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
@@ -27,6 +28,7 @@
sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
sp-keystore = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
sp-rpc = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
+sp-trie = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }
pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier", branch = "unique-polkadot-v0.9.36" }
client/rpc/src/pov_estimate.rsdiffbeforeafterboth242425use sc_service::{NativeExecutionDispatch, config::ExecutionStrategy};25use sc_service::{NativeExecutionDispatch, config::ExecutionStrategy};26use sp_state_machine::{StateMachine, TrieBackendBuilder};26use sp_state_machine::{StateMachine, TrieBackendBuilder};27use trie_db::{Trie, TrieDBBuilder};272828use jsonrpsee::{core::RpcResult as Result, proc_macros::rpc};29use jsonrpsee::{core::RpcResult as Result, proc_macros::rpc};29use anyhow::anyhow;30use anyhow::anyhow;474848use sp_runtime::traits::Header;49use sp_runtime::traits::Header;495050use up_pov_estimate_rpc::PovInfo;51use up_pov_estimate_rpc::{PovInfo, TrieKeyValue};515252use crate::define_struct_for_server_api;53use crate::define_struct_for_server_api;5354244 results.push(xt_result);245 results.push(xt_result);245 }246 }247248 let root = proving_backend.root().clone();246249247 let proof = proving_backend250 let proof = proving_backend248 .extract_proof()251 .extract_proof()249 .expect("A recorder was set and thus, a storage proof can be extracted; qed");252 .expect("A recorder was set and thus, a storage proof can be extracted; qed");250 let proof_size = proof.encoded_size();253 let proof_size = proof.encoded_size();254255 let memory_db = proof.clone().into_memory_db();256257 let tree_db =258 TrieDBBuilder::<sp_trie::LayoutV1<HasherOf<Block>>>::new(&memory_db, &root).build();259260 let key_values = tree_db261 .iter()262 .map_err(|e| anyhow!("failed to retrieve tree db key values: {:?}", e))?263 .filter_map(|item| {264 let item = item.ok()?;265266 Some(TrieKeyValue {267 key: item.0,268 value: item.1,269 })270 })271 .collect();272251 let compact_proof = proof273 let compact_proof = proof252 .clone()274 .clone()263 compact_proof_size: compact_proof_size as u64,285 compact_proof_size: compact_proof_size as u64,264 compressed_proof_size: compressed_proof_size as u64,286 compressed_proof_size: compressed_proof_size as u64,265 results,287 results,288 key_values,266 })289 })267}290}268291primitives/pov-estimate-rpc/src/lib.rsdiffbeforeafterboth--- a/primitives/pov-estimate-rpc/src/lib.rs
+++ b/primitives/pov-estimate-rpc/src/lib.rs
@@ -32,6 +32,14 @@
pub compact_proof_size: u64,
pub compressed_proof_size: u64,
pub results: Vec<ApplyExtrinsicResult>,
+ pub key_values: Vec<TrieKeyValue>,
+}
+
+#[cfg_attr(feature = "std", derive(Serialize))]
+#[derive(Debug, TypeInfo)]
+pub struct TrieKeyValue {
+ pub key: Vec<u8>,
+ pub value: Vec<u8>,
}
sp_api::decl_runtime_apis! {