forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix: punish invalid dstx messages #7347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
thepastaclaw
wants to merge
2
commits into
dashpay:develop
Choose a base branch
from
thepastaclaw:fix/dstx-unknown-mn-cost
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+129
−7
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| #!/usr/bin/env python3 | ||
| # Copyright (c) 2026 The Dash Core developers | ||
| # Distributed under the MIT software license, see the accompanying | ||
| # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
| """Test P2P CoinJoin broadcast transaction handling.""" | ||
|
|
||
| import time | ||
|
|
||
| from test_framework.messages import ( | ||
| CCoinJoinBroadcastTx, | ||
| COIN, | ||
| COutPoint, | ||
| CTransaction, | ||
| CTxIn, | ||
| CTxOut, | ||
| msg_dstx, | ||
| ) | ||
| from test_framework.p2p import P2PInterface | ||
| from test_framework.script import ( | ||
| CScript, | ||
| OP_CHECKSIG, | ||
| OP_DUP, | ||
| OP_EQUALVERIFY, | ||
| OP_HASH160, | ||
| ) | ||
| from test_framework.test_framework import BitcoinTestFramework | ||
|
|
||
|
|
||
| class P2PDSTXTest(BitcoinTestFramework): | ||
| def set_test_params(self): | ||
| self.num_nodes = 1 | ||
| self.setup_clean_chain = True | ||
| self.extra_args = [["-debug=net"]] | ||
|
|
||
| def make_dstx(self): | ||
| tx = CTransaction() | ||
| tx.vin = [CTxIn(COutPoint(hash=i + 1, n=0)) for i in range(3)] | ||
| p2pkh = CScript([ | ||
| OP_DUP, | ||
| OP_HASH160, | ||
| b"\x01" * 20, | ||
| OP_EQUALVERIFY, | ||
| OP_CHECKSIG, | ||
| ]) | ||
| tx.vout = [CTxOut(nValue=COIN // 1000 + 1, scriptPubKey=p2pkh) for _ in tx.vin] | ||
| return CCoinJoinBroadcastTx( | ||
| tx=tx, | ||
| m_protxHash=1, | ||
| vchSig=b"\x01" * 96, | ||
| sigTime=int(time.time()), | ||
| ) | ||
|
|
||
| def run_test(self): | ||
| self.log.info("Leave IBD so unsolicited DSTX is processed") | ||
| self.generate(self.nodes[0], 1) | ||
|
|
||
| peer = self.nodes[0].add_p2p_connection(P2PInterface()) | ||
|
|
||
| self.log.info("Unknown masternode DSTX is ignored without peer misbehavior") | ||
| with self.nodes[0].assert_debug_log([], unexpected_msgs=["Misbehaving", "invalid dstx"]): | ||
| peer.send_and_ping(msg_dstx(self.make_dstx())) | ||
|
|
||
|
thepastaclaw marked this conversation as resolved.
|
||
| self.log.info("Structurally invalid DSTX is treated as peer misbehavior") | ||
| invalid_dstx = self.make_dstx() | ||
| invalid_dstx.tx.vout.pop() | ||
| with self.nodes[0].assert_debug_log(["Misbehaving", "invalid dstx"]): | ||
| peer.send_and_ping(msg_dstx(invalid_dstx)) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| P2PDSTXTest().main() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When this node is out of IBD but its active tip does not yet include the masternode that signed the DSTX,
ValidateDSTXsearches only the current tip and 23 ancestors and returns{false, true}from the “Can't find masternode” path. This new!bRetbranch therefore increments the peer's misbehavior score for a DSTX that may be valid from the relaying peer's newer chain view, turning a local inability to verify into punishment; consider distinguishing unverifiable/unknown-masternode cases from structural or signature failures before callingMisbehaving.Useful? React with 👍 / 👎.