Skip to content

Commit

Permalink
Use configured client options in assign_new_chain_to_key. (#3254)
Browse files Browse the repository at this point in the history
## Motivation

In `assign_new_chain_to_key` we need a temporary `Client` instance
tracking the new chain and its parent. We currently set all options to
their defaults.

## Proposal

Use the configured options instead.

## Test Plan

This should at best negligibly change performance when assigning a key
to a new chain. CI will catch regressions.

## Release Plan

- Nothing to do / These changes follow the usual release cycle.

## Links

- Closes #3237
- [reviewer
checklist](https://github.com/linera-io/linera-protocol/blob/main/CONTRIBUTING.md#reviewer-checklist)
  • Loading branch information
afck authored Feb 5, 2025
1 parent 1fc0922 commit d414910
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 31 deletions.
35 changes: 35 additions & 0 deletions linera-core/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,41 @@ impl<P, S: Storage + Clone> Client<P, S> {
}
}

/// Returns a clone with a different set of tracked chains.
pub fn clone_with(
&self,
validator_node_provider: P,
name: impl Into<String>,
tracked_chains: impl IntoIterator<Item = ChainId>,
long_lived_services: bool,
) -> Self {
let tracked_chains = Arc::new(RwLock::new(tracked_chains.into_iter().collect()));
let state = WorkerState::new_for_client(
name.into(),
self.storage.clone(),
tracked_chains.clone(),
self.max_loaded_chains,
)
.with_long_lived_services(long_lived_services)
.with_allow_inactive_chains(true)
.with_allow_messages_from_deprecated_epochs(true);
let local_node = LocalNodeClient::new(state);
Self {
validator_node_provider,
local_node,
chains: DashMap::new(),
max_pending_message_bundles: self.max_pending_message_bundles,
message_policy: MessagePolicy::new(BlanketMessagePolicy::Accept, None),
cross_chain_message_delivery: self.cross_chain_message_delivery,
grace_period: self.grace_period,
tracked_chains,
notifier: Arc::new(ChannelNotifier::default()),
storage: self.storage.clone(),
max_loaded_chains: self.max_loaded_chains,
blob_download_timeout: self.blob_download_timeout,
}
}

/// Returns the storage client used by this client's local node.
#[instrument(level = "trace", skip(self))]
pub fn storage_client(&self) -> &S {
Expand Down
39 changes: 8 additions & 31 deletions linera-service/src/linera/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,7 @@
#![deny(clippy::large_futures)]

use std::{
borrow::Cow,
collections::HashMap,
env,
num::NonZeroUsize,
path::PathBuf,
process,
sync::Arc,
time::{Duration, Instant},
borrow::Cow, collections::HashMap, env, path::PathBuf, process, sync::Arc, time::Instant,
};

use anyhow::{anyhow, bail, ensure, Context};
Expand All @@ -40,12 +33,11 @@ use linera_client::{
wallet::{UserChain, Wallet},
};
use linera_core::{
client,
data_types::{ChainInfoQuery, ClientOutcome},
node::{CrossChainMessageDelivery, ValidatorNodeProvider},
node::ValidatorNodeProvider,
remote_node::RemoteNode,
worker::Reason,
JoinSetExt as _, DEFAULT_GRACE_PERIOD,
JoinSetExt as _,
};
use linera_execution::{
committee::{Committee, ValidatorName, ValidatorState},
Expand Down Expand Up @@ -1078,15 +1070,8 @@ impl Runnable for Job {
"Linking chain {chain_id} to its corresponding key in the wallet, owned by \
{owner}",
);
Self::assign_new_chain_to_key(
chain_id,
message_id,
storage,
owner,
None,
&mut context,
)
.await?;
Self::assign_new_chain_to_key(chain_id, message_id, owner, None, &mut context)
.await?;
println!("{}", chain_id);
context.save_wallet().await?;
info!(
Expand Down Expand Up @@ -1199,7 +1184,6 @@ impl Runnable for Job {
Self::assign_new_chain_to_key(
outcome.chain_id,
outcome.message_id,
storage.clone(),
owner,
Some(validators),
&mut context,
Expand Down Expand Up @@ -1238,7 +1222,6 @@ impl Job {
async fn assign_new_chain_to_key<S>(
chain_id: ChainId,
message_id: MessageId,
storage: S,
owner: Owner,
validators: Option<Vec<(ValidatorName, String)>>,
context: &mut ClientContext<S, impl Persist<Target = Wallet>>,
Expand All @@ -1247,17 +1230,11 @@ impl Job {
S: Storage + Clone + Send + Sync + 'static,
{
let node_provider = context.make_node_provider();
let client = client::Client::new(
let client = context.client.clone_with(
node_provider.clone(),
storage,
100,
CrossChainMessageDelivery::Blocking,
false,
vec![message_id.chain_id, chain_id],
"Temporary client for fetching the parent chain",
NonZeroUsize::new(20).expect("Chain worker limit should not be zero"),
DEFAULT_GRACE_PERIOD,
Duration::from_secs(1),
vec![message_id.chain_id, chain_id],
false,
);

// Take the latest committee we know of.
Expand Down

0 comments on commit d414910

Please sign in to comment.