Repository navigation
Description
A client cannot ask a node what a signed state transition would cost, or whether it would be accepted, without broadcasting it and paying for it. We would like a read-only DAPI call that runs a signed transition against the latest committed state and returns the consensus verdict and a fee breakdown, without admitting it to the mempool.
We hit this building Dash Forge, a git forge that runs on Platform.
Expected Behavior
A read-only call, for example simulateStateTransition(state_transition), that takes the same bytes as broadcastStateTransition and returns:
- the verdict: success, or the first consensus error (code and message, encoded as broadcast errors are today);
- the fee it would be charged: storage fee, processing fee, refunds (per identity), and fixed costs such as the contract registration cost or document action fees;
- the admission requirement: what the identity's balance and the signing key's remaining budget must cover for Drive to accept it. Today this differs from the charge (see below).
It would never enter the mempool, never be gossiped, and leave the nonce untouched. It could be rate-limited like any other expensive read.
Cosmos SDK has the same thing in cosmos.tx.v1beta1.Service/Simulate (service.proto). It returns the gas used and the execution result of a transaction without broadcasting it.
Current Behavior
- There is no such call. The Platform service's only write is
broadcastStateTransition, and its response is empty (platform.proto L9-L12, L199-L201). The only fee estimate in the DAPI protos is Core'sgetEstimatedTransactionFee, which is for L1 transactions (core.proto L12). - Most of the machinery already exists, but it is not reachable by clients:
- CheckTx runs fee validation "in dry run (estimated fees)" and keeps the estimated
FeeResult(check_tx/v0/mod.rs L179-L194). The ABCI handler reports only its total, asgas_wanted, to Tenderdash (abci/handler/check_tx.rs L66-L70). - rs-dapi already calls Tenderdash's
check_txRPC, documented as "Check a transaction without adding it to the mempool" (tenderdash_client.rs L484-L490). It uses it only internally, when a broadcast reports a duplicate that is neither in the mempool nor in the chain (broadcast_state_transition.rs L218-L226). - drive-abci has a test-only
execute_txthat runs a transition inside a transaction and returns its execution result (check_tx/v0/mod.rs L42-L85). That is close to the dry run we are asking for, but it is behind#[cfg(test)].
- CheckTx runs fee validation "in dry run (estimated fees)" and keeps the estimated
- The CheckTx figure is an admission estimate, not the charge. Fee validation calls
apply_drive_operationswithapply = false, which "only estimate[s] costs" from estimated layer information (apply_drive_operations/mod.rs L18-L26, validate_fees_of_event/v0/mod.rs L118-L143, v1/mod.rs L229-L241). The v0 code also notesTODO: Should take into account refunds as well. The key-budget requirement is defined in v1/mod.rs L26-L48. So even with CheckTx exposed, the actual charge is only known after execution.
What this costs us in practice:
- What-if questions cost real DASH. To decide whether two optional indexes were worth their per-write cost, we registered six probe contracts on a 5.0.0-beta.1 devnet and measured writes against them. The deployer's balance went from 599,868,517,600 to 494,309,793,700 credits, so the run cost 1.056 DASH; 1.019 DASH of that was the six registrations. The answer was that each index added about 14.4 M credits (+26.7 %) to every write, so we dropped both.
- Admission differs from the charge, and we learn it from refusals. On an earlier 4.2 beta devnet (also protocol 14), Drive refused a 10-byte comment until the signing key had 79,623,000 credits of budget left and the identity had 193,644,600 credits of balance. The same write was charged about 52.2 M. We keep a table of these requirements read from refusal messages (cost.test.ts L143-L148, cost.ts L298-L316).
- Our cost previews drift between betas. They come from hand-measured balance deltas (cost.ts L1-L80). For example, we measured a review at 35.9 M credits on a 4.2.0-beta.5 devnet and at 49.6 M to 49.9 M on a 4.2.0-beta.7 devnet. Some of that change is ours and some is Platform's, and we cannot tell which without measuring again.
Possible Solution
A suggestion; the maintainers will know the right shape better:
- A read-only Platform RPC, for example
simulateStateTransition({ bytes state_transition }), returning{ code, info, fee: { storage_fee, processing_fee, refunds[], fixed_fee }, admission: { required_balance, required_key_budget }, metadata }. - In drive-abci, run the transition as block execution would, at the last committed block info, inside a GroveDB transaction that is always rolled back. Return the verdict, the actual
FeeResult, and the admission figures from fee validation. The test-onlyexecute_txabove already has this shape. - Skip CheckTx's mempool bookkeeping. For example, the first-time check takes a shielded-proof nonce permit (check_tx/v0/mod.rs L200-L222). Bound the work as fix(drive-abci): bound CheckTx verification work #4164 did for CheckTx.
- The result is a quote from one node's state, not a proof. Clients would treat it as such.
A smaller first step would be to expose the existing CheckTx outcome through DAPI as a read-only call: the code, the info, and the estimated FeeResult split into storage, processing and refunds. That alone gives the verdict and the admission side, though not the exact charge.
An optional extension: accept an ordered list of transitions from one identity and run them in one discarded transaction. A contract create followed by writes against it could then be priced without registering anything, which would have covered our index question.
Alternatives Considered
- Broadcast and measure the balance delta (what we do now). It costs real credits, uses up a nonce, and needs real contract registrations for what-if questions.
documentCreateCost(feat(drive): compute what creating a document costs for the SDKs #5159). It runs offline and gives exact storage for a create. Its processing is estimated (exact: false, assuming 1,000 existing documents by default), it covers creates only, and it reports neither a verdict nor the admission requirement. We filed a separate request for more SDK-side cost functions as SDK: cost functions for document replace and delete, contract update, key operations and the admission requirement #5265. Those complement this request but cannot see state.calculate_min_required_fee(feat(platform)!: state transition minimum required balance for fees #2899, which closed Feature Request: Estimate fee method for platform transactions #2807). It is a pre-check floor. For a document batch it is a flat minimum per sub-transition (batch_transition/state_transition_estimated_fee_validation.rs L22-L33), not what a write costs. Storage depends on state, for example whether a write creates new index subtrees, so a full answer needs the node.- Fee receipts after execution (the idea behind the closed draft feat(dapi): return actual fees paid in state transition broadcast responses #2977). Useful and complementary, but they arrive after paying.
Additional Context
- Related: SDK: cost functions for document replace and delete, contract update, key operations and the admission requirement #5265 (SDK cost functions), Feature Request: Estimate fee method for platform transactions #2807 (closed; asked for a fee-estimation RPC), Improve fee estimation API for state transition #3041 (open; unsigned fee estimation for address transitions), CheckTx gas_wanted under-reports the data-contract registration cost (Paid execution event) #3806 (open; the CheckTx fee estimate leaves out the contract registration cost, which a simulation built on that path should fold in), feat(dapi): return actual fees paid in state transition broadcast responses #2977 (closed draft; actual fees in broadcast results).
- Environment: Platform 5.0.0-beta.1 (protocol 14) on a devnet (sakura). Clients:
@dashevo/evo-sdkand@dashevo/wasm-sdk5.0.0-beta.1, anddash-sdk(rs-sdk) at tagv5.0.0-beta.1. The admission and drift figures above come from earlier 4.2 beta devnets, also on protocol 14.
Activity