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:
- Issues a new fragment request for the updated height
- Verifies the new fragment (1 block higher)
- Resets
runtime_download to NotStarted — discarding the already-downloaded runtime
- Downloads
:code again (~1.5-2.5 MiB)
- 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.
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_downloadis unconditionally reset toRuntimeDownload::NotStarted: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:
runtime_downloadtoNotStarted— discarding the already-downloaded runtime:codeagain (~1.5-2.5 MiB)The second download is redundant — the runtime code hasn't changed between two consecutive blocks.
Measured impact
Tested on Paseo with a fresh
lightSyncStatecheckpoint::code)Proposed fix
Check the verified fragment header's digest for a
RuntimeEnvironmentUpdateditem before resettingruntime_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.