Skip to content

light-base: child-trie support for chainHead_v1_storage#3278

Merged
lrubasze merged 4 commits into
mainfrom
tiago-chainhead-childtrie
Jun 2, 2026
Merged

light-base: child-trie support for chainHead_v1_storage#3278
lrubasze merged 4 commits into
mainfrom
tiago-chainhead-childtrie

Conversation

@BigTava
Copy link
Copy Markdown
Contributor

@BigTava BigTava commented Jun 1, 2026

Summary

  • Adds child-trie reads to chainHead_v1_storage so callers can read contract storage (or any default child trie) without going through a runtime call.

Adds child-trie reads to chainHead_v1_storage so callers can read contract
storage (or any default child trie) without going through a runtime call.

- sync_service: new `child_storage_query` that fetches a child storage
  proof, resolves the child root from the main trie at
  `:child_storage:default:<child_trie>`, and verifies each requested key
  against it. Only Value and Hash request types are supported.
- json_rpc_service: chainHead_v1_storage routes to `child_storage_query`
  when `childTrie` is set, and rejects unsupported request types in that
  mode with `-32000`.
- codec: `build_child_storage_proof_request` now sends the prefixed
  `:child_storage:default:<child_trie>` key in field 3 of the protobuf
  RemoteReadChildRequest. Substrate's `ChildType::from_prefixed_key`
  rejects the bare child trie name with `InvalidChildStorageKey`, so the
  prefix must be present. This path was previously unexercised because
  runtime calls prefer call proofs for small parameters.
Copy link
Copy Markdown
Contributor

@skunert skunert left a comment

Choose a reason for hiding this comment

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

Looks good!

Comment thread light-base/src/sync_service.rs Outdated
Comment thread lib/src/network/codec/storage_call_proof.rs Outdated
Addresses two review comments on #3278:

- Add `trie::default_child_trie_root_key` (and `DEFAULT_CHILD_STORAGE_PREFIX`)
  for the `:child_storage:default:<trie_id>` lookup key. Use it from the new
  child-storage codec and effective-root resolution, plus the pre-existing
  duplicates in `runtime_call.rs`, `state_request.rs`, `runtime_service.rs`
  (both call sites), and `sync_service/parachain.rs`.
- Replace the isomorphic `ChildStorageProofRequestError` -> `StorageProofRequestError`
  squash in `StorageQuery::advance` with a proper `StorageQueryNetworkError`
  wrapper that preserves which side the error came from.
  `StorageQueryErrorDetail::Network` now carries the wrapper. Small helpers
  on it (`is_no_connection`, `is_request_too_large`, `protocol_request_error`)
  keep the existing branching logic and `is_network_problem` readable.
Comment thread light-base/src/sync_service.rs
@BigTava BigTava self-assigned this Jun 2, 2026
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!

Copy link
Copy Markdown
Contributor

@lrubasze lrubasze left a comment

Choose a reason for hiding this comment

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

LGTM with some nit

Comment thread light-base/src/sync_service.rs Outdated
@lrubasze lrubasze enabled auto-merge (squash) June 2, 2026 15:32
@lrubasze lrubasze merged commit 836f162 into main Jun 2, 2026
39 checks passed
@lrubasze lrubasze deleted the tiago-chainhead-childtrie branch June 2, 2026 15:44
@lrubasze lrubasze mentioned this pull request Jun 2, 2026
lrubasze added a commit that referenced this pull request Jun 2, 2026
This is to:
- publish `smoldot-v3.2.0` npm.
- publish crates `smoldot-light v1.2.0`, `smoldot v1.2.0`

## Changes

### Added

- `chainHead_v1_storage` can now read child-trie storage (the default
child trie), letting callers read e.g. contract storage directly without
going through a runtime call.
([#3278](#3278))
- Implement the `ext_trie_blake2_256_verify_proof_version_1` and
`ext_trie_blake2_256_verify_proof_version_2` host functions. The
verifier handles Substrate's compact proof format (as produced by
`sp_trie::generate_trie_proof`).
([#3263](#3263))

### Fixed

- `ext_transaction_index_index_version_1` and
`ext_transaction_index_renew_version_1` now consume their parameters
with the correct wasm value types (3xI32 and 2xI32 respectively), fixing
a wasm-executor crash when a substrate runtime calls either function.
Behavior remains a no-op since smoldot is a light client.
([#3263](#3263))
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.

4 participants