difftreelog
feat retrieve key values from proof trie
in: master
4 files changed
Cargo.lockdiffbeforeafterboth12847 "sp-rpc",12847 "sp-rpc",12848 "sp-runtime",12848 "sp-runtime",12849 "sp-state-machine",12849 "sp-state-machine",12850 "sp-trie",12851 "trie-db",12850 "unique-runtime",12852 "unique-runtime",12851 "up-common",12853 "up-common",12852 "up-data-structs",12854 "up-data-structs",client/rpc/Cargo.tomldiffbeforeafterboth16jsonrpsee = { version = "0.16.2", features = ["server", "macros"] }16jsonrpsee = { version = "0.16.2", features = ["server", "macros"] }17anyhow = "1.0.57"17anyhow = "1.0.57"18zstd = { version = "0.11.2", default-features = false }18zstd = { version = "0.11.2", default-features = false }19trie-db = { version = "0.24.0", default-features = false }192020sc-rpc-api = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }21sc-rpc-api = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }21sc-service = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }22sc-service = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }27sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }28sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }28sp-keystore = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }29sp-keystore = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }29sp-rpc = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }30sp-rpc = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }31sp-trie = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }30sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }32sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.36" }31pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier", branch = "unique-polkadot-v0.9.36" }33pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier", branch = "unique-polkadot-v0.9.36" }3234client/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.rsdiffbeforeafterboth32 pub compact_proof_size: u64,32 pub compact_proof_size: u64,33 pub compressed_proof_size: u64,33 pub compressed_proof_size: u64,34 pub results: Vec<ApplyExtrinsicResult>,34 pub results: Vec<ApplyExtrinsicResult>,35 pub key_values: Vec<TrieKeyValue>,35}36}3738#[cfg_attr(feature = "std", derive(Serialize))]39#[derive(Debug, TypeInfo)]40pub struct TrieKeyValue {41 pub key: Vec<u8>,42 pub value: Vec<u8>,43}364437sp_api::decl_runtime_apis! {45sp_api::decl_runtime_apis! {38 pub trait PovEstimateApi {46 pub trait PovEstimateApi {