Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 7 additions & 3 deletions client/api/src/proof_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ use sp_storage::{ChildInfo, StorageKey};
/// Interface for providing block proving utilities.
pub trait ProofProvider<Block: BlockT> {
/// Reads storage value at a given block + key, returning read proof.
fn read_proof(&self, id: &BlockId<Block>, keys: &[Vec<u8>]) -> sp_blockchain::Result<StorageProof>;
fn read_proof(
&self,
id: &BlockId<Block>,
keys: &mut dyn Iterator<Item=&[u8]>,
) -> sp_blockchain::Result<StorageProof>;

/// Reads child storage value at a given block + storage_key + key, returning
/// read proof.
Expand All @@ -33,7 +37,7 @@ pub trait ProofProvider<Block: BlockT> {
id: &BlockId<Block>,
storage_key: &[u8],
child_info: ChildInfo,
keys: &[Vec<u8>],
keys: &mut dyn Iterator<Item=&[u8]>,
) -> sp_blockchain::Result<StorageProof>;

/// Execute a call to a contract on top of state in a block of given hash
Expand Down Expand Up @@ -64,4 +68,4 @@ pub trait ProofProvider<Block: BlockT> {
storage_key: Option<&StorageKey>,
key: &StorageKey,
) -> sp_blockchain::Result<ChangesProof<Block::Header>>;
}
}
2 changes: 1 addition & 1 deletion client/finality-grandpa/src/finality_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl<BE, Block: BlockT> AuthoritySetForFinalityProver<Block> for Arc<dyn Storage
}

fn prove_authorities(&self, block: &BlockId<Block>) -> ClientResult<StorageProof> {
self.read_proof(block, &[GRANDPA_AUTHORITIES_KEY.to_vec()])
self.read_proof(block, &mut std::iter::once(GRANDPA_AUTHORITIES_KEY))
}
}

Expand Down
16 changes: 12 additions & 4 deletions client/network/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,19 @@ pub trait Client<Block: BlockT>: Send + Sync {
-> Result<(Block::Header, StorageProof), Error>;

/// Get storage read execution proof.
fn read_proof(&self, block: &Block::Hash, keys: &[Vec<u8>]) -> Result<StorageProof, Error>;
fn read_proof(
&self,
block: &Block::Hash,
keys: &mut dyn Iterator<Item=&[u8]>,
) -> Result<StorageProof, Error>;

/// Get child storage read execution proof.
fn read_child_proof(
&self,
block: &Block::Hash,
storage_key: &[u8],
child_info: ChildInfo,
keys: &[Vec<u8>],
keys: &mut dyn Iterator<Item=&[u8]>,
) -> Result<StorageProof, Error>;

/// Get method execution proof.
Expand Down Expand Up @@ -132,7 +136,11 @@ impl<B, E, Block, RA> Client<Block> for SubstrateClient<B, E, Block, RA> where
ProofProvider::<Block>::header_proof(self, &BlockId::Number(block_number))
}

fn read_proof(&self, block: &Block::Hash, keys: &[Vec<u8>]) -> Result<StorageProof, Error> {
fn read_proof(
&self,
block: &Block::Hash,
keys: &mut dyn Iterator<Item=&[u8]>,
) -> Result<StorageProof, Error> {
ProofProvider::<Block>::read_proof(self, &BlockId::Hash(block.clone()), keys)
}

Expand All @@ -141,7 +149,7 @@ impl<B, E, Block, RA> Client<Block> for SubstrateClient<B, E, Block, RA> where
block: &Block::Hash,
storage_key: &[u8],
child_info: ChildInfo,
keys: &[Vec<u8>],
keys: &mut dyn Iterator<Item=&[u8]>,
) -> Result<StorageProof, Error> {
ProofProvider::<Block>::read_child_proof(self, &BlockId::Hash(block.clone()), storage_key, child_info, keys)
}
Expand Down
7 changes: 5 additions & 2 deletions client/network/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1473,7 +1473,10 @@ impl<B: BlockT, H: ExHashT> Protocol<B, H> {

trace!(target: "sync", "Remote read request {} from {} ({} at {})",
request.id, who, keys_str(), request.block);
let proof = match self.context_data.chain.read_proof(&request.block, &request.keys) {
let proof = match self.context_data.chain.read_proof(
&request.block,
&mut request.keys.iter().map(AsRef::as_ref)
) {
Ok(proof) => proof,
Err(error) => {
trace!(target: "sync", "Remote read request {} from {} ({} at {}) failed with: {}",
Expand Down Expand Up @@ -1523,7 +1526,7 @@ impl<B: BlockT, H: ExHashT> Protocol<B, H> {
&request.block,
&request.storage_key,
child_info,
&request.keys,
&mut request.keys.iter().map(AsRef::as_ref),
) {
Ok(proof) => proof,
Err(error) => {
Expand Down
9 changes: 7 additions & 2 deletions client/network/src/protocol/light_client_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ where

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

let proof = match self.chain.read_proof(&block, &request.keys) {
let proof = match self.chain.read_proof(&block, &mut request.keys.iter().map(AsRef::as_ref)) {
Ok(proof) => proof,
Err(error) => {
log::trace!("remote read request {} from {} ({} at {:?}) failed with: {}",
Expand Down Expand Up @@ -516,7 +516,12 @@ where

let proof =
if let Some(info) = ChildInfo::resolve_child_info(request.child_type, &request.child_info[..]) {
match self.chain.read_child_proof(&block, &request.storage_key, info, &request.keys) {
match self.chain.read_child_proof(
&block,
&request.storage_key,
info,
&mut request.keys.iter().map(AsRef::as_ref)
) {
Ok(proof) => proof,
Err(error) => {
log::trace!("remote read child request {} from {} ({} {} at {:?}) failed with: {}",
Expand Down
8 changes: 6 additions & 2 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1088,7 +1088,11 @@ impl<B, E, Block, RA> ProofProvider<Block> for Client<B, E, Block, RA> where
E: CallExecutor<Block>,
Block: BlockT,
{
fn read_proof(&self, id: &BlockId<Block>, keys: &[Vec<u8>]) -> sp_blockchain::Result<StorageProof> {
fn read_proof(
&self,
id: &BlockId<Block>,
keys: &mut dyn Iterator<Item=&[u8]>,
) -> sp_blockchain::Result<StorageProof> {
self.state_at(id)
.and_then(|state| prove_read(state, keys)
.map_err(Into::into))
Expand All @@ -1099,7 +1103,7 @@ impl<B, E, Block, RA> ProofProvider<Block> for Client<B, E, Block, RA> where
id: &BlockId<Block>,
storage_key: &[u8],
child_info: ChildInfo,
keys: &[Vec<u8>],
keys: &mut dyn Iterator<Item=&[u8]>,
) -> sp_blockchain::Result<StorageProof> {
self.state_at(id)
.and_then(|state| prove_child_read(state, storage_key, child_info, keys)
Expand Down
4 changes: 2 additions & 2 deletions client/src/light/fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ pub mod tests {
.and_then(|v| Decode::decode(&mut &v.0[..]).ok()).unwrap();
let remote_read_proof = remote_client.read_proof(
&remote_block_id,
&[well_known_keys::HEAP_PAGES.to_vec()],
&mut std::iter::once(well_known_keys::HEAP_PAGES),
).unwrap();

// check remote read proof locally
Expand Down Expand Up @@ -427,7 +427,7 @@ pub mod tests {
&remote_block_id,
b":child_storage:default:child1",
CHILD_INFO_1,
&["key1".as_bytes().to_vec()],
&mut std::iter::once("key1".as_bytes()),
).unwrap();

// check locally
Expand Down