Repository navigation
feat(platform): prove the state before and after the block of a state transition - #6038
Conversation
… transition A proof of a state transition's keys shows the state at the block the proof was made at. Made when a client asks, it is of whatever block the node has reached. This adds a second proof of the same keys, of the block before the one that executed the transition, so the two show what that block changed. The proof of the state before a block can only be made before that block is committed, so a node proves only the transitions it was asked about in advance: - drive-abci: a registry of state transition hashes and the proofs made for them, in memory on `Platform`. The finalize handler proves the keys of each registered transition of the block before the platform state takes the block in and before the commit, with the previous block's signature, and again after the commit, with the new block's. Outside consensus: it reads committed state, a transition that cannot be proved is skipped, and no protocol version is involved. Bounds: 1,024 registrations, 64 blocks for a registration to find its block, 64 blocks a proof pair is kept. - dapi-grpc: the internal Drive service gains `registerStateTransitionExecutionProof` and `getStateTransitionExecutionProof`. `WaitForStateTransitionResultResponseV0` gains the optional `state_before_block`. Published clients regenerated. - rs-dapi: a proving wait registers its transition with Drive when the transition is not in a block yet. When it lands, the response carries Drive's pair if the after side is of the executing block and the before side is of the block right before it, and a proof of current state otherwise, as before. - drive-proof-verifier: `verify_state_transition_result_around_block` verifies the response as `FromProof` does and the state before the block against its own block's signature. The state is read for the transition kinds whose proof is a snapshot of the keys they affect; for the others the answer is `NotReadable` and nothing of that proof is verified. - drive: `Drive::state_transition_proof_binds_execution` is public and versioned. The pair shows what the block changed, not what one transition did: another transition of the same block that touched the same keys is part of it. In-place changes to shipped generations: - `verify_state_transition_was_executed_with_proof` 0 and 1: the private classifier is renamed `state_transition_proof_binds_execution_v0` and made visible to its dispatcher. Same body, same output. Not in this commit: rs-sdk, wasm and FFI do not call the new verifier, the transition kinds whose proof binds execution have no reader for their prior state, registrations do not survive a restart, and the extra finalize time for registered transitions is not measured. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Two ways a caller could make the registrations of the previous commit cost a node more than their use: - A registration outlived the wait that made it, for 64 blocks. Waits for hashes that never land could fill Drive's 1,024 slots, and honest proving waits then got a proof of current state instead of the pair. Now each registration lasts as long as its wait: rs-dapi holds it in a guard whose drop calls the new internal `unregisterStateTransitionExecutionProof`, so a wait that times out, fails or is cancelled by its client frees its slot. Drive counts the registrations of each hash, so another wait for the same transition keeps it registered. The 64-block lifetime stays as a backstop for an rs-dapi that stops without unregistering. - Every registered transition of a block was proved twice while the block was finalized, with no bound. Now at most 32 are, in block order. Measured in a debug build on a small test state, proving 32 registered transfers adds 3 to 5 ms to finalizing a block. Also: Drive's three handlers are plain functions over the registry, so they are tested without a Core RPC; rs-dapi's calls to Drive are tested against a recording Drive stand-in; imports replace two inline type paths. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
|
✅ Final review complete — no blockers (commit 9949742) · triage: critical |
thepastaclaw
left a comment
There was a problem hiding this comment.
Final validation — Phase 1 + Phase 2
The finalizer takes snapshots on the intended sides of the commit, but the client does not authenticate the transition’s execution block and can reject valid prior state. The PR also regresses freshness for existing v0 waits and needs tighter bounds on finalization work and registration lifetime. The Rust workspace, wasm32, JavaScript, Kotlin, and Swift checks passed; four lower-priority findings were omitted from the inline comments.
🔴 6 blocking | 🟡 4 suggestion(s)
Review provenance
Source: reviewer 1: gpt-6.2-astra (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 3: gpt-6.2-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 4: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 5: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); reviewer 6: gpt-6.2-astra (agent: phase2-reviewer, role: tenderdash-consensus-security); reviewer 7: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 8: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.2-sol(effort low) — The change is intricate and directly expands the signature verification surface:verify_state_transition_result_around_blockinpackages/rs-drive-proof-verifier/src/proof/state_before_block.rsauthenticates and pairs proofs from adjacent quorum-signed blocks. - Phase 1 reviewers:
muse-spark-1.3-contributor— general (completed, effort xhigh); agentphase1-reviewer,muse-spark-1.3-contributor— rust-quality (completed, effort xhigh); agentphase1-reviewer - Phase 1 model:
muse-spark-1.3-contributor— not quota-gated; passed overgemini-3.8-flash-high(antigravity quota lookup failed),glm-5.3-flash(not used above high effort; tier asks max) - Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
- Fresh verifier:
gpt-6.2-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.2-astra— general (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— platform-versioning (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— rust-quality (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— security-auditor (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— tenderdash-consensus-security (completed, effort high); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.
In `packages/rs-drive-proof-verifier/src/proof/state_before_block.rs`:
- [BLOCKING] packages/rs-drive-proof-verifier/src/proof/state_before_block.rs:61-65: The verified pair does not establish the transition’s execution height
For a credit transfer, Drive verifies the sender’s and recipient’s balance keys, not the request’s transaction hash or execution result. The signed test fixture changes those balances directly without executing the request and still gets `Verified`. DAPI’s check against its Tenderdash event is not evidence the client can authenticate, and the pair check does not compare the signed chain IDs. Either describe the Rust and protobuf results as adjacent same-chain snapshots at a node-reported execution height, with inclusion unverified, or authenticate the requested hash and successful result against the same signed after-block commitment using `block_proof::verify_block_proof` and `verify_transaction_proof`. In either case, require the two signed chain IDs to match.
- [BLOCKING] packages/rs-drive-proof-verifier/src/proof/state_before_block.rs:172-183: Select prior-state readers independently of execution binding
`state_transition_proof_binds_execution` returns `false` for `DataContractUpdate`, but both verifier generations use the same reader, which compares the proved contract to the requested new contract via `first_mismatch`. Drive can prove the old contract; the before-side then rejects it and the outer `?` discards the valid after-outcome. The same distinction applies to key-limit updates that require the new limits and no-history mints that require a recipient balance to exist. Give Drive an explicit prior-state reader or supported-kind gate, return `NotReadable` for unsupported kinds, and still report verification errors for supported kinds. Cover a changed contract and an authenticated absent-before balance in signed-pair tests.
- [SUGGESTION] packages/rs-drive-proof-verifier/src/proof/state_before_block.rs:209-214: Return the verified owner balance on the before side
`outcome.into_result()` discards the separately authenticated owner credit balance. For a readable no-history token operation, callers can compare token balances and read the after-side owner credit balance, but cannot access the before-side owner credit balance even when the proof included and verified it. Preserve that optional value on `StateBeforeBlock` so callers can compare the authenticated balances without re-verifying the proof.
In `packages/rs-dapi/src/services/platform_service/wait_for_state_transition_result.rs`:
- [BLOCKING] packages/rs-dapi/src/services/platform_service/wait_for_state_transition_result.rs:307-319: Keep historical proofs opt-in so existing v0 waits remain fresh
The already-included transaction path also calls `fill_success_result`, which uses a retained pair to replace the existing `proof` and `metadata` fields. A repeat wait for a transaction executed at height 55 can therefore return height 55 while Drive and the client are at 57. The SDK applies its default one-block tolerance to `wait_for_state_transition_result`, so it rejects the honest response as stale and can ban the responder when banning is enabled. Ignoring the new protobuf field does not help. Leave existing v0 requests on the current-state path unless the client explicitly requests historical proofs, and test a repeat wait while the pair is still cached two blocks behind the tip.
- [BLOCKING] packages/rs-dapi/src/services/platform_service/wait_for_state_transition_result.rs:417-424: Give each wait a registration lease that survives cancellation during acquisition
Drive records the registration before replying, but DAPI creates the cleanup guard only after it receives that reply. Cancellation between those events releases the DAPI permit while the Drive registration still occupies a slot until block-based expiry. The existing cancellation test suspends only after the guard has been acquired. Cleanup by hash cannot safely close the gap: waiters for the same hash inherit the first waiter’s expiry, and a late release after expiry or Drive restart can decrement a new waiter’s registration. Give each wait an independently expiring lease, with idempotent acquisition and release tied to that lease, and make cleanup independent of whether the waiting future receives the acknowledgment. Test cancellation after insertion but before acknowledgment, and a stale release after re-registration.
- [BLOCKING] packages/rs-dapi/src/services/platform_service/wait_for_state_transition_result.rs:110-119: Keep optional Drive calls from consuming the normal wait deadline
Registration runs before the configured wait timer starts, and the production Drive channel has no per-call timeout. A stalled registration keeps the permit occupied and prevents DAPI from reading an already-queued transaction event until the outer gRPC deadline. The pair lookup has the opposite placement problem: it runs inside the event wait, ahead of `get_proofs`, and can consume all the remaining time before the fallback is attempted. Give both optional calls short budgets within the wait deadline, reserving time for the existing path. Test a stalled registration and a stalled pair lookup with a working current-state proof endpoint.
In `packages/rs-drive-abci/src/platform_types/state_transition_execution_proofs.rs`:
- [BLOCKING] packages/rs-drive-abci/src/platform_types/state_transition_execution_proofs.rs:344-349: Bound proof generation and retained bytes on the finalization path
The 32-transition limit caps calls, not the work in each call. An `IdentityUpdate` uses `identity_all_keys_query`, which selects the whole key tree with `new_all_keys_query(identity_id, None)` and `insert_all()`. Even a small update can therefore make synchronous `FinalizeBlock` traverse and serialize the accumulated key set twice, although the client returns `NotReadable` for the before side. Separately, retention is height-only: after pruning, up to 2,080 pairs can retain two variable-length buffers each, outside the pending-registration limit. Restrict the synchronous path to query shapes with a known work bound or enforce a budget during generation. Cap cached bytes separately and use the existing fallback when a pair is skipped.
In `packages/rs-drive-abci/src/platform_types/platform/mod.rs`:
- [SUGGESTION] packages/rs-drive-abci/src/platform_types/platform/mod.rs:296: Start the registration clock at the restored block height
`open_with_client_saved_state` restores `committed_block_height_guard` from `height`, but the registry defaults to zero. After reopening at height 100, a new registration made before block 101 is stamped at zero. If block 101 does not contain the transition, expiry removes the registration before it can be used in block 102. Initialize the registry from the restored height or use the authoritative committed height when registering. Test a wait registered after reopening whose transition lands in the second block.
In `packages/rs-drive-abci/src/abci/handler/finalize_block.rs`:
- [SUGGESTION] packages/rs-drive-abci/src/abci/handler/finalize_block.rs:165-171: Track proved queries against pinned read snapshots in GroveDB
The pre-commit view must be captured before commit; the proof does not inherently have to be built then. Both pinned GroveDB (`89dc7351f09f`) and its default-branch revision (`2cfc1ce1f8e4`) expose `start_snapshot_read_transaction`, but `get_proved_path_query` rejects any supplied transaction. Link a GroveDB issue or PR for proving against caller-pinned read-only snapshots so proof construction can eventually move off the synchronous finalization path. ABCI should still own selecting the heights and bounding snapshot lifetime. This follow-up does not replace the work and memory limits needed here.
In `packages/rs-drive-abci/tests/state_before_block.rs`:
- [SUGGESTION] packages/rs-drive-abci/tests/state_before_block.rs:56-64: Test a signed pair across a producer-layout upgrade
Both `signed_proof_at` and `metadata_at` use `PlatformVersion::latest()`, so the tests cannot detect the before reader accidentally using the after producer’s version. Add a signed pair across protocol versions 13 and 14 using a supported operation whose layout changes, such as a no-history token transfer with existing balances on both sides. The later proof includes the owner credit balance and the earlier one does not; one client verifier should accept both layouts.
|
Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix; thepastaclaw left review threads unresolved; resolve them. |
- Opt in: a wait returns the state before the block only when its request sets the new `prove_state_before_block`. Without it nothing is registered and `proof`/`metadata` stay of the node's latest block, so existing clients keep their freshness checks. The SDKs leave it unset for now. - Prior-state readers: Drive's `verify_state_transition_prior_state_with_proof` reads the state before a credit transfer, top-up or credit withdrawal of an identity, with a balance that does not exist yet read as absent. Every other kind is `NotReadable` without reading its proof, so a contract update or a key limit update no longer fails the whole verification. The private classifier is no longer exposed, so the shipped verifier generation is untouched again. New slot `verify_state_transition_prior_state_with_proof`, 0 in every table: client-side only, not read by block execution. - Bounded finalization: Drive proves only those three kinds, whose proofs are a few balance keys, so an identity update's whole key set is never proved while a block is finalized. Kept pairs have a 16 MiB budget; a pair past it is not kept and its client gets a proof of current state. - Registrations are per-wait leases: rs-dapi picks a 16-byte lease and arms its release before sending the registration, so a wait cancelled while the call is on its way still releases it. Each lease expires on its own, a release ends only its own lease, and a registration that arrives after its release is not taken. - Deadlines: registration and the pair lookup each get 1 s, and the wait's own deadline starts before registration, so neither delays the existing path. - The registry starts at the height Drive opens at, so a registration taken right after a restart does not expire at the next block. - The client verifier requires both proofs to be of the same chain and says what it does not verify: the transition's inclusion in the later block. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
`prove_state_before_block` is a request field older nodes do not know. A node that drops it answers with a proof of current state and no `state_before_block`, which the result allows, so it needs no protocol version gate. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 1 + Phase 2
The opt-in response now correctly describes two adjacent, same-chain snapshots without claiming transaction inclusion. Two new blockers remain: the public Drive reader omits the minimum proof-envelope check, and the new flag breaks replay of Rust SDK waits recorded on the base revision. Rust workspace and wasm32 tests, the Drive and RS-DAPI images, and the JS and npm builds passed; Swift, JS lint and tests, and end-to-end checks were still pending.
🔴 4 blocking | 🟡 4 suggestion(s) | 💬 1 nitpick(s)
Still open from earlier rounds (1)
- 🔴 Blocking: Keep optional Drive calls from consuming the normal wait deadline —
packages/rs-dapi/src/services/platform_service/wait_for_state_transition_result.rs:494-499(thread)
Review provenance
Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.2-astra (agent: phase2-reviewer, role: general); reviewer 3: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 4: gpt-6.2-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 5: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 6: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); reviewer 7: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); reviewer 8: gpt-6.2-astra (agent: phase2-reviewer, role: tenderdash-consensus-security); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.2-sol(effort low) — The change is intricate and directly expands cryptographic verification in rs-drive-proof-verifier/src/proof/state_before_block.rs, where the verifier must authenticate and link two signed state snapshots. - Phase 1 reviewers:
muse-spark-1.3-contributor— general (completed, effort xhigh); agentphase1-reviewer,muse-spark-1.3-contributor— rust-quality (completed, effort xhigh); agentphase1-reviewer - Phase 1 model:
muse-spark-1.3-contributor— not quota-gated; passed overgemini-3.8-flash-high(antigravity quota lookup failed),glm-5.3-flash(not used above high effort; tier asks max) - Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
- Fresh verifier:
gpt-6.2-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.2-astra— general (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— platform-versioning (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— rust-quality (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— security-auditor (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— tenderdash-consensus-security (completed, effort high); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.
In `packages/rs-drive-abci/src/platform_types/state_transition_execution_proofs.rs`:
- [BLOCKING] packages/rs-drive-abci/src/platform_types/state_transition_execution_proofs.rs:139-144: Give each wait a registration lease that survives cancellation during acquisition
The pre-armed guard releases the right lease, but `remember_release` silently drops a release when its 4,096-entry table is full. Completed waits populate that table too, so it can be full while active slots are free. If the acquisition arrives after that acknowledged release, `register` accepts it and the cancelled waiter has no guard left to free the slot. Preserve release-before-acquire ordering under saturation without growing the registry, and extend the existing late-registration test to cover that boundary.
- [SUGGESTION] packages/rs-drive-abci/src/platform_types/state_transition_execution_proofs.rs:380-394: Stop decoding candidates once the per-block proof slots are filled
`collect::<Vec<_>>()` exhausts the iterator before `take(32)` runs. Finalization still hashes the rest of the block, checks the registry, and deserializes and retains additional readable matches just to report the overflow count. Stop the lazy scan after the first 32 readable matches in block order, or look ahead by one readable match if the warning is useful.
In `packages/rs-drive/src/verify/state_transition/verify_state_transition_prior_state_with_proof/v0/mod.rs`:
- [BLOCKING] packages/rs-drive/src/verify/state_transition/verify_state_transition_prior_state_with_proof/v0/mod.rs:39-47: Enforce the minimum proof-envelope version in the public Drive reader
The high-level pair verifier checks the GroveDB envelope, but callers of `Drive::verify_state_transition_prior_state_with_proof` reach the balance and revision readers without that check. Pinned GroveDB still dispatches V0 envelopes to its historical verifier. Drive's `grovedb_proof_envelope` policy rejects V0 because checking the returned root against a signed root does not make V0 item values trustworthy. Enforce the existing envelope floor for readable kinds at the Drive boundary and test the public method directly. Unsupported kinds should still return `Ok(None)` without decoding the proof.
- [SUGGESTION] packages/rs-drive/src/verify/state_transition/verify_state_transition_prior_state_with_proof/v0/mod.rs:151-163: Exercise the top-up and withdrawal readers with real prior-state proofs
The predicate test selects all three supported kinds, but only the transfer exercises the new reader with proof bytes. A top-up reads a merged balance-and-revision query, while a withdrawal reads a standalone balance proof. Round-trip both through `prove_state_transition` and the public prior-state reader, asserting the root, identity ID, balance, and revision. Include a top-up whose identity did not exist before the block: both balance and revision should be `None` even though the entire revision subtree is absent.
In `packages/dapi-grpc/protos/platform/v0/platform.proto`:
- [BLOCKING] packages/dapi-grpc/protos/platform/v0/platform.proto:2711: Default the new flag to false when replaying pre-PR SDK recordings
Prost defaults an absent wire tag to `false`, but SDK recordings use Serde JSON. A wait recorded at the base revision contains `state_transition_hash`, `prove`, and `request_user_balance`, with no `prove_state_before_block`. The generated `Mockable::mock_deserialize` uses `serde_json::from_slice(...).expect(...)`, so `MockDapiClient::load` now panics on that previously valid recording. Add a `SERDE_DEFAULT` field attribute in `packages/dapi-grpc/build.rs`, following the additive `GetDocumentsRequestV1` fields, and test replay of a base-format request with tag 4's JSON field absent.
In `packages/rs-drive-proof-verifier/src/proof/state_before_block.rs`:
- [SUGGESTION] packages/rs-drive-proof-verifier/src/proof/state_before_block.rs:43-45: Distinguish the node-reported epoch from signed block metadata
Both public result structs expose the full `ResponseMetadata` alongside verified state. `verify_tenderdash_signature` binds the height, time, protocol version, Core height, root, and chain ID, but not `epoch`; the after-side verifier deliberately does not use it. Document on both metadata fields that `epoch` is node-reported so callers do not treat an epoch change as quorum-authenticated.
- [SUGGESTION] packages/rs-drive-proof-verifier/src/proof/state_before_block.rs:100-106: Move the before-proof out of the owned response
Cloning `state_before_block` duplicates its proof bytes and signature before the height and chain checks. The verifier owns the response, and the after-side `FromProof` path only reads its result and metadata. Take the optional field instead.
In `packages/rs-platform-version/src/version/drive_versions/drive_verify_method_versions/mod.rs`:
- [NITPICK] packages/rs-platform-version/src/version/drive_versions/drive_verify_method_versions/mod.rs:225-229: State why the historical table addition cannot change consensus
`FinalizeBlock` does read this slot through `state_transition_prior_state_is_readable`. What makes the addition inert for consensus is that the decision controls only an optional, node-local proof, not block acceptance, fees, or durable state. Use that explanation here and in the PR's in-place changes section.
In `packages/rs-dapi/src/services/platform_service/wait_for_state_transition_result.rs`:
- [BLOCKING] packages/rs-dapi/src/services/platform_service/wait_for_state_transition_result.rs:494-499: Keep optional Drive calls from consuming the normal wait deadline
(carried; thread: https://github.com/dashpay/platform/pull/6038#discussion_r4652655052)
|
Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix; thepastaclaw left review threads unresolved; resolve them. |
…oofs - Early releases under saturation: a lease stays held until its wait releases it, also once its transition is proved, so ordinary releases find it and need no memory. Only a release that arrives before its registration is remembered; when one cannot be, every new registration is refused for the lifetime a remembered release is kept, so a forgotten release's late registration is never taken. - Deadlines: the registration may take a quarter of what is left of the wait, the pair lookup half, each at most 1 s, so the proof of current state always keeps time before the wait's deadline. - Drive's public prior-state reader refuses a GroveDB proof envelope older than V1 for the kinds it reads, and still answers other kinds without decoding the proof. - Waits recorded before `prove_state_before_block` existed replay: the field defaults to false in JSON. - Finalization stops scanning a block once 32 readable registered transitions are found, looking one further only to warn. - Tests of the top-up and withdrawal readers on real proofs, including a top-up of an identity that does not exist yet. - Docs: `epoch` in the returned metadata is node-reported, not signed; why the new version slot cannot change consensus. The verifier takes the before-proof out of the response instead of copying it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Your move: thepastaclaw left review threads unresolved; resolve them. |
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 1 + Phase 2
The head keeps historical proofs opt-in, bounds finalization work, and makes clear that the signed snapshots do not prove transaction inclusion. One new blocker remains in the lease registry: cancellation cleanup can disable fresh before-state registrations even after Drive recovers and active slots are free. Rust workspace tests, the Drive and RS-DAPI image builds, and NPM release validation passed in CI; the JS build, Swift SDK build and tests, and Dashmate helper image were still pending.
🔴 2 blocking | 🟡 5 suggestion(s) | 💬 1 nitpick(s)
Still open from earlier rounds (1)
- 🔴 Blocking: Keep optional Drive calls from consuming the normal wait deadline —
packages/rs-dapi/src/services/platform_service/wait_for_state_transition_result.rs:120-124(thread)
Review provenance
Source: reviewer 1: gpt-6.2-astra (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 3: gpt-6.2-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 4: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 5: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 6: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); reviewer 7: gpt-6.2-astra (agent: phase2-reviewer, role: tenderdash-consensus-security); reviewer 8: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.2-sol(effort low) — The new paired-proof verifier inpackages/rs-drive-proof-verifier/src/proof/state_before_block.rschanges the cryptographic acceptance rules for balance proofs by checking that two quorum-authenticated snapshots form a valid before-and-after pair. - Phase 1 reviewers:
muse-spark-1.3-contributor— general (completed, effort xhigh); agentphase1-reviewer,muse-spark-1.3-contributor— rust-quality (completed, effort xhigh); agentphase1-reviewer - Phase 1 model:
muse-spark-1.3-contributor— not quota-gated; passed overgemini-3.8-flash-high(antigravity quota lookup failed),glm-5.3-flash(not used above high effort; tier asks max) - Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
- Fresh verifier:
gpt-6.2-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.2-astra— general (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— platform-versioning (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— rust-quality (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— security-auditor (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— tenderdash-consensus-security (completed, effort high); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.
In `packages/rs-drive-abci/src/platform_types/state_transition_execution_proofs.rs`:
- [BLOCKING] packages/rs-drive-abci/src/platform_types/state_transition_execution_proofs.rs:151-158: Keep fresh proof registrations available after cancellation cleanup saturates
When the early-release table fills, the next unmatched release sets `released_overflow_at`, and `register` refuses unrelated fresh leases even with zero active registrations. Public DAPI waits can produce unmatched releases: cancellation drops the acquisition future, so the buffered Drive channel can discard the acquisition before dispatch, while the pre-armed guard independently sends cleanup. These entries accumulate across waits and outlive their wait permits. Even after Drive recovers, the refusal lasts until the committed height is more than 64 blocks past the overflow height. The current-state fallback keeps waits working but cannot recover a missed before-state proof after commit. Keep stale-acquisition protection bounded without rejecting unrelated new leases, and extend the saturation test to distinguish a forgotten acquisition from a fresh one.
- [SUGGESTION] packages/rs-drive-abci/src/platform_types/state_transition_execution_proofs.rs:400-415: Skip paid failures before allocating finalization proof slots
`prepare_proposal` retains `PaidConsensusError` transactions in the block, and this filter selects candidates by kind without checking the execution result. A registered failed transfer can therefore take one of the 32 slots and generate a pair that neither DAPI path uses: the indexed path returns on a nonzero result code, and the event path returns the transaction error. Use the selected proposal's execution results to skip unsuccessful transactions before the cap, without changing consensus results. Cover a paid failure before 32 registered successful transfers.
In `packages/dapi-grpc/protos/drive/v0/drive.proto`:
- [SUGGESTION] packages/dapi-grpc/protos/drive/v0/drive.proto:42-44: Document the single-acquisition lease contract
The proto and `StateTransitionExecutionProofs::register` say an acquisition after release changes nothing. But after `register → unregister → duplicate register`, the first unregister removes the live entry without recording a release, so the duplicate can take a slot until expiry. Current rs-dapi sends one acquisition per lease, so this does not reopen its cancellation race. Document the single-attempt rule in both APIs, including that an ambiguous acknowledgment must not trigger a retry on the same lease, or enforce the stronger advertised contract and test that ordering.
In `packages/rs-drive-proof-verifier/src/proof/state_before_block.rs`:
- [SUGGESTION] packages/rs-drive-proof-verifier/src/proof/state_before_block.rs:139-150: Decode the transition once for both proof readers
This function decodes the transition, then `StateTransitionProofOutcome::maybe_from_proof_with_metadata` decodes the same bytes while the first value is still live. Even responses without a before proof pay for both decodes. Share an internal after-proof helper that borrows the decoded transition so both entry points use one verification implementation without duplicating parsing or peak transition memory for large batches.
- [NITPICK] packages/rs-drive-proof-verifier/src/proof/state_before_block.rs:197-203: Describe the actual producer-version policy for before proofs
The comment says the producer version must be known, but `proof_query_platform_version` accepts versions above `LATEST_VERSION` by returning the latest known tables. This call discards those tables; the prior-state reader uses the caller's version. Document the fallback and why the currently supported balance and revision queries do not need a producer-specific layout. That distinction matters if a future protocol moves a key: proved absence at the old location is not absence at the new one.
In `packages/rs-dapi/src/services/platform_service/wait_for_state_transition_result.rs`:
- [SUGGESTION] packages/rs-dapi/src/services/platform_service/wait_for_state_transition_result.rs:1047-1059: Synchronize the cancellation test with Drive receiving the lease
A 100 ms client timeout and a 500 ms server delay do not establish that Drive received the registration before cancellation. On a slow runner the client timer can elapse before `Call::Register` is recorded. Use `Registration::Stall`, wait for the fixture to signal receipt while the acquisition is still pending, then drop the acquisition future and assert that the same lease is released. Keep a timeout as a watchdog rather than as the ordering mechanism.
- [BLOCKING] packages/rs-dapi/src/services/platform_service/wait_for_state_transition_result.rs:120-124: Keep optional Drive calls from consuming the normal wait deadline
(carried; thread: https://github.com/dashpay/platform/pull/6038#discussion_r4652655052)
In `packages/dapi-grpc/protos/platform/v0/platform.proto`:
- [SUGGESTION] packages/dapi-grpc/protos/platform/v0/platform.proto:2711: Mark the Rust source break in the PR title
The new protobuf tags are wire-compatible, but existing Rust struct literals for the request and response need new fields, and existing `DriveInternal` implementations need new methods. The Breaking Changes section already describes this; the title still says `feat(platform):`. Use `feat(platform)!:` as requested by the PR template. No protobuf envelope or Platform protocol bump is needed.
|
Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix; thepastaclaw left review threads unresolved; resolve them. |
…s result A wait read every failure of Tenderdash's `tx` lookup as "in no block yet" and went on to wait for the transaction's event. When the lookup failed for another reason (a transport error, a timeout, an index read that failed) and the transaction was in a block already, that event had come before the wait subscribed, so the wait ran into its timeout for an executed transition. Only Tenderdash's own answer that its index does not hold the hash now counts as "in no block yet". After any other failure the wait keeps listening for the event and repeats the lookup, 500 ms later at first and then at doubling intervals up to 8 s, until Tenderdash answers one: with the transaction, which ends the wait, or that it holds no such hash, after which only the event can. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…e-before-block verifiers `verify_state_transition_result_around_block`, `verify_state_before_block` and `verify_state_transition_proof_outcome` took `provider` after `platform_version`. All three are new with the before/after block proofs, so they follow the rule that `platform_version` closes a parameter list. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…dget do - A release of a lease Drive does not hold is remembered as one that came before its registration, also when the lease was released already or has expired. The docs called a repeated release a no-op; they now say what it costs, and a test pins it. - The registry and the per-block proving budgets are the node's, shared by every caller: a registration names only a hash, so a client can use them up with transitions others sent. The module docs now say so, and that a wait left out answers with a proof of current state. Co-Authored-By: Claude Fable 5.2 <[email protected]>
… items of the before/after block proofs (#6240)
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 2 only (queue backlog)
New on this head: This revision retries failed Tenderdash transaction lookups alongside the event subscription, moves platform_version to the end of the new verifier signatures, and clarifies the proof registry’s release and budget rules. No code checks had failed at review time: Kotlin SDK build and tests passed, while Rust workspace and wasm32 tests, Docker and JavaScript builds, and npm release validation were still pending.
🟡 4 suggestion(s) | 💬 1 nitpick(s)
Approved: nothing here blocks the merge. The non-blocking findings are optional: fix them forward, in this PR or a follow-up, without waiting for another review round.
Review provenance
Source: reviewer 1: gpt-6.2-astra (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 3: gpt-6.2-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 4: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 5: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); reviewer 6: gpt-6.2-astra (agent: phase2-reviewer, role: tenderdash-consensus-security); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.2-sol(effort low) — The change is intricate and directly extends cryptographic proof verification in rs-drive-proof-verifier/src/proof/state_before_block.rs, where two quorum-authenticated snapshots must be verified and bound to adjacent blocks. - Phase 1 reviewers: not run (skipped for throughput: 11 PRs queued, above the 10 limit)
- Fresh verifier:
gpt-6.2-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.2-astra— general (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— platform-versioning (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— rust-quality (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— security-auditor (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— tenderdash-consensus-security (completed, effort high); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.
In `packages/rs-dapi/src/services/platform_service/wait_for_state_transition_result.rs`:
- [SUGGESTION] packages/rs-dapi/src/services/platform_service/wait_for_state_transition_result.rs:204-206: A wait can time out after its retry misses a transaction that is still being indexed
Impact: A client that starts waiting just after its transaction’s event was forwarded can time out even though the transaction becomes queryable before the wait expires.
Once the retry gets a clean miss, this wait can no longer discover the transaction through the index. In Tenderdash v2.0.0-dev.2, `internal/state/indexer/indexer_service.go` accumulates transaction events and does not call `IndexTxEvents` until the whole block batch is ready. DAPI can therefore forward an early transaction’s event before the index has its entry. If the wait subscribes after that event, its first lookup fails, and its retry reads before the batch is written, `break None` disables further lookups and no event is replayed when indexing finishes. Keep a bounded, backed-off recheck after a miss on the recovery path, within the existing deadline and without delaying event delivery. Cover `Failed → Missing → Found` with no event; ordinary initial misses need not start polling.
- [SUGGESTION] packages/rs-dapi/src/services/platform_service/wait_for_state_transition_result.rs:1945-1949: The event-during-retry test hangs if the second lookup never happens
Impact: A developer who breaks retry scheduling gets a stuck test instead of an assertion identifying the missing second lookup.
The handler’s timeout does not end `deliver_event`: `tokio::join!` waits for both futures. If the handler returns without issuing a second lookup, the counter can no longer reach two and the fixture polls forever. Bound the fixture wait with a watchdog, as the recording Drive fixture does.
- [SUGGESTION] packages/rs-dapi/src/services/platform_service/wait_for_state_transition_result.rs:206-210: Pending waits keep querying Tenderdash when its transaction index is disabled
Impact: An operator running rs-dapi against a custom Tenderdash node without a KV index gets repeated RPCs for pending waits that can only be answered by events.
These calls cannot recover while that node configuration is in effect. Tenderdash’s `Tx` returns `transaction querying is disabled due to no kvEventSink` when the KV index is disabled. The initial lookup and the retry loop both treat that reply like a transient read failure. Dashmate’s stock configuration enables the index, but rs-dapi can use a separately configured Tenderdash endpoint. Recognize the explicit disabled response as non-retryable without treating it as a clean miss, leave the event subscription active, and test that an event still completes the wait after exactly one lookup.
In `packages/rs-dapi/src/services/platform_service/get_recent_state_transition_status.rs`:
- [SUGGESTION] packages/rs-dapi/src/services/platform_service/get_recent_state_transition_status.rs:244: DAPI handlers interpret the same Tenderdash index miss differently
Impact: A duplicate broadcast whose transaction is no longer in the mempool or index can return a Tenderdash RPC error instead of reaching the intended `CheckTx` fallback.
The new retry makes a second endpoint depend on the status handler to interpret Tenderdash’s `tx` wire response. `TenderdashClient::tx` returns `TenderdashClientError` for a clean miss, which status and wait recognize through this helper, but duplicate-broadcast handling looks for `DapiError::NotFound` and propagates the same reply instead. The broadcast discrepancy predates this round; the new sibling dependency is the reason to address ownership here. Put the miss classification in the Tenderdash client, for example with a lookup that returns `Ok(None)` for a clean miss and preserves read failures as errors. Keep endpoint-specific behavior, including backoff, in the callers. The upstream wire ambiguity is already tracked in dashpay/tenderdash#1605.
In `packages/rs-drive-proof-verifier/src/proof/state_before_block.rs`:
- [NITPICK] packages/rs-drive-proof-verifier/src/proof/state_before_block.rs:98-99: The PR’s Rust verifier example passes the last two arguments in the old order
Impact: A Rust caller copying the example from the PR description gets a type error.
The example under “Client verification” still passes `platform_version, provider`, but the public signature and in-tree callers now pass `provider, platform_version`. Swap the arguments in the PR description; the code signature is correct.
|
Bots are done — your move: post |
thepastaclaw
left a comment
There was a problem hiding this comment.
CI failed after approval — commit c1f838c
The standing review approved this commit; this follow-up moves the verdict to COMMENT: checks that failed after the review may relate to this change, and the evidence does not rule it out.
Failing checks:
Why it is unclear: The log tail shows 80 browser tests passing and names @dashevo/wallet-lib as the failed package, but omits its failing test or error. The PR changes generated JavaScript gRPC clients, but the excerpt does not show whether those changes affected the wallet-lib failure.
Nothing was re-reviewed: the findings of the standing review are unchanged. The next push gets a full review; a re-run that passes does not restore the approval.
Review provenance
Source: CI-check lane gpt-6.2-sol (agent: triage); no reviewer or verifier lanes ran for this follow-up
- Verdict moved because CI failed on this commit after the review; failure logs read: 1 GitHub Actions job(s)
…ver repeated The test delivers its event once Tenderdash has received a second lookup. Without one it polled the counter for good: the handler's own timeout does not end the other half of the join. The wait for the second lookup now ends after 10 seconds with a message that names it. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
…e Tenderdash client `is_missing_from_index` and `is_missing_from_mempool` read the text Tenderdash answers `tx` and `unconfirmed_tx` with. They lived in the getRecentStateTransitionStatus handler, and the wait handler imported one of them from there. They move, with their tests, to the Tenderdash client, which owns what Tenderdash's answers mean. Both handlers read them from there. No behaviour changes. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 1 + Phase 2
New on this head: The two commits since c1f838c4ec move Tenderdash lookup-miss classification into the client without changing retry behavior, and add a 10-second watchdog to the event-during-retry test. GitHub reports that the Kotlin SDK build and tests and both generation jobs passed; NPM release validation and review-policy checks were still pending, with no failed code checks reported.
🔴 0 blocking | 🟡 0 suggestion(s) | 💬 0 nitpick(s)
Review provenance
Source: reviewer 1: gpt-6.2-astra (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 3: gpt-6.2-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 4: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 5: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 6: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); reviewer 7: gpt-6.2-astra (agent: phase2-reviewer, role: tenderdash-consensus-security); reviewer 8: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.2-sol(effort low) — The diff adds intricate verification in packages/rs-drive-proof-verifier/src/proof/state_before_block.rs that determines whether two quorum-signed state proofs can be accepted as an authenticated before-and-after pair. - Phase 1 reviewers:
muse-spark-1.3-contributor— general (completed, effort xhigh); agentphase1-reviewer,muse-spark-1.3-contributor— rust-quality (completed, effort xhigh); agentphase1-reviewer - Phase 1 model:
muse-spark-1.3-contributor— not quota-gated; passed overgemini-3.8-flash-high(lane failed),glm-5.3-flash(not used above high effort; tier asks max) - Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
- Fresh verifier:
gpt-6.2-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.2-astra— general (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— platform-versioning (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— rust-quality (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— security-auditor (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— tenderdash-consensus-security (completed, effort high); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify the current code and confirm that no unresolved issues remain.
No unresolved findings remain from the prior review on this head.
|
Bots are done — your move: post |
Basic explanation
What this does: When a wallet sends a transaction to Platform and waits for it with a proof, it gets back a signed snapshot of the balances the transaction touched, taken at whatever block the node has reached. A snapshot alone cannot show that anything changed. With this PR a client can ask, while it waits, for the same balances as the block before the transaction's block left them, next to the ones that block left. Both snapshots are signed by the validator quorum of the same chain, so the client sees what that block changed, for example a balance going from 1.0 to 0.995 Dash. It works for credit transfers, top-ups and credit withdrawals of an identity. The node can only take the "before" snapshot while the block is being finalized, so it does this only for transactions a waiting client asked about in advance.
Value: A wallet can confirm from signed data what a block did to the balances its transaction touched, instead of trusting that a snapshot of the current state means the transaction ran. It is the base for proof-carrying state transition events (the "proof before and after" work from #2795, and the subscriptions in #5285). Nothing changes for clients that do not ask; for asked-about transactions, a debug build on a small test state measured about 3 to 5 ms more per block for 32 of them.
Risks: Low for consensus: no protocol version, nothing written to state, and a failure to prove never fails a block. The extra work runs inside block finalization, bounded to 32 transactions per block, to the three kinds above (a few balance keys each), and to 16 MiB of kept proofs. A client that asks gets the proof of the block that executed its transaction, which can be older than the node's latest block; clients that do not ask are unaffected. The pair shows what the whole block changed, not one transaction, and the transaction's inclusion in that block is what the node reports, not something the pair proves. Not tested on a live network (local devnet with rs-dapi, Drive and Tenderdash together).
Issue being fixed or feature implemented
A proof returned by
waitForStateTransitionResultauthenticates the state of the transition's keys at the block the node had reached when it answered. For credit transfers, top-ups and withdrawals that proof is a snapshot of balances, which cannot tell "the transition executed" from "the state never changed", part of the gap described in #4270. A second proof of the same keys at the block before makes the change itself visible and signed.The proof of the state before a block can only be made before that block is committed, so the node must know in advance which transitions to prove. The rs-dapi wait that is already running when the transition is broadcast is that signal.
What was done?
gRPC (
dapi-grpc)platform.proto:WaitForStateTransitionResultRequestV0gainsprove_state_before_block(JSON defaultfalse, so recorded SDK waits still replay);WaitForStateTransitionResultResponseV0gains an optionalstate_before_block(aProofand itsResponseMetadata), present only when asked for. The flag's doc says a kept pair is served to any caller who knows the hash, which shows the node was asked for it (not by whom).drive.proto: the internalDriveInternalservice gainsregisterStateTransitionExecutionProof,unregisterStateTransitionExecutionProof(both with a 16-byte lease: 8 bytes naming the caller, then a big-endian sequence it increases; each lease is sent in one registration only, and one whose release came first is answeredFAILED_PRECONDITION, within the bounds Drive remembers releases for) andgetStateTransitionExecutionProof.scripts/patch-protobuf-js.shalso fixes the Drive web declarations' Platform import (../../../platform/v0/web/platform_pb, as the JavaScript already had), so the new Drive response types type-check for TypeScript consumers.Drive (
rs-drive-abci)platform_types/state_transition_execution_proofs.rs(crate-visible): an in-memory registry onPlatformof transitions to prove, held by per-wait leases, and of the proof pairs made. A lease is held until its wait releases it or it expires, after 64 blocks or 15 minutes on the node's clock, whichever comes first; a full registry also drops the leases that ran out of time when a new registration needs a slot, and so does the snapshot of waiting transitions a block is proved from, so leases whose release never arrived (an rs-dapi that restarted) do not hold the slots for hours on a quiet chain. Each lease expires on its own, and a release ends only its own lease. A release that arrives before its registration is remembered so the registration is not taken, and forgotten once it has refused it. When 1,024 such releases are remembered, the one with the lowest sequence is forgotten and its caller's low-water mark raised to it, so its late registration is still refused withFAILED_PRECONDITIONwhile new leases are taken (marks for at most 64 callers, each kept for a lease lifetime). A refused registration is never acknowledged, so a wait still in flight learns it holds nothing.abci/handler/finalize_block.rs: beforefinalize_block_proposaland the commit (after the request is cleaned, so the debug phase report keepssetupas it was and times the two proving steps asprove_registered_state_transitions_before_blockand..._after_block, sampled only on blocks that proved something), the registered transitions of the block are proved against committed state, which is still the previous block's, with that block's signature and metadata; right after the commit, again with the new block's. Each side's GroveDB proof envelope is checked against the clients' floor on its own; a side below it (made at protocol version 11 or earlier) is not made, so the first block after the upgrade to 12 keeps no pair. Expired pairs are forgotten before the block's own are kept, so the bytes they free count. Each side is signed off and described by the metadata generation of its own block (committed_block_proof_and_metadata, versioned); an unknown generation skips the pair.Drive::state_transition_proof_has_fixed_keys, perprove_state_transitionversion, checked for each side at its own block's version); one pass over the block, against a snapshot of the waiting hashes, decodes at most 64 registered transitions whatever their kind and proves at most 32; 16 MiB of kept pairs; 1,024 registrations; 64 blocks a pair is kept; 64 blocks or 15 minutes a lease lives without a release. The registry starts at the height Drive opens at.query/service.rs: the three internal calls (RESOURCE_EXHAUSTEDwhen the registry is full).rs-dapi
proveandprove_state_before_blockregisters its transaction with a new lease alongside the Tenderdash lookup, since the block can be finalized during the lookup. If the transaction is already indexed it answers at once and drops the registration, held or still on its way. If not, the event wait's own timeout starts at the miss, and a registration still on its way finishes within it. The release is armed before the call, so the registration ends with the wait however it ends: answered, timed out, failed, or cancelled by the client, even mid-call. Each registration holds one of 1,024 process-wide permits until its release with Drive ends, after the wait; with none free the wait registers nothing, and a registration Drive refuses outright frees its permit at once:RESOURCE_EXHAUSTED,INVALID_ARGUMENT,FAILED_PRECONDITION, andUNIMPLEMENTEDfrom an older Drive without the call. Any other status may follow a registration Drive took, so that one is still released.DEADLINE_EXCEEDED. The optional Drive calls also end by the ingress layer'sIngressDeadline: the earlier of its own timer and the client'sgrpc-timeoutless the margin, counted from when the headers arrived (no time at all when the margin does not fit). The registration may take a quarter of what is left and the pair lookup half, each at most 1 s, so the proof of current state always keeps time before that deadline; a transaction already in a block gets the same deadline for its Drive calls.is_missing_from_index, the checkgetRecentStateTransitionStatusalready used; it andis_missing_from_mempoolnow live in the Tenderdash client, which both handlers read them from). After any other failure the wait keeps listening for the event and repeats the lookup: 500 ms later, then at doubling intervals up to 8 s, until Tenderdash answers one, with the transaction or that it holds no such hash. A wait whose first lookup is answered makes no extra call. This predates the pair and applies to every wait.Before (transaction executed in block 55, node at block 57):
After, asking for it while the transaction was not yet in a block:
Without
prove_state_before_block, or when the node has no pair: unchanged from before.Client verification (
drive-proof-verifier,drive)Drive::verify_state_transition_prior_state_with_proof(new): reads the state before a credit transfer, top-up or credit withdrawal of an identity, with a balance that does not exist yet (an identity created in the same block) read as absent. It refuses a GroveDB proof envelope older than V1. Other kinds returnNonewithout reading the proof.verify_state_transition_result_around_block(new,proof/state_before_block.rs): decodes the transition once and verifies the response asFromProofdoes forStateTransitionProofOutcome(the shared part moved intoverify_state_transition_proof_outcome), requires the two proofs to be of the same chain and of consecutive blocks, and verifies the before-proof against its own block's quorum signature. It answersNotInResponse,NotReadableorVerified(StateBeforeBlock). It takes no network: trust comes from the provider's quorum keys, as forFromProof.In-place changes to shipped generations
DRIVE_VERIFY_METHOD_VERSIONS_V1andV3(every protocol version): a new field,verify_state_transition_prior_state_with_proof: 0. The client-side reader reads it, and so doesFinalizeBlock, throughstate_transition_prior_state_is_readable, to pick which registered transitions to prove. That choice only controls an optional, node-local proof for clients; no block's acceptance, fees, results or state depend on it, so consensus cannot change.Not in this PR
prove_state_before_blockor call the new verifier yet.finalize_block, so a failed registered transition can take a slot.How Has This Been Tested?
rs-drive-abci/src/abci/handler/finalize_block.rstests: real blocks throughfinalize_block. A registered transfer gets a pair whose sides verify against the roots of blocks 1 and 2; an unregistered one gets none; nothing is proved for the first block; only 32 of 33 registered transfers are proved; a registered identity update is not proved; no pair is started when the block before ran at protocol version 11, whose proof envelope clients refuse; at most 64 registered transitions of a block are decoded.rs-drive-abci/src/platform_types/state_transition_execution_proofs.rstests: leases (several per transition, taken and released once, a late registration after its release, a stale release, forgotten releases still refused by the low-water mark while fresh leases are taken, a live registration below the mark refused rather than acknowledged, an early release forgotten once it refused its registration, a late registration taken once its caller's mark is forgotten), the limit and a freed slot, expiry per lease in blocks and in time, a full registry giving the slots of timed-out leases to a new registration between blocks, a transition whose leases ran out of time since the last block not waited for while one with a live lease is, the start height after a restart, retention and the byte budget, a pair kept on the block that frees the bytes it needs.rs-drive-abci/src/query/service.rstests: the three internal handlers (RESOURCE_EXHAUSTED,FAILED_PRECONDITIONafter a release, both sides or none, hash and lease lengths).rs-drive/src/verify/state_transition/verify_state_transition_prior_state_with_proof/v0tests: which kinds are read (a contract update and an identity update are not), and a recipient that does not exist yet read as absent.rs-drive-abci/tests/state_before_block.rs: proofs signed by a test quorum through the client verifier: before and after of a transfer, a recipient created in the block, a before-proof signed at protocol version 13, a pair across a quorum rotation (each side against its own quorum and Core height, the other side's signature refused), a response without the before-state, and two forgeries refused.rs-drive-proof-verifier/src/proof/state_before_block.rstests: refusals that need no signature (missing parts, another chain, a block that is not the previous one) andNotReadable.rs-dapiwait_for_state_transition_result.rstests, against a recording Drive stand-in: leases (released on drop, one per registration, released when cancelled after Drive received it, nothing to release and the permit free at once when refused (also withUNIMPLEMENTED), a release still sent after a status that does not say Drive refused, a registration permit held while Drive holds the release's reply), registration while the Tenderdash lookup is still on its way (fails with the earlier order), an indexed transaction answered without waiting for a stalled registration, a stalled registration counted within the event wait rather than added to it, a stalled registration and a stalled pair lookup, the optional-work deadline under an earlier ingress deadline, no pair lookup with no time left, an unflagged wait whose event comes after a slow Tenderdash lookup, and an unflagged wait cut off by a 300 ms client deadline through tonic and the ingress layer answeringDEADLINE_EXCEEDED(both fail with the earlier timing), the pair used only when asked for and around the executing block, a failed lookup repeated until it finds the transaction, the repeats ending once Tenderdash says it holds no such hash, and an event still ending the wait while the lookups keep failing (that one fails after 10 s, not hangs, if the lookup is never repeated).rs-drive/src/prove/prove_state_transitiontest: every protocol version declares a credit transfer's proof of fixed keys and an identity update's not.rs-drive-abci/src/query/response_metadatatest: an unknown metadata generation is refused.rs-dapiserver/grpc.rstests: the ingress layer hands the service its optional-work deadline, and none when the client's deadline is shorter than the margin.cargo testfiltered to the above indrive-abci,drive,drive-proof-verifier,rs-dapi,dapi-grpc(protobuf_request_errors),platform-versionanddash-sdk;cargo clippy --all-features --all-targets -D warningson those crates;cargo check --workspace --all-targets;cargo check -p drive --no-default-features --features verify;yarn workspace @dashevo/dapi-grpc test:unit;.github/scripts/check-grpc-coverage.py.rs-dapitests that only talk to the in-memory Drive stand-in and measure a limit run on tokio's paused clock; the ones that need the Tenderdash stand-in over a real socket hold its answer behind a gate instead of sleeping, or compare against the widest window the code allows.Breaking Changes
None for consensus or on the wire: the new RPCs, request flag and response field are additive, and a client that does not set the flag gets the same response as before.
Rust API:
dapi_grpc::drive::v0::drive_internal_server::DriveInternalgains three required methods; code that buildsWaitForStateTransitionResultRequestV0orWaitForStateTransitionResultResponseV0with a struct literal must addprove_state_before_block: falseorstate_before_block: None;DriveVerifyStateTransitionMethodVersionsgains a field.TypeScript: the generated web client type
WaitForStateTransitionResultRequestV0.AsObjectgains a requiredproveStateBeforeBlock; a typed object literal must addproveStateBeforeBlock: falseto keep today's request.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 ·
9949742/self-reviewedrust-dapi(packages/rs-dapi/src/clients/tenderdash_client.rs,packages/rs-dapi/src/clients/tenderdash_websocket.rs,packages/rs-dapi/src/server/grpc.rsand 6 more) — lklimek or shumkovrs-drive-abci— you own itrs-drive— you own itrs-platform-wallet-ffi(packages/rs-platform-wallet-ffi/src/identity_top_up/submission_result_tests.rs) — HashEngineering or ZocoLini or llbartekll or romchornyirs-platform-wallet(packages/rs-platform-wallet/src/wallet/identity/network/top_up_from_addresses/external_identity_tests.rs) — HashEngineering or ZocoLini or llbartekll or romchornyirust-sdk(packages/rs-sdk/src/platform/transition/broadcast_request.rs,packages/rs-sdk/src/sdk/quorum_key.rs,packages/rs-sdk/tests/fetch/broadcast.rs) — lklimek or shumkovjs-wasm-sdk(packages/wasm-sdk/src/queries/system.rs) — shumkovWhen every merge requirement is met, the
PR Hygienecheck passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.