Skip to content

fix(webrtc): warp sync slow initialization and webrtc handshake bug#3256

Open
gab8i wants to merge 3 commits into
mainfrom
gab_webrtc
Open

fix(webrtc): warp sync slow initialization and webrtc handshake bug#3256
gab8i wants to merge 3 commits into
mainfrom
gab_webrtc

Conversation

@gab8i
Copy link
Copy Markdown
Contributor

@gab8i gab8i commented May 13, 2026

The following PR just extract work already done within paritytech/smoldot-archive#2222.

The fixes are:

  • Solving a deadlock within the multistream-select task loop
  • Initializing warp sync faster by avoiding the need to wait for Grandpa notifications. This is especially needed by WebRTC because data channel creation introduces latency, and thus not waiting for the channel to open saves time during syncing.

haikoschol and others added 2 commits May 13, 2026 15:58
Initialize warp sync source finalized_block_height with best_block_number
from gossip handshake instead of 0, so warp sync triggers immediately
without waiting for a GrandPa neighbor packet.
@gab8i gab8i changed the title fix: warp sync slow initialization and webrtc handshake bug fix(webrtc): warp sync slow initialization and webrtc handshake bug May 13, 2026
Copy link
Copy Markdown
Collaborator

@dmitry-markin dmitry-markin left a comment

Choose a reason for hiding this comment

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

Substream waking in WebRTC looks good.

The idea behind optimistically targeting warp sync at the best block and not finalized one is also good, but we need to rename finalized_block_height to something like optimistic_finalized_block_height, or a better name, so future code doesn't rely on this value as actually being finalized.

Also, the comment at warp_sync.rs:768 likely needs updating and the corresponding logic checked for correctness.

// Wait for either platform data or a coordinator write
// notification (e.g. after AcceptInNotifications queues a
// handshake response that needs to be flushed).
let write_listener = write_ready.listen();
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.

Should we move the write_ready.listen() outside the Box::pin future?

Currently, the write listener is registered once the the when_substreams_rw_ready is firstly polled.
This means we could arrive in a situation where .notify(usize::MAX); is called before registering the listener call.

For this to happen we need to:

  • receive WakeUpReason::CoordinatorMessage(message)
  • message_sending.as_ref().as_pin_ref().is_none() should have some data to effectively take the None path and ignore the when_substreams_rw_ready.select_next_some()

Moving the listener above Box::pin solves this regardless of which states call when_substreams_rw_ready.poll_next and avoids the problem entirely

Copy link
Copy Markdown
Contributor

@lexnv lexnv left a comment

Choose a reason for hiding this comment

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

LGTM!

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.

6 participants