Skip to content

Commit

Permalink
get_proof doesn't return option
Browse files Browse the repository at this point in the history
  • Loading branch information
aroralanuk committed Nov 7, 2023
1 parent 7ff416e commit 46873ab
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 43 deletions.
10 changes: 3 additions & 7 deletions rust/agents/relayer/src/merkle_tree/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,10 @@ impl MerkleTreeBuilder {
&self,
leaf_index: u32,
root_index: u32,
) -> Result<Option<Proof>, MerkleTreeBuilderError> {
match self
.prover
) -> Result<Proof, MerkleTreeBuilderError> {
self.prover
.prove_against_previous(leaf_index as usize, root_index as usize)
{
Ok(proof) => Ok(Some(proof)),
Err(prover_err) => Err(MerkleTreeBuilderError::from(prover_err)),
}
.map_err(MerkleTreeBuilderError::from)
}

pub fn count(&self) -> u32 {
Expand Down
9 changes: 1 addition & 8 deletions rust/agents/relayer/src/msg/metadata/aggregation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,7 @@ impl AggregationIsmMetadataBuilder {

let metas_and_gas_count = metas_and_gas.len();
if metas_and_gas_count < threshold {
info!("Could not fetch all metadata: Found {metas_and_gas_count} of the {threshold} required ISM metadata pieces for message_id {message_id}", metas_and_gas_count=metas_and_gas_count, threshold=threshold, message_id=message.id());
for (module_type, ism_address) in err_isms {
info!(
"Invalid ISM: {module_type} at {ism_address}",
module_type = module_type,
ism_address = ism_address
);
}
info!(?err_isms, %metas_and_gas_count, %threshold, message_id=message.id().to_string(), "Could not fetch all metadata, ISM metadata count did not reach aggregation threshold");
return None;
}
Some(Self::n_cheapest_metas(metas_and_gas, threshold))
Expand Down
40 changes: 19 additions & 21 deletions rust/agents/relayer/src/msg/metadata/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,31 +101,29 @@ impl BaseMetadataBuilder {
}
}

pub async fn get_proof(
&self,
leaf_index: u32,
checkpoint: Checkpoint,
) -> Result<Option<Proof>> {
pub async fn get_proof(&self, leaf_index: u32, checkpoint: Checkpoint) -> Result<Proof> {
const CTX: &str = "When fetching message proof";
let proof = self.origin_prover_sync
let proof = self
.origin_prover_sync
.read()
.await
.get_proof(leaf_index, checkpoint.index)
.context(CTX)?
.and_then(|proof| {
// checkpoint may be fraudulent if the root does not
// match the canonical root at the checkpoint's index
if proof.root() == checkpoint.root {
return Some(proof)
}
info!(
?checkpoint,
canonical_root = ?proof.root(),
"Could not fetch metadata: checkpoint root does not match canonical root from merkle proof"
);
None
});
Ok(proof)
.context(CTX)?;

if proof.root() == checkpoint.root {
Ok(proof)
} else {
info!(
?checkpoint,
canonical_root = ?proof.root(),
"Could not fetch metadata: checkpoint root does not match canonical root from merkle proof"
);
Err(MerkleTreeBuilderError::MismatchedRoots {
prover_root: proof.root(),
incremental_root: checkpoint.root,
}
.into())
}
}

pub async fn highest_known_leaf_index(&self) -> Option<u32> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,10 @@ impl MultisigIsmMetadataBuilder for MerkleRootMultisigMetadataBuilder {
highest_leaf_index, "Couldn't get checkpoint in range"
)
);
unwrap_or_none_result!(
proof,
self.get_proof(leaf_index, quorum_checkpoint.checkpoint.checkpoint)
.await
.context(CTX)?,
debug!(leaf_index, checkpoint=?quorum_checkpoint, "Couldn't get proof")
);
let proof = self
.get_proof(leaf_index, quorum_checkpoint.checkpoint.checkpoint)
.await
.context(CTX)?;
Ok(Some(MultisigMetadata::new(
quorum_checkpoint,
leaf_index,
Expand Down

0 comments on commit 46873ab

Please sign in to comment.