Skip to content

Commit

Permalink
Remove redundant prepare_chain calls. (#2961)
Browse files Browse the repository at this point in the history
  • Loading branch information
afck authored Nov 27, 2024
1 parent f8cb708 commit 4cac5fb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 16 deletions.
5 changes: 3 additions & 2 deletions linera-client/src/client_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ where
Fut: Future<Output = Result<ClientOutcome<T>, E>>,
Error: From<E>,
{
client.prepare_chain().await?;
// Try applying f optimistically without validator notifications. Return if committed.
let result = f(client).await;
self.update_and_save_wallet(client).await?;
Expand Down Expand Up @@ -635,7 +636,7 @@ where
.take(num_new_chains)
.collect();
let certificate = chain_client
.execute_without_prepare(operations)
.execute_operations(operations)
.await?
.expect("should execute block with OpenChain operations");
let executed_block = certificate.executed_block();
Expand Down Expand Up @@ -704,7 +705,7 @@ where
// Put at most 1000 fungible token operations in each block.
for operations in operations.chunks(1000) {
chain_client
.execute_without_prepare(operations.to_vec())
.execute_operations(operations.to_vec())
.await?
.expect("should execute block with OpenChain operations");
}
Expand Down
16 changes: 2 additions & 14 deletions linera-core/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ where
/// Prepares the chain for the next operation, i.e. makes sure we have synchronized it up to
/// its current height and are not missing any received messages from the inbox.
#[instrument(level = "trace")]
async fn prepare_chain(&self) -> Result<Box<ChainInfo>, ChainClientError> {
pub async fn prepare_chain(&self) -> Result<Box<ChainInfo>, ChainClientError> {
#[cfg(with_metrics)]
let _latency = metrics::PREPARE_CHAIN_LATENCY.measure_latency();

Expand Down Expand Up @@ -1925,16 +1925,6 @@ where
pub async fn execute_operations(
&self,
operations: Vec<Operation>,
) -> Result<ClientOutcome<ConfirmedBlockCertificate>, ChainClientError> {
self.prepare_chain().await?;
self.execute_without_prepare(operations).await
}

/// Executes a list of operations, without calling `prepare_chain`.
#[instrument(level = "trace", skip(operations))]
pub async fn execute_without_prepare(
&self,
operations: Vec<Operation>,
) -> Result<ClientOutcome<ConfirmedBlockCertificate>, ChainClientError> {
loop {
// TODO(#2066): Remove boxing once the call-stack is shallower
Expand Down Expand Up @@ -2627,7 +2617,6 @@ where
application_permissions: ApplicationPermissions,
balance: Amount,
) -> Result<ClientOutcome<(MessageId, ConfirmedBlockCertificate)>, ChainClientError> {
self.prepare_chain().await?;
loop {
let (epoch, committees) = self.epoch_and_committees(self.chain_id).await?;
let epoch = epoch.ok_or(LocalNodeError::InactiveChain(self.chain_id))?;
Expand Down Expand Up @@ -2823,7 +2812,6 @@ where
committee: Committee,
) -> Result<ClientOutcome<Certificate>, ChainClientError> {
loop {
self.prepare_chain().await?;
let epoch = self.epoch().await?;
match self
.execute_block(vec![Operation::System(SystemOperation::Admin(
Expand Down Expand Up @@ -2936,7 +2924,7 @@ where
}
})
.collect();
self.execute_without_prepare(operations).await
self.execute_operations(operations).await
}

/// Sends money to a chain.
Expand Down
3 changes: 3 additions & 0 deletions linera-core/src/unit_tests/client_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1459,6 +1459,7 @@ where
// Try to read the blob. This is a different client but on the same chain, so when we synchronize this with the validators
// before executing the block, we'll actually download and cache locally the blobs that were published by `client_a`.
// So this will succeed.
client1_b.prepare_chain().await?;
let certificate = client1_b
.execute_operation(SystemOperation::ReadBlob { blob_id: blob0_id }.into())
.await?
Expand Down Expand Up @@ -1651,6 +1652,7 @@ where
builder.set_fault_type([2], FaultType::Offline).await;
builder.set_fault_type([0, 1, 3], FaultType::Honest).await;

client2_b.prepare_chain().await.unwrap();
let bt_certificate = client2_b
.burn(None, Amount::from_tokens(1))
.await
Expand Down Expand Up @@ -2178,6 +2180,7 @@ where
assert!(client0.pending_block().is_none());

// Burn another token so Client 1 sees that the blob is already published
client1.prepare_chain().await.unwrap();
client1.burn(None, Amount::from_tokens(1)).await.unwrap();
client1.synchronize_from_validators().await.unwrap();
client1.process_inbox().await.unwrap();
Expand Down

0 comments on commit 4cac5fb

Please sign in to comment.