From 1dd26f015fdf83bb12aae6a9fa0e45f3211d71f4 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 8 Mar 2024 15:35:03 -0800 Subject: [PATCH] Display initial sync time on status page (#3250) --- src/index.rs | 3 +++ src/index/updater.rs | 14 +++++++++++--- src/subcommand/env.rs | 3 +++ src/templates/status.rs | 1 + templates/status.html | 2 ++ tests/json_api.rs | 8 +++++--- 6 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/index.rs b/src/index.rs index 460df7e901..2a91505261 100644 --- a/src/index.rs +++ b/src/index.rs @@ -97,6 +97,7 @@ pub(crate) enum Statistic { UnboundInscriptions = 11, IndexTransactions = 12, IndexSpentSats = 13, + InitialSyncTime = 14, } impl Statistic { @@ -464,6 +465,7 @@ impl Index { let blessed_inscriptions = statistic(Statistic::BlessedInscriptions)?; let cursed_inscriptions = statistic(Statistic::CursedInscriptions)?; + let initial_sync_time = statistic(Statistic::InitialSyncTime)?; let mut content_type_counts = rtx .open_table(CONTENT_TYPE_TO_COUNT)? @@ -481,6 +483,7 @@ impl Index { content_type_counts, cursed_inscriptions, height, + initial_sync_time: Duration::from_micros(initial_sync_time), inscriptions: blessed_inscriptions + cursed_inscriptions, lost_sats: statistic(Statistic::LostSats)?, minimum_rune_for_next_block: Rune::minimum_at_height( diff --git a/src/index/updater.rs b/src/index/updater.rs index 840ebccb1a..aa3697d2b0 100644 --- a/src/index/updater.rs +++ b/src/index/updater.rs @@ -42,7 +42,9 @@ pub(crate) struct Updater<'index> { impl<'index> Updater<'index> { pub(crate) fn update_index<'a>(&'a mut self, mut wtx: WriteTransaction<'a>) -> Result { + let start = Instant::now(); let starting_height = u32::try_from(self.index.client.get_block_count()?).unwrap() + 1; + let starting_index_height = self.height; wtx .open_table(WRITE_TRANSACTION_STARTING_BLOCK_COUNT_TO_TIMESTAMP)? @@ -120,9 +122,8 @@ impl<'index> Updater<'index> { .insert( &self.height, &SystemTime::now() - .duration_since(SystemTime::UNIX_EPOCH) - .map(|duration| duration.as_millis()) - .unwrap_or(0), + .duration_since(SystemTime::UNIX_EPOCH)? + .as_millis(), )?; } @@ -131,6 +132,13 @@ impl<'index> Updater<'index> { } } + if starting_index_height == 0 && self.height > 0 { + wtx.open_table(STATISTIC_TO_COUNT)?.insert( + Statistic::InitialSyncTime.key(), + &u64::try_from(start.elapsed().as_micros())?, + )?; + } + if uncommitted > 0 { self.commit(wtx, value_cache)?; } diff --git a/src/subcommand/env.rs b/src/subcommand/env.rs index b562c60a63..293a11295e 100644 --- a/src/subcommand/env.rs +++ b/src/subcommand/env.rs @@ -156,9 +156,12 @@ rpcport={bitcoind_port} eprintln!( "{} +{server_url} +{} bitcoin-cli -datadir='{relative}' getblockchaininfo {} {} --data-dir '{relative}' wallet balance", + "`ord` server URL:".blue().bold(), "Example `bitcoin-cli` command:".blue().bold(), "Example `ord` command:".blue().bold(), ord.display(), diff --git a/src/templates/status.rs b/src/templates/status.rs index b96cf26241..1ea12b0e1d 100644 --- a/src/templates/status.rs +++ b/src/templates/status.rs @@ -7,6 +7,7 @@ pub struct StatusHtml { pub content_type_counts: Vec<(Option>, u64)>, pub cursed_inscriptions: u64, pub height: Option, + pub initial_sync_time: Duration, pub inscriptions: u64, pub lost_sats: u64, pub minimum_rune_for_next_block: Rune, diff --git a/templates/status.html b/templates/status.html index 4b74246ac4..0d2c3957b7 100644 --- a/templates/status.html +++ b/templates/status.html @@ -20,6 +20,8 @@

Status

{{ self.started }}
uptime
{{ humantime::format_duration(self.uptime) }}
+
initial sync time
+
{{ humantime::format_duration(self.initial_sync_time) }}
minimum rune for next block
{{ self.minimum_rune_for_next_block }}
version
diff --git a/tests/json_api.rs b/tests/json_api.rs index 6d514b4eaf..77bd07ec99 100644 --- a/tests/json_api.rs +++ b/tests/json_api.rs @@ -482,10 +482,11 @@ fn get_status() { .parse::>() .unwrap(); - let dummy_uptime = Duration::from_secs(1); + let dummy_duration = Duration::from_secs(1); + status_json.initial_sync_time = dummy_duration; status_json.started = dummy_started; - status_json.uptime = dummy_uptime; + status_json.uptime = dummy_duration; pretty_assert_eq!( status_json, @@ -495,6 +496,7 @@ fn get_status() { content_type_counts: vec![(Some("text/plain;charset=utf-8".into()), 1)], cursed_inscriptions: 0, height: Some(3), + initial_sync_time: dummy_duration, inscriptions: 1, lost_sats: 0, minimum_rune_for_next_block: Rune(99218849511960410), @@ -504,7 +506,7 @@ fn get_status() { started: dummy_started, transaction_index: false, unrecoverably_reorged: false, - uptime: dummy_uptime, + uptime: dummy_duration, } ); }