Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: chain follower get_block #345

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions hermes/crates/cardano-chain-follower/src/follow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ impl ChainFollower {
}
}

if self.mithril_tip.is_none() || current_mithril_tip > self.mithril_tip {
if (self.mithril_tip.is_none() || current_mithril_tip > self.mithril_tip)
&& self.current < self.mithril_tip
{
let snapshot = MithrilSnapshot::new(self.chain);
if let Some(block) = snapshot.read_block_at(&current_mithril_tip).await {
// The Mithril Tip has moved forwards.
Expand Down Expand Up @@ -145,7 +147,9 @@ impl ChainFollower {

// In most cases we will be able to get the next block.
if next_block.is_none() {
next_block = get_live_block(self.chain, &self.current, 1, true);
// If we don't know the previous block, get the block requested.
let advance = if self.previous.is_unknown() { 0 } else { 1 };
next_block = get_live_block(self.chain, &self.current, advance, true);
}

// If we can't get the next consecutive block, then
Expand Down Expand Up @@ -291,8 +295,9 @@ impl ChainFollower {
/// block.
pub async fn get_block(chain: Network, point: Point) -> Option<ChainUpdate> {
// Get the block from the chain.
let mut follower = Self::new(chain, point.clone(), point).await;

// This function suppose to run only once, so the end point
// can be set to `TIP_POINT`
let mut follower = Self::new(chain, point, TIP_POINT).await;
follower.next().await
}

Expand Down
Loading