feat(protocol): switch L2 fee controller to p-controller#21350
feat(protocol): switch L2 fee controller to p-controller#21350linoscope wants to merge 2 commits intol2_fee_vaultfrom
Conversation
|
Claude finished @linoscope's task in 4m 57s —— View job Code Review
Overall: Clean, correct implementation. The P-controller is a real improvement over the EIP-1559 controller — stateless, no signed integer arithmetic, immediate response to current conditions. A few things to address below. Issues1.
Fix: either emit 2. Formula "dead zone" when The formula is Consider documenting this, or using 3. No validation that
Missing Test Coverage (
|
Overview
This PR builds on top of @ggonzalez94 's #21214 by switching the fee update logic from an EIP-1559-style multiplicative step to a proportional (P) controller.
New fee is calculated as follows:
effectiveBalance = max(0, balance - totalLiabilities)epsilon = max(0, (targetBalanceWei - effectiveBalance) / targetBalanceWei)pTerm = Kp * epsilon * (maxFeePerGasWei - minFeePerGasWei)newFee = clamp(pTerm, minFeePerGasWei, maxFeePerGasWei)This means fee reacts directly to the current deficit: when the vault is at/above target, the proportional term is zero and the final fee is bounded by min/max; when deficit grows, fee scales proportionally up to max.
Reasoning to take this approach v.s. EIP-1559 is given in the next section. A more comprehensive comparison with other approaches (e.g., PI-controller, P-controller with feed forward) will be shared separately soon.
EIP-1559-style v.s. P-Controller
The two charts below are the simulated fee and vault values based on last year's base/blob fee history.
Here is the simulator UI: Link
Some insights:
This is because:
fee_next = fee_now * (1 + error/denominator) where error = (targetVault - vault)/targetVault), so when it ramps up during a deficit it has resistance to changing quickly and can stay high even after conditions improve, which creates undershoot/overshoot in both fee and vault.fee = Kp * deficit), so the fee reacts quicker to decific increases, and once the deficit shrinks, the fee shrinks immediately too.