Repository navigation
perf(generate): refresh gas weights without pausing generation - #357
Conversation
| if gas_refresh.as_ref().is_some_and(|refresh| refresh.is_finished()) { | ||
| let refresh = gas_refresh.take().expect("finished refresh exists"); | ||
| // A failed refresh keeps the weights in use; only the first sample must succeed. | ||
| match runtime.block_on(refresh).wrap_err("gas sampling task failed").and_then(|r| r) { | ||
| Ok(estimates) => selector.set_sampled_gas_estimates(&estimates)?, | ||
| Err(error) => eprintln!("gas sampling refresh failed; keeping weights: {error:#}"), | ||
| } |
There was a problem hiding this comment.
🟡 (optional) Operators now get generation that keeps running when a later gas sample shows a mix item reverting or the RPC failing. The base aborted in that case, and the PR description says it still does. The Err(error) => eprintln!(...) arm at generate.rs:1765 drops every refresh error, including simulation_gas's "gas sample call {index} failed" revert check. Fix: either propagate refresh errors as the base did, or keep the log-and-continue path for transport/RPC errors only and still abort on a failed or reverting sample call. If you keep the current behaviour, correct the PR description.
Why this was flagged
Trigger: generate runs with --gas-weighted-mix and a gas sampling RPC. After the first sample, a workload item starts reverting, for example because a sender's token balance or allowance runs out, or the sampling RPC goes away. simulate_gas_samples returns an Err, either from simulation_gas ("gas sample call {index} failed", generate.rs:2272) or from the request. The loop at generate.rs:1763-1766 logs it with eprintln! and carries on with stale weights. It retries every GAS_SAMPLE_INTERVAL and fails the same way each time, so the run finishes and writes a workload of transactions that revert on chain. On the base, refresh_gas_estimates(...)? inside the loop returned the error and stopped generation, which acted as a periodic liveness check on the workload. The PR description says "A failed refresh still aborts generation". The code comment at 1762 says the opposite, so the description and the code disagree.
Verification: Trigger: a run with --gas-weighted-mix and a gas sampling RPC, where a later refresh fails after the first sample succeeded. In the base, refresh_gas_estimates(...)? was called inside the loop, so any refresh error ended generate_txs with an error. Every refresh error is swallowed at generate.rs:1763-1766, revert-status failures included.
| if let Some(client) = &gas_client && | ||
| gas_refresh.is_none() && | ||
| last_gas_sample.elapsed() >= gas_sample_interval | ||
| { | ||
| refresh_gas_estimates(adapter, spec, setup_bindings, ctx, &mut selector, provider)?; | ||
| let samples = gas_samples(adapter, spec, setup_bindings, ctx, &selector)?; | ||
| gas_refresh = Some(runtime.spawn(simulate_gas_samples(client.clone(), samples))); | ||
| last_gas_sample = Instant::now(); |
There was a problem hiding this comment.
🟡 (optional) Operators benchmarking a node with --gas-weighted-mix now get near-continuous eth_simulateV1 traffic to that node. The base left about 10 s idle between refreshes. last_gas_sample is reset when a refresh is spawned, not when it finishes. So a refresh lasting close to gas_sample_interval is followed at once by the next. Fix: measure the interval from the moment the refresh result is collected, by setting last_gas_sample = Instant::now() where the finished handle is taken at 1761. Keep the first-sample reset at 1743.
Why this was flagged
generate runs with --gas-weighted-mix. gas_sample_rpc is args.rpc (generate.rs:162), the node under benchmark. Each refresh sends one eth_simulateV1 per mix item in sequence (simulate_gas_samples), which the PR puts at about 8.5 s for 27 items. At generate.rs:1773-1774 the refresh is spawned and last_gas_sample is reset straight away. The next refresh is gated only by gas_refresh.is_none() and elapsed() >= gas_sample_interval (1769-1770), so it starts 10 s after the previous one started. With D = 8.5 s the duty cycle is 85%. On the base, last_gas_sample = Instant::now() ran after the blocking refresh_gas_estimates returned, giving at least 10 s without simulate load (duty D/(D+10), about 46%). No cap or backoff bounds how often refreshes are sent, so the node under benchmark serves extra simulation load that skews its measurements.
Verification: In HEAD, line 1773 spawns simulate_gas_samples and line 1774 resets last_gas_sample = Instant::now() straight away, so the interval now runs from start to start. With 8.5 s refreshes, the duty cycle of eth_simulateV1 traffic rises from about 8.5/18.5 (46%) to about 8.5/10 (85%), and to 100% if a refresh takes 10 s or more. The target is args.rpc (line 162), the node under benchmark.
With
--gas-weighted-mix,generatere-sampled gas every 10 s by sending one blockingeth_simulateV1per mix item, one after another, inside the generation loop. With a 27-item mix, each refresh took about 8.5 s, sobench sendhad nothing to send for most of every 10 s. tempo bench-e2e run 41826454576 hit 622 TPS in bursts but averaged 324.The first sample still blocks, so the mix is set before any workload is emitted. Later refreshes build their calls on the loop, which is cheap, then run the RPCs on the tokio runtime. Their weights apply once every call has returned, matched by item, because the selector may prune entries in the meantime. A failed refresh still aborts generation.