Skip to content

refactor(host): make HostState generic over the component backends#110

Merged
mfw78 merged 1 commit into
developfrom
refactor/host-generic-hoststate
Jul 2, 2026
Merged

refactor(host): make HostState generic over the component backends#110
mfw78 merged 1 commit into
developfrom
refactor/host-generic-hoststate

Conversation

@mfw78

@mfw78 mfw78 commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

What

Makes HostState generic over the component seam: HostState<C, W, S, H> (chain, cow, store handle, http), with all ten WIT Host impls rewritten as generic impls bounded on the seam traits, a Components bundle threading the shared backends through a generic Supervisor and event loop, and the concrete pools wired in bootstrap. Store and linker construction are deduplicated behind build_store and build_linker, removing the near-identical blocks the module-restart path carried.

Three typing improvements ride the rewrite, since these are exactly the signatures being rewritten:

  • Chain ids are typed as alloy_chains::Chain end to end: the seam traits, both pools, the event loop, the supervisor, and the engine.toml chains map keys (HashMap<Chain, ChainConfig>; numeric TOML keys stay canonical and named keys such as [chains.sepolia] now also parse; no existing config file changes). Every metric label, structured log field, and the persisted last_dispatched_block key keeps the numeric id, pinned by a new test, so observable identifiers and stored data are unchanged.
  • The CoW passthrough method is typed as http::Method, with the four-method allowlist and its error text preserved and the guest string uppercased before parsing at the WIT glue.
  • HttpClient::fetch speaks http::Request<Vec<u8>> / http::Response<Vec<u8>> with an explicit timeout, keeping the seam free of bindgen types; conversion lives in the glue and the stub's guest-visible message is byte-identical.

Why

The concrete pools were baked into HostState, so backends could not be swapped or faked and every host impl was welded to production types. This is the structural step that lets the following change collapse the runtime's shape into a single associated-type lattice parameter, and it was the one moment the chain-id, method, and HTTP typing could land without touching the same ten impl blocks twice.

Closes #87. Closes #101. Closes #102. Closes #104.

Testing

Executed in five ordered slices, each passing the full workspace gate (fmt, clippy with -D warnings, rustdoc with -D warnings, tests) before the next began. New tests: named-key and invalid-key config parsing, and the progress-marker key format pin for a named chain. Final audits confirm no BTreeMap<u64, _> remains, no Chain reaches a metric label, log field, or persisted key through its Display form, and the WIT boundary still speaks plain u64.

AI Assistance: Claude Code used for implementation, adversarial review, and PR preparation.

Base automatically changed from refactor/host-wasi-randomness to develop July 2, 2026 12:15
HostState, every WIT Host impl, the supervisor, and the event loop
are now generic over the component seam traits, with the concrete
pools wired in bootstrap. Chain ids are typed as alloy_chains::Chain
end to end including the engine config map keys, the CoW passthrough
method is typed as http::Method, and HttpClient::fetch speaks
http::Request/Response. Store and linker construction are deduplicated
behind build_store and build_linker.
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.

1 participant