Repository navigation
coinjoin/server: validate DSQUEUE denomination; remove redundant time stamp screens; tests: add denom and timestamp coverage - #6865
Conversation
…stamp screens; rely on IsTimeOutOfBounds(); tests: add denom and timestamp coverage
✅ No Merge Conflicts DetectedThis PR currently has no conflicts with other open PRs. |
WalkthroughA pre-check was added in src/coinjoin/server.cpp within ProcessDSQUEUE to validate dsq.nDenom using CoinJoin::IsValidDenomination. On invalid input, it logs an "invalid denomination" message with the peer id, sets ret.m_error to MisbehavingError{10}, and returns early. Existing validations remain unchanged. Two unit tests were added: queue_denomination_validation (valid/invalid denomination cases) and queue_timestamp_validation (IsTimeOutOfBounds with current, ±15s, and ±60s, assuming COINJOIN_QUEUE_TIMEOUT=30). No public/exported entity changes. Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Single, focused input-validation addition plus two straightforward tests; low heterogeneity and logic density. Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
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 |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/test/coinjoin_queue_tests.cpp (1)
68-96: ReferenceCOINJOIN_QUEUE_TIMEOUTdirectly in the assertions.Hard-coding
15and60seconds will go stale ifCOINJOIN_QUEUE_TIMEOUTever changes. Drive the checks off the constant to keep the test aligned with production values.- q.nTime = current_time + 15; // 15 seconds in future + q.nTime = current_time + (COINJOIN_QUEUE_TIMEOUT - 1); @@ - q.nTime = current_time - 15; // 15 seconds ago + q.nTime = current_time - (COINJOIN_QUEUE_TIMEOUT - 1); @@ - q.nTime = current_time + 60; // 60 seconds in future + q.nTime = current_time + (COINJOIN_QUEUE_TIMEOUT + 1); @@ - q.nTime = current_time - 60; // 60 seconds ago + q.nTime = current_time - (COINJOIN_QUEUE_TIMEOUT + 1);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/coinjoin/server.cpp(1 hunks)src/test/coinjoin_queue_tests.cpp(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/**/*.{cpp,h,cc,cxx,hpp}
📄 CodeRabbit inference engine (CLAUDE.md)
src/**/*.{cpp,h,cc,cxx,hpp}: Dash Core C++ codebase must be written in C++20 and require at least Clang 16 or GCC 11.1
Dash uses unordered_lru_cache for efficient caching with LRU eviction
Files:
src/test/coinjoin_queue_tests.cppsrc/coinjoin/server.cpp
src/{test,wallet/test,qt/test}/**/*.{cpp,h,cc,cxx,hpp}
📄 CodeRabbit inference engine (CLAUDE.md)
Unit tests for C++ code should be placed in src/test/, src/wallet/test/, or src/qt/test/ and use Boost::Test or Qt 5 for GUI tests
Files:
src/test/coinjoin_queue_tests.cpp
🧬 Code graph analysis (1)
src/test/coinjoin_queue_tests.cpp (1)
src/node/interfaces.cpp (1)
GetSmallestDenomination(387-390)
🪛 GitHub Actions: Clang Diff Format Check
src/test/coinjoin_queue_tests.cpp
[error] 60-60: Clang format differences found between before/after formatting. See diff_output.txt for details; please run clang-format to fix formatting.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
- GitHub Check: linux64_sqlite-build / Build source
- GitHub Check: linux64_fuzz-build / Build source
- GitHub Check: linux64_ubsan-build / Build source
- GitHub Check: linux64-build / Build source
- GitHub Check: arm-linux-build / Build source
- GitHub Check: mac-build / Build source
- GitHub Check: win64-build / Build source
- GitHub Check: linux64_nowallet-build / Build source
- GitHub Check: linux64_tsan-build / Build source
- GitHub Check: Lint / Run linters
🔇 Additional comments (2)
src/coinjoin/server.cpp (1)
120-125: Denomination guard is a solid early exit.Thanks for validating
dsq.nDenomup front and assigning a misbehavior score before doing any heavier work. This closes a validation gap without disturbing the rest of the flow.src/test/coinjoin_queue_tests.cpp (1)
56-66: Re-run clang-format on src/test/coinjoin_queue_tests.cpp
CI has detected formatting deviations in this file, but clang-format isn’t available in this environment. Please run clang-format locally onsrc/test/coinjoin_queue_tests.cppand commit the updated formatting so the CI check passes.
| BOOST_CHECK(!CoinJoin::IsValidDenomination(999)); // Invalid value | ||
| } | ||
|
|
||
| BOOST_AUTO_TEST_CASE(queue_timestamp_validation) |
There was a problem hiding this comment.
nit: should've been a separate commit
The server started rejecting DSQUEUE messages with an invalid denomination (misbehaving 10) in dashpay#6865, but the wallet-side handler never got that check. A client accepted a signed DSQUEUE with a bogus denomination into its queue, where it matched no session and only took up a slot. Validate client DSQUEUEs with CoinJoin::ValidateDSQueue, the checks the server already uses, so the client rejects such queues with the same penalty. The client keeps its own duplicate tracking under cs_ProcessDSQueue, the ready-queue submission and the mixing-rate threshold. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The server started rejecting DSQUEUE messages with an invalid denomination (misbehaving 10) in dashpay#6865, but the wallet-side handler never got that check. A client accepted a signed DSQUEUE with a bogus denomination into its queue, where it matched no session and only took up a slot. Validate client DSQUEUEs with CoinJoin::ValidateDSQueue, the checks the server already uses, so the client rejects such queues with the same penalty. The client keeps its own duplicate tracking under cs_ProcessDSQueue, the ready-queue submission and the mixing-rate threshold. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nts by sharing the server validation 79defda fix(coinjoin): validate DSQUEUE denomination on mixing clients (pasta) 8957837 refactor(coinjoin): extract shared DSQUEUE validation from the server (pasta) Pull request description: ## Issue being fixed or feature implemented Mixing clients accept a signed DSQUEUE with an invalid denomination into their queue. Masternodes have rejected such queues (misbehaving 10) since #6865, but that check was added only to the server's DSQUEUE handler. The wallet-side handler keeps its own copy of the same validation, and the two copies have drifted apart. The bogus queue matches no session, but it takes up a queue slot, and it counts toward the masternode's mixing-rate threshold. ## What was done? - **refactor:** moved the DSQUEUE checks that both roles share into `CoinJoin::ValidateDSQueue` (`src/coinjoin/coinjoin.{h,cpp}`): - denomination - masternode lookup by protx - time bounds - collateral lookup - operator signature It returns the signing masternode and the score to penalize the peer with. `CCoinJoinServer::ProcessDSQUEUE` now uses it. The server's checks, order and penalties are unchanged. - **fix:** `CJWalletManagerImpl::ProcessDSQueue` uses the same function, so clients now reject invalid denominations with the same penalty as the server (10). The duplicate check is passed in as a callback. Each role keeps its own queue storage and locking, and duplicates are still dropped before the BLS signature is verified. Each caller applies the returned penalty its own way (`PeerMisbehaving` on the server, `MisbehavingError` on the client). Remaining differences between the two handlers, kept on purpose and not changed here: - **Mixing-rate threshold:** the server applies it, and `AllowMixing`, only to non-ready queues, and never stores or relays ready queues. The client first tries to submit to its session for a ready queue. If no session is waiting on that masternode, it applies the threshold and stores the ready queue like any other. So on clients, ready queues count toward the threshold. This is long-standing behavior. It may deserve its own look, but this PR doesn't change it. - **Duplicate tracking:** the server uses `TryCheckDuplicate` under `TRY_LOCK` and drops the message silently on lock contention. The client takes a blocking lock, checks `HasQueue(hash)` then `HasQueueFromMasternode`, and holds `cs_ProcessDSQueue` until it has stored the queue. - **After validation:** the server relays the queue. The client marks queues it already joined as tried. Side effects of the client change: - The client penalizes the peer that relayed the queue, as the server already does. Only masternodes relay DSQUEUEs, and since v23.0.0 they drop invalid denominations before relaying. A masternode running something older than v23.0.0 could relay a bad-denomination queue that another masternode signed, and get scored 10. The server has behaved this way since #6865. - A ready queue with an invalid denomination is now dropped before the client tries to submit to its session. `masternodeOutpoint` is not serialized, so in practice every DSQUEUE is resolved through `m_protxHash`. The collateral lookup and protx fill-in after it can't fail for network input. I kept them so the server code moves over line for line. ## How Has This Been Tested? - New unit test `coinjoin_queue_tests/client_rejects_invalid_queues`: - It registers a masternode on a DIP3 regtest chain and feeds signed DSQUEUEs through `CJWalletManager::processMessage`. - It checks the returned penalty and whether the queue was stored for: an invalid denomination (non-ready and ready queue), a missing protx, an unknown protx and a wrong signer. - A valid queue from the same masternode is the accepted control. - Without the client change, the invalid-denomination row fails: the queue is stored and no penalty is returned. - Both commits build on their own, and `coinjoin_queue_tests` passes on each. - Also run on Linux x86_64 with `--enable-debug`: - unit tests: `coinjoin_queue_tests`, `coinjoin_inouts_tests`, `coinjoin_dstxmanager_tests`, `coinjoin_tests` - functional tests: `rpc_coinjoin.py`, `p2p_dstx.py` - lints: `lint-circular-dependencies.py`, `lint-includes.py`, `lint-whitespace.py` ## Breaking Changes None. ## Checklist: - [x] I have performed a self-review of my own code - [ ] I have made corresponding changes to the documentation - [ ] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) Top commit has no ACKs. Tree-SHA512: b34ea65f1977b646253eba334a9b4cbc638869070589f1fac57d3c621b1a149a2d421b952087044dbd087d5fd4189ae57128eeea846174492a6c1410c7e6a4da
Issue being fixed or feature implemented
Ensure we believe that a DSQ is fully valid before we broadcast it further; add unit tests
What was done?
Describe your changes in detail
How Has This Been Tested?
Please describe in detail how you tested your changes.
Include details of your testing environment, and the tests you ran
to see how your change affects other areas of the code, etc.
Breaking Changes
Please describe any breaking changes your code introduces
Checklist:
Go over all the following points, and put an
xin all the boxes that apply.