mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 10:27:59 +00:00
State machine call proof backend (#3945)
* drafting a proof extraction at the hashdb level (to include everything for the 'call' proof case). * use full proof by default (replace previous proof recorder). * fix warnings. * Cache value not found in proof recorder. * Remove need or internal backend struct. * fix type. * doc
This commit is contained in:
@@ -410,7 +410,7 @@ fn generate_call_api_at_calls(decl: &ItemTrait) -> Result<TokenStream> {
|
||||
initialized_block: &std::cell::RefCell<Option<#crate_::BlockId<Block>>>,
|
||||
native_call: Option<NC>,
|
||||
context: #crate_::ExecutionContext,
|
||||
recorder: &Option<std::rc::Rc<std::cell::RefCell<#crate_::ProofRecorder<Block>>>>,
|
||||
recorder: &Option<#crate_::ProofRecorder<Block>>,
|
||||
) -> std::result::Result<#crate_::NativeOrEncoded<R>, T::Error> {
|
||||
let version = call_runtime_at.runtime_version_at(at)?;
|
||||
use #crate_::InitializeBlock;
|
||||
|
||||
@@ -257,7 +257,7 @@ fn generate_runtime_api_base_structures(impls: &[ItemImpl]) -> Result<TokenStrea
|
||||
commit_on_success: std::cell::RefCell<bool>,
|
||||
initialized_block: std::cell::RefCell<Option<#block_id>>,
|
||||
changes: std::cell::RefCell<#crate_::OverlayedChanges>,
|
||||
recorder: Option<std::rc::Rc<std::cell::RefCell<#crate_::ProofRecorder<#block>>>>,
|
||||
recorder: Option<#crate_::ProofRecorder<#block>>,
|
||||
}
|
||||
|
||||
// `RuntimeApi` itself is not threadsafe. However, an instance is only available in a
|
||||
@@ -300,11 +300,9 @@ fn generate_runtime_api_base_structures(impls: &[ItemImpl]) -> Result<TokenStrea
|
||||
self.recorder
|
||||
.take()
|
||||
.map(|recorder| {
|
||||
let trie_nodes = recorder
|
||||
.borrow_mut()
|
||||
.drain()
|
||||
.into_iter()
|
||||
.map(|record| record.data)
|
||||
let trie_nodes = recorder.read()
|
||||
.iter()
|
||||
.filter_map(|(_k, v)| v.as_ref().map(|v| v.to_vec()))
|
||||
.collect();
|
||||
#crate_::StorageProof::new(trie_nodes)
|
||||
})
|
||||
@@ -339,7 +337,7 @@ fn generate_runtime_api_base_structures(impls: &[ItemImpl]) -> Result<TokenStrea
|
||||
&Self,
|
||||
&std::cell::RefCell<#crate_::OverlayedChanges>,
|
||||
&std::cell::RefCell<Option<#crate_::BlockId<#block>>>,
|
||||
&Option<std::rc::Rc<std::cell::RefCell<#crate_::ProofRecorder<#block>>>>,
|
||||
&Option<#crate_::ProofRecorder<#block>>,
|
||||
) -> std::result::Result<#crate_::NativeOrEncoded<R>, E>,
|
||||
E,
|
||||
>(
|
||||
|
||||
@@ -59,16 +59,14 @@ use rstd::result;
|
||||
pub use codec::{Encode, Decode};
|
||||
use primitives::OpaqueMetadata;
|
||||
#[cfg(feature = "std")]
|
||||
use std::{panic::UnwindSafe, cell::RefCell, rc::Rc};
|
||||
#[cfg(feature = "std")]
|
||||
use primitives::Hasher as HasherT;
|
||||
use std::{panic::UnwindSafe, cell::RefCell};
|
||||
|
||||
pub use sr_api_proc_macro::{decl_runtime_apis, impl_runtime_apis};
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
/// A type that records all accessed trie nodes and generates a proof out of it.
|
||||
pub type ProofRecorder<B> = state_machine::ProofRecorder<
|
||||
<<<<B as BlockT>::Header as HeaderT>::Hashing as HashT>::Hasher as HasherT>::Out
|
||||
<<<B as BlockT>::Header as HeaderT>::Hashing as HashT>::Hasher
|
||||
>;
|
||||
|
||||
/// Something that can be constructed to a runtime api.
|
||||
@@ -168,7 +166,7 @@ pub trait CallRuntimeAt<Block: BlockT> {
|
||||
initialize_block: InitializeBlock<'a, Block>,
|
||||
native_call: Option<NC>,
|
||||
context: ExecutionContext,
|
||||
recorder: &Option<Rc<RefCell<ProofRecorder<Block>>>>,
|
||||
recorder: &Option<ProofRecorder<Block>>,
|
||||
) -> Result<NativeOrEncoded<R>, Self::Error>;
|
||||
|
||||
/// Returns the runtime version at the given block.
|
||||
|
||||
Reference in New Issue
Block a user