-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat(consensus): tipset gas reservations and reservation‑aware mpool pre‑pack #13427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
834afe0 to
ed000a4
Compare
# Conflicts: # CHANGELOG.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR implements tipset-scoped gas reservations that will activate at network version 28, preventing miner penalties from underfunded messages while maintaining identical receipts and gas accounting. The implementation includes optional reservation-aware mempool pre-pack simulation.
Key changes:
- Adds engine-managed gas reservation orchestration with Begin/End calls around explicit tipset messages
- Implements strict sender partitioning to prevent valid individual blocks from forming invalid tipsets due to aggregate over-reservation
- Provides optional mempool pre-pack simulation to avoid constructing blocks that would fail reservation checks
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| chain/consensus/features.go | Feature flag system for pre-activation reservation behavior control |
| chain/consensus/reservations.go | Core reservation logic including plan building and error handling |
| chain/consensus/compute_state.go | Integration of Begin/End reservation calls around explicit message execution |
| chain/vm/fvm.go | FVM reservation session implementation with CBOR plan encoding |
| chain/vm/vmi.go, vm.go, execution.go | VM interface extensions for reservation support |
| chain/messagepool/selection.go | Reservation-aware pre-pack simulation using sender balance checks |
| metrics/metrics.go | Observability metrics for reservation plan tracking |
| documentation/en/tipset-reservations.md | Operator documentation for activation and monitoring |
| CHANGELOG.md | Release notes entry |
| Test files | Comprehensive test coverage for reservation logic |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| seenSenders[s] = struct{}{} | ||
| } | ||
|
|
||
| params := &reward.AwardBlockRewardParams{Miner: b.Miner, |
Copilot
AI
Dec 9, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The struct initialization formatting is inconsistent. The opening brace should be on the same line as the field list, or all fields should be on separate lines with proper indentation.
| params := &reward.AwardBlockRewardParams{Miner: b.Miner, | |
| params := &reward.AwardBlockRewardParams{ | |
| Miner: b.Miner, |
feat(consensus): tipset gas reservations and reservation‑aware mpool pre‑pack
This PR wires Lotus into the engine‑managed tipset gas reservation design described in a pending FIP proposal, and adds an optional reservation‑aware mempool pre‑pack pass. The goal is to eliminate miner‑charged underfunded messages in a tipset while preserving receipts and gas outputs.
Summary
Σ(gas_limit * gas_fee_cap)), deduped by CID across blocks.This branch assumes matching
multistage-executionbranches inref-fvm(engine reservations) andfilecoin-ffi(Begin/End FFI) are present.Changes
Consensus and activation
chain/consensus/features.goReservationFeatureFlagswith:MultiStageReservations(best‑effort pre‑activation enablement).MultiStageReservationsStrict(pre‑activation behaviour: legacy fallback vs tipset‑invalidating).Featureglobals with env‑based defaults:LOTUS_ENABLE_TIPSET_RESERVATIONSLOTUS_ENABLE_TIPSET_RESERVATIONS_STRICTchain/consensus/reservations.goReservationsEnabled(nv):nv >= ReservationsActivationNetworkVersion()→ always true (reservations required).Feature.MultiStageReservations.buildReservationPlan(bms []FilecoinBlockMessages) map[address.Address]abi.TokenAmount:gas_limit * gas_fee_capper sender.startReservations/endReservations:vmi.StartTipsetReservations/EndTipsetReservationswhen enabled.metrics.ReservationPlanSendersandmetrics.ReservationPlanTotal.handleReservationErrorto decide, pre‑activation:ErrReservationsNotImplemented.ErrReservationsInsufficientFunds/ErrReservationsPlanTooLarge:ErrReservationsNotImplementedbecomes a node error.chain/consensus/compute_state.gostartReservations(ctx, vmi, bms, nv)(before applying any explicit messages).deferedendReservations(ctx, vmi, nv)plus an explicitendReservationscall before cron to scope reservations to explicit messages only.VM interface and FVM wiring
chain/vm/vmi.go&chain/vm/execution.govm.Interfacewith:StartTipsetReservations(ctx context.Context, plan map[address.Address]abi.TokenAmount) errorEndTipsetReservations(ctx context.Context) errorvmExecutor.StartTipsetReservations/EndTipsetReservationsby:ApplyMessage/ApplyImplicitMessage).chain/vm/fvm.gofilecoin-ffiand define:ReservationsActivationNetworkVersion()(currentlynetwork.Version28).func (vm *FVM) BeginReservations(plan []byte) errorfunc (vm *FVM) EndReservations() errorfunc (vm *FVM) StartTipsetReservations(ctx context.Context, plan map[address.Address]abi.TokenAmount) errorfunc (vm *FVM) EndTipsetReservations(ctx context.Context) error[[address_bytes, amount_bytes], ...].ffi.FVM.BeginReservations/ffi.FVM.EndReservations, which return typed errors potentially wrapped with short engine‑provided messages from ref‑fvm.reservationsActiveto avoid calling End when no Begin occurred (empty plan or legacy fallback).ErrReservationsNotImplementedas a benign signal and fall back to legacy mode.handleReservationError.ErrReservationsNotImplementedas a node error (engine too old).chain/vm/vm.goStartTipsetReservations/EndTipsetReservationsonLegacyVMto satisfy the interface; reservations are only supported in FVM mode.chain/vm/fvm_reservations_test.goreservationStatusToErrormapping from raw status codes to typed errors.Mempool reservation‑aware pre‑pack (optional)
chain/types/mpool.go&chain/messagepool/config.goEnableReservationPrePacktoMpoolConfig, defaultfalse.chain/messagepool/selection.goselectedMessageswith:reservationEnabled,reservationCtx,reservationTipset.reservedBySender(Σ(cap×limit)per sender for selected messages).balanceBySender(sender balances at the selection base tipset).reservationsPrePackEnabled() bool:EnableReservationPrePackandconsensus.ReservationsEnabled(nextNv).initReservations(ctx, ts, mp)to initialize tracking maps when enabled.reserveForMessages(sender, msgs)to:mp.api.StateGetActor/GetActorAfterand cache it.reserveForMessagesfromtryToAdd/tryToAddWithDepsto:chain/messagepool/selection_test.goTestReservationPrePackPrunesOverCommittedChain:TestReservationPrePackAccumulatesCapTimesLimit:Metrics and docs
metrics/metrics.goReservationPlanSenders(vm/reservations_plan_senders) – number of unique senders in the plan.ReservationPlanTotal(vm/reservations_plan_total_atto) – total reserved Σ(cap×limit) in attoFIL.documentation/en/tipset-reservations.mdnetwork.Version28/UpgradeXxHeight.CHANGELOG.mdActivation & gating
Feature.MultiStageReservations= false → legacy mode (no Begin/End, no pre‑pack).Feature.MultiStageReservations= true,MultiStageReservationsStrict= false:Feature.MultiStageReservations= true,MultiStageReservationsStrict= true:ErrReservationsNotImplemented, which still triggers legacy fallback.ReservationsEnabledalways true.ErrReservationsNotImplementedis treated as a node error (engine too old).Testing
chain/consensus/reservations_test.go– plan build, env/feature gating, error handling paths.chain/vm/fvm_reservations_test.go– status‑to‑error mapping, CBOR plan encode/decode.chain/messagepool/selection_test.go– reservation pre‑pack heuristics.go testruns (already exercised locally on this branch):go test ./chain/consensus -run TestReservationgo test ./chain/vm -run TestReservationgo test ./chain/messagepool -run TestReservationNotes
ref-fvmmultistage-execution(engine reservation session + enforcement).filecoin-ffimultistage-execution(Begin/End FFI + error messages).ExitCode,GasUsed, events) andGasOutputsremain unchanged; the reservation ledger is internal to the engine.