Repository navigation
feat(rs-dapi): refuse shielded broadcasts from addresses that keep sending invalid proofs - #5001
Conversation
…nding invalid proofs Drive refuses a shielded transition whose Orchard proof does not verify without charging anyone, yet each one still takes one of the node's few CheckTx proof slots. DAPI now meters those failures per client address: a broadcast with Orchard actions reserves its action count before it reaches Tenderdash, keeps the charge only when Drive answers InvalidShieldedProofError (40902), and an address over its allowance is refused with RESOURCE_EXHAUSTED plus ratelimit-reset, so the SDK tries another node. An address may have 4 failed actions outstanding (two usual bundles); they drain one every 30 s. After a failure it gets one broadcast at a time, so a failing address is held to 2 actions a minute per node. An address with no failures may have one largest bundle's worth (16 actions) in flight. The client address is the last x-forwarded-for entry the gateway appends, trusted only from a private peer; IPv6 is grouped by /48. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Warning Review limit reachedNext included review available in 5 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 (3)
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 |
|
🕓 Queued for automated review — 5th in line, estimated start in ~0.9 h (commit 356bdda)
|
Issue being fixed or feature implemented
A shielded transition proves who is spending only through its Halo 2 proof. When that proof does not verify, Drive's CheckTx refuses the transition without charging anyone (there is no proven note to take a fee from), but the verification has already taken one of the node's CheckTx proof slots (1 to 4 per node). Nothing limits how many such transitions one client sends, so a single sender can keep a node's slots busy, and honest shielded transitions on that node are refused with "check tx verification capacity is temporarily unavailable" until it stops.
Drive cannot tell who sent a transition; DAPI can. This PR meters proof failures per client address in DAPI, before Drive does any work.
What was done?
ShieldedProofFailureBudgetinpackages/rs-dapi/src/services/platform_service/shielded_proof_failure_budget.rs, held byPlatformServiceImpl.broadcastStateTransitionnow:InvalidShieldedProofError(40902). Any other answer, including Drive's busy refusal, gives it back. A request whose client disconnects mid-broadcast is charged, since Drive may already have verified it.RESOURCE_EXHAUSTEDand aratelimit-resetheader. That is the header Envoy's rate limiter already sends, so rs-dapi-client stops using this node for that long and retries on another one.Limits, per address and per node (constants in the module):
max_shielded_transition_actions, 16)Client address: the last
x-forwarded-forentry, which the gateway appends (use_remote_address: true); earlier entries come from the client and are ignored. The header is trusted only from a loopback or private peer, which is where the gateway sits; any other peer is taken to be the client. IPv6 addresses are grouped by /48, so one allocation cannot rotate through its own /64s.Before / after
An address sending 2-action
ShieldedTransferbundles whose proofs do not verify:A 16-action bundle whose proof does not verify:
A wallet whose proofs verify:
Notes for reviewers
xff_num_trusted_hops. Users behind one shared address (CGNAT) share one allowance; a refusal only covers shielded broadcasts on this node, and the SDK moves to another node.How Has This Been Tested?
cargo test -p rs-dapi --lib: 327 passed, 18 of them new. They cover: verified proofs are never refused; refusal after two failed bundles with the right retry time; exactly one bundle a minute for an address that keeps failing (10 simulated minutes); one broadcast at a time after a failure; the in-flight cap; a failed largest bundle waiting for a full drain; a dropped reservation being charged; an oversized bundle charged as 16 actions; eviction when the table is full; address extraction (gateway-appended entry, header ignored from a public peer, IPv6 /48, IPv4-mapped IPv6); action counting; the refusal status and its whole-secondratelimit-reset; the 40902 code pinned against dpp.cargo fmt -p rs-dapi --checkandcargo clippy -p rs-dapi --all-targets: clean.Breaking Changes
None. This is node-local DAPI policy; nothing nodes have to agree on changes.
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
PR Hygiene ·
356bdda/skip-botsproceeds without the ones not yet reported/self-reviewedonce the bots are donerust-dapi(packages/rs-dapi/src/services/platform_service/broadcast_state_transition.rs,packages/rs-dapi/src/services/platform_service/mod.rs,packages/rs-dapi/src/services/platform_service/shielded_proof_failure_budget.rs) — lklimek or shumkovWhen every box is checked the
PR Hygienecheck passes and this can merge.