Skip to content

Commit 19d84f4

Browse files
authored
linera_core: split chain client out of client (#4843)
## Motivation I'm trying to work on the client, but the file `client/mod.rs` was too big, and my `rust-analyzer` was struggling. ## Proposal Split `ChainClient` into its own module. This roughly halves the file, though since we import everything unqualified there is an overhead in total LoC to creating new modules. ## Test Plan CI. ## Release Plan - Nothing to do / These changes follow the usual release cycle. ## Links - [reviewer checklist](https://github.com/linera-io/linera-protocol/blob/main/CONTRIBUTING.md#reviewer-checklist)
1 parent 4093142 commit 19d84f4

File tree

18 files changed

+3203
-3156
lines changed

18 files changed

+3203
-3156
lines changed

linera-client/src/benchmark.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use linera_base::{
1616
time::Instant,
1717
};
1818
use linera_core::{
19-
client::{ChainClient, ChainClientError},
19+
client::chain_client::{self, ChainClient},
2020
Environment,
2121
};
2222
use linera_execution::{system::SystemOperation, Operation};
@@ -42,7 +42,7 @@ pub enum BenchmarkError {
4242
#[error("Failed to join task: {0}")]
4343
JoinError(#[from] task::JoinError),
4444
#[error("Chain client error: {0}")]
45-
ChainClient(#[from] ChainClientError),
45+
ChainClient(#[from] chain_client::Error),
4646
#[error("Current histogram count is less than previous histogram count")]
4747
HistogramCountMismatch,
4848
#[error("Expected histogram value, got {0:?}")]

linera-client/src/chain_listener.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ use linera_base::{
1919
task::NonBlockingFuture,
2020
};
2121
use linera_core::{
22-
client::{AbortOnDrop, ChainClient, ChainClientError, ListeningMode},
22+
client::{
23+
chain_client::{self, ChainClient},
24+
AbortOnDrop, ListeningMode,
25+
},
2326
node::NotificationStream,
2427
worker::{Notification, Reason},
2528
Environment,
@@ -332,7 +335,7 @@ impl<C: ClientContext + 'static> ChainListener<C> {
332335
.storage
333336
.read_confirmed_block(hash)
334337
.await?
335-
.ok_or(ChainClientError::MissingConfirmedBlock(hash))?
338+
.ok_or(chain_client::Error::MissingConfirmedBlock(hash))?
336339
.into_block();
337340
let blobs = block.created_blobs().into_iter();
338341
let new_chains = blobs
@@ -359,7 +362,7 @@ impl<C: ClientContext + 'static> ChainListener<C> {
359362
.signer()
360363
.contains_key(&chain_owner)
361364
.await
362-
.map_err(ChainClientError::signer_failure)?
365+
.map_err(chain_client::Error::signer_failure)?
363366
{
364367
context_guard
365368
.update_wallet_for_new_chain(
@@ -583,7 +586,7 @@ impl<C: ClientContext + 'static> ChainListener<C> {
583586
.process_inbox_without_prepare()
584587
.await
585588
{
586-
Err(ChainClientError::CannotFindKeyForChain(chain_id)) => {
589+
Err(chain_client::Error::CannotFindKeyForChain(chain_id)) => {
587590
debug!(%chain_id, "Cannot find key for chain");
588591
}
589592
Err(error) => warn!(%error, "Failed to process inbox."),

linera-client/src/client_context.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use {
3636
data_types::Amount,
3737
identifiers::{ApplicationId, BlobType},
3838
},
39-
linera_core::client::ChainClientError,
39+
linera_core::client::chain_client,
4040
linera_execution::{
4141
system::{OpenChainConfig, SystemOperation},
4242
Operation,
@@ -331,7 +331,7 @@ where
331331
block_cache_size: usize,
332332
execution_state_cache_size: usize,
333333
) -> Self {
334-
use linera_core::{client::ChainClientOptions, node::CrossChainMessageDelivery};
334+
use linera_core::{client::chain_client, node::CrossChainMessageDelivery};
335335

336336
let send_recv_timeout = Duration::from_millis(4000);
337337
let retry_delay = Duration::from_millis(1000);
@@ -363,9 +363,9 @@ where
363363
name,
364364
chain_worker_ttl,
365365
sender_chain_worker_ttl,
366-
ChainClientOptions {
366+
chain_client::Options {
367367
cross_chain_message_delivery: CrossChainMessageDelivery::Blocking,
368-
..ChainClientOptions::test_default()
368+
..chain_client::Options::test_default()
369369
},
370370
block_cache_size,
371371
execution_state_cache_size,
@@ -987,7 +987,7 @@ where
987987
.map(|chain_client| async move {
988988
chain_client.process_inbox().await?;
989989
info!("Processed inbox for chain {:?}", chain_client.chain_id());
990-
Ok::<(), ChainClientError>(())
990+
Ok::<(), chain_client::Error>(())
991991
})
992992
.buffer_unordered(wrap_up_max_in_flight);
993993
stream.try_collect::<Vec<_>>().await?;

linera-client/src/client_options.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use linera_base::{
1111
};
1212
use linera_core::{
1313
client::{
14-
BlanketMessagePolicy, ChainClientOptions, MessagePolicy,
15-
DEFAULT_CERTIFICATE_DOWNLOAD_BATCH_SIZE, DEFAULT_SENDER_CERTIFICATE_DOWNLOAD_BATCH_SIZE,
14+
chain_client, BlanketMessagePolicy, MessagePolicy, DEFAULT_CERTIFICATE_DOWNLOAD_BATCH_SIZE,
15+
DEFAULT_SENDER_CERTIFICATE_DOWNLOAD_BATCH_SIZE,
1616
},
1717
node::CrossChainMessageDelivery,
1818
DEFAULT_GRACE_PERIOD,
@@ -189,15 +189,15 @@ pub struct ClientContextOptions {
189189
}
190190

191191
impl ClientContextOptions {
192-
/// Creates [`ChainClientOptions`] with the corresponding values.
193-
pub(crate) fn to_chain_client_options(&self) -> ChainClientOptions {
192+
/// Creates [`chain_client::Options`] with the corresponding values.
193+
pub(crate) fn to_chain_client_options(&self) -> chain_client::Options {
194194
let message_policy = MessagePolicy::new(
195195
self.blanket_message_policy,
196196
self.restrict_chain_ids_to.clone(),
197197
);
198198
let cross_chain_message_delivery =
199199
CrossChainMessageDelivery::new(self.wait_for_outgoing_messages);
200-
ChainClientOptions {
200+
chain_client::Options {
201201
max_pending_message_bundles: self.max_pending_message_bundles,
202202
message_policy,
203203
cross_chain_message_delivery,

linera-client/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub(crate) enum Inner {
2121
#[error("chain error: {0}")]
2222
Chain(#[from] linera_chain::ChainError),
2323
#[error("chain client error: {0}")]
24-
ChainClient(#[from] linera_core::client::ChainClientError),
24+
ChainClient(#[from] linera_core::client::chain_client::Error),
2525
#[error("options error: {0}")]
2626
Options(#[from] crate::client_options::Error),
2727
#[error("persistence error: {0}")]

linera-client/src/unit_tests/chain_listener.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use linera_base::{
1111
ownership::{ChainOwnership, TimeoutConfig},
1212
};
1313
use linera_core::{
14-
client::{ChainClient, ChainClientOptions, Client},
14+
client::{chain_client, ChainClient, Client},
1515
environment,
1616
test_utils::{MemoryStorageBuilder, StorageBuilder as _, TestBuilder},
1717
};
@@ -122,7 +122,7 @@ async fn test_chain_listener() -> anyhow::Result<()> {
122122
format!("Client node for {:.8}", chain_id0),
123123
Duration::from_secs(30),
124124
Duration::from_secs(1),
125-
ChainClientOptions::test_default(),
125+
chain_client::Options::test_default(),
126126
5_000,
127127
10_000,
128128
)),
@@ -210,7 +210,7 @@ async fn test_chain_listener_admin_chain() -> anyhow::Result<()> {
210210
"Client node with no chains".to_string(),
211211
Duration::from_secs(30),
212212
Duration::from_secs(1),
213-
ChainClientOptions::test_default(),
213+
chain_client::Options::test_default(),
214214
5_000,
215215
10_000,
216216
)),

0 commit comments

Comments
 (0)