From e5c3dc16e025b1bc1c0e2ba00f1b8aef03b216d0 Mon Sep 17 00:00:00 2001 From: Simon Paitrault Date: Tue, 12 Mar 2024 11:09:21 +0100 Subject: [PATCH] chore: refactor after review Signed-off-by: Simon Paitrault --- crates/topos-tce-api/src/runtime/error.rs | 3 +++ crates/topos-tce-storage/src/validator/mod.rs | 4 ++++ crates/topos-tce/src/app_context/api.rs | 22 +++++++++++++++---- crates/topos-tce/src/app_context/network.rs | 14 +++++++++--- 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/crates/topos-tce-api/src/runtime/error.rs b/crates/topos-tce-api/src/runtime/error.rs index a5ee2d20f..e36a724f7 100644 --- a/crates/topos-tce-api/src/runtime/error.rs +++ b/crates/topos-tce-api/src/runtime/error.rs @@ -16,4 +16,7 @@ pub enum RuntimeError { #[error("Unexpected store error: {0}")] Store(#[from] StorageError), + + #[error("Communication error: {0}")] + CommunicationError(String), } diff --git a/crates/topos-tce-storage/src/validator/mod.rs b/crates/topos-tce-storage/src/validator/mod.rs index 3f1fc8a1d..282cd242d 100644 --- a/crates/topos-tce-storage/src/validator/mod.rs +++ b/crates/topos-tce-storage/src/validator/mod.rs @@ -139,6 +139,8 @@ impl ValidatorStore { } /// Returns the number of certificates in the pending pool (by iterating) + /// + /// Performance can be an issue on this one as we iter over all the pending certificates. pub fn iter_count_pending_certificates(&self) -> Result { Ok(self .pending_tables @@ -158,6 +160,8 @@ impl ValidatorStore { } /// Returns the number of certificates in the precedence pool (by iterating) + /// + /// Performance can be an issue on this one as we iter over all the precedence certificates. pub fn iter_count_precedence_pool_certificates(&self) -> Result { Ok(self .pending_tables diff --git a/crates/topos-tce/src/app_context/api.rs b/crates/topos-tce/src/app_context/api.rs index 387cd5456..57c3eb2cd 100644 --- a/crates/topos-tce/src/app_context/api.rs +++ b/crates/topos-tce/src/app_context/api.rs @@ -25,12 +25,13 @@ impl AppContext { .insert_pending_certificate(&certificate) { Ok(Some(pending_id)) => { + let certificate_id = certificate.id; debug!( "Certificate {} from subnet {} has been inserted into pending pool", - certificate.id, certificate.source_subnet_id + certificate_id, certificate.source_subnet_id ); - _ = self + if let Err(_) = self .tce_cli .get_double_echo_channel() .send(DoubleEchoCommand::Broadcast { @@ -38,9 +39,22 @@ impl AppContext { cert: *certificate, pending_id, }) - .await; + .await + { + error!( + "Unable to send DoubleEchoCommand::Broadcast command to double \ + echo for {}", + certificate_id + ); - sender.send(Ok(PendingResult::InPending(pending_id))) + sender.send(Err(RuntimeError::CommunicationError( + "Unable to send DoubleEchoCommand::Broadcast command to double \ + echo" + .to_string(), + ))) + } else { + sender.send(Ok(PendingResult::InPending(pending_id))) + } } Ok(None) => { debug!( diff --git a/crates/topos-tce/src/app_context/network.rs b/crates/topos-tce/src/app_context/network.rs index c92b3fbda..6416d3213 100644 --- a/crates/topos-tce/src/app_context/network.rs +++ b/crates/topos-tce/src/app_context/network.rs @@ -43,12 +43,13 @@ impl AppContext { match self.validator_store.insert_pending_certificate(&cert) { Ok(Some(pending_id)) => { + let certificate_id = cert.id; debug!( "Certificate {} has been inserted into pending pool", - cert.id + certificate_id ); - _ = self + if let Err(_) = self .tce_cli .get_double_echo_channel() .send(DoubleEchoCommand::Broadcast { @@ -56,7 +57,14 @@ impl AppContext { cert, pending_id, }) - .await; + .await + { + error!( + "Unable to send DoubleEchoCommand::Broadcast command to \ + double echo for {}", + certificate_id + ); + } } Ok(None) => { debug!(