Repository navigation
feat(sdk): let apps that build document creates by hand state the contest fund - #5163
Merged
Merged
Conversation
…test fund A create in a contested index (a DPNS name, a moderation charter) must state its prefunded voting balance: the contested index and the most it pays into the contest. Without it, or stating too little, Platform refuses it with 40114 and still charges its fees. sdk.documents.create fills it in, but an app building the transition through wasm-dpp2 had to reimplement the pricing and the index keying in JS. - rs-sdk: Sdk::prefunded_voting_balance_to_join returns the contested index with the fund to join; contest_fund_to_join delegates to it. - wasm-sdk / evo-sdk: getContestFundToJoin(document) and sdk.documents.contestFundToJoin(document) return the PrefundedVotingBalance to pass to new DocumentCreateTransition, or undefined for a document that joins no contest. - wasm-dpp2: DocumentCreateTransition takes an optional dataContract, so a contested document states the contest's fund on its contested index as the Rust builder does, and an optional contestFund that replaces the amount, like apply_contest_fund. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
|
Warning Review limit reachedNext included review available in 20 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Repository: dashpay/platform/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (9)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
PastaPastaPasta
added a commit
that referenced
this pull request
Sep 29, 2026
Pick up #5163 (let apps that build document creates by hand state the contest fund). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
2 of 24 tasks
QuantumExplorer
added a commit
that referenced
this pull request
Sep 29, 2026
…nywhere Conflicts: - v14.rs: #5158 took changelog item 57 (moderator abilities); the skipIfAbsent item becomes 58, and names the review's new refusals (coverage index without a timeRange, stored ranking sharing a level with a null-layout index, byte array skip needs minItems >= 1) - book index-only rules: keep the skip rules, take `moderatorAbilities.delete` Co-Authored-By: Claude Opus 5.5 <[email protected]>
11 of 14 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Basic explanation
What this does: Some documents join a contest when they are created, for example a short DPNS name or a moderation charter. The create has to say how much it will pay into that contest's fund, and which of the type's indexes holds the contest.
sdk.documents.createworks this out on its own, but an app that builds the create transition itself with thewasm-dpp2classes got no help. This PR gives it two ways: an SDK call that looks up the current price and returns the value to put on the transition, and new options on the transition builder that fill in the contest's base price from the contract without any network call.Value: A contested create that states no fund, or too little, is refused with error 40114 and still pays its fees. Apps no longer need to reimplement the pricing (the base fund, doubling past 250 contenders from protocol version 14) or the index keying in JavaScript to avoid that.
Risks: Low. Client-side only, no consensus change. Every addition is new and optional: existing calls behave as before, and
Sdk::contest_fund_to_joinkeeps its signature. The price the helper returns can go stale if contenders join between the read and the submit; the docs say how to leave headroom from protocol version 14, and that before 14 the amount must be exact.Issue being fixed or feature implemented
Since 4.2.0-beta.5 a contested create states the most it pays into the vote poll fund (
prefundedVotingBalance), and from protocol version 14 that fund doubles once a contest holds 250 contenders and again for every 50 more.sdk.documents.createstates the current join price, but apps that build the create transition themselves through wasm-dpp2 would have had to rebuild the pricing and the index keying in JS. This exposes both.What was done?
Sdk::prefunded_voting_balance_to_join(document_type, document)returns the contested index name with the fund to join now (counted with proved vote state queries, as before).contest_fund_to_joinnow delegates to it and returns only the credits, unchanged for callers.getContestFundToJoin(document): Promise<PrefundedVotingBalance | undefined>. It resolves the document's contract through the contract cache, and copies theDocumentbefore the first await so the caller's object is not borrowed during the read.sdk.documents.contestFundToJoin(document), plus a README paragraph in "Building a document create transition by hand".new DocumentCreateTransition(...)takes two optional fields:dataContract: when given andprefundedVotingBalanceis not, a contested document states the contest's fund on its contested index, the same amount rs-dpp'sfrom_documentstates (what joining costs below 250 contenders). A contract that is not the document's is refused.contestFund: replaces the stated amount, like rs-dpp'sapply_contest_fund. WithoutdataContractorprefundedVotingBalancethere is no index to attach it to, so the build is refused.generatedFromproperties regenerated, as the platform does; the transition keeps the document's own values.prefundedVotingBalanceand the new calls say what differs before protocol version 14 (the amount must equal the contest's fund exactly).Before / after
A hand-built create of a contested DPNS name:
How Has This Been Tested?
cargo test -p dash-sdk --features mocks --lib contest_fund: 2 passed. The page-by-page test now also checks the index name at 250 contenders; the no-read test covers a type with no contested index and a contested type whose label matches no contested index (20 characters, or a digit other than 0 and 1).contestFundreplacing it, no fund for a non-matching document, refusal ofcontestFundwithout an index source, refusal of a foreign contract).Documentargument is refused before any read.wasm-sdk/tests/functional/voting.spec.ts(contested DPNS name returnsparentNameAndLabelwith the funddocumentCreateCostreports at the network's version; an uncontested name returnsundefined). Not run locally: they need the local dashmate network and will first run in CI.cargo clippy(dash-sdk, wasm-sdk, wasm-dpp2 on wasm32),cargo fmt --checkand eslint on the changed files are clean.Breaking Changes
None. All additions are optional, and
Sdk::contest_fund_to_joinkeeps its signature and behaviour.Checklist:
structure.rs, regeneratedgrovedb-structure.json, and checked the structure viewer link posted on this pull requestFor repository code-owners and collaborators only
🤖 Generated with Claude Code