From e818858777a1f7b6b1664081bb06993bcfcecd28 Mon Sep 17 00:00:00 2001 From: ftheirs Date: Mon, 25 Nov 2024 10:00:13 -0300 Subject: [PATCH 1/4] handle getProof without storage root idx --- .../rpc/src/pathfinder/methods/get_proof.rs | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/crates/rpc/src/pathfinder/methods/get_proof.rs b/crates/rpc/src/pathfinder/methods/get_proof.rs index 7d4103be00..e2f0923da9 100644 --- a/crates/rpc/src/pathfinder/methods/get_proof.rs +++ b/crates/rpc/src/pathfinder/methods/get_proof.rs @@ -263,20 +263,23 @@ pub async fn get_proof( let storage_root_idx = tx .storage_root_index(header.number) - .context("Querying storage root index")? - .ok_or(GetProofError::ProofMissing)?; - - // Generate a proof for this contract. If the contract does not exist, this will - // be a "non membership" proof. - let contract_proof = StorageCommitmentTree::get_proof( - &tx, - header.number, - &input.contract_address, - storage_root_idx, - )? - .into_iter() - .map(|(node, _)| node) - .collect(); + .context("Querying storage root index")?; + + let contract_proof = if let Some(storage_root_idx) = storage_root_idx { + // Generate a proof for this contract. If the contract does not exist, this will + // be a "non membership" proof. + StorageCommitmentTree::get_proof( + &tx, + header.number, + &input.contract_address, + storage_root_idx, + )? + .into_iter() + .map(|(node, _)| node) + .collect() + } else { + Vec::new() + }; let contract_proof = ProofNodes(contract_proof); From c0898b35355dd81293f35cd6d524dad288a82903 Mon Sep 17 00:00:00 2001 From: ftheirs Date: Mon, 25 Nov 2024 11:27:59 -0300 Subject: [PATCH 2/4] improvement --- .../rpc/src/pathfinder/methods/get_proof.rs | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/crates/rpc/src/pathfinder/methods/get_proof.rs b/crates/rpc/src/pathfinder/methods/get_proof.rs index e2f0923da9..f879997d7e 100644 --- a/crates/rpc/src/pathfinder/methods/get_proof.rs +++ b/crates/rpc/src/pathfinder/methods/get_proof.rs @@ -265,21 +265,16 @@ pub async fn get_proof( .storage_root_index(header.number) .context("Querying storage root index")?; - let contract_proof = if let Some(storage_root_idx) = storage_root_idx { - // Generate a proof for this contract. If the contract does not exist, this will - // be a "non membership" proof. - StorageCommitmentTree::get_proof( - &tx, - header.number, - &input.contract_address, - storage_root_idx, - )? - .into_iter() - .map(|(node, _)| node) - .collect() - } else { - Vec::new() - }; + let contract_proof = storage_root_idx + .map(|idx| { + // Generate a proof for this contract, creating a "non-membership" proof if the contract does not exist. + StorageCommitmentTree::get_proof(&tx, header.number, &input.contract_address, idx) + .unwrap_or_default() + .into_iter() + .map(|(node, _)| node) + .collect() + }) + .unwrap_or_default(); let contract_proof = ProofNodes(contract_proof); From e7d8f05054612de03f5ed9c0b8d93d762e42f9bd Mon Sep 17 00:00:00 2001 From: ftheirs Date: Mon, 25 Nov 2024 11:30:43 -0300 Subject: [PATCH 3/4] clippy --- crates/rpc/src/pathfinder/methods/get_proof.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/rpc/src/pathfinder/methods/get_proof.rs b/crates/rpc/src/pathfinder/methods/get_proof.rs index f879997d7e..fac84bde17 100644 --- a/crates/rpc/src/pathfinder/methods/get_proof.rs +++ b/crates/rpc/src/pathfinder/methods/get_proof.rs @@ -267,7 +267,8 @@ pub async fn get_proof( let contract_proof = storage_root_idx .map(|idx| { - // Generate a proof for this contract, creating a "non-membership" proof if the contract does not exist. + // Generate a proof for this contract, creating a "non-membership" proof if the + // contract does not exist. StorageCommitmentTree::get_proof(&tx, header.number, &input.contract_address, idx) .unwrap_or_default() .into_iter() From ca995acdaf6899178cca79a22ab8109a80a515a5 Mon Sep 17 00:00:00 2001 From: ftheirs Date: Mon, 25 Nov 2024 13:47:18 -0300 Subject: [PATCH 4/4] propagate error from StorageCommitmentTree::get_proof correctly --- crates/rpc/src/pathfinder/methods/get_proof.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/crates/rpc/src/pathfinder/methods/get_proof.rs b/crates/rpc/src/pathfinder/methods/get_proof.rs index fac84bde17..63dac7ed87 100644 --- a/crates/rpc/src/pathfinder/methods/get_proof.rs +++ b/crates/rpc/src/pathfinder/methods/get_proof.rs @@ -270,11 +270,9 @@ pub async fn get_proof( // Generate a proof for this contract, creating a "non-membership" proof if the // contract does not exist. StorageCommitmentTree::get_proof(&tx, header.number, &input.contract_address, idx) - .unwrap_or_default() - .into_iter() - .map(|(node, _)| node) - .collect() + .map(|proof| proof.into_iter().map(|(node, _)| node).collect()) }) + .transpose()? .unwrap_or_default(); let contract_proof = ProofNodes(contract_proof);