Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 57 minutes. View limit details
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. |
|
✅ Final review complete — no blockers (commit 4213ebe) · triage: normal |
3f68557 to
5aa802d
Compare
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
5aa802d to
c0a4e1c
Compare
|
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.
Final validation — Phase 1 + Phase 2
Changes requested: 6 blockers
- Caught-up subscriptions keep sending checkpoints after Tenderdash stops answering —
packages/rs-dapi/src/services/platform_service/subscribe_to_state_transitions/stream.rs:145-149(new)
Impact: An app following the tip can stop receiving new matches without getting a stream error or triggering the SDK's idle failover. - Canceled subscription reads free fetch slots before Tenderdash finishes —
packages/rs-dapi/src/services/platform_service/subscribe_to_state_transitions/block_source.rs:218-225(new)
Impact: When block reads are slow, reconnecting subscribers can add new work while the previous reads are still competing with other Tenderdash requests. - Subscription limits and pruned history can ban nodes that still serve ordinary queries —
packages/rs-sdk/src/platform/subscriptions.rs:394-397(new)
Impact: An app whose subscriptions fill a node's quota or request history the node no longer retains can temporarily lose unrelated SDK queries through that node. - An unchecked checkpoint can skip requested replay and make healthy nodes look unavailable —
packages/rs-sdk/src/platform/subscriptions.rs:511-530(new)
Impact: A client that saves a bad checkpoint can lose its replay position and, on reconnect, lose access to nodes that are otherwise serving correctly. - Malformed bytes from one node end a resumable subscription with an upgrade error —
packages/rs-sdk/src/platform/subscriptions.rs:551-559(new)
Impact: A subscriber with a valid resume cursor can stop receiving events and be told to upgrade even though another node can serve the block to the current SDK. - Historical replay runs CPU-heavy matching on the workers that serve ordinary RPCs —
packages/rs-dapi/src/services/platform_service/subscribe_to_state_transitions/stream.rs:398-408(new)
Impact: Concurrent catch-up subscriptions on a busy document contract can delay unrelated requests, even when the blocks are cached and no transitions match.
This PR adds a Tenderdash-backed stream for committed state transitions, with document and address filters, checkpoint-based replay, automatic Rust SDK reconnects, and an Envoy route. On this head, the Drive and rs-dapi image builds, Rust workspace and wasm32 checks, and end-to-end suites passed; review and PR Hygiene checks are still pending. Seven additional verified suggestions are omitted from the inline review budget.
🔴 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: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 7: 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) — Beyond the generated bindings, this is an intricate streaming change that adds a peer-facing deserialization path inpackages/rs-sdk/src/platform/subscriptions.rs::decode, where remote nodes supply both the state-transition bytes and the protocol version used to decode them. - 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
🤖 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/subscribe_to_state_transitions/stream.rs`:
- [BLOCKING] packages/rs-dapi/src/services/platform_service/subscribe_to_state_transitions/stream.rs:145-149: Caught-up subscriptions keep sending checkpoints after Tenderdash stops answering
Impact: An app following the tip can stop receiving new matches without getting a stream error or triggering the SDK's idle failover.
An unreadable backend looks like a quiet chain until the stream is forced to reconnect. Once the tracker has published a nonzero height, failed tip probes only produce a debug log. `current_tip` still accepts that height for new streams, and the caught-up scan keeps sending ten-second checkpoints that satisfy the SDK's silence detector. Publish backend health alongside the last readable tip and end affected streams with `UNAVAILABLE` after a bounded failure interval. Test sustained probe failures separately from successful probes at an unchanged height.
- [BLOCKING] packages/rs-dapi/src/services/platform_service/subscribe_to_state_transitions/stream.rs:398-408: Historical replay runs CPU-heavy matching on the workers that serve ordinary RPCs
Impact: Concurrent catch-up subscriptions on a busy document contract can delay unrelated requests, even when the blocks are cached and no transitions match.
Neither the fetch semaphore nor response backpressure bounds matching work. `match_block` runs synchronously on one of DAPI's four Tokio workers after the read completes. For each document transition, a subscription can test up to 16 filters with 12 alternatives each; constrained alternatives can copy the same document and regenerate its stored fields repeatedly. A nonmatching block does not reach a response send, and a cache miss also performs synchronous base64 decoding, hashing, and transition decoding. Put conversion and matching behind bounded blocking work, preserve capacity for ordinary RPCs, and reuse the stored document form across alternatives that test the same transition.
In `packages/rs-dapi/src/services/platform_service/subscribe_to_state_transitions/block_source.rs`:
- [BLOCKING] packages/rs-dapi/src/services/platform_service/subscribe_to_state_transitions/block_source.rs:218-225: Canceled subscription reads free fetch slots before Tenderdash finishes
Impact: When block reads are slow, reconnecting subscribers can add new work while the previous reads are still competing with other Tenderdash requests.
The advertised eight-call limit does not bound outstanding backend work. The fetch future owns the permits, so a stream disconnect through `unless_closed` or a read timeout can release them after the RPC has been dispatched. Tenderdash's deployed `v2.0.0-dev.3` block handlers ignore the request context and continue their store reads. Follow the neighboring block queries' `run_holding_permit` pattern: keep queued work cancellable, let the dispatched task own the permit through completion, and put the deadline on the stream's wait for the shared result. Test that a timed-out waiter exits without freeing a slot before the backend finishes.
In `packages/rs-sdk/src/platform/subscriptions.rs`:
- [BLOCKING] packages/rs-sdk/src/platform/subscriptions.rs:394-397: Subscription limits and pruned history can ban nodes that still serve ordinary queries
Impact: An app whose subscriptions fill a node's quota or request history the node no longer retains can temporarily lose unrelated SDK queries through that node.
Replay eligibility and stream admission change the shared SDK address pool. A pruned height returned as `FAILED_PRECONDITION` reaches `blame` both during streaming and on open; `blame` bans the address for all methods by default. A fully pruned page takes a different path: Tenderdash rejects the range before returning metas, and DAPI maps that rejection to `UNAVAILABLE` rather than the documented history refusal. Admission's `RESOURCE_EXHAUSTED` can also cause a shared ban on open because the transport request inherits `ban_busy_address = true`. Classify missing history explicitly, keep replay exclusions local to the subscription or cursor, and opt out of busy-address bans for this RPC as the neighboring block queries do. Test that a node refusing the stream can still serve a current-state query.
- [BLOCKING] packages/rs-sdk/src/platform/subscriptions.rs:511-530: An unchecked checkpoint can skip requested replay and make healthy nodes look unavailable
Impact: A client that saves a bad checkpoint can lose its replay position and, on reconnect, lose access to nodes that are otherwise serving correctly.
Switching nodes does not recover from a checkpoint that has already poisoned the resume cursor. The endpoint promises that opening at `h` starts with a checkpoint at `h - 1`, but the SDK accepts a higher checkpoint and even accepts a transition before the opening checkpoint. It also accepts subsequent forward jumps without corroboration. If the saved cursor is more than 1,000 blocks ahead of another node, that node returns `UNAVAILABLE`, which the default open executor can turn into a shared ban. Require the opening checkpoint on every stream, verify its exact height for explicit starts, corroborate implausible forward jumps against proved height metadata, and distinguish a cursor-ahead refusal from a node-health failure.
- [BLOCKING] packages/rs-sdk/src/platform/subscriptions.rs:551-559: Malformed bytes from one node end a resumable subscription with an upgrade error
Impact: A subscriber with a valid resume cursor can stop receiving events and be told to upgrade even though another node can serve the block to the current SDK.
The SDK treats a matching hash as evidence that other nodes would return the same bytes, although the unproved response supplies both. Every decode error becomes terminal `Undecodable`; the existing test confirms that malformed bytes at a supported version never trigger a reconnect. The decoder also accepts trailing bytes even for blocks whose protocol selects exact consumption, so some malformed items pass rather than fail. Preserve typed decode outcomes and resume on another node for bad encoding under a supported version. Keep the local depth bound distinct, corroborate an unknown-version diagnosis before requiring an upgrade, and select permissive or exact decoding from the existing protocol slot.
In `packages/dash-platform-queries/src/subscriptions/participants.rs`:
- [SUGGESTION] packages/dash-platform-queries/src/subscriptions/participants.rs:36-39: A shield with no surplus matches an address it never credits
Impact: A wallet watching `RECIPIENT` can receive a successful shield notification even though the watched address received no credits.
The matcher reports every named `surplus_output` as a recipient, but the proto, Rust role and endpoint docs describe a recipient as an address the transition credits. The wallet's single-recipient funding flow can supply that address while shielding exactly the lock value minus the fee. Drive emits the address balance addition only for positive surplus, which depends on execution state, not just the serialized transition. Either define `RECIPIENT` consistently as a named potential output and test zero surplus, or use execution-derived effects to preserve the actual-credit guarantee.
In `packages/dapi-grpc/protos/platform/v0/platform.proto`:
- [SUGGESTION] packages/dapi-grpc/protos/platform/v0/platform.proto:189-190: The public Node and browser DAPI clients do not expose the new stream
Impact: JavaScript users of the documented `v0.PlatformPromiseClient` get an undefined method when they try to open a state-transition subscription.
The service descriptors and messages expose the RPC, but `node.js` and `browser.js` export handwritten Platform wrappers, and neither forwards `subscribeToStateTransitions`. The existing Core wrappers already show how to return a stream without promisifying it. Add and test equivalent forwarding in both Platform wrappers; this does not require the deferred wasm-sdk or js-evo-sdk bindings.
In `packages/dash-platform-queries/src/subscriptions/proto.rs`:
- [SUGGESTION] packages/dash-platform-queries/src/subscriptions/proto.rs:107-126: Nested filter operands are copied recursively before the encoder can reject them
Impact: A Rust caller passing a deeply nested operand can exhaust its thread stack instead of receiving a local invalid-operand error.
`narrowed` walks nested arrays and clones unsupported containers before the shared encoder checks whether the operand is a scalar or a flat list. The pre-pass also makes subscriptions send representable 128-bit integers as numbers while V1 document queries send the same values as decimal text, which the typed integer path rejects. Handle representable integers during one depth-bounded encoding traversal, and define and test the behavior for out-of-range integers and unsupported containers.
In `packages/dash-platform-queries/src/documents/from_proto.rs`:
- [SUGGESTION] packages/dash-platform-queries/src/documents/from_proto.rs:1-3: Subscriptions and document queries maintain separate decoders for the same wire clause
Impact: An operator or operand-validation fix applied to only one decoder can make the two RPCs interpret the same protobuf clause differently.
The new module copies the ordinary operator mapping, typed operand decoding and list-depth check from Drive ABCI's V1 document query. The comment is the only synchronization between them. Keep the schema-independent decoding in `dash-platform-queries`, which Drive ABCI already depends on, and map shared decode errors to the endpoint's `QueryError::InvalidArgument`. Window resolution can remain endpoint-specific without introducing a gRPC dependency in Drive.
|
Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix; thepastaclaw left review threads unresolved; resolve them. |
|
Your move: thepastaclaw left review threads unresolved; resolve them. |
…ment schema DriveDocumentQueryFilter had no consumer, and clause values only matched transition values sent in the same encoding: an identifier as bytes never equalled one as base58 or Identifier, and a u8 field never equalled a U64 operand. Clause values and the transition values a clause reads are now both brought to the form the schema stores, element by element on typed arrays, so filters match regardless of how a client encoded an operand. Clauses on fields outside the schema are refused before their value is decoded, and null never satisfies an ordered comparison. The filter is generic over how it holds its contract, so a subscription builds its filters once instead of per transition. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A server-streaming Platform RPC that delivers committed, successfully executed state transitions matching any of up to 16 document or address filters, interleaved with checkpoints a client resumes from. Drive answers it with unimplemented; DAPI serves it. Generated clients are regenerated. BREAKING CHANGE: platform_server::Platform gains the subscribe_to_state_transitions method and its stream type, which implementations must add. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dash_platform_queries::subscriptions defines the request's document and address filters, their wire conversion, and ResolvedFilters, which binds document filters to their contracts and tells which filters a transition matches. Address roles are classified in one exhaustive match over every StateTransition variant, so a new variant does not compile until it is classified. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…block store Each subscription walks committed heights with its own cursor, up to the highest height whose execution results are saved, so history and new blocks are read the same way and a missed websocket event cannot lose a block. Block and meta-page reads are single-flight, shared through a byte-bounded cache, and limited to 8 Tenderdash calls in flight. A height is never skipped: an undecodable transaction, an unknown protocol version or a pruned height ends the stream there. Limits: 256 subscriptions per node, 16 per source, starts within 50k blocks behind and 1k ahead of the tip, and a client that does not read for 60 s is ended with RESOURCE_EXHAUSTED after its buffered messages. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The gateway route uses the Core streams' timeouts and replaces the route for subscribePlatformEvents, which has no RPC behind it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sdk::subscribe_to_state_transitions returns a subscription that checks each transition's hash, decodes it with a bounded value depth, and resumes from the last checkpoint on another node with capped backoff. A node that sends a wrong hash, bad match indexes or a regressing checkpoint is banned; a transition the SDK cannot decode ends the subscription instead, since every node would send the same bytes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…are rebased onto The subscription commits were written against an older v5.2-dev. Rebased onto the before/after block proofs, they meet code that did not exist then: - dash-platform-queries: classify the two variants added since. A private document create from the shielded pool names no platform address. A document erase has no action a filter can name, so only a document filter without actions delivers it; a test covers that. - rs-dapi: the stream now reads blocks through the calls getBlocks and getOwnerTransactionsInBlock use, which have no deadline. Keep the 30 second deadline the stream's reads had, so a stream fails and the client resumes elsewhere instead of stalling. - rs-dapi-client: declare the protocol version from which every node serves subscribeToStateTransitions and list the method in the request inventory. - rs-sdk: fill the new ExecutionError field in a test, drop an import that is no longer used, and run the deep-value test on a thread with enough stack. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…tocol 16 A 5.1 node does not know subscribeToStateTransitions. It answers UNIMPLEMENTED, which gets it banned. The request declares the protocol version from which every node serves it, but Sdk::subscribe_to_state_transitions opened the stream without checking. It now asks the gate the fetch paths ask, once, before the first stream. On a network not proven at protocol version 16 the call fails with ProtocolVersionNotActive and nothing is sent. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…address An identity creation from the shielded pool names an address that is credited only when the identity cannot be created. The transition then fails, and a subscription delivers only transitions that succeeded. So an address filter matched that address exactly when it was not credited. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
- A transition that failed is never delivered, even one that was charged for and still changed the balance of an address it names. - A document erase is delivered only by a filter that lists no actions. The Objective-C header carries the proto comments, so it is regenerated. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…criptions Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ly flat clause values Review fixes in the subscription filters: - decode_committed_state_transition decodes a transition the way the block's protocol version decoded it for execution: from the version that takes a raw transition to be exactly one encoded transition, bytes left over after it are refused. rs-dapi and the SDK both decoded leniently at every version. - A clause value is a scalar or a flat list of scalars. A nested list or a map was walked and copied in full before the encoder refused it, which a deep value could exhaust the stack with. It is now refused where it starts. - A recipient is an address a transition names as an output. Whether it is credited is for execution to say: a shield from an asset lock names where its surplus goes and may leave none. The docs said "credits"; they now say so, and a test pins the surplus address of a shield that leaves nothing. The Objective-C header carries the proto comments, so it is regenerated. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…d them when the tip cannot be read Review fixes in the stream: - A Tenderdash read keeps its share of the fetch budget until Tenderdash has answered it. The budget was held by the future of whoever waited, so a stream that went away or stopped waiting freed it while Tenderdash still worked on the read, and reconnecting clients could pile work on a slow node. The read now runs in a task that owns the permits, as the block queries do; the 30 second deadline is on the wait, queueing for the budget included. - Blocks are decoded on the blocking pool, inside that task, and matched there too, two blocks at a time across all subscriptions. Both ran on the four async threads that serve every other request. - The tip carries whether the node could read it. Once reading it has failed for 30 seconds, streams that have caught up end with UNAVAILABLE and new ones are refused. They kept sending checkpoints, which say the chain is quiet and keep the client from moving to a node that works. - A range of metas wholly below the store's base is read as heights the node does not keep. Tenderdash refuses such a range, which was answered as UNAVAILABLE, where a range that reaches the base was answered as FAILED_PRECONDITION. - A start ahead of the node's tip is FAILED_PRECONDITION, as a pruned height is: the node lacks the height and is not failing. UNAVAILABLE is retried by the client's executor, which bans the node for it. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ame one rule for where to resume Two suggestions from the review that approved the subscription stream: - A stream that opens before the tip is known asks Tenderdash for it, one status call at a time. Many clients open at once after a restart, and the ones still waiting their turn did not see the tracker publish the tip: with a status that takes seconds, the last of them ran out of time though the tip was known. They now take the tracker's publication when it comes first. - The proto comment, the endpoint doc and two stream errors still said to resume from the last checkpoint. A client that reads the stream itself and does so moves its place to resume from back when a node starts at its tip. They now give the one rule the SDK follows: the height to resume from is the greater of the one held and a checkpoint plus one. The Objective-C header carries the proto comments, so it is regenerated. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
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: This revision lets a subscription use the tracker’s published tip while its own startup read is still pending, and documents how raw RPC clients can keep their resume height from moving backward. No CI checks had failed at review time; the Rust workspace and wasm32 tests, JS and NPM builds, and Docker image builds were still pending.
🟡 1 suggestion(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: muse-spark-1.3-contributor (agent: phase1-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); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.2-sol(effort low) — The intricate streaming implementation adds peer-facing deserialization inpackages/rs-sdk/src/platform/subscriptions.rs, where the SDK decodes state-transition bytes supplied by remote DAPI nodes according to the reported protocol version. - 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
🤖 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/subscribe_to_state_transitions/stream.rs`:
- [SUGGESTION] packages/rs-dapi/src/services/platform_service/subscribe_to_state_transitions/stream.rs:561-566: Raw RPC clients get conflicting resume advice when a replacement stream opens behind them
Impact: A raw RPC client that follows a read or decode error from a lagging replacement node can rewind its saved cursor and replay blocks it already processed.
A client holding resume height 101 can reopen on a node at height 95 and then be told to resume from 96 if that block fails to read once the node reaches it. The endpoint guide correctly tells the client to keep 101, but `read_failure` and both error branches in `matches_in` still prescribe the failed block’s height. Keep the block height as diagnostic information and remove the resume-height advice from all three errors; only the client knows the cursor it already holds.
|
Bots are done — your move: post |
…height to resume from Three statuses that end a stream told the client to resume from the block that ended it: a block that cannot be read, one executed under a protocol version the node does not know, and one with a transaction the node cannot decode. A node asked to start above its tip starts at its tip, so that block can be below the height the client holds. A client holding 101 that reopens on a node at 95 was told to resume from 96, and one that followed the status moved its place back and replayed blocks it had processed. The statuses now name the block and leave the height to the client, which is the only one that knows it. The rule stays where it is stated once: the height to resume from is the greater of the one held and a checkpoint plus one. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
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: This head removes explicit restart heights from three subscription failure messages without changing their gRPC codes, and adds regression coverage for a decode failure below the requested start and a timed-out block read. GitHub reports no failed code checks; NPM release build validation, macOS generation, and changed-package detection are still pending.
🟡 1 suggestion(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.
Still open from earlier rounds (1)
- 🟡 Suggestion: Raw RPC clients get conflicting resume advice when a replacement stream opens behind them —
packages/dapi/doc/endpoints/streams/subscribeToStateTransitions.md:46-52(thread)
Review provenance
Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); reviewer 3: gpt-6.2-astra (agent: phase2-reviewer, role: general); reviewer 4: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 5: gpt-6.2-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 6: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 7: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.2-sol(effort low) — The change is intricate and adds peer-facing deserialization in packages/rs-sdk/src/platform/subscriptions.rs, where the SDK decodes state-transition bytes supplied by remote DAPI nodes. - 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
🤖 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/dapi/doc/endpoints/streams/subscribeToStateTransitions.md`:
- [SUGGESTION] packages/dapi/doc/endpoints/streams/subscribeToStateTransitions.md:46-52: Raw RPC clients get conflicting resume advice when a replacement stream opens behind them
(carried; thread: https://github.com/dashpay/platform/pull/6249#discussion_r4698463882)
|
Bots are done — your move: post |
…scriptions-on-6038 Conflicts: - packages/dapi-grpc/build.rs: VERSIONED_REQUESTS holds both sides' additions (the two emergency switch requests and the subscription request), 78 entries. - the Java and Python Platform clients: regenerated from the merged proto with `yarn build` in packages/dapi-grpc. The other generated clients merged to what the generator writes. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
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: This head merges the updated v5.2-dev base branch; the subscription implementation and its prior fixes are unchanged since the last reviewed commit. CI has no failed code checks, while Kotlin SDK, NPM validation, changed-package detection, macOS generation, and PR Hygiene checks remain pending.
🔴 0 blocking | 🟡 0 suggestion(s) | 💬 0 nitpick(s)
Review provenance
Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); reviewer 3: gpt-6.2-sol (agent: phase2-reviewer, role: general); reviewer 4: gpt-6.2-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 5: gpt-6.2-sol (agent: phase2-reviewer, role: rust-quality); reviewer 6: gpt-6.2-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)
- Triage:
normalbygpt-6.2-sol(effort low) — This is a large, intricate cross-cutting API and streaming change, but it does not modify consensus, funds, cryptography, storage migrations, or other critical surfaces as defined. - 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) - Fresh verifier:
gpt-6.2-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.2-sol— general (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— rust-quality (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— security-auditor (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: It lets an app ask a node "tell me when something I care about happens" instead of asking again and again. The app names what it cares about (documents on a contract, or Platform addresses), and the node sends each matching transaction as soon as its block is final. This is the work of #5285 by PastaPastaPasta, brought up to date with today's
v5.2-devand finished for review. #5285 itself is untouched.Value: Apps and wallets stop polling. A wallet watching its addresses, or an app watching a document type, learns of a change within one block and makes one long-lived request instead of many short ones. Nodes answer from blocks they already store, so Drive and block execution do no extra work.
Risks: Medium, and outside consensus. No code that runs during block execution changes. The new risk is load on a node's API side: each stream holds a connection open, bounded by 256 streams per node and 16 per source, with reads and matching bounded too. The stream is the node's word, not a proof, so a client must still read state with a proved query before acting. Not yet run on a live network.
Issue being fixed or feature implemented
Closes #5274.
Applications that react to Platform activity poll for it today, and a wallet watching its addresses does the same. Polling cost grows with users times feeds, runs into the gateway's per-IP limit, and notices changes late.
#5285 adds
subscribeToStateTransitions, a server-streaming Platform RPC, for this. It was written against av5.2-devthat is now about 470 commits old and no longer merges. This branch carries its six commits on today'sv5.2-dev, which since gained the block queries (#6038), protocol version 16 (#6253) and two new kinds of transition. If this merges, #5285 can be closed.What was done?
The feature (commits 1 to 6, by PastaPastaPasta, author and messages kept; #5285 describes each in full):
feat(drive):DriveDocumentQueryFiltercompares values in the form the schema stores, so one value in two encodings matches. It is generic over how it holds its contract, so a subscription builds it once.feat(dapi)!: the RPC, its messages and the regenerated clients. A request carries 1 to 16 filters and an optional start height. A response is a match (height, time, protocol version, hash, bytes, which filters and batch positions matched) or a checkpoint.feat(sdk):dash_platform_queries::subscriptions: the filter types, their wire form, andResolvedFilters, which binds document filters to their contracts and matches transitions.feat(rs-dapi): the stream, served from the Tenderdash block store. Each subscription walks committed heights with its own cursor and never skips one. Reads are shared through a bounded cache, with at most 8 Tenderdash calls in flight.feat(dashmate): an Envoy route with the Core streams' timeouts.feat(sdk):Sdk::subscribe_to_state_transitions, which checks each transition's hash, resumes from the last checkpoint on another node, and bans a node that sends something invalid.What bringing it onto today's
v5.2-devtookplatform.proto,VERSIONED_REQUESTSindapi-grpc/build.rs(now 78), the metrics allowlist, imports,Cargo.tomlandCargo.lock.yarn workspace @dashevo/dapi-grpc build, not merged by hand.rs-drive/src/query/filter.rs: keeps the newerrefuse_state_generated_fieldscheck and theErasearm next to feat(platform)!: subscribe to committed state transitions matching document and address filters #5285's genericDriveDocumentQueryFilter<C>.rs-dapi/src/clients/tenderdash_client.rs: both branches addedblock,block_resultsand the types they return. The versions already onv5.2-devstay (getBlocksandgetOwnerTransactionsInBlockuse them), and from feat(platform)!: subscribe to committed state transitions matching document and address filters #5285 only what was missing is added: theblockchaincall withBlockMetaandResultBlockchainInfo,nullaccepted forExecTxResult.events, and the decoding tests. The stream and the block queries now read blocks through one client.What changed compared with #5285
On the node (
rs-dapi)A stream never starts above the node's tip:
A checkpoint says every height up to it was scanned, and a node cannot say that of heights it has not reached.
A read keeps its place until Tenderdash answers. At most 8 Tenderdash calls are in flight. A call now counts against that until Tenderdash has answered it, whether or not a stream still waits, and none of the calls the stream makes (block, results, metas, status) has a deadline of its own. Before, a client that left, or a wait that timed out, freed the place while Tenderdash was still working, so reconnecting clients could pile work on a slow node. One status call is in flight at a time, so a slow status takes one place and not the ones block reads need.
A stream that opens before the node knows its tip takes the tip as soon as the node has it:
A stream waits 30 seconds for a read, from when it asks, whatever the read waits on in turn (its turn to match, another stream reading the same block, the 8 places, Tenderdash). It then ends with
UNAVAILABLE.Decoding and matching run on the blocking pool, not on the four async threads that serve every other request. A stream holds a decoded block only while it has one of two places to match it.
A node that cannot read its chain tip says so:
Missing history is always
FAILED_PRECONDITION. A range wholly below the store's base, a block pruned after its metas were read, and a start too far ahead of the node's tip were answered asUNAVAILABLE, which says the node is failing.A status that ends a stream names the block that ended it, and no height to resume from:
The same holds for a block the node cannot decode, or one executed under a protocol version it does not know.
In the SDK (
dash-sdk)The SDK refuses to subscribe until the network runs protocol version 16. A 5.1 node does not know the method. The request declares the version (
needs_protocol_version, listed inrs-dapi-client/tests/request_inventory.rs), andSdk::subscribe_to_state_transitionschecks it before the first stream, the way the fetch paths do for every other method a release added:A node that only lacks history, or has no room for another stream, is not banned:
The place to resume from only moves up, and so do the checkpoints an app is given. Every stream must open with a checkpoint, no higher than the height before its start:
Within one stream a checkpoint never goes back.
Bytes the SDK cannot decode must come from two nodes before it blames itself:
Leftover bytes: rs-dapi and the SDK decode a committed transition as its block's protocol version did, which from protocol version 14 refuses bytes left over after the transition. A decoder generation this build does not know is refused, as execution refuses it.
SDK tests: the new
ExecutionError::possibly_acceptedfield, and a 16 MiB stack for the test that builds a value 300 levels deep (the pattern the other deep-value tests use).In the filters (
dash-platform-queries)A private document create from the shielded pool names no Platform address, so no address filter matches it.
A document erase (the purge of a deleted document's retained revisions) has no action a filter can name. Drive's filter already refuses to describe an erase by content. So it is delivered only by a filter without actions:
An
ERASEaction can be added to the proto later without breaking clients.An address filter no longer matches the fallback address of an identity creation from the shielded pool. That address is credited only when the identity cannot be created, and the transition then fails. A failed transition is never delivered, so every delivered one named the address without crediting it:
RECIPIENTmeans named as an output. Whether a named output is credited can depend on execution: a shield from an asset lock names where its surplus goes and may leave none. The proto and docs said "credits"; they now say what is matched.A clause value is a scalar or a flat list of scalars. A nested list or a map is refused where it starts, without being walked.
Elsewhere
dapi-grpc): the Node and browserPlatformPromiseClientforwardsubscribeToStateTransitionsand return the stream, as the Core clients do for theirs.platform.proto,subscribeToStateTransitions.md): a transition that failed is never delivered, even one that was charged for and still changed an address balance (the fee taken from an address input, or the fallback credit above). A wallet learns of those fromgetRecentAddressBalanceChangesor a proved balance read.dash-platform-queriesfor its tests only. A test there now fails when the two read a clause differently.Not in this PR
getBlocksreturns when asked to prove), or a proved read during the stream. A signature would not show that nothing below a true height was left out; that takes a second node.getBlocksandgetOwnerTransactionsInBlockanswers are still decoded leniently at every protocol version.DriveDocumentQueryFilter).oneoftakes new filter kinds later without breaking clients.How Has This Been Tested?
On macOS (arm64), debug builds, on this head (which merges
v5.2-devat 58d2566):cargo test -p rs-dapi --lib: 526 passed. This includes the stream tests (the scan loop against an in-memory chain: replay then live without gaps, start heights in and out of the window, idle checkpoints, per-source limits, stalled clients) and the Tenderdash decoding tests. New here: a start ahead of the tip begins at the tip and scans every block after it; a read nobody waits for keeps its place until Tenderdash answers; a slow status holds one place however many ask for it; a stream that opens while its own status call waits takes the tip the tracker publishes; a second reader of a stalled block, and a scan queued for its turn to match, give up 30 seconds after they asked; a range wholly below the store's base, and a block pruned after its metas were read, are heights the node lacks; a caught-up stream keeps checkpointing while the tip is read at one height and ends once it cannot be read; a status that ends a stream names its block and no height to resume from.cargo test -p dash-platform-queries --lib subscriptions: 24 passed. New here: an erase reaches only a filter without actions; no address filter matches the fallback address of an identity creation; a shield's surplus address matches whatever it is credited; a nested list or a map, 100,000 levels deep in one case, is refused without being walked; a committed transition decodes by its block's decoder generation, and an unknown generation is refused.cargo test -p dash-sdk --lib -- subscriptions protocol_gate: 102 passed. New here: subscribing is refused until the network is verified at protocol version 16; a node lacking heights is passed over and not banned; a stream that opens above its start, lower than a node may start, or without a checkpoint is a node fault; a stream that opens below the place to resume from has its matches delivered and its checkpoints kept back, and a break reopens at the place asked for; what is committed after the next stream opens is delivered; undecodable bytes end the subscription only when a second node delivers them, and one node repeating them three times ends it without the upgrade advice; leftover bytes are refused where the protocol refuses them; the subscription ends after 8 nodes in a row lack the heights.cargo test -p drive-abci --lib query::document_query::v1::conversions: 1 passed, the test that holds the two where clause decoders together.cargo test -p rs-dapi-client --test request_inventory: 5 passed, 1 ignored (it rewrites a committed file).cargo test -p drive --lib query::filter: 85 passed.yarn workspace @dashevo/dapi-grpc test:unit: 83 passed, 6 of them new for the two JavaScript clients;yarn lintis clean.python3 .github/scripts/check-grpc-coverage.py: passes.cargo check --locked -p wasm-sdk --target wasm32-unknown-unknown --lib: builds, sodash-sdkwith the subscription module type-checks forwasm32.cargo fmt --all -- --checkandcargo clippy --all-targets --all-features --locked -- --no-deps -D warningsondash-platform-queries,rs-dapi,rs-dapi-client,dash-sdk,dapi-grpc,driveanddrive-abci: clean.Not done: no run against a local network or devnet; the network-only test
tests/fetch/state_transition_subscriptions.rsonly compiles.Public interface changes
gRPC (
platform.proto), additiverpc subscribeToStateTransitions(SubscribeToStateTransitionsRequest) returns (stream SubscribeToStateTransitionsResponse).SubscribeToStateTransitionsRequestwithDocumentFilter(contract, optional document type, up to 12ActionMatchalternatives, optional batch owner),AddressFilter(up to 256 addresses and aRole:ANY,SENDER,RECIPIENT) and an optionalfrom_block_height.SubscribeToStateTransitionsResponse: aStateTransitionMatchor aCheckpoint.from_block_heightabove the block after the node's tip is scanned from that block. The first checkpoint is then lower thanfrom_block_height - 1, and matches belowfrom_block_heightcan be delivered again. In feat(platform)!: subscribe to committed state transitions matching document and address filters #5285 the node waited for the height and delivered nothing before it. A client that reads the stream itself resumes from the highest checkpoint it received, not the last: its height to resume from is the greater of the one it holds (the height it first asked to start at included) and a checkpoint plus one.rs-dapi. Drive'sQueryServiceanswersUNIMPLEMENTED; the gateway routes the method tors-dapi.INVALID_ARGUMENT(malformed or undecidable filter),NOT_FOUND(unknown data contract),OUT_OF_RANGE(start behind the replay window),RESOURCE_EXHAUSTED(limits, or a client that does not read),FAILED_PRECONDITION(the node no longer keeps a block, is more than 1,000 blocks short of the start height, or cannot decode a block),UNAVAILABLE(the node cannot read from Tenderdash, its chain tip included). Compared with feat(platform)!: subscribe to committed state transitions matching document and address filters #5285, a start too far ahead of the node's tip and pruned heights moved fromUNAVAILABLEtoFAILED_PRECONDITION, and a status message names the block that ended the stream but no height to resume from.dash-sdkSdk::subscribe_to_state_transitions(filters, from_block_height, config) -> Result<StateTransitionSubscription, Error>. It fails withError::ProtocolVersionNotActiveuntil a verified answer shows the network at protocol version 16.platform::subscriptions:StateTransitionSubscription(next,resume_height,into_stream),SubscriptionEvent,StateTransitionEvent,SubscriptionConfig.StateTransitionSubscription::nextends with an error when the request is refused, a live start breaks before its first checkpoint, two nodes deliver bytes the SDK cannot decode (or the only node that answers delivers them three times), or 8 nodes in a row lack the heights asked for. Anything else is resumed.SubscriptionEvent::Checkpointis never lower than the one before it, andresume_heightnever goes down, so the last checkpoint is the one to save. AStateTransitionevent can be for a height below the last checkpoint: a transition delivered again by a node that started at its tip.dash-platform-queriessubscriptions:StateTransitionFilter,DocumentFilter,DocumentActionMatch,DocumentAction,Role,ResolvedFilters,FilterMatch,SubscriptionFilterError,subscribe_request,check_filter_count,decode_committed_state_transition,MAX_START_ABOVE_TIPand the otherMAX_*limits.documents::from_proto: decoding of where clauses from their wire form.rs-dapi-clientTransportRequestis implemented forSubscribeToStateTransitionsRequest; itsneeds_protocol_version()returnsSome(16)and its settings ask not to ban a busy node (ban_busy_address: Some(false)).dapi-grpc(JavaScript)PlatformPromiseClient#subscribeToStateTransitions(request, metadata, options)in the Node client and(request, metadata)in the browser client. Both return the stream, not a promise.lib/utils/rewireStream.js, which the Core browser client now uses too in place of its own copy.driveDriveDocumentQueryFilter<'a>becomesDriveDocumentQueryFilter<C: Deref<Target = DataContract>>(breaking, see below).canonicalize_where_clause,DriveDocumentQueryFilter::canonicalize_clause_values.validate()now refuses clauses on fields outside the schema and operands that are not in canonical form.rs-dapi(crate-internal)TenderdashClient::blockchain,TenderdashClient::status_for_block_query,BlockMeta,ResultBlockchainInfo;PlatformServiceImplgains thesubscriptionsfield.dashmatesubscribeToStateTransitionsas a long-lived stream, in place of the route forsubscribePlatformEvents, which has no RPC.Breaking Changes
Both are Rust API only:
dapi-grpc:platform_server::Platformgains the associated typesubscribeToStateTransitionsStreamand the methodsubscribe_to_state_transitions. Implementations must add both; returningunimplemented, as drive-abci'sQueryServicedoes, is enough.drive:DriveDocumentQueryFilter<'a>becomesDriveDocumentQueryFilter<C: Deref<Target = DataContract>>. Code naming the type writesDriveDocumentQueryFilter<&'a DataContract>.On the wire the RPC and its messages are additive. No consensus code and no shipped protocol generation 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 ·
4213ebe/self-reviewedgithub(.github/grpc-queries-cache.json) — ktechmidas or shumkovdashmate(packages/dashmate/docs/services/gateway.md,packages/dashmate/templates/platform/gateway/envoy.yaml.dot) — ktechmidas or shumkovrust-dapi(packages/rs-dapi/Cargo.toml,packages/rs-dapi/src/clients/tenderdash_client.rs,packages/rs-dapi/src/metrics.rsand 7 more) — lklimek or shumkovrs-drive-abci— you own itrs-drive— you own itrust-sdk(packages/rs-sdk/src/platform.rs,packages/rs-sdk/src/platform/subscriptions.rs,packages/rs-sdk/src/sdk/protocol_gate_tests.rsand 2 more) — lklimek or shumkovWhen every merge requirement is met, the
PR Hygienecheck passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.