feat(payload): add shared resource metering evaluator - #4673
Conversation
Define one versioned schedule and decision model for both payload builders, including per-dimension dry-run, fail-open arithmetic, and transaction-versus-block scope. Move provider and rejection-cache ownership into the payload crate while preserving builder-core re-exports.
🟡 Heimdall Review Status
|
| /// Independently budgeted resource dimensions. | ||
| pub dimensions: Vec<ResourceMeteringDimension>, | ||
| #[serde(skip)] | ||
| operation_index: HashMap<String, Vec<(usize, u64, u64)>>, |
There was a problem hiding this comment.
nit: operation_index uses HashMap (non-deterministic iteration order). This is fine here since evaluate() only does key lookups (not iteration), but worth noting that the Serialize derive on ResourceMeteringSchedule will skip this field (#[serde(skip)]), so serialization determinism is preserved. If a future change iterates operation_index in a consensus-sensitive path, it should switch to BTreeMap.
| ); | ||
| if decision.should_exclude() { | ||
| self.record_decision(tx_hash, &decision); | ||
| } | ||
| (simulated, decision) |
There was a problem hiding this comment.
Note: predict only records decisions where should_exclude() is true (enforced throttles). Dry-run throttle observations at the prediction stage are silently dropped — the metric/log won't fire until decide_executed runs after execution. This means if a caller uses predict to skip execution entirely (which it can't today since should_exclude() is false for dry-run), the observation would be lost.
This is fine given the current flow where CalculationFailed and dry-run Throttle both proceed to execution, but it's worth documenting explicitly that predict intentionally under-reports dry-run observations, since a future caller might expect the metrics to be recorded here regardless of the exclude decision.
Review SummaryPR: feat(payload): add shared resource metering evaluator This PR introduces a versioned resource-metering schedule and decision model ( Block-Production Safety AssessmentThis PR is block-production-sensitive (touches metering and payload assembly paths). After reviewing against the block production review guide:
No critical block-production findings. Minor Findings
What Looks Good
|
|
Caution This PR may regress performance. 1 benchmark(s) slower by more than 10% beyond the noise band: Benchmark results (advisory)Median time on the PR head versus the base branch, measured on the same host. Wall-clock, so a change is only flagged when it clears ±10% and the confidence intervals do not overlap. Only benchmarks past the ±10% threshold (plus new or dropped ones) are listed. This check never blocks a merge.
46 benchmark(s) within ±10% omitted. |
Summary
dryRun(omitted = enforce), fail-open arithmetic, and transaction-versus-block throttle scope.Stacked replacement for the shared evaluator slice of #4428. Later PRs in this stack add observations, native admission, Flashblocks admission, and wall-clock retirement.
Test plan
cargo test --lib -p base-execution-payload-buildertype=routine
risk=low
impact=sev5