From 46873ab9a5808a0c5f36114732f53108e2173b05 Mon Sep 17 00:00:00 2001 From: -f Date: Mon, 6 Nov 2023 19:39:14 -0500 Subject: [PATCH] get_proof doesn't return option --- .../agents/relayer/src/merkle_tree/builder.rs | 10 ++--- .../relayer/src/msg/metadata/aggregation.rs | 9 +---- rust/agents/relayer/src/msg/metadata/base.rs | 40 +++++++++---------- .../metadata/multisig/merkle_root_multisig.rs | 11 ++--- 4 files changed, 27 insertions(+), 43 deletions(-) diff --git a/rust/agents/relayer/src/merkle_tree/builder.rs b/rust/agents/relayer/src/merkle_tree/builder.rs index 81672450bb..fecfc828e0 100644 --- a/rust/agents/relayer/src/merkle_tree/builder.rs +++ b/rust/agents/relayer/src/merkle_tree/builder.rs @@ -75,14 +75,10 @@ impl MerkleTreeBuilder { &self, leaf_index: u32, root_index: u32, - ) -> Result, MerkleTreeBuilderError> { - match self - .prover + ) -> Result { + 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 { diff --git a/rust/agents/relayer/src/msg/metadata/aggregation.rs b/rust/agents/relayer/src/msg/metadata/aggregation.rs index 59835d6c62..de91b1ea24 100644 --- a/rust/agents/relayer/src/msg/metadata/aggregation.rs +++ b/rust/agents/relayer/src/msg/metadata/aggregation.rs @@ -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)) diff --git a/rust/agents/relayer/src/msg/metadata/base.rs b/rust/agents/relayer/src/msg/metadata/base.rs index efc1195962..95ec94eec9 100644 --- a/rust/agents/relayer/src/msg/metadata/base.rs +++ b/rust/agents/relayer/src/msg/metadata/base.rs @@ -101,31 +101,29 @@ impl BaseMetadataBuilder { } } - pub async fn get_proof( - &self, - leaf_index: u32, - checkpoint: Checkpoint, - ) -> Result> { + pub async fn get_proof(&self, leaf_index: u32, checkpoint: Checkpoint) -> Result { 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 { diff --git a/rust/agents/relayer/src/msg/metadata/multisig/merkle_root_multisig.rs b/rust/agents/relayer/src/msg/metadata/multisig/merkle_root_multisig.rs index 4bd1261907..c35971791d 100644 --- a/rust/agents/relayer/src/msg/metadata/multisig/merkle_root_multisig.rs +++ b/rust/agents/relayer/src/msg/metadata/multisig/merkle_root_multisig.rs @@ -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,