Skip to content

fix: don't keep the startup finalized block pinned forever - #2266

Merged
marian-radu merged 3 commits into
masterfrom
mr/fix-startup-best-block-pin
Aug 4, 2026
Merged

fix: don't keep the startup finalized block pinned forever#2266
marian-radu merged 3 commits into
masterfrom
mr/fix-startup-best-block-pin

Conversation

@marian-radu

@marian-radu marian-radu commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Problem

FollowStreamDriver's replay buffer holds BlockRefs and entries only leave it when a later Finalized event reports the block.
At subscription start the node unconditionally reports the current best block. When best == finalized, always on instant-seal, a connect-time race otherwise, that block was finalized before we started watching, so no Finalized event we receive ever reports it and the pin lasts for the life of the subscription, so the node can't prune state past that block.

Fix

Keep only the latest BestBlockChanged in the buffer. This behavior matches the node rather than diverging from it.
Subscribers joining mid-stream now receive only the latest best-block event. Existing subscribers are unaffected.

Testing

startup_best_block_event_is_not_kept_alive_forever asserts the replay buffer no longer references block 0 and that an unpin was issued for it.

@marian-radu marian-radu added the bug Something isn't working label Jul 31, 2026
@marian-radu
marian-radu requested a review from lexnv July 31, 2026 15:55
Comment thread subxt/src/backend/chain_head/follow_stream_driver.rs Outdated
@lexnv
lexnv requested a review from DenzelPenzel August 3, 2026 08:35
// subscription would see.
shared
.block_events_for_new_subscriptions
.retain(|e| !matches!(e, FollowEvent::BestBlockChanged(_)));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks! It makes sense, this effectively cleans up the block_events_for_new_subscriptions. If we had:

  • new block 1 + bestBlock 1 + new Block 2 + bestBlock 2
  • new subscribers would see: new block 1 + new block 2 + best block 2

@DenzelPenzel DenzelPenzel left a comment

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.

LGTM, thanks!

@marian-radu
marian-radu merged commit e2b7360 into master Aug 4, 2026
50 of 63 checks passed
@marian-radu
marian-radu deleted the mr/fix-startup-best-block-pin branch August 4, 2026 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants