Skip to content

chainHead_unstable_finalizedDatabase returns incomplete DB when runtime not yet cached #3231

@replghost

Description

@replghost

Problem

chainHead_unstable_finalizedDatabase returns a database without runtime code when called shortly after the initialized event from chainHead_v1_follow. The sync service has reached a finalized block, but the runtime service is still downloading :code from a peer.

The returned DB has valid chain info (~43KB) but no runtimeCode, codeMerkleValue, or codeClosestAncestorExcluding. Feeding this back as databaseContent on the next start is useless - smoldot ignores it and does a full warp sync + runtime download anyway.

Reproduction

const client = start({ maxLogLevel: 3 });
const chain = await client.addChain({ chainSpec });

// Subscribe and wait for initialized
chain.sendJsonRpc(JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'chainHead_v1_follow', params: [true] }));
// ... wait for initialized event ...

// Call immediately after initialized
chain.sendJsonRpc(JSON.stringify({ jsonrpc: '2.0', id: 2, method: 'chainHead_unstable_finalizedDatabase', params: [] }));
// Returns ~43KB DB with chain info but NO runtimeCode

// Wait 5-10 seconds, call again
chain.sendJsonRpc(JSON.stringify({ jsonrpc: '2.0', id: 3, method: 'chainHead_unstable_finalizedDatabase', params: [] }));
// Returns ~2.3MB DB with chain info AND runtimeCode

Observed on Paseo Asset Hub parachain cold start with smoldot dev/pending-20260423.

Expected behavior

chainHead_unstable_finalizedDatabase should either:

  1. Wait for the runtime service to have a cached runtime before serializing, or
  2. Include a complete: boolean field so callers know whether to retry

Context

This affects the dotli warm-start persistence feature. We save the DB to IndexedDB after initialized fires so users get fast warm starts on return visits. When the DB is incomplete (no runtime), the warm start falls back to a full cold sync - defeating the purpose.

Current workaround: retry the save after 5s if the DB is too small (<100KB).

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