Skip to content

sdk%refac: consolidate exports, types, add utf8 serde codec to process domain names, preserve unknown values, drop legacy macro#11

Merged
kwvg merged 26 commits into
dashpay:developfrom
kwvg:gen_refac
Jun 22, 2026
Merged

sdk%refac: consolidate exports, types, add utf8 serde codec to process domain names, preserve unknown values, drop legacy macro#11
kwvg merged 26 commits into
dashpay:developfrom
kwvg:gen_refac

Conversation

@kwvg

@kwvg kwvg commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Motivation

Our codec work in base-sdk#4 reduced a lot of boilerplate required to define types, this pull request does a lot of code reorganisation that's now possible due to definitions being overall shorter. Plus we want to start stabilising names as upcoming pull requests may use them as fixed identifiers.

Additional Information

  • GovObjectType::Unknown and ScriptKind::Unknown now preserve the raw integer value instead of discarding it, ensuring better forward compatibility.

  • A UTF-8 serde helper has been added to correctly render Domain::name as a string rather than raw bytes to ensure they're rendered correctly in the parser demo introduced in base-sdk#10

Breaking Changes

  • All internal modules in primitives and p2p_core have been made private. Public items are re-exported directly from crate roots, so use dash_primitives::BlockHeader continues to work while use dash_primitives::block_header::BlockHeader does not.

  • CService has been renamed to ServiceV1.

  • NetAddr has been renamed to VersionAddr.

  • Key container newtypes have moved from dash_types to dash_pkc.

  • The helper macro dash_num::util::make_hash256! has been dropped.

How Has This Been Tested?

cargo fmt --check
cargo test --features _internal,std
./contrib/lint_all.py

Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional tests
  • I have made corresponding changes to the documentation (note: N/A)
  • I have assigned this pull request to a milestone (for repository code-owners and collaborators only)

@kwvg kwvg added this to the 0.1 milestone Jun 16, 2026
@kwvg kwvg self-assigned this Jun 16, 2026
@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR consolidates Dash SDK primitive types by relocating crypto byte wrappers into dash-pkc, introducing a pkgs/primitives/src/types/ module with address and network-info contracts, moving scattered transaction/block/validation definitions into owning modules, and flattening p2p_core and primitives crate exports from pub mod to curated pub use re-exports. Enum unknown variants are widened to preserve original values, build tools are enhanced with shared formatting utilities, and downstream codebases are updated to reference consolidated module paths.

Changes

SDK primitive consolidation and crate API reshaping

Layer / File(s) Summary
Repository policy rules
contrib/codeql/decl.ql, contrib/semgrep/types.yml
CodeQL query extended to check bare Unknown enum variants and enforce NumCodec raw value preservation; Semgrep rule blocks selected type macros in pkgs/types/src/.
Build and test infrastructure
contrib/common.py, contrib/git_filter.py, contrib/lint_all.py
Common module defines shared ANSI formatting constants and format_table() helper for Markdown table rendering; new git_filter.py CLI tool runs user commands across resolved git commit ranges with per-commit status tracking and summary reporting; lint_all.py refactored to use centralized table formatting.
Crypto key/signature byte types to dash-pkc
pkgs/pkc/src/lib.rs, pkgs/pkc/Cargo.toml, pkgs/pkc/src/bls_chia/pk.rs, pkgs/pkc/src/bls_chia/sig.rs, pkgs/pkc/src/bls_ietf/pk.rs, pkgs/pkc/src/bls_ietf/sig.rs, pkgs/pkc/src/k256/pk.rs, pkgs/pkc/src/k256/sig.rs, pkgs/types/src/lib.rs, pkgs/types/src/serialize.rs
BlsPublicKeyBytes, BlsSignatureBytes, EcdsaPublicKeyBytes, EcdsaSignatureBytes defined in pkc via make_bytes! and removed from dash_types; all BLS/ECDSA module serde and From/TryFrom impls retarget crate::* byte types; UTF-8 serde helper module added to types.
ParseHexError consolidation and flattened hash paths
pkgs/num/src/hash.rs, pkgs/num/src/lib.rs, pkgs/num/src/util.rs, pkgs/dev/src/lambda.rs, pkgs/params/src/types.rs
ParseHexError defined in hash.rs with Display and conditional std::error::Error impl, error.rs module removed, lib.rs re-exports from hash; make_hash256! macro alias removed; downstream code uses flattened dash_primitives::tx_hash and double_sha256 paths.
Address and NetInfo types module
pkgs/primitives/Cargo.toml, pkgs/primitives/src/types/addrv1.rs, pkgs/primitives/src/types/addrv2.rs, pkgs/primitives/src/types/netinfo.rs, pkgs/primitives/src/types/mod.rs, pkgs/primitives/src/support.rs
New types module provides AddrV1/ServiceV1 (legacy), NetworkType/AddrV2/ServiceV2 (BIP155 v2), and NetInfoPurpose/NetInfoEntry/ExtendedNetInfo/NetInfo (extended net-info) with full BaseCodec implementations; NetworkType removed from support; base58ck and dash-pkc added as dependencies with feature forwarding.
Payload types consolidation and ProTx validation
pkgs/primitives/src/payload/mod.rs, pkgs/primitives/src/payload/proregtx.rs, pkgs/primitives/src/payload/proupservtx.rs, pkgs/primitives/src/payload/proupregtx.rs, pkgs/primitives/src/payload/prouprevtx.rs, pkgs/primitives/src/payload/quorum.rs, pkgs/primitives/src/payload/mnhftx.rs, pkgs/primitives/src/payload/assetunlock.rs, pkgs/primitives/src/payload/cbtx.rs
payload/mod.rs owns TxType/MnType enums (with Unknown(u16) variants and NumCodec), ProTxInvalid validation error enum, QuorumHash/InputsHash hash types, ProTx constants, and check_sptx_netinfo() net-info validator; validation.rs module removed; ProRegTx/ProUpServTx migrate to shared NetInfo type; payload modules update imports to source consolidated types from super and crate::types.
Block, transaction, script, and governance consolidation
pkgs/primitives/src/block.rs, pkgs/primitives/src/transaction.rs, pkgs/primitives/src/script.rs, pkgs/primitives/src/gov.rs, pkgs/primitives/src/lib.rs, pkgs/primitives/src/block_header.rs, pkgs/primitives/src/outpoint.rs, pkgs/primitives/src/tx_in.rs, pkgs/primitives/src/tx_out.rs, pkgs/primitives/src/tx_types.rs
BlockHeader/BlockInvalid with size constants and hash types move to block.rs; OutPoint/TxIn/TxOut/TxInvalid move to transaction.rs with BaseCodec serialization and Display; KeyId (20-byte wrapper) and to_base58c() method added to script.rs; GovObjectType::Unknown gains i32 payload for preserving unknown governance codes; old module files emptied/deleted; primitives/lib.rs switches from scattered pub mod to consolidated pub use re-exports.
P2P compact filter and address entry consolidation
pkgs/p2p_core/src/msg/compact_filters.rs, pkgs/p2p_core/src/msg/addr.rs, pkgs/p2p_core/src/msg/version.rs, pkgs/p2p_core/src/msg/mod.rs, pkgs/p2p_core/src/primitives/mn_list.rs
cfcheckpt/cfheaders/cfilter modules removed; compact_filters.rs consolidates all BIP157 types (FilterType, GetCFilters/CFilter, GetCFHeaders/CFHeaders, GetCFCheckpt/CFCheckpt) with explicit BaseCodec encode/decode; TimestampedAddr/AddrV2Entry defined locally in msg/addr.rs with full codec; VersionAddr struct added to msg/version.rs; GetMnListDiff/MnListDiff P2P wrappers move to mn_list.rs; msg/mod.rs reorganizes submodule visibility and expands public re-exports; SimplifiedMnListEntry.service changes from CService to ServiceV1.
P2P core and primitives API flattening
pkgs/p2p_core/src/lib.rs, pkgs/p2p_core/src/primitives/mod.rs, pkgs/p2p_core/src/primitives/short_id.rs, pkgs/p2p_core/src/v2/mod.rs, pkgs/p2p_core/src/msg/headers.rs, pkgs/p2p_core/src/msg/headers2.rs, pkgs/p2p_core/src/msg/inv.rs, pkgs/p2p_core/tests/addrv2.rs
p2p_core and primitives submodules transition from pub mod to private mod with curated pub use re-exports at crate root; encode_v2/decode_v2 re-exported from crate root; import paths in headers/headers2/inv/v2/tests updated to use flattened crate::primitives::* access instead of nested submodule paths.
Script crate API adjustments
pkgs/script/Cargo.toml, pkgs/script/src/lib.rs
dash-types dependency removed from Cargo.toml and related feature forwarding cleaned up; encode_key_id() helper function removed (moved to primitives::script); ScriptKind::Unknown enum variant changes from unit to Unknown(u8) to preserve first opcode byte value; classify() returns Unknown(byte) or Unknown(0) for empty scripts; derive_address() and unit tests updated for new Unknown(u8) form.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Description check ✅ Passed The pull request description clearly articulates the motivation (code reorganization after codec work), key changes (module restructuring, type renaming, enhanced forward compatibility), and testing approach. It is directly related to the changeset.
Title check ✅ Passed The title clearly summarizes the main changes: consolidating exports, reorganizing module structure, renaming types, and adding codec improvements across the SDK.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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.

@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown

Note

This pull request has no conflicts! 🎊 🎉 🎊

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 5

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pkgs/primitives/src/payload/proregtx.rs (1)

211-223: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Validate legacy net_info emptiness in ProRegTx::check.

NetInfoType::Legacy currently bypasses emptiness checks, so invalid v1/v2 service endpoints can pass validation.

Suggested fix
-    if let NetInfoType::Extended(ref ext) = self.net_info {
-      if ext.is_empty() {
-        return Some(ProTxInvalid::NetInfoEmpty);
-      }
-      if let Some(e) = check_sptx_netinfo(&ext.entries, self.mn_type, self.version >= PROTX_VERSION_EXT_ADDR) {
-        return Some(e);
-      }
-    }
+    match &self.net_info {
+      NetInfoType::Extended(ext) => {
+        if ext.is_empty() {
+          return Some(ProTxInvalid::NetInfoEmpty);
+        }
+        if let Some(e) =
+          check_sptx_netinfo(&ext.entries, self.mn_type, self.version >= PROTX_VERSION_EXT_ADDR)
+        {
+          return Some(e);
+        }
+      }
+      NetInfoType::Legacy(mn) => {
+        if mn.is_empty() {
+          return Some(ProTxInvalid::NetInfoEmpty);
+        }
+      }
+    }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkgs/primitives/src/payload/proregtx.rs` around lines 211 - 223, The
ProRegTx::check method validates the Extended variant of NetInfoType for
emptiness but does not perform the same validation for the Legacy variant,
allowing invalid legacy service endpoints to pass. Add an emptiness check for
NetInfoType::Legacy (matching the pattern used for NetInfoType::Extended) that
returns ProTxInvalid::NetInfoEmpty if the legacy entries collection is empty,
ensuring both legacy and extended net_info types are validated consistently.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkgs/num/src/hash.rs`:
- Around line 16-24: The ParseHexError enum is missing the Hash derive trait in
its derive macro. Add Hash to the derive attribute on the ParseHexError enum
definition to comply with the project coding guidelines that require deriving
Clone, Debug, PartialEq, Eq, and Hash together on enums.

In `@pkgs/primitives/src/payload/proregtx.rs`:
- Around line 155-163: The encoding logic for net_info in the version check
branches fails silently when the version and net_info variant disagree (e.g.,
version >= 3 with Legacy, or version < 3 with Extended), producing corrupted
payloads instead of failing fast. Replace the if-let and else-if chain with a
match statement on net_info that validates the version constraint for each
variant, panicking or returning an error when NetInfoType::Extended is
encountered with version < 3 or NetInfoType::Legacy is encountered with version
>= 3, ensuring all cases are explicitly handled and mismatches are caught
immediately.

In `@pkgs/primitives/src/payload/proupservtx.rs`:
- Around line 109-117: The ProUpServTx encoding logic silently skips net_info
encoding when there is a mismatch between the version field and the NetInfoType
variant, which can result in malformed payloads. In the encode method, when
version >= 3, ensure the net_info is an Extended variant, and when version < 3,
ensure the net_info is a Legacy variant. Rather than using if let which silently
skips on mismatch, use pattern matching that panics or returns an error to
enforce the invariant that version and net_info variant must match. This
prevents silently serializing incomplete or malformed data.

In `@pkgs/primitives/src/types/netinfo.rs`:
- Around line 290-292: The is_empty method in ExtendedNetInfo is incomplete and
does not accurately reflect whether the struct contains any address data.
Currently it only checks if self.entries (purpose groups) is empty, but
according to the documented contract it must also verify that no actual address
entries exist. Update the is_empty method in ExtendedNetInfo to check all
relevant fields that store address information, ensuring it returns true only
when there are genuinely no addresses carried by the struct, not just when no
purpose groups exist.
- Around line 212-221: The match statement handling entry_type in the decode
function currently returns NetInfoEntry::Invalid for unknown entry types (the
default case at line 220) without consuming any payload bytes, which causes the
decode stream to become misaligned for subsequent entries. Replace the default
case that returns NetInfoEntry::Invalid with a proper error return that fails
fast (using appropriate error handling mechanism for your codec), ensuring that
unknown entry types are treated as decoding errors rather than silently accepted
values. This will prevent the data stream from being desynchronized when
unexpected entry types are encountered.

---

Outside diff comments:
In `@pkgs/primitives/src/payload/proregtx.rs`:
- Around line 211-223: The ProRegTx::check method validates the Extended variant
of NetInfoType for emptiness but does not perform the same validation for the
Legacy variant, allowing invalid legacy service endpoints to pass. Add an
emptiness check for NetInfoType::Legacy (matching the pattern used for
NetInfoType::Extended) that returns ProTxInvalid::NetInfoEmpty if the legacy
entries collection is empty, ensuring both legacy and extended net_info types
are validated consistently.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 4e8d54d8-e69f-4d1a-b037-d663923a497c

📥 Commits

Reviewing files that changed from the base of the PR and between 4a1b68e and 634ade5.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (64)
  • contrib/semgrep/types.yml
  • pkgs/dev/src/lambda.rs
  • pkgs/num/src/error.rs
  • pkgs/num/src/hash.rs
  • pkgs/num/src/lib.rs
  • pkgs/p2p_core/src/lib.rs
  • pkgs/p2p_core/src/msg/addr.rs
  • pkgs/p2p_core/src/msg/cfcheckpt.rs
  • pkgs/p2p_core/src/msg/cfheaders.rs
  • pkgs/p2p_core/src/msg/cfilter.rs
  • pkgs/p2p_core/src/msg/compact_filters.rs
  • pkgs/p2p_core/src/msg/headers.rs
  • pkgs/p2p_core/src/msg/headers2.rs
  • pkgs/p2p_core/src/msg/inv.rs
  • pkgs/p2p_core/src/msg/mnlistdiff.rs
  • pkgs/p2p_core/src/msg/mod.rs
  • pkgs/p2p_core/src/msg/version.rs
  • pkgs/p2p_core/src/primitives/filter_type.rs
  • pkgs/p2p_core/src/primitives/mn_list.rs
  • pkgs/p2p_core/src/primitives/mod.rs
  • pkgs/p2p_core/src/primitives/net_addr.rs
  • pkgs/p2p_core/src/primitives/short_id.rs
  • pkgs/p2p_core/src/v2/mod.rs
  • pkgs/p2p_core/tests/addrv2.rs
  • pkgs/params/src/types.rs
  • pkgs/pkc/Cargo.toml
  • pkgs/pkc/src/bls_chia/pk.rs
  • pkgs/pkc/src/bls_chia/sig.rs
  • pkgs/pkc/src/bls_ietf/pk.rs
  • pkgs/pkc/src/bls_ietf/sig.rs
  • pkgs/pkc/src/k256/pk.rs
  • pkgs/pkc/src/k256/sig.rs
  • pkgs/pkc/src/lib.rs
  • pkgs/primitives/Cargo.toml
  • pkgs/primitives/src/block.rs
  • pkgs/primitives/src/block_header.rs
  • pkgs/primitives/src/gov.rs
  • pkgs/primitives/src/lib.rs
  • pkgs/primitives/src/outpoint.rs
  • pkgs/primitives/src/payload/assetlock.rs
  • pkgs/primitives/src/payload/assetunlock.rs
  • pkgs/primitives/src/payload/cbtx.rs
  • pkgs/primitives/src/payload/mnhftx.rs
  • pkgs/primitives/src/payload/mod.rs
  • pkgs/primitives/src/payload/proregtx.rs
  • pkgs/primitives/src/payload/proupregtx.rs
  • pkgs/primitives/src/payload/prouprevtx.rs
  • pkgs/primitives/src/payload/proupservtx.rs
  • pkgs/primitives/src/payload/quorum.rs
  • pkgs/primitives/src/script.rs
  • pkgs/primitives/src/support.rs
  • pkgs/primitives/src/transaction.rs
  • pkgs/primitives/src/tx_in.rs
  • pkgs/primitives/src/tx_out.rs
  • pkgs/primitives/src/tx_types.rs
  • pkgs/primitives/src/types/addrv1.rs
  • pkgs/primitives/src/types/addrv2.rs
  • pkgs/primitives/src/types/mod.rs
  • pkgs/primitives/src/types/netinfo.rs
  • pkgs/primitives/src/validation.rs
  • pkgs/script/Cargo.toml
  • pkgs/script/src/lib.rs
  • pkgs/types/src/lib.rs
  • pkgs/types/src/serialize.rs
💤 Files with no reviewable changes (14)
  • pkgs/num/src/error.rs
  • pkgs/primitives/src/tx_in.rs
  • pkgs/script/src/lib.rs
  • pkgs/p2p_core/src/primitives/filter_type.rs
  • pkgs/primitives/src/tx_types.rs
  • pkgs/p2p_core/src/msg/cfcheckpt.rs
  • pkgs/primitives/src/block_header.rs
  • pkgs/p2p_core/src/msg/mnlistdiff.rs
  • pkgs/types/src/lib.rs
  • pkgs/p2p_core/src/msg/cfheaders.rs
  • pkgs/p2p_core/src/msg/cfilter.rs
  • pkgs/primitives/src/tx_out.rs
  • pkgs/primitives/src/outpoint.rs
  • pkgs/primitives/src/validation.rs

Comment thread pkgs/num/src/hash.rs
Comment on lines +16 to +24
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum ParseHexError {
/// The hex string has an odd number of characters.
OddLength,
/// The decoded byte count does not match the expected length.
InvalidLength { expected: usize, got: usize },
/// A non-hex character was encountered.
InvalidChar(u8),
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win

Add Hash derive on ParseHexError to align with project policy.

This enum currently derives Clone, Debug, PartialEq, and Eq, but misses Hash.

Proposed patch
-#[derive(Clone, Debug, PartialEq, Eq)]
+#[derive(Clone, Debug, PartialEq, Eq, Hash)]
 pub enum ParseHexError {

As per coding guidelines: "Derive Clone, Debug, PartialEq, Eq, Hash eagerly."

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum ParseHexError {
/// The hex string has an odd number of characters.
OddLength,
/// The decoded byte count does not match the expected length.
InvalidLength { expected: usize, got: usize },
/// A non-hex character was encountered.
InvalidChar(u8),
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum ParseHexError {
/// The hex string has an odd number of characters.
OddLength,
/// The decoded byte count does not match the expected length.
InvalidLength { expected: usize, got: usize },
/// A non-hex character was encountered.
InvalidChar(u8),
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkgs/num/src/hash.rs` around lines 16 - 24, The ParseHexError enum is missing
the Hash derive trait in its derive macro. Add Hash to the derive attribute on
the ParseHexError enum definition to comply with the project coding guidelines
that require deriving Clone, Debug, PartialEq, Eq, and Hash together on enums.

Source: Coding guidelines

Comment thread pkgs/primitives/src/payload/proregtx.rs
Comment thread pkgs/primitives/src/payload/proupservtx.rs
Comment on lines +212 to +221
let entry_type = u8::decode(data)?;
let entry = match entry_type {
0x01 => NetInfoEntry::Service(ServiceV1::decode(data)?),
0x02 => {
let name: Vec<u8> = Vec::decode(data)?;
let port = codec::read_u16_be(data)?;
NetInfoEntry::Domain { name, port }
}
_ => NetInfoEntry::Invalid,
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Fail fast on unknown entry_type to prevent decode stream desynchronization.

Line 220 currently accepts unknown entry types as Invalid without consuming any payload bytes. That can misalign parsing for subsequent entries and fields.

Proposed fix
         let entry = match entry_type {
           0x01 => NetInfoEntry::Service(ServiceV1::decode(data)?),
           0x02 => {
             let name: Vec<u8> = Vec::decode(data)?;
             let port = codec::read_u16_be(data)?;
             NetInfoEntry::Domain { name, port }
           }
-          _ => NetInfoEntry::Invalid,
+          _ => {
+            return Err(DecodeError::InvalidValue {
+              expected: 0x02,
+              actual: u64::from(entry_type),
+            })
+          }
         };
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkgs/primitives/src/types/netinfo.rs` around lines 212 - 221, The match
statement handling entry_type in the decode function currently returns
NetInfoEntry::Invalid for unknown entry types (the default case at line 220)
without consuming any payload bytes, which causes the decode stream to become
misaligned for subsequent entries. Replace the default case that returns
NetInfoEntry::Invalid with a proper error return that fails fast (using
appropriate error handling mechanism for your codec), ensuring that unknown
entry types are treated as decoding errors rather than silently accepted values.
This will prevent the data stream from being desynchronized when unexpected
entry types are encountered.

Comment thread pkgs/primitives/src/types/netinfo.rs Outdated
Comment on lines +290 to +292
fn is_empty(&self) -> bool {
self.entries.is_empty()
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

ExtendedNetInfo::is_empty does not match its documented contract.

Line 291 only checks whether purpose groups exist, not whether any address entries exist. This can return false even when no addresses are carried.

Proposed fix
   fn is_empty(&self) -> bool {
-    self.entries.is_empty()
+    self.entries.iter().all(|(_, group)| {
+      group.iter().all(|entry| matches!(entry, NetInfoEntry::Invalid))
+    })
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
fn is_empty(&self) -> bool {
self.entries.is_empty()
}
fn is_empty(&self) -> bool {
self.entries.iter().all(|(_, group)| {
group.iter().all(|entry| matches!(entry, NetInfoEntry::Invalid))
})
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkgs/primitives/src/types/netinfo.rs` around lines 290 - 292, The is_empty
method in ExtendedNetInfo is incomplete and does not accurately reflect whether
the struct contains any address data. Currently it only checks if self.entries
(purpose groups) is empty, but according to the documented contract it must also
verify that no actual address entries exist. Update the is_empty method in
ExtendedNetInfo to check all relevant fields that store address information,
ensuring it returns true only when there are genuinely no addresses carried by
the struct, not just when no purpose groups exist.

@kwvg kwvg changed the title sdk%refac: consolidate exports, types, add utf8 serde codec to process domain names, preserve unknown types in GovObjectType sdk%refac: consolidate exports, types, add utf8 serde codec to process domain names, preserve unknown types, drop legacy macro Jun 19, 2026
@kwvg

kwvg commented Jun 20, 2026

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@contrib/codeql/decl.ql`:
- Around line 88-99: The new branch checking for Unknown variant enforcement at
line 88 does not apply the same filtering conditions as other policy checks in
the query. Add guard conditions to ensure this branch only applies to evaluated
crates, serde internal types, and encodable types by wrapping the entire
exists(Enum e | bareUnknownVariant(e, item) and...) block with conditions
checking isEvaluatedCrate, isSerdeInternalType, and isNotEncodable, similar to
how other branches in the query filter their scope. This prevents false
positives outside the intended lint targets.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: b41b857b-e8b3-445e-bcec-415611dd6c51

📥 Commits

Reviewing files that changed from the base of the PR and between 634ade5 and dc04af3.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (66)
  • contrib/codeql/decl.ql
  • contrib/semgrep/types.yml
  • pkgs/dev/src/lambda.rs
  • pkgs/num/src/error.rs
  • pkgs/num/src/hash.rs
  • pkgs/num/src/lib.rs
  • pkgs/num/src/util.rs
  • pkgs/p2p_core/src/lib.rs
  • pkgs/p2p_core/src/msg/addr.rs
  • pkgs/p2p_core/src/msg/cfcheckpt.rs
  • pkgs/p2p_core/src/msg/cfheaders.rs
  • pkgs/p2p_core/src/msg/cfilter.rs
  • pkgs/p2p_core/src/msg/compact_filters.rs
  • pkgs/p2p_core/src/msg/headers.rs
  • pkgs/p2p_core/src/msg/headers2.rs
  • pkgs/p2p_core/src/msg/inv.rs
  • pkgs/p2p_core/src/msg/mnlistdiff.rs
  • pkgs/p2p_core/src/msg/mod.rs
  • pkgs/p2p_core/src/msg/version.rs
  • pkgs/p2p_core/src/primitives/filter_type.rs
  • pkgs/p2p_core/src/primitives/mn_list.rs
  • pkgs/p2p_core/src/primitives/mod.rs
  • pkgs/p2p_core/src/primitives/net_addr.rs
  • pkgs/p2p_core/src/primitives/short_id.rs
  • pkgs/p2p_core/src/v2/mod.rs
  • pkgs/p2p_core/tests/addrv2.rs
  • pkgs/params/src/types.rs
  • pkgs/pkc/Cargo.toml
  • pkgs/pkc/src/bls_chia/pk.rs
  • pkgs/pkc/src/bls_chia/sig.rs
  • pkgs/pkc/src/bls_ietf/pk.rs
  • pkgs/pkc/src/bls_ietf/sig.rs
  • pkgs/pkc/src/k256/pk.rs
  • pkgs/pkc/src/k256/sig.rs
  • pkgs/pkc/src/lib.rs
  • pkgs/primitives/Cargo.toml
  • pkgs/primitives/src/block.rs
  • pkgs/primitives/src/block_header.rs
  • pkgs/primitives/src/gov.rs
  • pkgs/primitives/src/lib.rs
  • pkgs/primitives/src/outpoint.rs
  • pkgs/primitives/src/payload/assetlock.rs
  • pkgs/primitives/src/payload/assetunlock.rs
  • pkgs/primitives/src/payload/cbtx.rs
  • pkgs/primitives/src/payload/mnhftx.rs
  • pkgs/primitives/src/payload/mod.rs
  • pkgs/primitives/src/payload/proregtx.rs
  • pkgs/primitives/src/payload/proupregtx.rs
  • pkgs/primitives/src/payload/prouprevtx.rs
  • pkgs/primitives/src/payload/proupservtx.rs
  • pkgs/primitives/src/payload/quorum.rs
  • pkgs/primitives/src/script.rs
  • pkgs/primitives/src/support.rs
  • pkgs/primitives/src/transaction.rs
  • pkgs/primitives/src/tx_in.rs
  • pkgs/primitives/src/tx_out.rs
  • pkgs/primitives/src/tx_types.rs
  • pkgs/primitives/src/types/addrv1.rs
  • pkgs/primitives/src/types/addrv2.rs
  • pkgs/primitives/src/types/mod.rs
  • pkgs/primitives/src/types/netinfo.rs
  • pkgs/primitives/src/validation.rs
  • pkgs/script/Cargo.toml
  • pkgs/script/src/lib.rs
  • pkgs/types/src/lib.rs
  • pkgs/types/src/serialize.rs
💤 Files with no reviewable changes (15)
  • pkgs/primitives/src/tx_out.rs
  • pkgs/num/src/error.rs
  • pkgs/primitives/src/outpoint.rs
  • pkgs/primitives/src/tx_types.rs
  • pkgs/p2p_core/src/msg/cfilter.rs
  • pkgs/types/src/lib.rs
  • pkgs/primitives/src/tx_in.rs
  • pkgs/p2p_core/src/msg/cfcheckpt.rs
  • pkgs/num/src/util.rs
  • pkgs/p2p_core/src/primitives/filter_type.rs
  • pkgs/p2p_core/src/msg/mnlistdiff.rs
  • pkgs/p2p_core/src/msg/cfheaders.rs
  • pkgs/primitives/src/block_header.rs
  • pkgs/primitives/src/validation.rs
  • pkgs/p2p_core/src/primitives/net_addr.rs
✅ Files skipped from review due to trivial changes (13)
  • pkgs/p2p_core/src/primitives/short_id.rs
  • pkgs/p2p_core/src/msg/headers2.rs
  • pkgs/p2p_core/src/msg/inv.rs
  • pkgs/primitives/src/payload/assetunlock.rs
  • pkgs/primitives/src/types/mod.rs
  • pkgs/pkc/Cargo.toml
  • pkgs/pkc/src/lib.rs
  • pkgs/p2p_core/tests/addrv2.rs
  • pkgs/primitives/src/payload/cbtx.rs
  • pkgs/primitives/src/payload/assetlock.rs
  • pkgs/p2p_core/src/msg/headers.rs
  • pkgs/p2p_core/src/v2/mod.rs
  • pkgs/primitives/src/payload/proupregtx.rs
🚧 Files skipped from review as they are similar to previous changes (29)
  • pkgs/primitives/src/payload/mnhftx.rs
  • pkgs/dev/src/lambda.rs
  • pkgs/params/src/types.rs
  • pkgs/types/src/serialize.rs
  • contrib/semgrep/types.yml
  • pkgs/primitives/src/types/addrv2.rs
  • pkgs/p2p_core/src/lib.rs
  • pkgs/primitives/Cargo.toml
  • pkgs/primitives/src/payload/quorum.rs
  • pkgs/pkc/src/k256/sig.rs
  • pkgs/pkc/src/bls_ietf/pk.rs
  • pkgs/primitives/src/payload/prouprevtx.rs
  • pkgs/pkc/src/bls_ietf/sig.rs
  • pkgs/script/Cargo.toml
  • pkgs/pkc/src/bls_chia/sig.rs
  • pkgs/pkc/src/k256/pk.rs
  • pkgs/primitives/src/script.rs
  • pkgs/num/src/hash.rs
  • pkgs/p2p_core/src/primitives/mn_list.rs
  • pkgs/p2p_core/src/msg/mod.rs
  • pkgs/pkc/src/bls_chia/pk.rs
  • pkgs/primitives/src/transaction.rs
  • pkgs/num/src/lib.rs
  • pkgs/primitives/src/lib.rs
  • pkgs/p2p_core/src/msg/compact_filters.rs
  • pkgs/primitives/src/block.rs
  • pkgs/primitives/src/support.rs
  • pkgs/primitives/src/payload/mod.rs
  • pkgs/primitives/src/payload/proregtx.rs

Comment thread contrib/codeql/decl.ql

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@contrib/git_filter.py`:
- Around line 219-223: The exception handler in the try-except block around
main() is catching the overly broad Exception class, which masks unexpected
defects. Replace the Exception catch with a tuple of the specific exception
types that main() can raise: RuntimeError (from _git_ok() when git commands
fail), FileNotFoundError (from root_dir() if the workspace root is not found),
and OSError and its subclasses (from tempfile.mkdtemp()). This allows unexpected
exceptions to propagate while still handling all expected operational failures.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 2aef0dee-0bd2-486e-abbe-66d2ac47b704

📥 Commits

Reviewing files that changed from the base of the PR and between dc04af3 and 0964dab.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (61)
  • contrib/codeql/decl.ql
  • contrib/common.py
  • contrib/git_filter.py
  • contrib/lint_all.py
  • contrib/semgrep/types.yml
  • pkgs/num/src/error.rs
  • pkgs/num/src/hash.rs
  • pkgs/num/src/lib.rs
  • pkgs/num/src/util.rs
  • pkgs/p2p_core/src/lib.rs
  • pkgs/p2p_core/src/msg/addr.rs
  • pkgs/p2p_core/src/msg/cfcheckpt.rs
  • pkgs/p2p_core/src/msg/cfheaders.rs
  • pkgs/p2p_core/src/msg/cfilter.rs
  • pkgs/p2p_core/src/msg/compact_filters.rs
  • pkgs/p2p_core/src/msg/mnlistdiff.rs
  • pkgs/p2p_core/src/msg/mod.rs
  • pkgs/p2p_core/src/msg/version.rs
  • pkgs/p2p_core/src/primitives/filter_type.rs
  • pkgs/p2p_core/src/primitives/mn_list.rs
  • pkgs/p2p_core/src/primitives/mod.rs
  • pkgs/p2p_core/src/primitives/net_addr.rs
  • pkgs/p2p_core/tests/addrv2.rs
  • pkgs/pkc/Cargo.toml
  • pkgs/pkc/src/bls_chia/pk.rs
  • pkgs/pkc/src/bls_chia/sig.rs
  • pkgs/pkc/src/bls_ietf/pk.rs
  • pkgs/pkc/src/bls_ietf/sig.rs
  • pkgs/pkc/src/k256/pk.rs
  • pkgs/pkc/src/k256/sig.rs
  • pkgs/pkc/src/lib.rs
  • pkgs/primitives/Cargo.toml
  • pkgs/primitives/src/block.rs
  • pkgs/primitives/src/block_header.rs
  • pkgs/primitives/src/gov.rs
  • pkgs/primitives/src/lib.rs
  • pkgs/primitives/src/outpoint.rs
  • pkgs/primitives/src/payload/assetlock.rs
  • pkgs/primitives/src/payload/assetunlock.rs
  • pkgs/primitives/src/payload/cbtx.rs
  • pkgs/primitives/src/payload/mnhftx.rs
  • pkgs/primitives/src/payload/mod.rs
  • pkgs/primitives/src/payload/proregtx.rs
  • pkgs/primitives/src/payload/proupregtx.rs
  • pkgs/primitives/src/payload/prouprevtx.rs
  • pkgs/primitives/src/payload/proupservtx.rs
  • pkgs/primitives/src/payload/quorum.rs
  • pkgs/primitives/src/script.rs
  • pkgs/primitives/src/support.rs
  • pkgs/primitives/src/transaction.rs
  • pkgs/primitives/src/tx_in.rs
  • pkgs/primitives/src/tx_out.rs
  • pkgs/primitives/src/types/addrv1.rs
  • pkgs/primitives/src/types/addrv2.rs
  • pkgs/primitives/src/types/mod.rs
  • pkgs/primitives/src/types/netinfo.rs
  • pkgs/primitives/src/validation.rs
  • pkgs/script/Cargo.toml
  • pkgs/script/src/lib.rs
  • pkgs/types/src/lib.rs
  • pkgs/types/src/serialize.rs
💤 Files with no reviewable changes (14)
  • pkgs/primitives/src/block_header.rs
  • pkgs/p2p_core/src/msg/cfheaders.rs
  • pkgs/p2p_core/src/primitives/filter_type.rs
  • pkgs/num/src/util.rs
  • pkgs/p2p_core/src/msg/cfcheckpt.rs
  • pkgs/primitives/src/tx_in.rs
  • pkgs/primitives/src/outpoint.rs
  • pkgs/types/src/lib.rs
  • pkgs/p2p_core/src/primitives/net_addr.rs
  • pkgs/p2p_core/src/msg/cfilter.rs
  • pkgs/p2p_core/src/msg/mnlistdiff.rs
  • pkgs/primitives/src/validation.rs
  • pkgs/primitives/src/tx_out.rs
  • pkgs/num/src/error.rs
✅ Files skipped from review due to trivial changes (8)
  • pkgs/primitives/src/payload/cbtx.rs
  • pkgs/pkc/Cargo.toml
  • pkgs/primitives/src/payload/assetunlock.rs
  • pkgs/primitives/src/payload/proupregtx.rs
  • pkgs/primitives/src/types/mod.rs
  • pkgs/types/src/serialize.rs
  • pkgs/primitives/src/payload/prouprevtx.rs
  • pkgs/p2p_core/tests/addrv2.rs
🚧 Files skipped from review as they are similar to previous changes (34)
  • contrib/semgrep/types.yml
  • pkgs/primitives/src/types/addrv1.rs
  • contrib/codeql/decl.ql
  • pkgs/primitives/src/payload/assetlock.rs
  • pkgs/primitives/src/payload/mnhftx.rs
  • pkgs/primitives/src/gov.rs
  • pkgs/pkc/src/bls_ietf/sig.rs
  • pkgs/pkc/src/bls_chia/pk.rs
  • pkgs/pkc/src/lib.rs
  • pkgs/pkc/src/bls_ietf/pk.rs
  • pkgs/pkc/src/k256/sig.rs
  • pkgs/pkc/src/k256/pk.rs
  • pkgs/p2p_core/src/primitives/mod.rs
  • pkgs/num/src/hash.rs
  • pkgs/primitives/src/script.rs
  • pkgs/primitives/src/types/addrv2.rs
  • pkgs/primitives/src/payload/quorum.rs
  • pkgs/script/Cargo.toml
  • pkgs/num/src/lib.rs
  • pkgs/p2p_core/src/msg/version.rs
  • pkgs/pkc/src/bls_chia/sig.rs
  • pkgs/p2p_core/src/primitives/mn_list.rs
  • pkgs/primitives/Cargo.toml
  • pkgs/p2p_core/src/msg/mod.rs
  • pkgs/primitives/src/payload/proregtx.rs
  • pkgs/p2p_core/src/lib.rs
  • pkgs/primitives/src/payload/proupservtx.rs
  • pkgs/p2p_core/src/msg/addr.rs
  • pkgs/p2p_core/src/msg/compact_filters.rs
  • pkgs/primitives/src/transaction.rs
  • pkgs/primitives/src/types/netinfo.rs
  • pkgs/primitives/src/block.rs
  • pkgs/primitives/src/payload/mod.rs
  • pkgs/script/src/lib.rs

Comment thread contrib/git_filter.py Outdated
@kwvg kwvg changed the title sdk%refac: consolidate exports, types, add utf8 serde codec to process domain names, preserve unknown types, drop legacy macro sdk%refac: consolidate exports, types, add utf8 serde codec to process domain names, preserve unknown values, drop legacy macro Jun 22, 2026
@kwvg kwvg merged commit c048988 into dashpay:develop Jun 22, 2026
37 checks passed
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.

1 participant