-
Notifications
You must be signed in to change notification settings - Fork 1
runtime: multi-module supervisor + block/log event loop #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
brunota20
wants to merge
13
commits into
nullislabs:main
Choose a base branch
from
bleu:feat/supervisor-event-loop
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2054584
chore(deps): pull cowprotocol, alloy, redb, reqwest, tracing
brunota20 f85d3d3
runtime: implement cow-api, chain, local-store host backends
brunota20 6f669c6
runtime: multi-module supervisor + block/log event loop
brunota20 ed48319
feat(supervisor): apply ADR-0001/0003/0005/0016 and trap-based module…
brunota20 1570036
feat(supervisor): add fuel + memory limits per module store (BLEU-818)
brunota20 32a2198
docs: rename nexum.toml -> module.toml in example, justfile, and READ…
brunota20 38ac8e3
test: fill host backend test gaps — manifest parsing, cow-api, provid…
brunota20 fdd64e4
test: E2E supervisor tests + fix wit_import_to_cap to skip type-only …
brunota20 7131282
style: apply rust-idiomatic rules (em-dashes, #[from] Orderbook, unus…
brunota20 0679580
review: apply lgahdl feedback on PR #9 (+ rebase PR #8 fixes)
brunota20 9a97ba9
refactor(manifest): split into types/load/capabilities/error submodules
brunota20 5ae6368
refactor(main): extract host impls + CLI + event loop + limits
brunota20 794091a
refactor: move large #[cfg(test)] modules to sibling files
brunota20 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,3 +21,4 @@ Thumbs.db | |
| # Environment | ||
| .env | ||
| .env.* | ||
| data/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| //! WIT bindings generated by `wasmtime::component::bindgen!`. | ||
| //! | ||
| //! Both `wit/nexum-host` and `wit/shepherd-cow` packages are listed | ||
| //! explicitly so wit-parser can resolve the cross-package reference | ||
| //! natively - no vendored `deps/` tree needed. The world name is fully | ||
| //! qualified. | ||
| //! | ||
| //! Every `Host` trait impl in [`crate::host::impls`] consumes types | ||
| //! generated here. | ||
|
|
||
| wasmtime::component::bindgen!({ | ||
| path: ["../../wit/nexum-host", "../../wit/shepherd-cow"], | ||
| world: "shepherd:cow/shepherd", | ||
| imports: { default: async }, | ||
| exports: { default: async }, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| //! Manual CLI parser. Kept hand-rolled (instead of pulling clap) because | ||
| //! the surface is small and unlikely to grow in 0.2. | ||
|
|
||
| use std::path::PathBuf; | ||
|
|
||
| /// Parsed CLI surface. | ||
| /// | ||
| /// `nexum-engine [<wasm-path> [<manifest-path>]] [--engine-config <path>]` | ||
| /// | ||
| /// Positional `<wasm-path>` is a backwards-compat shortcut that | ||
| /// synthesises a one-module engine config. Production deployments pass | ||
| /// `--engine-config` and declare modules in TOML. | ||
| #[derive(Debug, Default)] | ||
| pub struct Cli { | ||
| pub wasm: Option<PathBuf>, | ||
| pub manifest: Option<PathBuf>, | ||
| pub engine_config: Option<PathBuf>, | ||
| } | ||
|
|
||
| impl Cli { | ||
| pub fn parse() -> Self { | ||
| let mut args = std::env::args().skip(1); | ||
| let mut cli = Self::default(); | ||
| let mut positional = Vec::new(); | ||
| while let Some(arg) = args.next() { | ||
| match arg.as_str() { | ||
| "--engine-config" => cli.engine_config = args.next().map(PathBuf::from), | ||
| "-h" | "--help" => { | ||
| eprintln!( | ||
| "usage: nexum-engine [<wasm-path> [<manifest-path>]] \ | ||
| [--engine-config <path>]" | ||
| ); | ||
| std::process::exit(0); | ||
| } | ||
| _ => positional.push(arg), | ||
| } | ||
| } | ||
| if let Some(p) = positional.first() { | ||
| cli.wasm = Some(PathBuf::from(p)); | ||
| } | ||
| if let Some(p) = positional.get(1) { | ||
| cli.manifest = Some(PathBuf::from(p)); | ||
| } | ||
| cli | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| //! Engine-side runtime configuration. | ||
| //! | ||
| //! Distinct from `module.toml` (module manifest): this file describes | ||
| //! the *engine*'s I/O wiring - chain RPC endpoints and the on-disk | ||
| //! location of the `local-store` database. Both are required for the | ||
| //! 0.2 reference engine to do anything other than print stubs. | ||
| //! | ||
| //! Lookup order: | ||
| //! | ||
| //! 1. `--engine-config <path>` CLI flag (future), or third positional | ||
| //! argument today; | ||
| //! 2. `engine.toml` in the current working directory; | ||
| //! 3. defaults - no chains configured, `state_dir = ./data`. | ||
| //! | ||
| //! A missing config is OK for the example module (it only logs); for | ||
| //! the cow-api / chain backends it surfaces as `HostError { | ||
| //! kind: unsupported }` so guests learn early. | ||
|
|
||
| use std::collections::BTreeMap; | ||
| use std::path::{Path, PathBuf}; | ||
|
|
||
| use serde::Deserialize; | ||
| use tracing::{info, warn}; | ||
|
|
||
| /// Engine-side configuration loaded from `engine.toml`. | ||
| #[derive(Debug, Default, Deserialize)] | ||
| pub struct EngineConfig { | ||
| #[serde(default)] | ||
| pub engine: EngineSection, | ||
| /// Per-chain RPC URLs keyed by EVM chain id (decimal in TOML). | ||
| /// Used by the `chain::request` host call and as the alloy provider | ||
| /// pool seed. | ||
| #[serde(default)] | ||
| pub chains: BTreeMap<u64, ChainConfig>, | ||
| /// Modules the supervisor should boot. Each entry resolves a | ||
| /// `(component.wasm, module.toml)` pair on the local filesystem | ||
| /// for 0.2 - content-addressed resolution (Swarm / OCI / | ||
| /// `[[content.sources]]`) lands in 0.3 per | ||
| /// `docs/03-module-discovery.md`. | ||
| #[serde(default)] | ||
| pub modules: Vec<ModuleEntry>, | ||
| } | ||
|
|
||
| /// One `[[modules]]` table from `engine.toml`. | ||
| /// | ||
| /// Both fields are filesystem paths in 0.2. `manifest` defaults to | ||
| /// `module.toml` next to `path` if omitted, matching the bundle layout | ||
| /// in `docs/02-modules-events-packaging.md`. | ||
| #[derive(Debug, Deserialize)] | ||
| pub struct ModuleEntry { | ||
| /// Path to the compiled `.wasm` component. | ||
| pub path: std::path::PathBuf, | ||
| /// Path to the module's `module.toml`. Defaults to `<path-parent>/module.toml`. | ||
| #[serde(default)] | ||
| pub manifest: Option<std::path::PathBuf>, | ||
| } | ||
|
|
||
| #[derive(Debug, Deserialize)] | ||
| pub struct EngineSection { | ||
| #[serde(default = "default_state_dir")] | ||
| pub state_dir: PathBuf, | ||
| /// `tracing_subscriber::EnvFilter`-compatible directive. Defaults to | ||
| /// `info` when absent; `RUST_LOG` overrides at process start. | ||
| #[serde(default = "default_log_level")] | ||
| pub log_level: String, | ||
| } | ||
|
|
||
| impl Default for EngineSection { | ||
| fn default() -> Self { | ||
| Self { | ||
| state_dir: default_state_dir(), | ||
| log_level: default_log_level(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[derive(Debug, Deserialize)] | ||
| pub struct ChainConfig { | ||
| /// JSON-RPC endpoint. `ws://` and `wss://` engage alloy's pubsub | ||
| /// transport (required for `eth_subscribe`); `http://` and `https://` | ||
| /// engage the HTTP transport (request/response only). | ||
| pub rpc_url: String, | ||
| } | ||
|
|
||
| fn default_state_dir() -> PathBuf { | ||
| PathBuf::from("./data") | ||
| } | ||
|
|
||
| fn default_log_level() -> String { | ||
| "info".to_owned() | ||
| } | ||
|
|
||
| /// Read an engine config from disk, returning defaults if the file is | ||
| /// missing. Parse errors propagate. | ||
| pub fn load_or_default(path: Option<&Path>) -> anyhow::Result<EngineConfig> { | ||
| let path = match path { | ||
| Some(p) => p.to_path_buf(), | ||
| None => PathBuf::from("engine.toml"), | ||
| }; | ||
|
|
||
| if !path.exists() { | ||
| warn!( | ||
| path = %path.display(), | ||
| "engine.toml not found - running with defaults (no chain RPC endpoints; \ | ||
| chain::request and cow_api::submit_order will return Unsupported)" | ||
| ); | ||
| return Ok(EngineConfig::default()); | ||
| } | ||
|
|
||
| let raw = std::fs::read_to_string(&path)?; | ||
| let cfg: EngineConfig = toml::from_str(&raw)?; | ||
| info!( | ||
| path = %path.display(), | ||
| chains = cfg.chains.len(), | ||
| state_dir = %cfg.engine.state_dir.display(), | ||
| "engine config loaded", | ||
| ); | ||
| Ok(cfg) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idiomatic method to handle CLI in rust is to use
clap.