Skip to content

Commit

Permalink
In the node service, don't unnecessarily call prepare_chain. (#2479)
Browse files Browse the repository at this point in the history
  • Loading branch information
afck authored Sep 12, 2024
1 parent d82dfb9 commit 2125e35
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
5 changes: 3 additions & 2 deletions linera-client/src/chain_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use linera_base::{
};
use linera_chain::data_types::OutgoingMessage;
use linera_core::{
client::ChainClient,
client::{ChainClient, ChainClientError},
node::{LocalValidatorNodeProvider, ValidatorNode, ValidatorNodeProvider},
worker::Reason,
};
Expand Down Expand Up @@ -183,7 +183,8 @@ where
continue;
}
debug!("Processing inbox");
match client.process_inbox_if_owned().await {
match client.process_inbox_without_prepare().await {
Err(ChainClientError::CannotFindKeyForChain(_)) => continue,
Err(error) => {
warn!(%error, "Failed to process inbox.");
timeout = Timestamp::from(u64::MAX);
Expand Down
31 changes: 14 additions & 17 deletions linera-core/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2687,15 +2687,27 @@ where
}

#[tracing::instrument(level = "trace")]
/// Creates blocks without any operations to process all incoming messages. This may require
/// several blocks.
/// Synchronizes the chain with the validators and creates blocks without any operations to
/// process all incoming messages. This may require several blocks.
///
/// If not all certificates could be processed due to a timeout, the timestamp for when to retry
/// is returned, too.
pub async fn process_inbox(
&self,
) -> Result<(Vec<Certificate>, Option<RoundTimeout>), ChainClientError> {
self.prepare_chain().await?;
self.process_inbox_without_prepare().await
}

#[tracing::instrument(level = "trace")]
/// Creates blocks without any operations to process all incoming messages. This may require
/// several blocks.
///
/// If not all certificates could be processed due to a timeout, the timestamp for when to retry
/// is returned, too.
pub async fn process_inbox_without_prepare(
&self,
) -> Result<(Vec<Certificate>, Option<RoundTimeout>), ChainClientError> {
let mut certificates = Vec::new();
loop {
let incoming_bundles = self.pending_message_bundles().await?;
Expand All @@ -2713,21 +2725,6 @@ where
}
}

#[tracing::instrument(level = "trace")]
/// Creates blocks without any operations to process all incoming messages. This may require
/// several blocks.
///
/// If we are not a chain owner, this doesn't fail, and just returns an empty list.
pub async fn process_inbox_if_owned(
&self,
) -> Result<(Vec<Certificate>, Option<RoundTimeout>), ChainClientError> {
match self.process_inbox().await {
Ok(result) => Ok(result),
Err(ChainClientError::CannotFindKeyForChain(_)) => Ok((Vec::new(), None)),
Err(error) => Err(error),
}
}

#[tracing::instrument(level = "trace")]
/// Starts listening to the admin chain for new committees. (This is only useful for
/// other genesis chains or for testing.)
Expand Down

0 comments on commit 2125e35

Please sign in to comment.