Skip to content

refactor(platform-wallet): one owner for platform-node pool entries - #6037

Draft
Claudius-Maginificent wants to merge 1 commit into
v5.2-devfrom
refactor/platform-node-pool-single-owner
Draft

Claudius-Maginificent wants to merge 1 commit into
v5.2-devfrom
refactor/platform-node-pool-single-owner

Conversation

@Claudius-Maginificent

@Claudius-Maginificent Claudius-Maginificent commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

TL;DR: Internal clean-up: one piece of code now owns adding a masternode's platform-node key to the wallet, instead of two copies in the wallet and in its database layer. No behaviour change for users.

Detailed discussion

Pure internal change; no user-visible effect, so no user story or scenario.

What was done

  • Registration (populate_platform_node_pool) and SQLite load (provider_accounts::insert_platform_node_pool_entry) each built and inserted the ProviderPlatformKeys pool entry. Both now go through platform_wallet::wallet::provider_key_at_index::insert_platform_node_key and its PlatformNodePoolError.
  • Storage only maps the error; its provider_accounts module is removed.
  • Registration still builds every entry before inserting any and leaves the pool unchanged when a key is refused.

Stacked on #6036 (address-entry balance removal) → #6035 (funding-pool fix) → #5951; split out of #5951 because the rust-dashcore bump does not require it.

Testing

Existing and moved platform-node pool tests; CI-scope clippy and nextest for the wallet crates pass locally.

Breaking changes

None (crate-internal and storage-internal types only).

Checklist

  • I have performed a self-review of my own code
  • My Rust changes follow the coding conventions
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation if needed

🤖 Co-authored by Claudius the Magnificent AI Agent

🤖 Generated with Claude Code

https://claude.ai/code/session_01WunYYhpfoE88XJoyRt4hcR

@coderabbitai

coderabbitai Bot commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • 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

@lklimek lklimek mentioned this pull request Nov 21, 2026
10 of 13 tasks
@thepastaclaw

thepastaclaw commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Final review complete — no blockers (commit 0ccc6c2) · triage: normal

@lklimek
lklimek added this pull request to stack #6217 November 24, 2026 11:38
@lklimek
lklimek force-pushed the refactor/platform-node-pool-single-owner branch 3 times, most recently from 6346071 to 7f053f6 Compare November 27, 2026 14:11
Base automatically changed from refactor/core-address-entry-drop-balance to v5.2-dev December 1, 2026 08:24
Preserve the final PR scope, including merge resolutions, on the updated native stack.

Co-Authored-By: Codex <[email protected]>
@lklimek
lklimek force-pushed the refactor/platform-node-pool-single-owner branch from 7f053f6 to 0ccc6c2 Compare December 1, 2026 08:24
@github-actions github-actions Bot added this to the v5.2.0 milestone Dec 1, 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.

Final validation — Phase 1 + Phase 2

The refactor moves platform-node pool entry construction into the Rust wallet, leaves row decoding in SQLite, and preserves all-or-nothing registration. The Kotlin SDK build and tests passed; Rust wallet and workspace tests were skipped, and PR Hygiene was pending.

🟡 4 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: 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: platform-versioning); reviewer 6: gpt-6.2-sol (agent: phase2-reviewer, role: rust-quality); reviewer 7: gpt-6.2-sol (agent: phase2-reviewer, role: general); reviewer 8: gpt-6.2-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 9: gpt-6.2-sol (agent: phase2-reviewer, role: platform-versioning); reviewer 10: gpt-6.2-sol (agent: phase2-reviewer, role: rust-quality); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)

  • Triage: normal by gpt-6.2-sol (effort low) — The refactor spans wallet registration and SQLite rehydration, so it warrants checking that both paths preserve hardened entry construction and failure behavior, but it does not change key derivation, signing, or the storage format.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer, muse-spark-1.3-contributor — rust-quality (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (antigravity quota lookup failed), glm-5.3-flash (not used above high effort; tier asks max)
  • Second Phase-2 pass: on this first full review every Phase-2 reviewer also ran a second, independent time, and the verifier weighed both sets
  • Fresh verifier: gpt-6.2-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.2-sol — general (completed, effort high); agent phase2-reviewer, gpt-6.2-sol — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6.2-sol — platform-versioning (completed, effort high); agent phase2-reviewer, gpt-6.2-sol — rust-quality (completed, effort high); agent phase2-reviewer, gpt-6.2-sol — general (completed, effort high); agent phase2-reviewer, gpt-6.2-sol — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6.2-sol — platform-versioning (completed, effort high); agent phase2-reviewer, gpt-6.2-sol — rust-quality (completed, effort high); agent phase2-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-platform-wallet/src/wallet/provider_key_at_index.rs`:
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/provider_key_at_index.rs:234-245: The new wallet API accepts a platform-node key under the wrong node ID
  Impact: A Rust storage adapter that pairs a public key with a stale address can get a successful insert, after which Core transaction matching can miss the key's evonode registration.
  Core can miss a registration for a key the wallet's ownership lookup recognizes. The helper stores the supplied address and key independently and builds the path from a separately supplied network. Key-wallet's pool checks index validity and collisions, not whether the address identifies the key. The ProRegTx matcher reads the node ID from the stored P2PKH payload, while the wallet's ownership lookup recomputes it from the stored public key. SQLite already preserved the saved address before this PR, so this is not a reload regression. Make the cross-crate helper explicitly a persisted-row restore API and document that it preserves the address without checking it. If a general insertion API is needed, have the wallet derive the address from the key and take the network and base path from the destination pool.
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/provider_key_at_index.rs:324-328: Registration warnings lose the reason a platform-node key could not be stored
  Impact: When the pool refuses a key during registration, operators see the failed index but lose the reason, such as the address already being stored at another index.
  The fallback warning no longer includes the key-wallet diagnostic. The base formatted the underlying error directly; the new closure formats `PlatformNodePoolError` with `Display`, which omits the fields marked `#[source]`, and then stores only that text in `KeyDerivation(String)`. The registration warning logs that string, so it cannot recover the cause. Include the source before converting to a string.
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/provider_key_at_index.rs:340-345: Registration bypasses the platform-node insert helper used by SQLite
  Impact: A maintainer adding an insertion rule to the documented shared helper would change what SQLite reload accepts without changing what registration accepts.
  Registration and reload share row construction, but they still have separate insertion code. Contrary to the rustdoc at lines 293–295, registration calls `staged.insert` directly and constructs `PoolRefused` itself; the single-row helper makes the same call and maps the error separately. Share a private function that inserts a prepared row into a supplied pool, so registration can still pass its staged clone and reload can pass the live pool. Update the docs to name what is actually shared.
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/provider_key_at_index.rs:224-228: The insert helper documents path parity that native key-wallet generation does not provide
  Impact: A Rust caller comparing native key-wallet and Platform pool entries for the same Ed25519 index gets different derivation paths despite the documented parity.
  The recorded paths differ at the final child. This helper records a hardened child, while `AddressPool::generate_address_at_index` records a normal child in both the pinned rust-dashcore revision and the current `dev` revision, even though it uses a hardened child for the actual `AbsentHardened` derivation. Limit the parity claim to entries produced by Platform registration and SQLite restore; keep the hardened path here.
Out-of-scope follow-up suggestions (1)

These are valid observations, but they are outside this PR's scope and should be handled in separate issues or author/maintainer-requested PRs rather than blocking this review.

  • Key-wallet records the wrong child kind for natively generated hardened entries — Native AbsentHardened generation derives the key at a hardened child but records a normal child in AddressInfo.path. A consumer using that metadata to reproduce the key would attempt a non-hardened step, which SLIP-10 Ed25519 does not support. Platform registration and SQLite restore already recorded the hardened child before this PR.
    • Follow-up: Fix AddressPool::generate_address_at_index in dashpay/rust-dashcore so the recorded path uses the same child kind as the derivation.

Comment on lines +234 to +245
pub fn insert_platform_node_key(
wallet_info: &mut ManagedWalletInfo,
network: Network,
index: u32,
address: Address,
public_key: [u8; 32],
used: bool,
) -> Result<(), PlatformNodePoolError> {
let pool = platform_node_pool(wallet_info)?;
let info = platform_node_entry(network, index, address, public_key, used)?;
pool.insert(info)
.map_err(|source| PlatformNodePoolError::PoolRefused { index, source })

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.

🟡 Suggestion: The new wallet API accepts a platform-node key under the wrong node ID
Impact: A Rust storage adapter that pairs a public key with a stale address can get a successful insert, after which Core transaction matching can miss the key's evonode registration.

Core can miss a registration for a key the wallet's ownership lookup recognizes. The helper stores the supplied address and key independently and builds the path from a separately supplied network. Key-wallet's pool checks index validity and collisions, not whether the address identifies the key. The ProRegTx matcher reads the node ID from the stored P2PKH payload, while the wallet's ownership lookup recomputes it from the stored public key. SQLite already preserved the saved address before this PR, so this is not a reload regression. Make the cross-crate helper explicitly a persisted-row restore API and document that it preserves the address without checking it. If a general insertion API is needed, have the wallet derive the address from the key and take the network and base path from the destination pool.

source: gpt-6.2-sol (phase2-reviewer: general, architecture-layering, platform-versioning, rust-quality)

Comment on lines +324 to +328
let to_key_derivation = |index: u32, error: PlatformNodePoolError| {
PlatformWalletError::KeyDerivation(format!(
"failed to store platform node key {index}: {error}"
))
};

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.

🟡 Suggestion: Registration warnings lose the reason a platform-node key could not be stored
Impact: When the pool refuses a key during registration, operators see the failed index but lose the reason, such as the address already being stored at another index.

The fallback warning no longer includes the key-wallet diagnostic. The base formatted the underlying error directly; the new closure formats PlatformNodePoolError with Display, which omits the fields marked #[source], and then stores only that text in KeyDerivation(String). The registration warning logs that string, so it cannot recover the cause. Include the source before converting to a string.

Suggested change
let to_key_derivation = |index: u32, error: PlatformNodePoolError| {
PlatformWalletError::KeyDerivation(format!(
"failed to store platform node key {index}: {error}"
))
};
let to_key_derivation = |index: u32, error: PlatformNodePoolError| {
PlatformWalletError::KeyDerivation(format!(
"failed to store platform node key {index}: {error:?}"
))
};

source: muse-spark-1.3-contributor (phase1-reviewer: general, rust-quality); gpt-6.2-sol (phase2-reviewer: general, architecture-layering, platform-versioning, rust-quality)

Comment on lines +340 to 345
let mut staged = pool.clone();
for entry in entries {
let index = entry.index;
staged.insert(entry).map_err(|source| {
to_key_derivation(index, PlatformNodePoolError::PoolRefused { index, source })
})?;

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.

🟡 Suggestion: Registration bypasses the platform-node insert helper used by SQLite
Impact: A maintainer adding an insertion rule to the documented shared helper would change what SQLite reload accepts without changing what registration accepts.

Registration and reload share row construction, but they still have separate insertion code. Contrary to the rustdoc at lines 293–295, registration calls staged.insert directly and constructs PoolRefused itself; the single-row helper makes the same call and maps the error separately. Share a private function that inserts a prepared row into a supplied pool, so registration can still pass its staged clone and reload can pass the live pool. Update the docs to name what is actually shared.

source: muse-spark-1.3-contributor (phase1-reviewer: general, rust-quality); gpt-6.2-sol (phase2-reviewer: general, architecture-layering, platform-versioning, rust-quality)

Comment on lines +224 to +228
/// `address` is the P2PKH payload of the key's 20-byte platform node id
/// (`SHA256(pubkey)[..20]`, rust-dashcore #884); the path is the
/// `ProviderPlatformKeys` account path plus the hardened index. This is the
/// `AddressInfo` shape key-wallet's own EdDSA pool derivation produces, so a
/// freshly-registered wallet and a restored one carry identical entries.

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.

🟡 Suggestion: The insert helper documents path parity that native key-wallet generation does not provide
Impact: A Rust caller comparing native key-wallet and Platform pool entries for the same Ed25519 index gets different derivation paths despite the documented parity.

The recorded paths differ at the final child. This helper records a hardened child, while AddressPool::generate_address_at_index records a normal child in both the pinned rust-dashcore revision and the current dev revision, even though it uses a hardened child for the actual AbsentHardened derivation. Limit the parity claim to entries produced by Platform registration and SQLite restore; keep the hardened path here.

source: gpt-6.2-sol (phase2-reviewer: general, architecture-layering, platform-versioning, rust-quality)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants