Refactor wallets::representatives to use nano::locked#5018
Conversation
Test Results for Commit 44caafbPull Request 5018: Results Test Case Results
Last updated: 2026-01-29 17:56:40 UTC |
There was a problem hiding this comment.
Pull request overview
Refactors wallet representative tracking to use nano::locked instead of manually managed mutex+container pairs, and simplifies representative qualification checks.
Changes:
- Replace
walletandwalletsrepresentative containers/mutexes withnano::lockedwrappers. - Simplify
wallets::check_repAPI and move the shared logic intocheck_rep_impl. - Update unit tests to use the new
wallet::reps()accessor instead of direct mutex/container access.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| nano/node/wallet.hpp | Switch representative members to nano::locked; add wallet::reps(); update wallets::check_rep signature and add check_rep_impl. |
| nano/node/wallet.cpp | Update representative insertion/scanning logic to use nano::locked; refactor check_rep into check_rep + check_rep_impl. |
| nano/core_test/wallets.cpp | Adjust tests to use wallet::reps() instead of accessing internal mutex/container. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| bool nano::wallets::check_rep (nano::account const & account) | ||
| { | ||
| auto half_principal_weight = node.minimum_principal_weight () / 2; | ||
| auto representatives_locked = representatives.lock (); | ||
| return check_rep_impl (*representatives_locked, account, half_principal_weight); | ||
| } |
There was a problem hiding this comment.
wallets::check_rep() acquires the representatives lock before calling ledger.weight() inside check_rep_impl(). This increases lock hold time and contention compared to the prior pattern where the weight/vote_minimum check happened before locking. Consider computing weight (and early-returning for non-reps) before taking the representatives lock, and only locking for the insert / counter / half_principal update (e.g., pass weight into check_rep_impl, or split into a no-lock precheck + locked update).
No description provided.