Skip to content

Warp sync downloads runtime twice on every cold start #3199

@replghost

Description

@replghost

Summary

During warp sync on a live network, smoldot downloads the parachain/relay runtime (:code, ~1.5-2.5 MiB) twice on nearly every cold start. This roughly doubles cold-start time.

Root cause

In lib/src/sync/warp_sync.rs:1710, when a warp sync fragment is verified, runtime_download is unconditionally reset to RuntimeDownload::NotStarted:

self.inner.runtime_download = RuntimeDownload::NotStarted {
    hint_doesnt_match: false,
};

On a live network, GrandPa commit messages arrive every few seconds. When one arrives during the first runtime download cycle (advancing the finalized height by even 1 block), the warp sync state machine:

  1. Issues a new fragment request for the updated height
  2. Verifies the new fragment (1 block higher)
  3. Resets runtime_download to NotStarteddiscarding the already-downloaded runtime
  4. Downloads :code again (~1.5-2.5 MiB)
  5. Compiles the runtime again

The second download is redundant — the runtime code hasn't changed between two consecutive blocks.

Measured impact

Tested on Paseo with a fresh lightSyncState checkpoint:

Storage proof downloads Runtime builds Cold start
Before fix 2 (both :code) 2 ~6-8s
After fix 1 1 ~2.7s

Proposed fix

Check the verified fragment header's digest for a RuntimeEnvironmentUpdated item before resetting runtime_download. This digest is the authoritative signal that the runtime code has changed. Normal blocks (vast majority) do not contain it and can safely reuse the already-downloaded runtime.

See #3198 for the implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions