Skip to content
This repository was archived by the owner on Jan 11, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions fendermint/vm/topdown/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ pub enum Error {
ParentChainReorgDetected,
#[error("Cannot query parent at height {1}: {0}")]
CannotQueryParent(String, BlockHeight),
#[error("Look ahead limit reached from {0}: {1}")]
LookAheadLimitReached(BlockHeight, BlockHeight),
}
35 changes: 21 additions & 14 deletions fendermint/vm/topdown/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,16 +223,17 @@ where
return Ok(());
}

let ending_height = parent_chain_head_height - config.chain_head_delay;
// we consider the chain head finalized only after the `chain_head_delay`
let finalized_chain_head = parent_chain_head_height - config.chain_head_delay;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let finalized_chain_head = parent_chain_head_height - config.chain_head_delay;
let proposal_chain_head = parent_chain_head_height - config.chain_head_delay;


tracing::debug!(
last_recorded_height = last_recorded_height,
parent_chain_head_height = parent_chain_head_height,
ending_height = ending_height,
finalized_chain_head = finalized_chain_head,
"syncing heights",
);

if last_recorded_height == ending_height {
if last_recorded_height == finalized_chain_head {
tracing::debug!(
last_recorded_height = last_recorded_height,
"the parent has yet to produce a new block"
Expand All @@ -243,10 +244,10 @@ where
// we are going backwards in terms of block height, the latest block height is lower
// than our previously fetched head. It could be a chain reorg. We clear all the cache
// in `provider` and start from scratch
if last_recorded_height > ending_height {
if last_recorded_height > finalized_chain_head {
tracing::warn!(
last_recorded_height = last_recorded_height,
ending_height = ending_height,
finalized_chain_head = finalized_chain_head,
"last recorded height more than ending height"
);
return reset_cache(parent_proxy, provider, query).await;
Expand All @@ -255,7 +256,10 @@ where
// we are adding 1 to the height because we are fetching block by block, we also configured
// the sequential cache to use increment == 1.
let starting_height = last_recorded_height + 1;
let ending_height = min(ending_height, MAX_PARENT_VIEW_BLOCK_GAP + starting_height);
let ending_height = min(
finalized_chain_head,
MAX_PARENT_VIEW_BLOCK_GAP + starting_height,
);
tracing::debug!(
start = starting_height,
end = ending_height,
Expand All @@ -267,6 +271,7 @@ where
last_height_hash,
starting_height,
ending_height,
finalized_chain_head,
)
.await?;

Expand Down Expand Up @@ -389,12 +394,13 @@ async fn parent_views_in_block_range(
mut previous_hash: BlockHash,
start_height: BlockHeight,
end_height: BlockHeight,
look_ahead_limit: BlockHeight,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment of how look_ahead_limit modifies the behavior of this function?

) -> Result<GetParentViewPayload, Error> {
let mut updates = vec![];
let mut total_top_down_msgs = 0;

for h in start_height..=end_height {
match parent_views_at_height(parent_proxy, &previous_hash, h, end_height).await {
match parent_views_at_height(parent_proxy, &previous_hash, h, look_ahead_limit).await {
Ok((hash, changeset, cross_msgs)) => {
total_top_down_msgs += cross_msgs.len();

Expand Down Expand Up @@ -422,6 +428,13 @@ async fn parent_views_in_block_range(
if is_null_round_str(&err_msg) {
tracing::warn!(height = h, "null round detected, skip");
updates.push((h, None));
} else if let Error::LookAheadLimitReached(start, limit) = e {
tracing::warn!(
start_height = start,
limit_height = limit,
"look ahead limit reached, store updates so far in cache",
);
break;
} else {
return Err(e);
}
Expand Down Expand Up @@ -523,11 +536,5 @@ async fn next_block_hash(
}
}
}
Err(Error::CannotQueryParent(
format!(
"cannot get next block hash in range {}-{}, check your parent chain",
height, look_ahead_limit
),
look_ahead_limit,
))
Err(Error::LookAheadLimitReached(height, look_ahead_limit))
}