Skip to content

Commit f68b92d

Browse files
eugene-babichenkoNicolasDP
authored andcommitted
blockchain_stuck_notifier: configurable interval after which a warning will occur
1 parent 1dfd7ff commit f68b92d

File tree

5 files changed

+27
-4
lines changed

5 files changed

+27
-4
lines changed

doc/quickstart/02_passive_node.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ Description of the fields:
8484
this node should maintain.
8585
- `explorer`: (optional) Explorer settings
8686
- `enabled`: True or false
87+
- `no_blockchain_updates_warning_interval`: (optional, seconds) if no new blocks
88+
were received after this period of time, the node will start sending you
89+
warnings in the logs.
8790

8891
[multiaddr]: https://github.com/multiformats/multiaddr
8992

jormungandr/src/blockchain_stuck_notifier.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@ use tokio::timer::Interval;
1010
pub fn check_last_block_time(
1111
service_info: TokioServiceInfo,
1212
blockchain_tip: blockchain::Tip,
13+
check_interval: u64,
1314
) -> impl Future<Item = (), Error = ()> {
1415
let logger = service_info.logger().clone();
1516
let err_logger = logger.clone();
1617

17-
// TODO set from configuration
18-
let check_period = Duration::from_secs(180);
18+
// those are different values, because check_interval can be big
19+
// (30 minutes) and the notification may remain unseen
20+
let check_period = Duration::from_secs(check_interval);
21+
let notification_period = Duration::from_secs(60);
1922

20-
Interval::new_interval(check_period.clone())
23+
Interval::new_interval(notification_period)
2124
.map_err(move |e| error!(err_logger, "timer error: {}", e))
2225
.and_then(move |_| blockchain_tip.get_ref())
2326
.for_each(move |tip| {

jormungandr/src/main.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,17 @@ fn start_services(bootstrapped_node: BootstrappedNode) -> Result<(), start_up::E
296296

297297
{
298298
let blockchain_tip = blockchain_tip.clone();
299+
let no_blockchain_updates_warning_interval = bootstrapped_node
300+
.settings
301+
.no_blockchain_updates_warning_interval
302+
.clone();
299303

300304
services.spawn_future("blockchain_stuck_notifier", move |info| {
301-
blockchain_stuck_notifier::check_last_block_time(info, blockchain_tip)
305+
blockchain_stuck_notifier::check_last_block_time(
306+
info,
307+
blockchain_tip,
308+
no_blockchain_updates_warning_interval,
309+
)
302310
});
303311
}
304312

jormungandr/src/settings/start/config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ pub struct Config {
3030
pub p2p: P2pConfig,
3131

3232
pub explorer: Option<Explorer>,
33+
34+
/// the time interval with no blockchain updates after which alerts are thrown
35+
pub no_blockchain_updates_warning_interval: Option<u64>,
3336
}
3437

3538
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]

jormungandr/src/settings/start/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use std::{fs::File, path::PathBuf};
1414
const DEFAULT_FILTER_LEVEL: FilterLevel = FilterLevel::Info;
1515
const DEFAULT_LOG_FORMAT: LogFormat = LogFormat::Plain;
1616
const DEFAULT_LOG_OUTPUT: LogOutput = LogOutput::Stderr;
17+
const DEFAULT_NO_BLOCKCHAIN_UPDATES_WARNING_INTERVAL: u64 = 1800; // 30 min
1718

1819
custom_error! {pub Error
1920
ConfigIo { source: std::io::Error } = "Cannot read the node configuration file: {source}",
@@ -34,6 +35,7 @@ pub struct Settings {
3435
pub mempool: Mempool,
3536
pub leadership: Leadership,
3637
pub explorer: bool,
38+
pub no_blockchain_updates_warning_interval: u64,
3739
}
3840

3941
pub struct RawSettings {
@@ -173,6 +175,10 @@ impl RawSettings {
173175
.as_ref()
174176
.map_or(Leadership::default(), |cfg| cfg.leadership.clone()),
175177
explorer,
178+
no_blockchain_updates_warning_interval: config
179+
.as_ref()
180+
.and_then(|config| config.no_blockchain_updates_warning_interval)
181+
.unwrap_or(DEFAULT_NO_BLOCKCHAIN_UPDATES_WARNING_INTERVAL),
176182
})
177183
}
178184
}

0 commit comments

Comments
 (0)