feat: add engine‑managed tipset gas reservations to ref‑fvm #2236
+1,763
−26
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
feat: add engine‑managed tipset gas reservations to ref‑fvm
This PR implements engine‑managed tipset‑scope gas reservations inside ref‑fvm, as described in a pending FIP proposal.
Summary
ActorID.begin_reservation_session/end_reservation_sessionwith affordability checks and invariants.balance − reserved_remaining.Changes
Executor: session lifecycle and preflight
fvm/src/executor/mod.rsReservationSessionstruct (re‑exported fromdefault.rs) andReservationErrorenum:NotImplementedInsufficientFundsAtBegin { sender }SessionOpenSessionClosedNonZeroRemainderPlanTooLargeOverflowReservationInvariant(String)fvm/src/executor/default.rsReservationSession { reservations: HashMap<ActorID, TokenAmount>, open: bool }and anArc<Mutex<_>>onDefaultExecutor.begin_reservation_session(&mut self, plan: &[(Address, TokenAmount)]) -> Result<(), ReservationError>:MAX_SENDERS(65,536) and track plan failures via telemetry.ActorID).reserved_total <= balanceper sender.end_reservation_session(&mut self) -> Result<(), ReservationError>:open == trueand all reservation entries to be zero.gas_cost = gas_fee_cap * gas_limitusing big‑int; treat negative results asReservationError::Overflow.reservation_assert_coverage(sender, &gas_cost); do not pre‑deduct funds.reservation_prevalidation_decrementso the ledger can end at zero.Transfer enforcement and settlement
fvm/src/call_manager/default.rs&fvm/src/call_manager/mod.rsArc<Mutex<ReservationSession>>into the default call manager.transfer(from, to, value):reserved_remaining = reservations.get(from).unwrap_or(0).value + reserved_remaining <= from.balance; otherwise returnInsufficientFunds.value <= balancesemantics.fvm/src/executor/default.rsfinish_message) in reservation mode:GasOutputsas today.consumption = base_fee_burn + over_estimation_burn + miner_tip.consumptionfrom the sender’s actor balance.refundto the sender; the “refund effect” is realized by releasing the reservation ledger.reservations[sender]bygas_costusingreservation_prevalidation_decrement, update telemetry, and remove entries at zero.base_fee_burn + over_estimation_burn + refund + miner_tip == gas_cost.Telemetry
fvm/src/executor/telemetry.rsReservationTelemetryand helpers:reservations_openreservation_begin_failedsettle_basefee_burnsettle_tip_creditsettle_overburnsettle_refund_virtualsnapshot()(for potential host export) andreset()under#[cfg(test)].Kernel and test harness adjustments
fvm/src/kernel/default.rsCallManagertype where necessary so that all value‑moving operations (SendOps, SELFDESTRUCT, etc.) route through the reservation‑awaretransfer.fvm/tests/dummy.rsCallManagerimpl to accept the newReservationSessionargument inCallManager::new, keeping tests compiling against the updated trait.Tests
Unit tests in
fvm/src/executor/default.rs:ReservationError::Overflow.transfer, send to existing actors, SELFDESTRUCT, and implicit sends must respect free balance.consumption.end_reservation_sessionsucceeds.--features arb) continues to assert:base_fee_burn + over_estimation_burn + refund + miner_tip == gas_cost.Integration tests:
testing/integration/tests/reservation_transfer_enforcement.rs:value > free = balance − reserved_remaining.Activation and host behaviour
begin_reservation_session/end_reservation_session.ReservationErrorvariants (legacy fallback, tipset invalid, node error) based on network version and feature flags.Notes
ExitCode,GasUsed, events) andGasOutputsrelative to pre‑reservation behaviour, while removing miner exposure to intra‑tipset underfunded messages when hosts enable reservations.