Skip to content

Commit 1d37012

Browse files
committed
fix(cardano-chain-follower): comments
Signed-off-by: bkioshn <[email protected]>
1 parent bc4bfff commit 1d37012

File tree

8 files changed

+29
-31
lines changed

8 files changed

+29
-31
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use crate::{
4040
const MAX_NODE_CONNECT_TIME_SECS: u64 = 2;
4141

4242
/// The maximum number of times we wait for a nodeChainUpdate to connect.
43-
/// Currently set to never give up.
43+
/// Currently set to maximum of 5 retries.
4444
const MAX_NODE_CONNECT_RETRIES: u64 = 5;
4545

4646
/// Try and connect to a node, in a robust and quick way.
@@ -120,7 +120,7 @@ async fn resync_live_tip(client: &mut PeerClient, chain: Network) -> Result<Poin
120120
Ok(sync_to_point)
121121
}
122122

123-
/// Fetch a single block from the Peer, and Decode it.
123+
/// Fetch a single block from the Peer, and decode it.
124124
async fn fetch_block_from_peer(
125125
peer: &mut PeerClient, chain: Network, point: Point, previous_point: Point, fork: Fork,
126126
) -> anyhow::Result<MultiEraBlock> {

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ use crate::{
2222
/// Default Follower block buffer size.
2323
const DEFAULT_CHAIN_UPDATE_BUFFER_SIZE: usize = 32;
2424

25-
/// How many slots back from TIP is considered Immutable in the absence of a mithril
26-
/// snapshot.
25+
/// How many window (in slot) back from TIP is considered Immutable in the
26+
/// absence of a mithril snapshot.
2727
const DEFAULT_IMMUTABLE_SLOT_WINDOW: u64 = 12 * 60 * 60;
2828

2929
/// Type we use to manage the Sync Task handle map.
3030
type SyncMap = DashMap<Network, Mutex<Option<JoinHandle<()>>>>;
31+
3132
/// Handle to the mithril sync thread. One for each Network ONLY.
3233
static SYNC_JOIN_HANDLE_MAP: LazyLock<SyncMap> = LazyLock::new(|| {
3334
let map = DashMap::new();
@@ -68,7 +69,7 @@ impl ChainSyncConfig {
6869
}
6970
}
7071

71-
/// Sets the relay to use for Chain Sync.
72+
/// Sets the relay address to use for Chain Sync.
7273
///
7374
/// # Arguments
7475
///
@@ -101,12 +102,11 @@ impl ChainSyncConfig {
101102
self
102103
}
103104

104-
/// Sets the the Mithril snapshot Config the `ChainSync` will use.
105+
/// Sets the Mithril snapshot Config the `ChainSync` will use.
105106
///
106107
/// # Arguments
107108
///
108-
/// * `path`: Mithril snapshot path.
109-
/// * `update`: Auto-update this path with the latest mithril snapshot as it changes.
109+
/// * `cfg`: Mithril snapshot configuration.
110110
#[must_use]
111111
pub fn mithril_cfg(mut self, cfg: MithrilSnapshotConfig) -> Self {
112112
self.mithril_cfg = cfg;
@@ -117,10 +117,6 @@ impl ChainSyncConfig {
117117
///
118118
/// Must be done BEFORE the chain can be followed.
119119
///
120-
/// # Arguments
121-
///
122-
/// * `chain`: The chain to follow.
123-
///
124120
/// # Returns
125121
///
126122
/// `Result<()>`: On success.

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::{
2121
/// Type we use to manage the Sync Task handle map.
2222
type LiveChainBlockList = SkipMap<Point, MultiEraBlock>;
2323

24-
/// Because we have multi-entry relationships in the live-chain protect it with a
24+
/// Because we have multi-entry relationships in the live-chain, it need to protect it with a
2525
/// `read/write lock`. The underlying `SkipMap` is still capable of multiple simultaneous
2626
/// reads from multiple threads which is the most common access.
2727
#[derive(Clone)]
@@ -50,7 +50,8 @@ fn update_peer_tip(chain: Network, tip: Point) {
5050
PEER_TIP.insert(chain, tip);
5151
}
5252

53-
/// Set the last TIP received from the peer.
53+
/// Get the last TIP received from the peer.
54+
/// If the peer tip doesn't exist, get the UNKNOWN point.
5455
pub(crate) fn get_peer_tip(chain: Network) -> Point {
5556
(*PEER_TIP.get_or_insert(chain, Point::UNKNOWN).value()).clone()
5657
}
@@ -117,7 +118,7 @@ impl ProtectedLiveChainBlockList {
117118
Ok(check_first_live_block.point())
118119
}
119120

120-
/// Get the point of the first known block in the Live Chain.
121+
/// Get the point of the last known block in the Live Chain.
121122
fn get_last_live_point(live_chain: &LiveChainBlockList) -> Point {
122123
let Some(check_last_live_entry) = live_chain.back() else {
123124
// Its not an error if we can't get a latest block because the chain is empty,
@@ -151,7 +152,7 @@ impl ProtectedLiveChainBlockList {
151152
)));
152153
}
153154

154-
// Get the current Oldest block in the live chain.
155+
// Get the current oldest block in the live chain.
155156
let check_first_live_point = Self::get_first_live_point(&live_chain)?;
156157

157158
let last_backfill_block = blocks
@@ -160,7 +161,7 @@ impl ProtectedLiveChainBlockList {
160161
.clone();
161162
let last_backfill_point = last_backfill_block.point();
162163

163-
// Make sure the backfill will properly connect the partial Live chain to the Mithril
164+
// Make sure the backfill will properly connect the partial live chain to the Mithril
164165
// chain.
165166
if !last_backfill_point.strict_eq(&check_first_live_point) {
166167
return Err(Error::LiveSync(format!(
@@ -179,8 +180,8 @@ impl ProtectedLiveChainBlockList {
179180
Ok(())
180181
}
181182

182-
/// Check if the given point is strictly in the live-chain. This means the slot and
183-
/// Hash MUST be present.
183+
/// Check if the given point is strictly in the live-chain. This means the slot and
184+
/// block hash MUST be present.
184185
fn strict_block_lookup(live_chain: &LiveChainBlockList, point: &Point) -> bool {
185186
if let Some(found_block) = live_chain.get(point) {
186187
return found_block.value().point().strict_eq(point);
@@ -451,7 +452,7 @@ pub(crate) fn get_live_block(
451452
live_chain.get_block(point, advance, strict)
452453
}
453454

454-
/// Get the fill tp point for a chain.
455+
/// Get the fill to point for a chain.
455456
///
456457
/// Returns the Point of the block we are filling up-to, and it's fork count.
457458
///
@@ -493,7 +494,7 @@ pub(crate) fn live_chain_length(chain: Network) -> usize {
493494
live_chain.len()
494495
}
495496

496-
/// On an immutable update, purge the live-chain up to the new immutable tip.
497+
/// On an immutable update, purge the live chain up to the new immutable tip.
497498
/// Will error if the point is not in the Live chain.
498499
pub(crate) fn purge_live_chain(chain: Network, point: &Point) -> Result<()> {
499500
let live_chain = get_live_chain(chain);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl ChainUpdate {
4040
&self.data
4141
}
4242

43-
/// Gets the chain update's block data.
43+
/// Is the chain update immutable?
4444
#[must_use]
4545
pub fn immutable(&self) -> bool {
4646
self.data.immutable()

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub enum Error {
2121
/// Chainsync protocol error.
2222
#[error("Chainsync error: {0:?}")]
2323
Chainsync(chainsync::ClientError),
24-
/// Backfill Synch error.
24+
/// Backfill Sync error.
2525
#[error("Backfill Sync error: {0}")]
2626
BackfillSync(String),
2727
/// Live Sync error.
@@ -48,7 +48,7 @@ pub enum Error {
4848
/// Mithril snapshot traversal error.
4949
#[error("Failed to traverse block(s) from Mithril snapshot")]
5050
MithrilSnapshotTraverse(pallas::ledger::traverse::Error),
51-
/// Failed to parse
51+
/// Failed to parse network error.
5252
#[error("Failed to parse network")]
5353
ParseNetwork,
5454
/// Mithril Snapshot path is not a directory

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ pub struct ChainFollower {
2323
chain: Network,
2424
/// Where we end following.
2525
end: Point,
26-
/// Block we processed most recently.
26+
/// Point we processed most recently.
2727
previous: Point,
28-
/// Where we are currently in the following process.
28+
/// Point we are currently in the following process.
2929
current: Point,
3030
/// What fork were we last on
3131
fork: Fork,
@@ -134,7 +134,7 @@ impl ChainFollower {
134134
None
135135
}
136136

137-
/// If we can, get the next update from the mithril snapshot.
137+
/// If we can, get the next update from the live chain.
138138
async fn next_from_live_chain(&mut self) -> Option<ChainUpdate> {
139139
let mut next_block: Option<MultiEraBlock> = None;
140140
let mut update_type = chain_update::Kind::Block;
@@ -208,7 +208,7 @@ impl ChainFollower {
208208
None
209209
}
210210

211-
/// Update the current Point, and return `false` if this fails.
211+
/// Update the current Point, return `false` if this fails.
212212
fn update_current(&mut self, update: &Option<ChainUpdate>) -> bool {
213213
if let Some(update) = update {
214214
let decoded = update.block_data().decode();
@@ -323,7 +323,7 @@ impl ChainFollower {
323323
///
324324
/// # Arguments
325325
///
326-
/// * `chain` - The blockchain to post the transaction on.
326+
/// * `chain` - The blockchain network to post the transaction on.
327327
/// * `txn` - The transaction to be posted.
328328
///
329329
/// # Returns

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl MithrilSnapshot {
3333
/// Checks if the snapshot contains a given point.
3434
///
3535
/// # Arguments
36-
/// * `network`: The network that this function should check against.
36+
///
3737
/// * `point`: The point to be checked for existence within the specified Mithril
3838
/// snapshot.
3939
///

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use crate::{
2929

3030
/// Type we use to manage the Sync Task handle map.
3131
type SyncMap = DashMap<Network, Mutex<Option<JoinHandle<()>>>>;
32+
3233
/// Handle to the mithril sync thread. One for each Network ONLY.
3334
static SYNC_JOIN_HANDLE_MAP: LazyLock<SyncMap> = LazyLock::new(|| {
3435
let map = DashMap::new();
@@ -294,7 +295,7 @@ impl MithrilSnapshotConfig {
294295
snapshot_path
295296
}
296297

297-
/// Check if the Mithril Snapshot Path is valid an usable.
298+
/// Check if the Mithril Snapshot Path is valid and usable.
298299
async fn validate_path(&self) -> Result<()> {
299300
let path = self.path.clone();
300301
debug!(

0 commit comments

Comments
 (0)