Repository navigation
feat(platform)!: let the contract owner pay the gas of token-paid document actions - #4826
Merged
QuantumExplorer merged 5 commits intoSep 19, 2026
Merged
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Issue being fixed or feature implemented
A document type's token cost has carried
gasFeesPaidBy(0DocumentOwner, 1ContractOwner, 2PreferContractOwner) since 2.0, and every transition's$tokenPaymentInfocarries the same field, but nothing in the state machine ever read them: the action transformer copied the transition's value onto the action, no production code read it afterwards, and the execution event always debited the signer. So an app could not offer "post for free with the token we gave you", which is what the Yappr free-usage design needs (the optional token cost that lets a user fall back to paying credits comes in a follow-up PR).This PR makes the field do what it says, from protocol version 14 (unreleased, so the current v14 modules are extended in place).
What was done?
Semantics (
GasFeesPaidBy::resolve(offered_by_contract, requested)in rs-dpp): the document owner can always opt out, a preference is accepted by every offer (a document type that offers nothing just leaves the user paying), and an insistence (ContractOwner) is honoured only by a document type that commits to paying. Only a token-paid action can be sponsored, so every sponsored transition is backed by a token the contract owner chose to hand out.PreferContractOwneron the contract side means "I pay when I can, but I refuse to be the reason a transition fails", so it rejects an insisting user.Pipeline:
BatchTransitionAction::resolve_gas_payer()names one payer for the whole batch (mixed or two-sponsor batches are refused; latent under the current cap of one transition per batch);ResolvedGasSponsorholds the sponsor's balance.GasFeesPaidByNotAllowedError, 40129) or a batch naming two payers (InconsistentGasFeesPaidByInBatchError, 40130), as paid rejections.Paidexecution event carriesgas_sponsor.validate_fees_of_eventv1 judges the fee against the sponsor's balance while the signer only fundsremoved_balance; a sponsor that falls short refuses an insisting batch unpaid (GasSponsorInsufficientBalanceError, 40222) and hands a preferring batch back to the signer's balance.execute_eventv1 charges whoever was admitted, on the same estimate, and deducts nothing of a sponsored fee from a budgeted signing key.identity_minimum_balance_pre_check, PV14 tables) asks a batch that requests sponsorship for its principal only, so an identity with zero credits gets through check tx on tokens it was given.relies_on_gas_sponsor_to_pay), on the first check and on every recheck, as it already does for masternode votes, so a transition nobody could be charged for never reaches a proposer, and leaves the mempool once the tokens it counted on are spent (mempool policy, no consensus rule). What remains is the race every balance check has: two transitions admitted against the same committed state that spend the same tokens in one block.Known property: storage refunds still go to the document's owner, so a sponsored document refunds its owner when it is deleted or replaced by a smaller one. Each token the sponsor hands out is worth up to the storage fee of the largest document the type allows, so a sponsored document type should bound its documents' size. Documented in the book.
Docs:
book/src/fees/overview.md(new subsection), the v14 version doc, the meta-schema description ofgasFeesPaidBy, and the enum and field docs. wasm-dpp maps the three new errors; wasm-dpp2 is code-based and needs nothing.How Has This Been Tested?
All run locally on this branch (macOS,
cargo testdebug profile):cargo test -p dpp --lib -- gas_fees_paid_by state_error_discriminants: 10 passed (the resolve table; the frozenStateErrordiscriminants now pin 111 to 113, after the once-per-identity distribution error of feat(platform)!: once-per-identity token distribution #4827).cargo test -p drive --lib -- state_transition_action::batch: 662 passed, 5 new: the resolver on an empty and an unsponsored batch, the strictness the batch asked for, a refused insistence (40129), a batch naming two payers (40130), a nonce bump that names no payer of its own.cargo test -p drive-abci --lib -- gas_sponsorship: 15 new end-to-end tests passed, each asserting credits and gold balances of both identities:FirstTimeCheck), while the unsponsored one from the same user is refused by the pre-check;DocumentOwnerandPreferContractOwneroffers) is a paid rejection (40129) that the user pays for, no token moves;CheckTx,RecheckTx) and asks the batch transformer for state validation explicitly, since the mode names where validation runs, not how deep it goes;cargo test -p drive-abci --lib -- batch::tests check_tx validate_fees_of_event execute_event execution_event identity_balance masternode_vote: 600 passed, 9 ignored (key limits, token-paid creation, contract-bound keys, fee validation and execution suites unchanged).cargo clippy -p dpp -p drive -p drive-abci -p platform-version --all-features --all-targets -- -D warnings: clean.cargo check -p wasm-dpp: clean.cargo fmtapplied.Breaking Changes
Consensus: from protocol version 14 a token-paid document action can be charged to the contract owner, a request the document type does not offer is rejected, and the batch pre-check admits an unfunded signer whose batch asks for sponsorship. Wire format unchanged.
The field has been accepted since 2.0, so a contract already on chain whose token cost says
gasFeesPaidBy: 1or2starts paying for the transitions that ask for it when protocol version 14 activates.Checklist:
For repository code-owners and collaborators only
🤖 Generated with Claude Code
Summary by CodeRabbit