Skip to content

Commit eb4fc09

Browse files
bart-linerama2bd
andauthored
Port latest changes from #4643 to main (#4669)
## Motivation We did some development on #4643 that is not yet reflected on `main` ## Proposal Port the missing changes ## 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) --------- Co-authored-by: Mathieu Baudet <[email protected]>
1 parent 8705594 commit eb4fc09

File tree

7 files changed

+66
-26
lines changed

7 files changed

+66
-26
lines changed

linera-core/src/chain_worker/config.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ use std::sync::Arc;
77

88
use linera_base::{crypto::ValidatorSecretKey, time::Duration};
99

10+
use crate::CHAIN_INFO_MAX_RECEIVED_LOG_ENTRIES;
11+
1012
/// Configuration parameters for the [`ChainWorkerState`][`super::state::ChainWorkerState`].
11-
#[derive(Clone, Default)]
13+
#[derive(Clone)]
1214
pub struct ChainWorkerConfig {
1315
/// The signature key pair of the validator. The key may be missing for replicas
1416
/// without voting rights (possibly with a partial view of chains).
@@ -24,6 +26,8 @@ pub struct ChainWorkerConfig {
2426
pub grace_period: Duration,
2527
/// Idle chain workers free their memory after that duration without requests.
2628
pub ttl: Duration,
29+
/// The size to truncate receive log entries in chain info responses.
30+
pub chain_info_max_received_log_entries: usize,
2731
}
2832

2933
impl ChainWorkerConfig {
@@ -45,3 +49,17 @@ impl ChainWorkerConfig {
4549
self.key_pair.as_ref().map(Arc::as_ref)
4650
}
4751
}
52+
53+
impl Default for ChainWorkerConfig {
54+
fn default() -> Self {
55+
Self {
56+
key_pair: None,
57+
allow_inactive_chains: false,
58+
allow_messages_from_deprecated_epochs: false,
59+
long_lived_services: false,
60+
grace_period: Default::default(),
61+
ttl: Default::default(),
62+
chain_info_max_received_log_entries: CHAIN_INFO_MAX_RECEIVED_LOG_ENTRIES,
63+
}
64+
}
65+
}

linera-core/src/chain_worker/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,5 @@ pub(crate) use self::state::CrossChainUpdateHelper;
1414
pub(crate) use self::{
1515
actor::{ChainWorkerActor, ChainWorkerRequest},
1616
config::ChainWorkerConfig,
17-
state::{
18-
BlockOutcome, CHAIN_INFO_RECEIVED_LOG_MAX_ENTRIES_DEFAULT,
19-
CHAIN_INFO_RECEIVED_LOG_MAX_ENTRIES_VAR,
20-
},
17+
state::BlockOutcome,
2118
};

linera-core/src/chain_worker/state.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,6 @@ use crate::{
4848
worker::{NetworkActions, Notification, Reason, WorkerError},
4949
};
5050

51-
/// The maximum number of entries in a `received_log` included in a `ChainInfo` response.
52-
// TODO(#4638): Revisit the number.
53-
pub const CHAIN_INFO_RECEIVED_LOG_MAX_ENTRIES_DEFAULT: usize = 1000;
54-
pub const CHAIN_INFO_RECEIVED_LOG_MAX_ENTRIES_VAR: &str =
55-
"LINERA_CHAIN_INFO_RECEIVED_LOG_MAX_ENTRIES";
56-
5751
/// The state of the chain worker.
5852
pub(crate) struct ChainWorkerState<StorageClient>
5953
where
@@ -1417,11 +1411,10 @@ where
14171411
info.requested_sent_certificate_hashes = hashes;
14181412
if let Some(start) = query.request_received_log_excluding_first_n {
14191413
let start = usize::try_from(start).map_err(|_| ArithmeticError::Overflow)?;
1420-
let max_entries = std::env::var(CHAIN_INFO_RECEIVED_LOG_MAX_ENTRIES_VAR)
1421-
.ok()
1422-
.and_then(|var| var.parse().ok())
1423-
.unwrap_or(CHAIN_INFO_RECEIVED_LOG_MAX_ENTRIES_DEFAULT);
1424-
let end = (start.saturating_add(max_entries)).min(chain.received_log.count());
1414+
let max_received_log_entries = self.config.chain_info_max_received_log_entries;
1415+
let end = start
1416+
.saturating_add(max_received_log_entries)
1417+
.min(chain.received_log.count());
14251418
info.requested_received_log = chain.received_log.read(start..end).await?;
14261419
}
14271420
if query.request_manager_values {

linera-core/src/client/mod.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@ use tokio_stream::wrappers::UnboundedReceiverStream;
6565
use tracing::{debug, error, info, instrument, trace, warn, Instrument as _};
6666

6767
use crate::{
68-
chain_worker::{
69-
CHAIN_INFO_RECEIVED_LOG_MAX_ENTRIES_DEFAULT, CHAIN_INFO_RECEIVED_LOG_MAX_ENTRIES_VAR,
70-
},
7168
data_types::{ChainInfo, ChainInfoQuery, ChainInfoResponse, ClientOutcome, RoundTimeout},
7269
environment::Environment,
7370
local_node::{LocalChainInfoExt as _, LocalNodeClient, LocalNodeError},
@@ -79,6 +76,7 @@ use crate::{
7976
remote_node::RemoteNode,
8077
updater::{communicate_with_quorum, CommunicateAction, CommunicationError, ValidatorUpdater},
8178
worker::{Notification, ProcessableCertificate, Reason, WorkerError, WorkerState},
79+
CHAIN_INFO_MAX_RECEIVED_LOG_ENTRIES,
8280
};
8381

8482
mod chain_client_state;
@@ -841,17 +839,13 @@ impl<Env: Environment> Client<Env> {
841839
// Retrieve the list of newly received certificates from this validator.
842840
let mut remote_log = Vec::new();
843841
let mut offset = tracker;
844-
let max_entries = std::env::var(CHAIN_INFO_RECEIVED_LOG_MAX_ENTRIES_VAR)
845-
.ok()
846-
.and_then(|var| var.parse().ok())
847-
.unwrap_or(CHAIN_INFO_RECEIVED_LOG_MAX_ENTRIES_DEFAULT);
848842
loop {
849843
let query = ChainInfoQuery::new(chain_id).with_received_log_excluding_first_n(offset);
850844
let info = remote_node.handle_chain_info_query(query).await?;
851845
let received_entries = info.requested_received_log.len();
852846
offset += received_entries as u64;
853847
remote_log.extend(info.requested_received_log);
854-
if received_entries < max_entries {
848+
if received_entries < CHAIN_INFO_MAX_RECEIVED_LOG_ENTRIES {
855849
break;
856850
}
857851
}

linera-core/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,7 @@ pub use crate::join_set_ext::{JoinSetExt, TaskHandle};
2929

3030
pub mod environment;
3131
pub use environment::Environment;
32+
33+
/// The maximum number of entries in a `received_log` included in a `ChainInfo` response.
34+
// TODO(#4638): Revisit the number.
35+
pub const CHAIN_INFO_MAX_RECEIVED_LOG_ENTRIES: usize = 20_000;

linera-core/src/worker.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ use crate::{
4343
join_set_ext::{JoinSet, JoinSetExt},
4444
notifier::Notifier,
4545
value_cache::ValueCache,
46+
CHAIN_INFO_MAX_RECEIVED_LOG_ENTRIES,
4647
};
4748

4849
#[cfg(test)]
@@ -417,6 +418,26 @@ where
417418
self
418419
}
419420

421+
/// Returns an instance with the specified maximum size for received_log entries.
422+
///
423+
/// Sizes below `CHAIN_INFO_MAX_RECEIVED_LOG_ENTRIES` should be avoided.
424+
#[instrument(level = "trace", skip(self))]
425+
pub fn with_chain_info_max_received_log_entries(
426+
mut self,
427+
chain_info_max_received_log_entries: usize,
428+
) -> Self {
429+
if chain_info_max_received_log_entries < CHAIN_INFO_MAX_RECEIVED_LOG_ENTRIES {
430+
warn!(
431+
"The value set for the maximum size of received_log entries \
432+
may not be compatible with the latest clients: {} instead of {}",
433+
chain_info_max_received_log_entries, CHAIN_INFO_MAX_RECEIVED_LOG_ENTRIES
434+
);
435+
}
436+
self.chain_worker_config.chain_info_max_received_log_entries =
437+
chain_info_max_received_log_entries;
438+
self
439+
}
440+
420441
#[instrument(level = "trace", skip(self))]
421442
pub fn nickname(&self) -> &str {
422443
&self.nickname

linera-service/src/server.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use linera_base::{
3737
listen_for_shutdown_signals,
3838
};
3939
use linera_client::config::{CommitteeConfig, ValidatorConfig, ValidatorServerConfig};
40-
use linera_core::{worker::WorkerState, JoinSetExt as _};
40+
use linera_core::{worker::WorkerState, JoinSetExt as _, CHAIN_INFO_MAX_RECEIVED_LOG_ENTRIES};
4141
use linera_execution::{WasmRuntime, WithWasmDefault};
4242
#[cfg(with_metrics)]
4343
use linera_metrics::monitoring_server;
@@ -70,6 +70,7 @@ struct ServerContext {
7070
chain_worker_ttl: Duration,
7171
block_cache_size: usize,
7272
execution_state_cache_size: usize,
73+
chain_info_max_received_log_entries: usize,
7374
}
7475

7576
impl ServerContext {
@@ -98,7 +99,8 @@ impl ServerContext {
9899
.with_allow_inactive_chains(false)
99100
.with_allow_messages_from_deprecated_epochs(false)
100101
.with_grace_period(self.grace_period)
101-
.with_chain_worker_ttl(self.chain_worker_ttl);
102+
.with_chain_worker_ttl(self.chain_worker_ttl)
103+
.with_chain_info_max_received_log_entries(self.chain_info_max_received_log_entries);
102104
(state, shard_id, shard.clone())
103105
}
104106

@@ -396,6 +398,15 @@ enum ServerCommand {
396398
value_parser = util::parse_millis
397399
)]
398400
chain_worker_ttl: Duration,
401+
402+
/// Maximum size for received_log entries in chain info responses. This should
403+
/// generally only be increased from the default value.
404+
#[arg(
405+
long,
406+
default_value_t = CHAIN_INFO_MAX_RECEIVED_LOG_ENTRIES,
407+
env = "LINERA_SERVER_CHAIN_INFO_MAX_RECEIVED_LOG_ENTRIES",
408+
)]
409+
chain_info_max_received_log_entries: usize,
399410
},
400411

401412
/// Act as a trusted third-party and generate all server configurations
@@ -508,6 +519,7 @@ async fn run(options: ServerOptions) {
508519
grace_period,
509520
wasm_runtime,
510521
chain_worker_ttl,
522+
chain_info_max_received_log_entries,
511523
} => {
512524
linera_version::VERSION_INFO.log();
513525

@@ -523,6 +535,7 @@ async fn run(options: ServerOptions) {
523535
chain_worker_ttl,
524536
block_cache_size: options.block_cache_size,
525537
execution_state_cache_size: options.execution_state_cache_size,
538+
chain_info_max_received_log_entries,
526539
};
527540
let wasm_runtime = wasm_runtime.with_wasm_default();
528541
let store_config = storage_config

0 commit comments

Comments
 (0)