Skip to content

Commit ffdab78

Browse files
authored
Merge pull request #1921 from input-output-hk/jpraynaud/1920-infinite-preloader-signer
Feat: add infinite Cardano transactions preloader in signer
2 parents 8690abe + b77e52e commit ffdab78

File tree

6 files changed

+30
-8
lines changed

6 files changed

+30
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ As a minor extension, we have adopted a slightly different versioning convention
2727

2828
- Post `Chang` hard fork cleanup of the CI, devnet and infrastructure.
2929

30+
- Support infinite preloading of Cardano transactions in signer.
31+
3032
- **UNSTABLE** Cardano stake distribution certification:
3133

3234
- Implement the signable and artifact builders for the signed entity type `CardanoStakeDistribution`.

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mithril-signer/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-signer"
3-
version = "0.2.176"
3+
version = "0.2.177"
44
description = "A Mithril Signer"
55
authors = { workspace = true }
66
edition = { workspace = true }

mithril-signer/src/configuration.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ pub struct Configuration {
116116

117117
/// The maximum number of roll forwards during a poll of the block streamer when importing transactions.
118118
pub cardano_transactions_block_streamer_max_roll_forwards_per_poll: usize,
119+
120+
/// Preloading refresh interval in seconds
121+
pub preloading_refresh_interval_in_seconds: u64,
119122
}
120123

121124
impl Configuration {
@@ -153,6 +156,7 @@ impl Configuration {
153156
enable_transaction_pruning: false,
154157
transactions_import_block_chunk_size: BlockNumber(1000),
155158
cardano_transactions_block_streamer_max_roll_forwards_per_poll: 1000,
159+
preloading_refresh_interval_in_seconds: 60,
156160
}
157161
}
158162

mithril-signer/src/main.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use clap::{CommandFactory, Parser, Subcommand};
33
use config::{Map, Value};
44

55
use slog::{o, Drain, Level, Logger};
6-
use slog_scope::{crit, debug};
6+
use slog_scope::{crit, debug, info};
77
use std::path::PathBuf;
88
use std::sync::Arc;
99
use std::time::Duration;
@@ -80,6 +80,15 @@ pub struct Args {
8080
/// Will be ignored on (pre)production networks.
8181
#[clap(long)]
8282
allow_unparsable_block: bool,
83+
84+
/// Preloading refresh interval in seconds
85+
// TODO: Replace the default value to 43200 (12 hours) once the Cardano transactions is activated on mainnet
86+
#[clap(
87+
long,
88+
env = "PRELOADING_REFRESH_INTERVAL_IN_SECONDS",
89+
default_value_t = 7200
90+
)]
91+
preloading_refresh_interval_in_seconds: u64,
8392
}
8493

8594
impl Args {
@@ -184,7 +193,17 @@ async fn main() -> StdResult<()> {
184193
.map(|_| None)
185194
});
186195

187-
let preload_task = tokio::spawn(async move { cardano_transaction_preloader.preload().await });
196+
join_set.spawn(async move {
197+
let refresh_interval = config.preloading_refresh_interval_in_seconds;
198+
let mut interval = tokio::time::interval(Duration::from_secs(refresh_interval));
199+
loop {
200+
interval.tick().await;
201+
if let Err(err) = cardano_transaction_preloader.preload().await {
202+
crit!("🔥 Cardano transactions preloader failed: {err:?}");
203+
}
204+
info!("⟳ Next Preload Cardano Transactions will start in {refresh_interval} s",);
205+
}
206+
});
188207

189208
let (metrics_server_shutdown_tx, metrics_server_shutdown_rx) = oneshot::channel();
190209
if config.enable_metrics_server {
@@ -239,10 +258,6 @@ async fn main() -> StdResult<()> {
239258
.send(())
240259
.map_err(|e| anyhow!("Metrics server shutdown signal could not be sent: {e:?}"))?;
241260

242-
if !preload_task.is_finished() {
243-
preload_task.abort();
244-
}
245-
246261
join_set.shutdown().await;
247262

248263
debug!("Stopping"; "shutdown_reason" => shutdown_reason);

mithril-test-lab/mithril-end-to-end/src/mithril/signer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ impl Signer {
7070
),
7171
("ERA_READER_ADAPTER_PARAMS", &era_reader_adapter_params),
7272
("TRANSACTIONS_IMPORT_BLOCK_CHUNK_SIZE", "150"),
73+
("PRELOADING_REFRESH_INTERVAL_IN_SECONDS", "10"),
7374
]);
7475
if signer_config.enable_certification {
7576
env.insert(

0 commit comments

Comments
 (0)