Conversation
71f5460 to
e6d98e1
Compare
There was a problem hiding this comment.
Pull request overview
This PR improves the peer selection policy for dmq-node and refactors the validateSig function to remove the hashing function parameter.
Changes:
- Replaced trivial peer selection policy with a weighted selection algorithm that considers peer state (tepid flag) and failure history
- Refactored
validateSigto useLedger.hashKey (Ledger.VKey coldKey)directly instead of accepting a hashing function parameter - Added a tracer lock to prevent interleaved trace output
- Updated ouroboros-network dependency to a development branch
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| dmq-node/src/DMQ/Diffusion/PeerSelection.hs | Replaced trivial peer selection with weighted algorithm based on peer state and failures |
| dmq-node/src/DMQ/Protocol/SigSubmission/Validate.hs | Removed hashing function parameter from validateSig, refactored to use Ledger.hashKey directly, reordered validation checks for performance |
| dmq-node/test/DMQ/Protocol/SigSubmission/Test.hs | Updated test to match new validateSig signature |
| dmq-node/app/Main.hs | Added tracer lock for synchronized output, updated to pass RNG TVar to policy, removed unused imports |
| dmq-node/src/DMQ/Diffusion/NodeKernel.hs | Changed to qualified imports for Ledger modules |
| dmq-node/dmq-node.cabal | Removed unused cardano-ledger-core dependency from executable |
| cabal.project | Updated ouroboros-network dependency to development branch |
| dmq-node/changelog.d/20260122_162026_coot_peer_selection_policy.md | Documented breaking and non-breaking changes |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| inRng <- readTVar rngVar | ||
|
|
||
| let (rng, rng') = split inRng | ||
| rns = take (Set.size available) $ unfoldr (Just . random) rng :: [Word32] |
There was a problem hiding this comment.
There are two spaces between random) and rng on this line. Consider removing the extra space for consistency.
| rns = take (Set.size available) $ unfoldr (Just . random) rng :: [Word32] | |
| rns = take (Set.size available) $ unfoldr (Just . random) rng :: [Word32] |
| -- from coot/dmq-related-changes | ||
| tag: 625296c92363b8c5e77cddee40de4525421d2660 |
There was a problem hiding this comment.
This PR depends on an unreleased branch (coot/dmq-related-changes) of ouroboros-network. Consider documenting what changes in that branch are required for this PR to work, or ensure that branch is merged and released before merging this PR. Using unreleased dependencies can make builds unstable and difficult to reproduce.
| -> Word32 | ||
| -> (peerAddr, Word32) | ||
| failWeight failCnt peer r = | ||
| (peer, r `div` fromIntegral (failCnt peer + 1)) |
There was a problem hiding this comment.
The failWeight function uses integer division which could result in a weight of 0 when failCnt peer is large. When multiple peers have a weight of 0, their ordering becomes non-deterministic (dependent only on the random number). Consider using a minimum weight (e.g., max 1 (r \div` ...)`) to ensure some randomness is preserved, or document that this behavior is intentional.
| (peer, r `div` fromIntegral (failCnt peer + 1)) | |
| (peer, max 1 (r `div` fromIntegral (failCnt peer + 1))) |
| -- | Trivial peer selection policy used as dummy value | ||
| -- |
There was a problem hiding this comment.
The comment describes this as a "Trivial peer selection policy used as dummy value" but the implementation is now quite sophisticated with weighted selection based on tepid flags and failure counts. Consider updating the comment to reflect the actual implementation, e.g., "Weighted peer selection policy that prioritizes peers based on their state and failure history".
| -- | Trivial peer selection policy used as dummy value | |
| -- | |
| -- | Weighted peer selection policy that prioritizes peers based on | |
| -- their state and failure history. |
| else (peer, r) | ||
|
|
||
|
|
||
| -- Add scaled random number in order to prevent ordering based on SockAddr |
There was a problem hiding this comment.
The comment has incorrect indentation. It should start at column 1 like the function definition below it, not with a leading space.
| -- Add scaled random number in order to prevent ordering based on SockAddr | |
| -- Add scaled random number in order to prevent ordering based on SockAddr |
|
|
||
| ### Non-Breaking | ||
|
|
||
| - Added a lock to avoid race conditions between trace events. |
There was a problem hiding this comment.
The changelog entry mentions "Added a lock to avoid race conditions between trace events" but this appears to be unrelated to the PR title "PeerSelectionPolicy for dmq-node". Consider either updating the PR title to reflect all changes, or split this into a separate PR if it's an independent change.
| @@ -0,0 +1,9 @@ | |||
| ### Breaking | |||
|
|
|||
| - `validateSig`: removed the hashing function for cold key from arguments, added required constraints ledger's `hashKey . VKey` usage instead | |||
There was a problem hiding this comment.
The changelog mentions using "ledger's hashKey . VKey usage" but the actual implementation uses Ledger.hashKey (Ledger.VKey coldKey). While the meaning is the same, consider updating the changelog to match the actual code pattern for clarity.
| - `validateSig`: removed the hashing function for cold key from arguments, added required constraints ledger's `hashKey . VKey` usage instead | |
| - `validateSig`: removed the hashing function for cold key from arguments, added required constraints for using `Ledger.hashKey (Ledger.VKey coldKey)` instead |
The peer selection policy is based on `simplePeerSelectionPolicy` with two exceptions: * it doesn't take into account `PeerMetric`, since it's not available * it doesn't forget known local root peers The latter is important, since at least now there no other peers in the network.
Included IntersectMBO/ouroboros-network#5289 to `coot/dmq-related-changes`
Cryptographic checks are the most computationally complex, so it makes sense to run them last. Added comments.
It's enough for us to add `DSIGN crypto ~ Ledger.DSIGN` constraint to hash they key.
e6d98e1 to
363cb28
Compare
List of changes
dmq-nodeChecklist