Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
chore: refactor after review
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Paitrault <[email protected]>
  • Loading branch information
Freyskeyd committed Mar 12, 2024
1 parent e459b6a commit e5c3dc1
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
3 changes: 3 additions & 0 deletions crates/topos-tce-api/src/runtime/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ pub enum RuntimeError {

#[error("Unexpected store error: {0}")]
Store(#[from] StorageError),

#[error("Communication error: {0}")]
CommunicationError(String),
}
4 changes: 4 additions & 0 deletions crates/topos-tce-storage/src/validator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u64, StorageError> {
Ok(self
.pending_tables
Expand All @@ -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<u64, StorageError> {
Ok(self
.pending_tables
Expand Down
22 changes: 18 additions & 4 deletions crates/topos-tce/src/app_context/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,36 @@ 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 {
need_gossip: true,
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!(
Expand Down
14 changes: 11 additions & 3 deletions crates/topos-tce/src/app_context/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,28 @@ 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 {
need_gossip: false,
cert,
pending_id,
})
.await;
.await
{
error!(
"Unable to send DoubleEchoCommand::Broadcast command to \
double echo for {}",
certificate_id
);
}
}
Ok(None) => {
debug!(
Expand Down

0 comments on commit e5c3dc1

Please sign in to comment.