Skip to content

chore(sdk + twap-monitor): hex helpers via alloy_primitives::hex::encode - #51

Closed
brunota20 wants to merge 1 commit into
fix/twap-calldata-helper-cow-1077from
chore/hex-via-alloy-mfw78-followup
Closed

chore(sdk + twap-monitor): hex helpers via alloy_primitives::hex::encode#51
brunota20 wants to merge 1 commit into
fix/twap-calldata-helper-cow-1077from
chore/hex-via-alloy-mfw78-followup

Conversation

@brunota20

Copy link
Copy Markdown

Summary

mfw78's review of PR #8 flagged: "we already pull alloy, so pulling hex via there is really not much of a deal". PR #47 (COW-1074, commit acc9654) then introduced two new custom hex helpers that recreate the same antipattern at a different scope.

This PR removes both:

File Helper Before After
crates/shepherd-sdk/src/cow/app_data.rs encode_hex(&[u8; 32]) 9-line manual nibble loop with a 0123456789abcdef table format!(\"0x{}\", alloy_primitives::hex::encode(b))
modules/twap-monitor/src/strategy.rs hex_short(&[u8; 32]) 10-line manual nibble loop, same table format!(\"0x{}…\", alloy_primitives::hex::encode(&b[..8]))

Both crates already depend on alloy-primitives (sdk 1.6, twap-monitor 1.5), so this is a pure simplification - no Cargo.toml change. Both helpers keep their signatures so call sites (resolve_app_data in the SDK, every host.log line in twap-monitor strategy) need no changes. Comments on both helpers now explicitly reference mfw78's PR #8 guidance so the next person tempted to hand-roll the table has a hook.

Stack

Stacked on fix/twap-calldata-helper-cow-1077 (PR #50) → feat/ethflow-expected-excessive-validto-cow-1076 (PR #49) → feat/forward-orderbook-error-cow-1075 (PR #48) → feat/resolve-app-data-cow-1074 (PR #47).

Why a separate PR rather than amending #47

PR #47 is already In Review and #48/#49/#50 stack on top. Amending #47 would force-push 4 branches and obscure the reviewer's history. A small follow-up PR keeps each commit bisectable and lets the alloy alignment be reviewed in isolation.

The other surfaces flagged by mfw78 on PRs #8 and #9 are also being addressed:

Validation

  • cargo test -p shepherd-sdk -p twap-monitor: 32 + 23 passed, 0 failed.
  • cargo clippy --all-targets --tests -- -D warnings: clean.
  • cargo fmt --check: clean.
  • Zero em-dash drift in touched files.

AI assistance disclosure: drafted by Claude (Opus 4.7, 1M context) while sweeping all open PRs for the same antipatterns mfw78 flagged on PRs #8 and #9.

mfw78 review of PR #8 (nullislabs#8) flagged "we already pull alloy, so pulling hex via there is really not much of a deal". The PR #47 (COW-1074) commit acc9654 then introduced two new custom hex helpers that recreate the same antipattern at a different scope:

- `crates/shepherd-sdk/src/cow/app_data.rs::encode_hex` - 32-byte hash → `0x...`. Used by `resolve_app_data` to format the orderbook lookup path.
- `modules/twap-monitor/src/strategy.rs::hex_short` - 8-byte prefix → `0x...…`. Used to format `appData` hashes in INFO log lines.

Both crates already depend on `alloy-primitives` (sdk: 1.6, twap-monitor: 1.5), so the swap is a one-liner per call site:

- `encode_hex(b)` → `format!("0x{}", alloy_primitives::hex::encode(b))`
- `hex_short(b)` → `format!("0x{}…", alloy_primitives::hex::encode(&b[..8]))`

Both functions keep their old signature so callers (`resolve_app_data` in the SDK, every `host.log` line in twap-monitor strategy) need no changes.

Comments on both helpers now explicitly reference mfw78's PR #8 guidance so the next person tempted to hand-roll a `0123456789abcdef` table has a hook.

Validation: cargo test -p shepherd-sdk -p twap-monitor: 32 + 23 passed; cargo clippy --all-targets -- -D warnings: clean; cargo fmt --check: clean; zero em-dash drift.

Why this PR sits in a separate branch rather than amending PR #47: PR #47 is already In Review, and #48/#49/#50 stack on top of it. Amending would require force-pushing 4 branches. A small follow-up PR keeps each one bisectable and lets mfw78 review the alloy alignment in isolation.

AI assistance disclosure: drafted by Claude (Opus 4.7, 1M context) while sweeping all open PRs for the same antipatterns mfw78 flagged on PRs #8 and #9.
@brunota20

Copy link
Copy Markdown
Author

Work landed via dev/m4-base creation @ 64cb6d8 (M4 production hardening + PR #66 rust-idiomatic compliance squashed). The HEAD commit of this PR is now an ancestor of dev/m4-base. Closing as merged-by-ancestor.

@brunota20 brunota20 closed this Jun 24, 2026
lgahdl pushed a commit that referenced this pull request Jul 17, 2026
…ing (nullislabs#424)

* feat(runtime): gate the WASI surface behind manifest capabilities

Link only the WASI interfaces a module declares; undeclared sockets,
filesystem, cli and environment are refused at load, including the
0.1 fallback manifest. Refs #51

* feat(runtime): enforce per-module resource limits and local-store quota

Manifest [limits] overrides layer over the engine defaults per module;
the redb local store charges true on-disk bytes per namespace and
rejects over-quota writes. Module store paths are reduced to a single
sanitized path component. Refs #53

* feat(runtime): bound host-call wall time with a per-dispatch deadline

Fuel meters only guest instructions, so a dispatch parked in a blocked
host call is bounded by a wall-clock deadline over the whole on_event.
Refs nullislabs#107

* feat(runtime): rate-limit event dispatch per module

A per-module token bucket, checked before on_event, drops over-rate
events at the dispatch boundary without starving other modules.
Refs nullislabs#244

* feat(runtime): add a graceful-drain tier for durable-state flush on shutdown

Ctrl-C fires a shutdown signal that a durable-flush guard blocks on until
drained or a timeout elapses; redb writes are fsync-durable so a write is
never truncated. Reconnect pumps stay abort-only. Refs nullislabs#266

* fix(runtime): treat wasi:cli/environment as ambient; rustdoc and fmt for CI

Rust std imports wasi:cli/environment on every guest, and the host builds
the guest WasiCtx without inherit_env, so the guest environment is always
empty. Gating it was noise (every module would declare it) and guarded
nothing; the empty-env host isolation is the real boundary. The gate still
covers wasi:sockets and wasi:filesystem. Also drop two private intra-doc
links and apply rustfmt. Refs #51

* docs: tighten rustdoc and comments; remove issue-number citations

Cut the rationale/marketing prose to terse contract lines and drop every
issue-number reference from code comments and rustdoc.

* feat: add nexum-tasks crate and route every runtime spawn through it

Fold ShutdownController and the injectable executor into a dedicated
nexum-tasks crate owning task lifecycle and graceful shutdown:

- TaskManager owns the latched shutdown signal, the drain-guard
  counter, and the critical-task failure channel; dropping it fires
  shutdown, graceful_shutdown_with_timeout drives the bounded drain.
- TaskExecutor (Clone) exposes spawn, spawn_critical (return or panic
  shuts the runtime down), spawn_graceful (holds a GracefulShutdownGuard
  the drain blocks on), and spawn_blocking.
- The launcher constructs the manager, spawns the OS signal listener
  via spawn_critical and the event loop via spawn_graceful, deleting
  RuntimeDropGuard; RuntimeHandle holds the manager, wait() drains and
  also winds down on a critical-task end.
- BuilderContext threads the executor into component builders so the
  local-store open runs on the blocking pool through it.

No raw tokio::spawn/spawn_blocking/std::thread::spawn remains in
nexum-runtime; nexum-tasks is the sole spawning crate.
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