git.delta.rocks / unique-network / refs/commits / be09f662cdcf

difftreelog

feat retrieve key values from proof trie

Daniel Shiposha2022-11-24parent: #254f58f.patch.diff
in: master

4 files changed

modifiedCargo.lockdiffbeforeafterboth
12847 "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",
modifiedclient/rpc/Cargo.tomldiffbeforeafterboth
16jsonrpsee = { 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 }
1920
20sc-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" }
3234
modifiedclient/rpc/src/pov_estimate.rsdiffbeforeafterboth
2424
25use 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};
2728
28use jsonrpsee::{core::RpcResult as Result, proc_macros::rpc};29use jsonrpsee::{core::RpcResult as Result, proc_macros::rpc};
29use anyhow::anyhow;30use anyhow::anyhow;
4748
48use sp_runtime::traits::Header;49use sp_runtime::traits::Header;
4950
50use up_pov_estimate_rpc::PovInfo;51use up_pov_estimate_rpc::{PovInfo, TrieKeyValue};
5152
52use crate::define_struct_for_server_api;53use crate::define_struct_for_server_api;
5354
244 results.push(xt_result);245 results.push(xt_result);
245 }246 }
247
248 let root = proving_backend.root().clone();
246249
247 let proof = proving_backend250 let proof = proving_backend
248 .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();
254
255 let memory_db = proof.clone().into_memory_db();
256
257 let tree_db =
258 TrieDBBuilder::<sp_trie::LayoutV1<HasherOf<Block>>>::new(&memory_db, &root).build();
259
260 let key_values = tree_db
261 .iter()
262 .map_err(|e| anyhow!("failed to retrieve tree db key values: {:?}", e))?
263 .filter_map(|item| {
264 let item = item.ok()?;
265
266 Some(TrieKeyValue {
267 key: item.0,
268 value: item.1,
269 })
270 })
271 .collect();
272
251 let compact_proof = proof273 let compact_proof = proof
252 .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}
268291
modifiedprimitives/pov-estimate-rpc/src/lib.rsdiffbeforeafterboth
32 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}
37
38#[cfg_attr(feature = "std", derive(Serialize))]
39#[derive(Debug, TypeInfo)]
40pub struct TrieKeyValue {
41 pub key: Vec<u8>,
42 pub value: Vec<u8>,
43}
3644
37sp_api::decl_runtime_apis! {45sp_api::decl_runtime_apis! {
38 pub trait PovEstimateApi {46 pub trait PovEstimateApi {