Skip to content

refactor: build Platform types with their upstream constructors - #1126

Merged
lklimek merged 38 commits into
v1.0-devfrom
refactor/dpp-constructors
Oct 28, 2026
Merged

lklimek merged 38 commits into
v1.0-devfrom
refactor/dpp-constructors

Conversation

@Claudius-Maginificent

@Claudius-Maginificent Claudius-Maginificent commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

TL;DR

DET built several Platform types by hand as struct literals. Where the upstream crates (dpp, dash-sdk and dashcore at Platform 575d961f) offer a constructor or factory, DET now uses it. This is a pure refactor: nothing changes on the wire and nothing changes for the user.

  • Public keys: PublicKey { compressed, inner } becomes PrivateKey::public_key() or PublicKey::new(...).
  • Qualified keys: QualifiedIdentityPublicKey { .. } becomes DET's own From and from_identity_public_key_in_wallet constructors.
  • New documents: DashPay contact requests, contact info and the document screen build new documents through the document type's create_document_with_prevalidated_properties, wrapped in one helper, model::document::new_document_for_creation.
  • Document replacement: the document screen clones the original and applies the document setters.
  • Test identity: the v0.9.3 upgrade test builds its identity with Identity::new_with_id_and_keys.
  • Identity keys: identity public keys that aren't bound to a contract are built with IdentityPublicKey::default_versioned plus the key setters instead of IdentityPublicKeyV0 literals. That covers the registration master key in IdentityKeySpecs and 37 test keys. The unit tests share one test_support::identity_public_key fixture; the kittest and backend-e2e tests call the factory directly.

User story / Scenario

Not applicable. This is a refactor with no change a user can see.

Detailed discussion

The wire stays the same

DocumentCreateTransitionV0::from_document takes only the base (id, nonce, type, contract), the entropy and the properties from the document. The factory differs from the old literal in two ways, and neither reaches the transition:

  • It fills required system fields such as $createdAt.
  • It leaves an immutable document type (contactRequest) without a revision.

model::document::tests::factory_document_yields_the_hand_built_create_transition builds the create transition from the old hand-built document and from the factory document for contactRequest and contactInfo at protocol versions 13 and 14, and checks that the two are equal.

The factory keeps the properties exactly as given. create_document_from_data would have rewritten identifier values, and properties go on the wire, which is why the helper doesn't use it.

The replacement path produces exactly the document the old literal did. replacing_document_keeps_identity_and_drops_platform_set_fields checks this.

Which platform version each site uses

  • DashPay tasks use sdk.version(), the version their transition builder already uses.
  • The document screen uses AppContext::platform_version().
  • The test identity uses the network's starting protocol version.
  • IdentityKeySpecs::to_public_keys_map and to_key_storage now take a platform version. Registration passes the one each path already uses: AppContext::platform_version() on the asset-lock path and sdk.version() on the platform-address path.
  • The pause, resume, destroy-frozen-funds and token-config-update tasks sign with sdk.version(), the version of the SDK that broadcasts the transition. Before, they used AppContext::platform_version(), which can differ from the task's SDK after a connection rebuild.

Identity keys stay V0

In every platform version up to 14, identity_key_structure_version is 0, so the factory yields IdentityPublicKey::V0. identity_key_specs_build_v0_keys_at_protocols_13_and_14 checks that, at protocols 13 and 14, the specs' master key in both the public key map and the key storage equals the old hand-built V0 key. The identity-create encoding on mainnet (protocol 13) is therefore unchanged.

New error paths

  • If a document can't be built, the task now returns the dedicated TaskError::DocumentPreparationFailed with a typed ProtocolError source.
  • If registration can't build its public keys map, it now returns the dedicated TaskError::IdentityKeysPreparationFailed. Its typed source is SdkError::Protocol, wrapping dpp's own error. unknown_key_structure_keeps_the_typed_protocol_error checks both the variant and the source.
  • If registration can't build its key storage, it now returns the existing TaskError::IdentityCreationError.

Before, nothing could fail at any of these steps. In practice they only fail on a protocol version this build doesn't know.

The public keys map's existing validation failures (an unsupported key type, a purpose that doesn't allow the security level) were strings. They are now IdentityKeySpecError variants, held as the typed source of TaskError::PublicKeyMapBuildFailed, and the banner text is unchanged. a_disallowed_security_level_is_a_typed_key_spec_error checks this.

The factory derives a new document's id from its document type's contract, so the type must belong to the selected contract. The contract/document-type chooser kept the selected type when the user picked another contract. It now drops a type that belongs to a different contract, which covers every document action; selecting_a_contract_drops_another_contracts_document_type checks this. As a backstop, creating a document with a type from another contract stops with its own banner: "This document type belongs to another contract. Select a document type from the selected contract and try again." creating_refuses_a_document_type_from_another_contract and the_create_banner_explains_a_document_type_from_another_contract check this.

Left as literals, because upstream has no suitable constructor

  • IdentityPublicKeyV0 keys that may be bound to a contract: no upstream setter exists for contract_bounds. There are four sites: the two in the Add Key screen and the non-master keys in IdentityKeySpecs::to_public_keys_map and to_key_storage. Each carries a comment saying why.
  • DataContractV1: DataContractFactory goes through serialization format V0, which has no fields for tokens, groups, keywords or description.
  • Documents in test fixtures: they model documents fetched from the network, with arbitrary fields.
  • DocumentV0::default() placeholder in the replace path: Document has no Default.
  • Token and contract config types, ResourceVoteV0, ExtendedEpochInfoV0, ContenderWithSerializedDocumentV0, TokenPaymentInfoV0: no constructors exist.
  • Unsigned fee-estimation dummy transitions: the upstream constructors need a signer and a real asset lock.
  • tests/migration-fixtures/v0.9.3-public-identities/fixture-writer.rs: it is compiled inside the v0.9.3 tag, so it has to keep that version's API.

Verification

  • cargo clippy --all-features --all-targets -- -D warnings is clean.
  • cargo test --all-features --lib -- backend_task::identity::tests:: ui::contracts_documents::document_action_screen::tests:: ui::helpers::tests::: 21 passed.
  • cargo test --all-features --lib ui::tokens::claim_tokens_screen::tests::: 4 passed.
  • cargo test --all-features --test kittest tokens_screen::: 4 passed.
  • The full workspace suite is left to CI.
  • backend-e2e is network-gated and was not run. It compiles under clippy --all-targets.

🤖 Co-authored by Claudius the Magnificent AI Agent

🤖 Generated with Claude Code

https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q

PR Hygiene · 37b7720

  • Bots — coderabbitai ✓ · thepastaclaw skipped after the window
  • Self-review — not asked of a bot author
  • Build green
  • Approvals
    • files with no dedicated owner (src/backend_task/dashpay/contact_info.rs, src/backend_task/dashpay/contact_requests.rs, src/backend_task/dashpay/encryption.rs and 44 more) — nobody may approve: everyone who could attested to it

When every merge requirement is met, the PR Hygiene check passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.

Summary by CodeRabbit

  • New Features
    • Document creation now uses the selected contract and document type, and reports an error when they don’t match.
    • Replacing a document preserves its existing metadata while refreshing fields set during platform processing.
  • Bug Fixes
    • Identity key setup now accounts for the active platform version and provides clearer errors for unsupported key configurations.
    • Token signing and document creation use the version information associated with the active SDK.

lklimek and others added 25 commits October 24, 2026 18:21
Pin dash-sdk, rs-sdk-trusted-context-provider, platform-wallet and
platform-wallet-storage to dashpay/platform v5.1-dev 063589bf
(5.0.0-rc.8). The lockfile moves only the Platform packages.

The upstream V019 wallet-storage migration adds a nullable asset-lock
operation id; V001-V018 are unchanged. The compatibility bridge gets the
033ecae destination snapshot it compares against, and the pin guard
records the new revision with an unchanged migration fingerprint.

BREAKING CHANGE: the wallet storage upgrade to V019 is forward only. An
older build cannot open upgraded storage; going back needs a copy of the
data directory taken before the upgrade.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
The new rust-dashcore wraps secp256k1 keys in EcdsaSecretKey and
EcdsaPublicKey, returns secret bytes as Zeroizing, and drops the
Secp256k1 context argument. Signers, single-key wallets, DashPay
derivation, address and QR handling, migrations and their tests follow
the new types. Signing stays on the non-grinding dpp::secp256k1 path,
and a parity test pins the BLS signature bytes the previous SDK made.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
Handle the dpp and SDK types the new pin adds, keeping today's behaviour:

- Document replace keeps moderated_at and moderated_by; new documents
  start without them.
- The document editor refuses typed-array fields instead of dropping
  their contents, and keeps referenced key ids as numbers.
- Shielded token events show read-only in group actions, and the
  shielded pool token settings are refused before anything is signed.
- Contested document creation states the protocol's base contest fund,
  so the SDK never auto-quotes a larger one.
- Masternode vote reads use ResourceVoteWithCount, the SDK's new vote
  type; the vote count is not used yet.
- New query fields, wallet events, wallet error variants and asset-lock
  funding modes are handled where the SDK now requires them.
- Entropy-only document ids are documented as placeholders from
  protocol 14, and deferred upstream features link to their issues.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
The SDK was pinned to the protocol 13 table, so it could not build any
protocol 14 transition or follow the versioned identity lookup. It now
starts at upstream's per-network minimum and ratchets to what proven
responses report.

- System contracts are cached per protocol version and served through
  accessors. The context provider serves them at the version the proof
  verifier asks for and fails rather than serve another version's.
- A proved epoch sets the fee multiplier and raises the protocol version.
  An older epoch than the adopted one is ignored.
- Rebuilding the connection resets the protocol version, fee multiplier
  and adopted epoch under one lock before the new SDK is published, and
  drops reads begun on the old connection.
- Capabilities read the network's version through a helper that stays
  closed for a version this build does not define.
- Contest timing reads the live version; retired vote schedules keep the
  protocol 13 notice window they were created under.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
Compare the protocol 13 client tables with a recorded snapshot, so an
upstream change to them is reviewed, and check that keys and documents
DET builds on a protocol 13 network use encodings protocol 13 decodes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
Map the refusals the new protocol adds to flows DET already offers to
dedicated TaskError variants: a full username contest, a vote choice the
contest does not allow, a name someone else asked for first, a token
that cannot be moved, a changed immutable document field, a reference to
a document type that cannot be deleted, and a moderators' fee on a
contract without moderation. Names supplied by the node stay in the
typed source only, never in the message.

Token operations that fail inside the wallet runtime keep their SDK
cause, so they are classified like any SDK error; an unclassified one
names the operation that did not complete.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
Add a dated design note for the pin, the protocol version sources, the
connection state rules and the protocol 13 guards, and point AGENTS.md
at From<SdkError> for TaskError as the SDK error reference.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
…it refusals

Protocol version 14 refusals that flows already in DET can hit get
dedicated, actionable messages, each keeping the SDK error as its source:

- an identity banned or suspended (until when) on a moderated contract;
- a gas sponsor short of credits, a gas payer the document type does not
  offer, and mixed gas payers in one batch;
- pre-programmed token distributions of one time over the limit.

An overflowing shielded note total is logged at warn: it means corrupt or
hostile sync data, not routine noise.

Tests cover contracts saved at protocol 12 loading unchanged at 13 and 14,
and contracts saved at 14 decoding at 13 and in full again at 14.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
A lookup at another version, as the proof verifier makes at a response's
version, swapped out the app's set, so each such lookup reloaded the
system contracts and the next app read reloaded them again. Each
version now keeps its own set; the app's reads keep the set they last
got for a failed reload.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
…poch

When the epoch cannot be read, the proved DPNS fallback confirmed the
SDK's version, which starts at the network's upstream minimum (14 on
devnet), as the network's. It now confirms the version of the responses
the SDK verified, and nothing before any.

Restores the completed-withdrawal status list with the reason sending
FAILED to a protocol 13 network is safe, and its test, now comparing the
protocol 13 schema with the latest one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
The derived key DET signs with is copied into secp256k1's own type,
which keeps its bytes after use. Wrap it so it is erased on drop, as the
derived key it comes from would be; signatures stay byte-identical.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
… protocol 13

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
The new refusals sent users to another document editor or token client.
They now say the app cannot edit this field type, sign this action or
change this token setting yet, in one wording, and the shielded setting
refusal sits with the token contract errors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
Also corrects the platform compatibility fixtures README: no code reads
e3cd7cf.sql any more; it is the V001-V018 checksum reference.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
The protocol version fallback takes only a version the SDK verified, and
a mock expectation's metadata is never recorded as verified, so the three
headless refresh tests saw the version stay unconfirmed. The mock now has
the SDK accept the version from metadata treated as proved, as after a
live network's signed response, and a new test pins that a response the
SDK never verified leaves the version unconfirmed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
The SDK picks each transition's encoding from the platform version DET
passes in, so these tests checked dpp's version tables rather than DET.
The mainnet start version and the contest fund cap stay covered by the
platform_info and fee_estimation tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
The SDK at this pin already tracks the version the network has proven:
it records the version of every response whose proof and quorum
signature it verified, and a rebuilt connection is a new SDK that starts
from nothing. DET's own copy, raised from proved epochs and DPNS reads
and reset on every rebuild, duplicated that state. The app now reads the
current SDK's verified version; capabilities still stay closed before a
version is proven and for one this build does not define, and network
info shows the proven number or says none is confirmed. Proved epochs
still set the fee multiplier, in epoch order and only on the current
connection.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
A connection rebuild never changes the chain, the multiplier changes once
per epoch and feeds only fee estimates, so ordering epoch reads and
dropping those begun before a rebuild guarded against nothing worth the
machinery. A proved epoch read sets the multiplier directly again; an
unavailable epoch still keeps the last known value and labels it as
such. A rebuild still reads the epoch, so the new SDK proves the
network's version again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
A released protocol's tables and each network's minimum version are
upstream's to keep fixed; DET's start is covered by
platform_version_starts_at_the_network_minimum.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
Replace hand-written `PublicKey { compressed, inner }` literals with
`PrivateKey::public_key()` where the literal copied the private key's
compression flag, and with `PublicKey::new` where it forced a compressed
key. Both produce the same value as the literals they replace.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
Use `QualifiedIdentityPublicKey::from` and
`from_identity_public_key_in_wallet` instead of struct literals, and build
the v0.9.3 upgrade test's identity with `Identity::new_with_id_and_keys`
at the network's starting protocol version, so the identity structure
follows the platform version instead of being fixed to V0 by hand.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
…tory

DashPay contact requests, contact info and the generic document screen
built new documents as hand-written `DocumentV0` literals. They now go
through `model::document::new_document_for_creation`, which derives the
placeholder id from the entropy as before and calls the document type's
`create_document_with_prevalidated_properties`, so the document structure
follows the platform version. Properties are kept exactly as given.

The factory also fills required `$createdAt`-style fields and leaves an
immutable document without a revision. The create transition carries
neither, so the transition is unchanged; a test proves it for
`contactRequest` and `contactInfo` at protocol versions 13 and 14.

Document replacement clones the original and uses the document setters
instead of rebuilding it field by field, with the same result.

A failure to build the document now surfaces as the dedicated
`TaskError::DocumentPreparationFailed`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
…factory

Identity public keys that are not bound to a contract are now built with
`IdentityPublicKey::default_versioned` plus the key setters instead of
hand-written `IdentityPublicKeyV0` literals, so the key structure follows
the platform version.

- Production: `IdentityKeySpecs` builds its master key this way.
  `to_public_keys_map` and `to_key_storage` take the platform version their
  caller already uses (`AppContext::platform_version()` on the asset-lock
  path, `sdk.version()` on the platform-address path), and `to_key_storage`
  now reports a failure as `TaskError::IdentityCreationError`.
- Unit tests: one `test_support::identity_public_key` fixture.
- Integration tests (kittest, backend-e2e): the factory and setters inline.

Keys that may be bound to a contract stay `IdentityPublicKeyV0` literals:
the key setters cannot set contract bounds. A test proves the specs' keys
are the same V0 keys as before at protocol versions 13 and 14.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between ff59f84 and 37b7720.

Files selected for processing: 47
  • src/backend_task/dashpay/contact_info.rs
  • src/backend_task/dashpay/contact_requests.rs
  • src/backend_task/dashpay/encryption.rs
  • src/backend_task/error.rs
  • src/backend_task/identity/add_key_to_identity.rs
  • src/backend_task/identity/load_identity.rs
  • src/backend_task/identity/load_identity_from_wallet.rs
  • src/backend_task/identity/mod.rs
  • src/backend_task/identity/recover_legacy_keys.rs
  • src/backend_task/identity/register_dpns_name.rs
  • src/backend_task/identity/register_identity.rs
  • src/backend_task/migration/finish_unwire.rs
  • src/backend_task/migration/single_key_restore.rs
  • src/backend_task/migration/v093_upgrade.rs
  • src/backend_task/tokens/destroy_frozen_funds.rs
  • src/backend_task/tokens/pause_tokens.rs
  • src/backend_task/tokens/resume_tokens.rs
  • src/backend_task/tokens/update_token_config.rs
  • src/backend_task/wallet/mod.rs
  • src/context/test_support.rs
  • src/context/wallet_lifecycle/tests.rs
  • src/model/derived_identity_key.rs
  • src/model/document.rs
  • src/model/legacy_recovery.rs
  • src/model/mod.rs
  • src/model/qualified_identity/mod.rs
  • src/model/qualified_identity/qualified_identity_public_key.rs
  • src/model/single_key.rs
  • src/ui/contracts_documents/document_action_screen.rs
  • src/ui/helpers.rs
  • src/ui/identity/keys/add_key_screen.rs
  • src/ui/identity/keys/key_info_screen.rs
  • src/ui/masternodes/list_screen.rs
  • src/ui/masternodes/mod.rs
  • src/ui/tokens/claim_tokens_screen.rs
  • src/wallet_backend/dashpay.rs
  • src/wallet_backend/secret_access.rs
  • src/wallet_backend/single_key.rs
  • tests/backend-e2e/dashpay_tasks.rs
  • tests/backend-e2e/identity_in_vault_sign.rs
  • tests/backend-e2e/identity_tasks.rs
  • tests/backend-e2e/register_dpns.rs
  • tests/backend-e2e/z_broadcast_st_tasks.rs
  • tests/kittest/key_info_screen.rs
  • tests/kittest/keys_screen.rs
  • tests/kittest/masternode_tab.rs
  • tests/kittest/tokens_screen.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

The changes add version-aware document and identity-key construction paths, update callers to pass platform versions, and revise related UI validation and test fixtures. Wallet and migration code also uses public-key constructors, and token operations pass the SDK version to signing calls.

Changes: Document creation and selection

Layer / File(s) Summary
Document factory and task integration
src/model/document.rs, src/model/mod.rs, src/backend_task/dashpay/contact_info.rs, src/backend_task/dashpay/contact_requests.rs, src/backend_task/error.rs
A shared factory creates documents with the supplied document type, owner, properties, entropy, and platform version. DashPay contact document tasks use it and map preparation failures to DocumentPreparationFailed.
Document UI validation and replacement
src/ui/helpers.rs, src/ui/contracts_documents/document_action_screen.rs
Contract selection clears an incompatible document type. Document creation reports foreign document types, uses the shared factory, and replaces documents while retaining fields not explicitly reset.

Sequence Diagram(s)

sequenceDiagram
  participant ContractChooser
  participant DocumentActionScreen
  participant DocumentFactory
  ContractChooser->>DocumentActionScreen: selected contract and document type
  DocumentActionScreen->>DocumentActionScreen: validate contract ID match
  DocumentActionScreen->>DocumentFactory: create with type, owner, properties, entropy, and platform version
  DocumentFactory-->>DocumentActionScreen: document or protocol error
Loading

Version-aware identity keys

Layer / File(s) Summary
Versioned key conversion and registration
src/backend_task/identity/mod.rs, src/backend_task/error.rs, src/backend_task/identity/register_identity.rs, tests/backend-e2e/register_dpns.rs, src/context/wallet_lifecycle/tests.rs
Key storage and public-key map conversion accept a platform version and return typed errors. Registration paths and related callers pass the active version.
Shared identity-key fixtures and call sites
src/context/test_support.rs, src/backend_task/identity/*, src/model/derived_identity_key.rs, src/model/legacy_recovery.rs, src/model/qualified_identity/*, src/ui/identity/keys/*, src/ui/masternodes/*, src/ui/tokens/claim_tokens_screen.rs, src/backend_task/wallet/mod.rs, src/wallet_backend/dashpay.rs, tests/backend-e2e/*, tests/kittest/*
A shared helper and versioned setters replace direct V0 key construction in test fixtures. Wallet-backed qualified keys use their constructor, and the add-key UI converts keys through From.

Public-key construction updates

Layer / File(s) Summary
Wallet and migration public-key construction
src/backend_task/migration/*, src/model/single_key.rs, src/wallet_backend/secret_access.rs, src/wallet_backend/single_key.rs, src/context/wallet_lifecycle/tests.rs
Wallet and migration code derives public keys with PrivateKey::public_key() or creates them with PublicKey::new() instead of assembling their fields.

Token transition signing versions

Layer / File(s) Summary
Use the SDK version for signing
src/backend_task/tokens/destroy_frozen_funds.rs, src/backend_task/tokens/pause_tokens.rs, src/backend_task/tokens/resume_tokens.rs, src/backend_task/tokens/update_token_config.rs
The four token operations pass sdk.version() to transition signing.

Priority: Low

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Refactor

Suggested reviewers: lklimek, thepastaclaw

Merge Risk: Minimal · up to 37b77

No concrete issue requiring a change before merge is established by the available evidence. Normal checks and owner review can proceed.

Pre-merge checks: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Inconclusive Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surv… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "refactor: build Platform types with their upstream constructors" matches the main change. The PR replaces hand-built Platform values (identity public keys, qualified keys, documents, and id…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "refactor: build Platform types with their upstream constructors" matches the main change. The PR replaces hand-built Platform values (identity public keys, qualified keys, documents, and identity keys) with upstream constructors and factories, such as new_document_for_creation, identity_public_key, from_identity_public_key_in_wallet, and default_versioned. The title is concise and conveys the primary intent. The conventional-commit prefix is consistent with a behavior-preserving refactor. It does not mention the protocol 14 adaptation or the token signing change to sdk.version(), but those are secondary.

Full details: Docstring Coverage

Explanation

Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 80 functions across 42 files. (5 skipped: 5 too large.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@thepastaclaw

thepastaclaw commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

⛔ Final review complete — 1 blocking finding(s) (commit 37b7720)

lklimek and others added 2 commits October 26, 2026 09:57
Pause, resume, destroy-frozen-funds and token-config-update signed with
`AppContext::platform_version()` but broadcast through the task's `sdk`.
After a connection rebuild the two SDKs can differ, so sign with
`sdk.version()`, the version of the SDK that broadcasts, as the rest of
the backend does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
The proof verifier asks for contracts at the version it verifies with,
which can be newer than the SDK's. System contracts were already served
at that version; a saved user contract was decoded at the SDK's version
instead, dropping newer-protocol settings such as action fees. The
fallback now decodes it at the version asked for.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed bot-review-skipped A required review bot did not report; it was skipped by the window or by a person. and removed waiting-bots Waiting for the review bots to report on this head labels Oct 26, 2026
lklimek and others added 6 commits October 27, 2026 10:55
Resolve the contact_requests test-module import conflict by keeping both
sides: DppDocument (this branch's fixtures) and ContactInfoField (v1.0-dev's
new contactInfo tests). Build the new claim-tokens test key with the shared
versioned-factory fixture instead of an IdentityPublicKeyV0 literal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
IdentityKeySpecs::to_public_keys_map stringified the ProtocolError from
IdentityPublicKey::default_versioned into PublicKeyMapBuildFailed's detail,
dropping the source chain. It now returns TaskError directly and maps that
failure to the new IdentityKeysPreparationFailed variant, which keeps the
error as a typed Box<SdkError> source (SdkError::Protocol).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
The tokens_screen fixture still built its unbound key as an
IdentityPublicKeyV0 literal; it now uses IdentityPublicKey::default_versioned
plus the key setters, like the other kittest fixtures.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
The contract/document-type chooser keeps the selected type when the
contract changes. The document factory derives the new document's id from
the type's contract, so a stale type produced an id for one contract inside
a transition for another. Creating now stops with a message asking the user
to pick a type from the selected contract.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
The contract/document-type chooser kept the selected type after the user
picked another contract, so every document action could pair one contract
with another contract's type. Selecting a contract now clears a type that
belongs to a different contract.

The create guard stays as a backstop, and its message now reaches the
banner instead of hiding behind the generic "check its fields" text:
try_build_document returns a DocumentBuildError that tells the leftover
type apart from invalid fields.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
to_public_keys_map built its key-type and security-level failures as
format! strings stored in PublicKeyMapBuildFailed's detail field. They are
now IdentityKeySpecError variants carrying the key id, purpose, level and
type, and PublicKeyMapBuildFailed holds that error as its source. The
banner text is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — coderabbitai ✓ · thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added waiting-bots Waiting for the review bots to report on this head and removed waiting-self-review Waiting for the author to post /self-reviewed bot-review-skipped A required review bot did not report; it was skipped by the window or by a person. labels Oct 27, 2026

@thepastaclaw thepastaclaw left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review — Final validation — Phase 2 only (no Phase 1 for this repository)

Updated after discussion: 1 finding(s) of this review were settled in the inline threads; 1 blocking finding(s) still stand.

  • ✅ Withdrawn: 🔴 Match the tuple-shaped PublicKeyMapBuildFailed variant without moving the error

The refactor has a introduced test-compilation blocker: the new regression test matches a tuple-shaped error variant with struct syntax and then risks moving the error before inspecting its source. The document selector also leaves mutation state and in-flight fetch results associated with the previous contract/type usable after a selection change, which can enable or submit an operation using stale data. The previously reported platform-version mismatch remains a valid suggestion; Test Suite and Clippy were still queued in the supplied CI snapshot.

🔴 2 1 blocking | 🟡 1 suggestion(s)

1 finding(s) not shown inline (the lines are not part of this PR's diff)

🔴 Blocking: Invalidate fetched mutation state when the contract or document type changes
src/ui/contracts_documents/document_action_screen.rs:279-282

This branch clears only fetched_documents, leaving original_doc, field_inputs, fetched_price, and broadcast_status intact. A user can fetch a document or price for contract A, switch to contract B, select a document type, and still have Replace or Purchase enabled with the old document or price while the new contract/type is submitted. The replacement path does not verify that the fetched document belongs to the current contract/type. In addition, display_task_result accepts every Documents result without associating it with the query that produced it, so a late response from the old selection can repopulate this stale state after it was cleared. Selection changes must invalidate all mutation-specific state, and fetch results must be ignored or tagged with the selection that initiated them.

source: gpt-6.1-sol (phase2-reviewer: general)

1 carried-forward finding(s) already raised on this PR; not re-posting as new inline comments.

Review provenance

Source: reviewer 1: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.1-sol (effort low) — This is a large, cross-cutting refactor that changes cryptographic key construction, identity key handling, document creation, and transaction-signing platform-version selection across production paths such as src/backend_task/identity/mod.rs and src/backend_task/tokens/*.rs.
  • Phase 1 reviewers: not run (disabled for this repository)
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort xhigh); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `src/backend_task/identity/mod.rs`:
- [BLOCKING → WITHDRAWN in discussion; do not fix] src/backend_task/identity/mod.rs:1576-1582: Match the tuple-shaped PublicKeyMapBuildFailed variant without moving the error
  `TaskError::PublicKeyMapBuildFailed` is declared as a tuple variant in `src/backend_task/error.rs`, but this regression test uses struct-variant syntax (`{ .. }`), so the test does not compile. After correcting the pattern, matching the owned `error` would move it before the subsequent `error.source()` call; the assertion must borrow the error.

In `src/ui/contracts_documents/document_action_screen.rs`:
- [BLOCKING] src/ui/contracts_documents/document_action_screen.rs:279-282: Invalidate fetched mutation state when the contract or document type changes
  This branch clears only `fetched_documents`, leaving `original_doc`, `field_inputs`, `fetched_price`, and `broadcast_status` intact. A user can fetch a document or price for contract A, switch to contract B, select a document type, and still have Replace or Purchase enabled with the old document or price while the new contract/type is submitted. The replacement path does not verify that the fetched document belongs to the current contract/type. In addition, `display_task_result` accepts every `Documents` result without associating it with the query that produced it, so a late response from the old selection can repopulate this stale state after it was cleared. Selection changes must invalidate all mutation-specific state, and fetch results must be ignored or tagged with the selection that initiated them.
- [SUGGESTION] src/ui/contracts_documents/document_action_screen.rs:1451-1457: Use the same Platform version for document construction and broadcast
  (existing thread: https://github.com/dashpay/dash-evo-tool/pull/1126#discussion_r4382488150)
  The document factory is called with `self.app_context.platform_version()`, while the later `BroadcastDocument` task snapshots the SDK when it runs and uses that SDK's `version()` for contest-fund calculation and transition construction. A reconnect can replace the SDK between these operations, allowing the document to be prepared under one protocol version and broadcast under another. Construct the document in the backend from task inputs and the same SDK snapshot, or carry and compare one version snapshot through both stages. The protocol update being infrequent does not remove this ordering mismatch.

Comment thread src/backend_task/identity/mod.rs Resolved
@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed and removed waiting-bots Waiting for the review bots to report on this head labels Oct 27, 2026
@Claudius-Maginificent

Copy link
Copy Markdown
Collaborator Author

Real issue, but it predates this PR and is outside its diff (as the review notes, document_action_screen.rs:279-282 is not part of the change).

  • The selection-change block that clears only fetched_documents and no_documents_found comes from 62cb35a (2026-03-03). The Documents handler in display_task_result, which accepts results without tagging them to a query, dates from 82ac544 (2025-06-02). Both behave the same on v1.0-dev.
  • This PR changes how the document is built (dpp's factory) and refuses a document type left over from another contract (4a82f65, ed1a197). It does not change how fetched Replace/Purchase state flows into broadcasts.

The fix is tracked in a separate PR: #1155. That PR clears all fetched mutation state on a contract or document-type change and ignores fetch results and errors from a selection the screen no longer waits for.

🤖 Co-authored by Claudius the Magnificent AI Agent

@lklimek lklimek self-assigned this Oct 28, 2026
@lklimek

lklimek commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

/self-reviewed

@lklimek
lklimek enabled auto-merge (squash) October 28, 2026 14:21
@github-actions

Copy link
Copy Markdown
Contributor

Ready for review — files with no dedicated owner: nobody may approve.
Full checklist in the description.

@github-actions github-actions Bot added ready-for-human Bots have reported, the author has self-reviewed, and the build is green: this needs a human. bot-review-skipped A required review bot did not report; it was skipped by the window or by a person. and removed waiting-self-review Waiting for the author to post /self-reviewed labels Oct 28, 2026
@lklimek
lklimek disabled auto-merge October 28, 2026 14:32
@lklimek
lklimek merged commit 6f712b7 into v1.0-dev Oct 28, 2026
19 of 20 checks passed
@lklimek
lklimek deleted the refactor/dpp-constructors branch October 28, 2026 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot-review-skipped A required review bot did not report; it was skipped by the window or by a person. ready-for-human Bots have reported, the author has self-reviewed, and the build is green: this needs a human.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants