Skip to content

refactor(truapi): reach core storage through the stack - #2018

Closed
Mikelle wants to merge 215 commits into
mainfrom
feat/stack-8-storage-handle
Closed

Mikelle wants to merge 215 commits into
mainfrom
feat/stack-8-storage-handle

Conversation

@Mikelle

@Mikelle Mikelle commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Part of #1898. Stacked on #2017.

A refactor with no behaviour change. The core used to call CoreStorage on the platform from about 60 places. They now all go through Stack::storage.

That gives #2019 one place to add the stack's id to the key, and keeps this noisy diff out of it.

Stack::bundled checks a bundled descriptor against the stack pointer's key
and resolves the network, the dotNS TLD and the Relay, Asset Hub, People and
Bulletin genesis hashes. It refuses a pointer without a key, a descriptor
without People or Bulletin, a TLD the core does not serve, and Polkadot's
genesis hashes or `dot` unless the host build allows them. Stack::new
applies the same rules to values a Rust host resolved itself.

Nothing reads the stack yet; the host configuration takes it next.
PairingHostConfig, SigningHostConfig and RuntimeServices take a Stack in
place of the People, Bulletin and Asset Hub genesis hashes and the network
suffix. get_chain_info answers from the stack's chains and network, the
signing role derives identities under its TLD, and the Platform trait has
no supported_chains callback. The native HostRuntimeConfig takes a
BundledStack (pointer, descriptor, allowsReservedValues), and the wasm
runtimeConfig takes a `stack` of the same shape, or a `testStack` built
from its parts in a test-host build.

Session identity lookup takes the stack's Asset Hub as an Option, so an
all-zero genesis no longer stands for "none".

The CLI, the JS host, and the iOS and Android hosts adopt this in the
layers above.
The CLI builds the core's stack from the network it resolved: the descriptor's
network, which get_chain_info reports as an app bundling the same stack does,
its TLD, and the People, Bulletin and Asset Hub it serves. The descriptor's
id stays the product namespace and state directory, and feature_supported
answers from the served roles.

The core allows the stack Polkadot's reserved values, since the CLI vouches
for them itself: no stack runs under the polkadot namespace, and a chain with
one of Polkadot's genesis hashes runs only once the chain checks show it is a
fork. That is what lets pcf-devnet run on `dot`.
ProductRuntimeConfig.stack carries the stack's pointer, the bytes of the
signed descriptor the host bundles, and allowsReservedValues, in place of
people, bulletin, assetHub and networkSuffix. The supportedChains host
callback and the HostChainSet and HostChainEntry types are removed.

The test host runs a stack built from its parts: mockRuntimeConfig returns a
testStack over the MOCK_GENESIS chains, fromNetworks and liveChain build one
from their chains, startTestHost and createMockClient take
Partial<MockRuntimeConfig>, and MockHostConfig.servedChains lists the
genesis hashes featureSupported answers from under onlyServedChains.
The app bundles the signed descriptors of previewnet, paseo-next-v2 and
Polkadot, and hands the core the one its build runs: previewnet for Debug
and DevCI, paseo-next-v2 for Nightly and Safetynet, and Polkadot, with
reserved values allowed, for Release. get_chain_info reports the network
the descriptor declares. TrUAPIHost's HostBridge has no supportedChains
callback.
The app bundles the signed descriptors of previewnet, paseo-next-v2 and
Polkadot as assets, and hands the core the one its TestnetEnvironment runs:
previewnet for TESTNET, paseo-next-v2 for NIGHTLY, and Polkadot, with
reserved values allowed, for PRODUCTION. TrUAPIHost's HostBridge has no
supportedChains callback, and the chain directory only answers which
genesis hashes the host can dial.
…ts refusal

`Stack::bundled` and `Stack::new` refuse Polkadot's genesis hashes through
one helper that takes every hash to check. A reserved value is reported as
`StackError::ReservedTld` or `StackError::ReservedGenesis` carrying the hash,
with the same messages as before. `genesis_hash` is private, since
`chain_info` is its only caller.

The missing-chain test covers People as well as Bulletin, and the test
pointer link is built in one place. Docs separate `validUntil` from
`expiresAt` and say why Polkadot's values are reserved.
`Stack::bundled` looks chains up by `ChainIdentifier`, and one exhaustive
match gives the role a descriptor lists each under, so a new identifier
cannot be left without one. `StackError::MissingChain` carries the
`ChainIdentifier`; its message is unchanged.
…xtures

- `SigningHostConfig.stack` says the core does not check its TLD against
  the People chain's `NetworkSuffix`, rather than asking the host to make
  them match. `BundledStack` names the signed descriptor the build ships.
- `AllowanceAllocationError::NoAssetHub` replaces a `ChainNotServed`
  variant whose only use named Asset Hub as a string.
- The signing-host runtime moves its config's stack into the services
  instead of cloning it.
- Tests share `test_support::paseo_test_stack` for the stack nine of them
  spelled out, and build the keyless pointer with `test_stack_link`.
RUNTIME.md names the constructors instead of copying what `Stack::bundled`
refuses, and says the TLD and the People chain's `NetworkSuffix` have to
be equal without asking the host to make them so. The README points to it.
`CliPlatform` keeps the network's `Roles` of genesis hashes and answers
`feature_supported` from them, so `served_roles`, which only tests read
with its chain identifiers, moves to the test-only `network::testing`.
The test that guarded the served set against a dropped role goes, since
`Roles` holds all three by type. `core_stack` says it relies on
`NetworkSource::resolve_checked` having checked Polkadot's reserved
values. Rewraps the namespace doc, the `feature_supported` test doc and
the SPEC paragraph.
# Conflicts:
#	rust/crates/truapi/src/test_support.rs
# Conflicts:
#	rust/crates/truapi/src/stack.rs
#	rust/crates/truapi/src/stack/tests.rs
# Conflicts:
#	rust/crates/truapi/src/runtime/signing_host/wallet_account_holder/allowance_renewal/tests.rs

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

not clear to me what is specific to the Stack

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nothing really, it was only prep for #2019. With a directory per stack it isn't needed, so I closed this PR.

Base automatically changed from feat/stack-7-identity to main November 24, 2026 09:24
@Mikelle
Mikelle removed this pull request from stack #1969 November 24, 2026 14:40
Mikelle added a commit that referenced this pull request Nov 24, 2026
The change of #2020 on main, without the per-stack storage key of #2018 and
#2019: the core reads and writes its slots through CoreStorage as main does.

HostGrantStore holds the run it stamps allowance keys with, and
RingVrfRegistryStore the chains it keeps rings on, since neither reaches the
stack through a storage handle any more. SessionUsernamesRun takes codec
index 18. The tests that told a fork from its source by stack id are left
out, because core storage is kept apart per stack by the host.
@Mikelle Mikelle closed this Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:no-changeset Changes no published artifact, so the changeset check passes without one size:XL Pull requests only. 1000 to 1999 lines changed; consider splitting status:waiting-on-review Ready for a reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants