refactor: miscellaneous type safety and lookup improvements#7136
refactor: miscellaneous type safety and lookup improvements#7136PastaPastaPasta merged 3 commits intodashpay:developfrom
Conversation
ReadFixedBitSet/WriteFixedBitSet use size_t throughout, but their VarInt counterparts use int32_t for index tracking. This limits VarInt bitsets to 2^31 entries and involves mixed signed/unsigned arithmetic. Modernize to match the size_t convention using std::optional to replace the sentinel value of -1. Wire format is preserved: when last is unset (was -1), i - (-1) == i + 1, so the replacement expression produces identical values. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…tion IsCollateralValid manually looks up inputs from both the mempool and UTXO set using two separate code paths. The sibling function IsValidInOuts already uses CCoinsViewMemPool which unifies both lookups behind a single interface. Align the two functions by adopting the same pattern here. This also allows merging the cs_main lock scope to cover both the coin lookup and the ATMPIfSaneFee call, removing a redundant lock acquisition. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ion handling GetMember(const uint256&) provides safe hash-based member lookup returning nullptr when not found. However, index-based access throughout the justification code uses raw members[index] with no equivalent safety. Add GetMemberAtIndex(size_t) as the index-based counterpart and adopt it in PreVerifyMessage/ReceiveMessage for CDKGJustification, alongside structured binding modernization. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
✅ No Merge Conflicts DetectedThis PR currently has no conflicts with other open PRs. |
WalkthroughThis pull request refactors multiple core components to improve safety and consistency. The collateral validation logic is reworked to use a mempool-aware coin view with explicit synchronization, replacing previous per-input checks. DKG session member access patterns are strengthened with structured bindings and a new GetMemberAtIndex helper method to safely handle out-of-bounds cases. Bitset serialization logic is updated to use std::optional<size_t> for index tracking, replacing int-based logic and adding an explicit stopper VarInt to terminate sequences. Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
⚔️ Resolve merge conflicts (beta)
No actionable comments were generated in the recent review. 🎉 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 |
Issue being fixed or feature implemented
size_tconsistently in VarInt bitset serialization, replacing mixedint/unsigned inttypes
CCoinsViewMemPoolinIsCollateralValidto resolve inputs from both the UTXO set andmempool, removing manual mempool iteration
GetMemberAtIndex(size_t)for safe index-based DKG member lookup with nullptrreturn, matching the existing
GetMember(const uint256&)API, and add assertions at call siteswhere
PreVerifyMessageguarantees validityWhat was done?
see commits
How Has This Been Tested?
Breaking Changes
N/A
Checklist:
Go over all the following points, and put an
xin all the boxes that apply.