Skip to content

Commit e96216a

Browse files
committed
fix(cardano-chain-follower): break down stats
Signed-off-by: bkioshn <[email protected]>
1 parent 99f9b1a commit e96216a

File tree

8 files changed

+329
-283
lines changed

8 files changed

+329
-283
lines changed

rust/cardano-chain-follower/src/chain_sync.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ use crate::{
3333
error::{Error, Result},
3434
mithril_snapshot_config::MithrilUpdateMessage,
3535
mithril_snapshot_data::latest_mithril_snapshot_id,
36-
stats, ChainSyncConfig,
36+
stats::{self},
37+
ChainSyncConfig,
3738
};
3839

3940
/// The maximum number of seconds we wait for a node to connect.
@@ -199,7 +200,11 @@ async fn process_rollback(
199200
// We never really know how many blocks are rolled back when advised by the peer, but we
200201
// can work out how many slots. This function wraps the real work, so we can properly
201202
// record the stats when the rollback is complete. Even if it errors.
202-
stats::rollback(chain, stats::RollbackType::Peer, slot_rollback_size.into());
203+
stats::rollback::rollback(
204+
chain,
205+
stats::rollback::RollbackType::Peer,
206+
slot_rollback_size.into(),
207+
);
203208

204209
Ok(response)
205210
}

rust/cardano-chain-follower/src/chain_sync_live_chains.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use tracing::{debug, error};
1515
use crate::{
1616
error::{Error, Result},
1717
mithril_snapshot_data::latest_mithril_snapshot_id,
18-
stats,
18+
stats::{self},
1919
};
2020

2121
/// Type we use to manage the Sync Task handle map.
@@ -241,7 +241,11 @@ impl ProtectedLiveChainBlockList {
241241

242242
// Record a rollback statistic (We record the ACTUAL size our rollback effected our
243243
// internal live chain, not what the node thinks.)
244-
stats::rollback(network, stats::RollbackType::LiveChain, rollback_size);
244+
stats::rollback::rollback(
245+
network,
246+
stats::rollback::RollbackType::LiveChain,
247+
rollback_size,
248+
);
245249
}
246250

247251
let head_slot = block.point().slot_or_default();

rust/cardano-chain-follower/src/follow.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::{
1313
mithril_snapshot::MithrilSnapshot,
1414
mithril_snapshot_data::latest_mithril_snapshot_id,
1515
mithril_snapshot_iterator::MithrilSnapshotIterator,
16-
stats::{self, rollback},
16+
stats::{self},
1717
Statistics,
1818
};
1919

@@ -192,7 +192,11 @@ impl ChainFollower {
192192
if let Some(next_block) = next_block {
193193
// Update rollback stats for the follower if one is reported.
194194
if update_type == chain_update::Kind::Rollback {
195-
rollback(self.network, stats::RollbackType::Follower, rollback_depth);
195+
stats::rollback::rollback(
196+
self.network,
197+
stats::rollback::RollbackType::Follower,
198+
rollback_depth,
199+
);
196200
}
197201
// debug!("Pre Previous update 4 : {:?}", self.previous);
198202
self.previous = self.current.clone();
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//! Individual Follower Statistics.
2+
3+
use cardano_blockchain_types::Slot;
4+
use chrono::{DateTime, Utc};
5+
use serde::Serialize;
6+
7+
/// Individual Follower stats
8+
#[derive(Debug, Default, Clone, Serialize)]
9+
pub struct Follower {
10+
/// Synthetic follower connection ID
11+
pub id: u64,
12+
/// Starting slot for this follower (0 = Start at Genesis Block for the chain).
13+
pub start: Slot,
14+
/// Current slot for this follower.
15+
pub current: Slot,
16+
/// Target slot for this follower (MAX U64 == Follow Tip Forever).
17+
pub end: Slot,
18+
/// Current Sync Time.
19+
pub sync_start: DateTime<Utc>,
20+
/// When this follower reached TIP or its destination slot.
21+
pub sync_end: Option<DateTime<Utc>>,
22+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
//! Live Blockchain Statistics.
2+
3+
use cardano_blockchain_types::Slot;
4+
use chrono::{DateTime, Utc};
5+
use serde::Serialize;
6+
7+
use super::{follower::Follower, rollback::Rollbacks};
8+
9+
/// Statistics related to the live blockchain
10+
#[derive(Debug, Default, Clone, Serialize)]
11+
pub struct Live {
12+
/// The Time that synchronization to this blockchain started
13+
pub sync_start: DateTime<Utc>,
14+
/// The Time that synchronization to this blockchain was complete up-to-tip. None =
15+
/// Not yet synchronized.
16+
pub sync_end: Option<DateTime<Utc>>,
17+
/// When backfill started
18+
pub backfill_start: Option<DateTime<Utc>>,
19+
/// Backfill size to achieve synchronization. (0 before sync completed)
20+
pub backfill_size: u64,
21+
/// When backfill ended
22+
pub backfill_end: Option<DateTime<Utc>>,
23+
/// Backfill Failures
24+
pub backfill_failures: u64,
25+
/// The time of the last backfill failure
26+
pub backfill_failure_time: Option<DateTime<Utc>>,
27+
/// Current Number of Live Blocks
28+
pub blocks: u64,
29+
/// The current head of the live chain slot#
30+
pub head_slot: Slot,
31+
/// The current live tip slot# as reported by the peer.
32+
pub tip: Slot,
33+
/// Number of times we connected/re-connected to the Node.
34+
pub reconnects: u64,
35+
/// Last reconnect time,
36+
pub last_connect: DateTime<Utc>,
37+
/// Last reconnect time,
38+
pub last_connected_peer: String,
39+
/// Last disconnect time,
40+
pub last_disconnect: DateTime<Utc>,
41+
/// Last disconnect time,
42+
pub last_disconnected_peer: String,
43+
/// Is there an active connection to the node
44+
pub connected: bool,
45+
/// Rollback statistics.
46+
pub rollbacks: Rollbacks,
47+
/// New blocks read from blockchain.
48+
pub new_blocks: u64,
49+
/// Blocks that failed to deserialize from the blockchain.
50+
pub invalid_blocks: u64,
51+
/// Active Followers (range and current depth)
52+
pub follower: Vec<Follower>,
53+
}
54+
55+
impl Live {
56+
/// Reset incremental counters in the live statistics.
57+
pub(crate) fn reset(&mut self) {
58+
self.new_blocks = 0;
59+
self.reconnects = 0;
60+
self.invalid_blocks = 0;
61+
}
62+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
//! Mithril Snapshot Statistics
2+
3+
use cardano_blockchain_types::Slot;
4+
use chrono::{DateTime, Utc};
5+
use serde::Serialize;
6+
7+
/// Statistics related to Mithril Snapshots
8+
#[derive(Debug, Default, Clone, Serialize)]
9+
pub struct Mithril {
10+
/// Number of Mithril Snapshots that have downloaded successfully.
11+
pub updates: u64,
12+
/// The Immutable TIP Slot# - Origin = No downloaded snapshot
13+
pub tip: Slot,
14+
/// Time we started downloading the current snapshot. 1/1/1970-00:00:00 UTC = Never
15+
/// downloaded.
16+
pub dl_start: DateTime<Utc>,
17+
/// Time we finished downloading the current snapshot. if < `dl_start` its the
18+
/// previous time we finished.
19+
pub dl_end: DateTime<Utc>,
20+
/// Number of times download failed (bad server connection)
21+
pub dl_failures: u64,
22+
/// The time the last download took, in seconds.
23+
pub last_dl_duration: u64,
24+
/// The size of the download archive, in bytes. (If not started and not ended, current
25+
/// partial download size).
26+
pub dl_size: u64,
27+
/// Extraction start time. 1/1/1970-00:00:00 UTC = Never extracted.
28+
pub extract_start: DateTime<Utc>,
29+
/// Extraction end time. if `extract_end` < `extract_start` its the previous time we
30+
/// finished extracting.
31+
pub extract_end: DateTime<Utc>,
32+
/// Number of times extraction failed (bad archive)
33+
pub extract_failures: u64,
34+
/// Size of last extracted snapshot, in bytes.
35+
pub extract_size: u64,
36+
/// Deduplicated Size vs previous snapshot.
37+
pub deduplicated_size: u64,
38+
/// Number of identical files deduplicated from previous snapshot.
39+
pub deduplicated: u64,
40+
/// Number of changed files from previous snapshot.
41+
pub changed: u64,
42+
/// Number of new files from previous snapshot.
43+
pub new: u64,
44+
/// Mithril Certificate Validation Start Time. 1/1/1970-00:00:00 UTC = Never
45+
/// validated.
46+
pub validate_start: DateTime<Utc>,
47+
/// Mithril Certificate Validation End Time. if validate end < validate start its the
48+
/// previous time we finished validating.
49+
pub validate_end: DateTime<Utc>,
50+
/// Number of times validation failed (bad snapshot)
51+
pub validate_failures: u64,
52+
/// Blocks that failed to deserialize from the mithril immutable chain.
53+
pub invalid_blocks: u64,
54+
/// Download Or Validation Failed
55+
pub download_or_validation_failed: u64,
56+
/// Failed to get tip from mithril snapshot.
57+
pub failed_to_get_tip: u64,
58+
/// Tip failed to advance
59+
pub tip_did_not_advance: u64,
60+
/// Failed to send new tip to updater.
61+
pub tip_failed_to_send_to_updater: u64,
62+
/// Failed to activate new snapshot
63+
pub failed_to_activate_new_snapshot: u64,
64+
}
65+
66+
impl Mithril {
67+
/// Reset incremental counters in the mithril statistics.
68+
pub(crate) fn reset(&mut self) {
69+
self.updates = 0;
70+
self.dl_failures = 0;
71+
self.extract_failures = 0;
72+
self.validate_failures = 0;
73+
self.invalid_blocks = 0;
74+
}
75+
}

0 commit comments

Comments
 (0)