Commit 60cdb0b
Zachary Whitley
feat(per-actor): PerActorTvmHost wrapper for per-store budget enforcement
Adds a per-store budget wrapper around `SharedTvmHost` so embedders can
host *untrusted* actors on a shared substrate without one being able to
exhaust the directory for the others. Designed and requested by the
girder runtime — its E1 (host-side enforcement for untrusted tvm
actors) was previously blocked on a tvm-wasm hook; this commit is that
hook.
- `PerActorTvmHost { inner: SharedTvmHost, budget, state }`: per-store
outstanding-bytes accounting + overrun flag. `inner` is a regular
`SharedTvmHost` clone — two `PerActorTvmHost` instances built from
`shared.clone()` see the same regions but track budgets independently.
- `TvmBudget::{unlimited, outstanding_bytes(u64)}`: 0 = unlimited (the
fast path delegates with no accounting overhead — drop-in replacement
for `SharedTvmHost` at zero perf cost when unused).
- All four host traits (`types::Host`, `manager::Host`, `bytes::Host`,
`diagnostics::Host`) implemented:
* `alloc`: budget-check → delegate → record (handle→size in a private
HashMap keyed by `(region_id, generation, offset)`).
* `dealloc`: delegate → release the recorded size.
* Everything else: pure delegation to the inner `SharedTvmHost`.
- Overrun surfaces as `TvmError::AllocationFailed` (existing variant) +
a host-side `budget_overrun()` flag the embedder polls. No WIT change;
guests see identical behaviour to substrate-wide exhaustion. The
embedder reclassifies fatal-vs-graceful: substrate-wide exhaustion is
still graceful (a restart can't free shared bytes); per-actor overrun
is fatal-and-restartable (the new incarnation releases this actor's
regions, so a restart actually remediates).
- `add_per_actor_to_linker<T: AsMut<PerActorTvmHost>>` mirrors
`add_shared_to_linker` for the per-store wrapper.
- 5 unit tests in `per_actor::tests` cover: unlimited fast-path,
budget-deny + overrun flag, dealloc-releases, reset_overrun, and the
headline two-actors-share-substrate-independent-budgets case.
Pre-existing clippy warnings in `tvm-core` (introduced by recent Rust
1.96 lints) are *not* addressed here — out of scope, untouched files.
Existing tvm-wasm test suite stays fully green (87 tests across 20
binaries).1 parent fb33d3b commit 60cdb0b
3 files changed
Lines changed: 429 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
50 | 51 | | |
51 | 52 | | |
52 | 53 | | |
| |||
61 | 62 | | |
62 | 63 | | |
63 | 64 | | |
64 | | - | |
| 65 | + | |
| 66 | + | |
65 | 67 | | |
66 | 68 | | |
| 69 | + | |
67 | 70 | | |
68 | 71 | | |
69 | 72 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
45 | 61 | | |
46 | 62 | | |
47 | 63 | | |
| |||
0 commit comments