Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Expose the overlay from ApiExt #10922

Closed
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/api/src/call_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,6 @@ pub trait CallExecutor<B: BlockT>: RuntimeVersionOf {
at: &BlockId<B>,
method: &str,
call_data: &[u8],
overlay: Option<sp_api::OverlayedChanges>,
liuchengxu marked this conversation as resolved.
Show resolved Hide resolved
) -> Result<(Vec<u8>, StorageProof), sp_blockchain::Error>;
}
1 change: 1 addition & 0 deletions client/api/src/proof_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub trait ProofProvider<Block: BlockT> {
id: &BlockId<Block>,
method: &str,
call_data: &[u8],
overlay: Option<sp_api::OverlayedChanges>,
) -> sp_blockchain::Result<(Vec<u8>, StorageProof)>;

/// Given a `BlockId` iterate over all storage values starting at `start_keys`.
Expand Down
35 changes: 18 additions & 17 deletions client/network/src/light_client_requests/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,23 +159,24 @@ impl<B: Block> LightClientRequestHandler<B> {

let block = Decode::decode(&mut request.block.as_ref())?;

let proof =
match self
.client
.execution_proof(&BlockId::Hash(block), &request.method, &request.data)
{
Ok((_, proof)) => proof,
Err(e) => {
trace!(
"remote call request from {} ({} at {:?}) failed with: {}",
peer,
request.method,
request.block,
e,
);
StorageProof::empty()
},
};
let proof = match self.client.execution_proof(
&BlockId::Hash(block),
&request.method,
&request.data,
None,
) {
Ok((_, proof)) => proof,
Err(e) => {
trace!(
"remote call request from {} ({} at {:?}) failed with: {}",
peer,
request.method,
request.block,
e,
);
StorageProof::empty()
},
};

let response = {
let r = schema::v1::light::RemoteCallResponse { proof: proof.encode() };
Expand Down
3 changes: 2 additions & 1 deletion client/service/src/client/call_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ where
at: &BlockId<Block>,
method: &str,
call_data: &[u8],
overlay: Option<sp_api::OverlayedChanges>,
liuchengxu marked this conversation as resolved.
Show resolved Hide resolved
) -> sp_blockchain::Result<(Vec<u8>, StorageProof)> {
let state = self.backend.state_at(*at)?;

Expand All @@ -308,7 +309,7 @@ where

sp_state_machine::prove_execution_on_trie_backend(
&trie_backend,
&mut Default::default(),
&mut overlay.unwrap_or_default(),
&self.executor,
self.spawn_handle.clone(),
method,
Expand Down
3 changes: 2 additions & 1 deletion client/service/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1189,8 +1189,9 @@ where
id: &BlockId<Block>,
method: &str,
call_data: &[u8],
overlay: Option<sp_api::OverlayedChanges>,
) -> sp_blockchain::Result<(Vec<u8>, StorageProof)> {
self.executor.prove_execution(id, method, call_data)
self.executor.prove_execution(id, method, call_data, overlay)
}

fn read_proof_collection(
Expand Down
4 changes: 4 additions & 0 deletions primitives/api/proc-macro/src/impl_runtime_apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,10 @@ fn generate_runtime_api_base_structures() -> Result<TokenStream> {
state_version,
)
}

fn overlay(&self) -> std::cell::RefCell<#crate_::OverlayedChanges> {
self.changes.clone()
bkchr marked this conversation as resolved.
Show resolved Hide resolved
}
}

#[cfg(any(feature = "std", test))]
Expand Down
4 changes: 4 additions & 0 deletions primitives/api/proc-macro/src/mock_impl_runtime_apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ fn implement_common_api_traits(block_type: TypePath, self_ty: Type) -> Result<To
> where Self: Sized {
unimplemented!("`into_storage_changes` not implemented for runtime api mocks")
}

fn overlay(&self) -> std::cell::RefCell<#crate_::OverlayedChanges> {
bkchr marked this conversation as resolved.
Show resolved Hide resolved
unimplemented!("`overlay` not implemented for runtime api mocks")
}
}

impl #crate_::Core<#block_type> for #self_ty {
Expand Down
3 changes: 3 additions & 0 deletions primitives/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,9 @@ pub trait ApiExt<Block: BlockT> {
) -> Result<StorageChanges<Self::StateBackend, Block>, String>
where
Self: Sized;

/// TODO
fn overlay(&self) -> RefCell<OverlayedChanges>;
bkchr marked this conversation as resolved.
Show resolved Hide resolved
}

/// Parameters for [`CallApiAt::call_api_at`].
Expand Down