Skip to content

Conversation

@SupernaviX
Copy link
Collaborator

@SupernaviX SupernaviX commented Dec 2, 2025

Description

Update the PeerNetworkInterface module to produce rollback messages whenever it rolls back. We need this for custom indexers, which should be able to handle rollbacks immediately without waiting for a roll forward.

The logic changes were relatively involved:

  • If our preferred peer sends us a RollBackward message, emit our own Rollback message to whichever point we rolled back to.
  • If we choose a new preferred peer who we know is farther behind on the chain, emit a Rollback message to that chain's head.
  • If we choose a new preferred peer and we don't know which point they're at on the chain, wait until we receive a message from them, then decide where to roll back to (or if to roll back) based on that message.

This also fixes some other chain-sync bugs:

  • When making FindIntersect requests, include the earliest point we know of as a fallback (I wrote this before the piggy incident, when rolling back >600 blocks seemed farfetched 😅 )
  • If we can't connect to any peers at startup, make sure we resume chainsync as soon as we can.

Related Issue(s)

Completes #421

How was this tested?

Almost entirely through unit tests, though with some manual tests.

Checklist

  • My code builds and passes local tests
  • I added/updated tests for my changes, where applicable
  • I updated documentation (if applicable)
  • CI is green for this PR

Impact / Side effects

The node can actually emit rollback messages now, meaning they propagate downstream.

Reviewer notes / Areas to focus

The most involved method is switch_head_to_peer, which gets called whenever we change which peer we're following. It has to gracefully handle rolling our chain back to that peer's head, and if we don't know where that peer's head is yet it sets a flag to call it again when we know more.

@SupernaviX SupernaviX marked this pull request as ready for review December 2, 2025 22:27
@SupernaviX SupernaviX requested review from lowhung, shd and whankinsiv and removed request for shd and whankinsiv December 2, 2025 22:28
ChainEvent::RollForward { header, body } => {
self.block_sink.announce_roll_forward(header, body).await?;
self.published_blocks += 1;
if self.published_blocks.is_multiple_of(100) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This might be a silly question, but why do we log that a specific block was published every 100 blocks?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Two reasons:

  1. UpstreamChainFetcher had the same line
  2. it's been useful for me, for observing signs of life

};
let hash = Hash::try_from(hash).unwrap_or_default();
if let Some(slot_blocks) = self.blocks.get(&slot)
&& let Some(header) = slot_blocks.header(hash)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I didn't know you could let chain like this!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's a feature that's less than a year old, my favorite from Rust 2024 edition

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yay!

}

#[test]
fn should_gracefully_switch_to_new_chain_at_older_head() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Great tests!!

Copy link
Collaborator

@whankinsiv whankinsiv left a comment

Choose a reason for hiding this comment

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

Looks great! Really nice tests.

@SupernaviX SupernaviX merged commit 1d856bb into main Dec 3, 2025
2 checks passed
@SupernaviX SupernaviX deleted the sg/publish-rollback-messages branch December 3, 2025 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants