Skip to content

Commit 674bd65

Browse files
committed
feat: infinite preloading of Cardano transactions in signer
1 parent 8690abe commit 674bd65

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

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: 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: 60,
156160
}
157161
}
158162

mithril-signer/src/main.rs

Lines changed: 17 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,11 @@ 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(long, env = "PRELOADING_REFRESH_INTERVAL", default_value_t = 7200)]
87+
preloading_refresh_interval: u64,
8388
}
8489

8590
impl Args {
@@ -184,7 +189,17 @@ async fn main() -> StdResult<()> {
184189
.map(|_| None)
185190
});
186191

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

189204
let (metrics_server_shutdown_tx, metrics_server_shutdown_rx) = oneshot::channel();
190205
if config.enable_metrics_server {
@@ -239,10 +254,6 @@ async fn main() -> StdResult<()> {
239254
.send(())
240255
.map_err(|e| anyhow!("Metrics server shutdown signal could not be sent: {e:?}"))?;
241256

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

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

0 commit comments

Comments
 (0)