feat(dash): dedicated PlatformNodeId newtype for platform_node_id fields#885
Conversation
The platform_node_id on ProRegTx was typed Option<PubkeyHash> (and raw Option<[u8; 20]> on ProUpServTx), but the value is a Tenderdash/CometBFT node ID — SHA256(ed25519_pubkey) truncated to 20 bytes — not a hash160 public key hash. Sharing the PubkeyHash type is what let the two conventions get conflated in the first place (#883, fixed in #884). Introduce dashcore::PlatformNodeId, a 20-byte newtype with hex Display/FromStr, serde, bincode, and consensus encoding, plus from_ed25519_public_key encoding the canonical CometBFT derivation. Use it for platform_node_id on ProviderRegistrationPayload, ProviderUpdateServicePayload, and EntryMasternodeType::HighPerformance. All wire/persisted encodings stay byte-identical: consensus encoding is the same raw 20 bytes (existing test vectors still pass, and the v2 ProRegTx round-trip test now also asserts the decoded node-ID value), and a regression test locks the bincode layout to the old PubkeyHash layout so persisted dash-spv masternode-list snapshots keep decoding. key-wallet's platform-key matchers now compare raw bytes explicitly, making the hash160-vs-node-ID distinction visible at the comparison site; behavior is unchanged. The key-wallet-ffi C ABI is untouched. Follow-up to #883. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Warning Review limit reached
Next review available in: 6 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (11)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## dev #885 +/- ##
==========================================
+ Coverage 74.30% 74.36% +0.05%
==========================================
Files 326 327 +1
Lines 74636 74747 +111
==========================================
+ Hits 55462 55586 +124
+ Misses 19174 19161 -13
|
PR #884 added derivation_slip10::tenderdash_node_id and this branch added PlatformNodeId::from_ed25519_public_key — two copies of the same SHA256(pubkey)[0..20] derivation. Keep the dash-crate newtype as the single audited implementation and delegate the key-wallet helper to it; the #884 golden-vector tests pin the output unchanged. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Close the patch-coverage gaps codecov flagged: hex Display/FromStr round-trip (including wrong-length and non-hex failures), serde JSON round-trip as a hex string, and the zero-filled wire encoding of v2 high-performance ProRegTx / ProUpServTx payloads whose platform fields are None. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
What
Follow-up to #883 (fixed in #884). Introduces a dedicated
dashcore::PlatformNodeIdnewtype (20 bytes) and uses it forplatform_node_ideverywhere the value appears:ProviderRegistrationPayload.platform_node_id:Option<PubkeyHash>→Option<PlatformNodeId>ProviderUpdateServicePayload.platform_node_id:Option<[u8; 20]>→Option<PlatformNodeId>EntryMasternodeType::HighPerformance.platform_node_id(SML masternode list entry):PubkeyHash→PlatformNodeIdWhy
The field is semantically a Tenderdash/CometBFT node ID —
SHA256(ed25519_pubkey)[0..20]— not a hash160 public key hash; only the wire width (20 bytes) is the same. Typing it asPubkeyHashis what allowed the hash160 vs SHA256-truncated conventions to be conflated in #883. With a dedicated type, the compiler now rejects that mix-up.The type carries
from_ed25519_public_key, encoding the canonical CometBFT derivation (with a test asserting it equals truncated SHA256), plus hexDisplay/FromStr, serde, bincode, and consensus encoding.Compatibility
platform_node_idvalue and platform ports.EntryMasternodeType. A regression test (bincode_layout_matches_pubkey_hash) locks the new type's layout to the oldPubkeyHashlayout.ProviderUpdateServicePayload, where the previous raw[u8; 20]serialized as a number array in JSON and now serializes as a hex string, consistent with the other payloads.[u8; 20]; conversion goes throughto_byte_array()).[u8; 20]from JSON strings and never touches the dash consensus types.Reviewer notes
dashcrate (0.x).PubkeyHashvalues; they now compare raw bytes explicitly (addr_hash.as_byte_array() == platform_node_id.as_byte_array()), which keeps behavior identical while making the hash160-vs-node-ID distinction visible at the comparison site.dev(via fix(key-wallet): platform node id is the Tenderdash node ID (SHA256[0..20]), not hash160 #884) and this branch each carried a copy of the SHA256-truncated derivation; after mergingdevin,key_wallet::derivation_slip10::tenderdash_node_idnow delegates toPlatformNodeId::from_ed25519_public_key, keeping the dash-crate newtype as the single audited implementation. The fix(key-wallet): platform node id is the Tenderdash node ID (SHA256[0..20]), not hash160 #884 golden-vector tests pin the output unchanged.Testing
cargo test -p dashcore --all-features,-p key-wallet --all-features,-p key-wallet-ffi, rpc crates — all passcargo test -p dash-spvandcargo test -p dash-spv-ffi --test dashd_sync(exercises persisted masternode-list decode paths) — all passcargo clippy --all-features --all-targetsandcargo fmt --checkclean🤖 Generated with Claude Code