[net processing] Only accept sendcmpct with version=2

Subsequent commits will remove support for other versions of compact blocks.

Add a test that a received `sendcmpct` message with version = 1 is
ignored.
This commit is contained in:
John Newbery committed 2022-05-15 15:37:56 -04:00
1 parent 16730b64bb
commit 42882fc8fc
2 files changed
+12 -2

No files matched your search

+4 -2
View File
@@ -2883,7 +2883,10 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
bool fAnnounceUsingCMPCTBLOCK = false; bool fAnnounceUsingCMPCTBLOCK = false;
uint64_t nCMPCTBLOCKVersion = 0; uint64_t nCMPCTBLOCKVersion = 0;
vRecv >> fAnnounceUsingCMPCTBLOCK >> nCMPCTBLOCKVersion; vRecv >> fAnnounceUsingCMPCTBLOCK >> nCMPCTBLOCKVersion;
if (nCMPCTBLOCKVersion == 1 || nCMPCTBLOCKVersion == 2) {
// Only support compact block relay with witnesses
if (nCMPCTBLOCKVersion != CMPCTBLOCKS_VERSION) return;
LOCK(cs_main); LOCK(cs_main);
// fProvidesHeaderAndIDs is used to "lock in" version of compact blocks we send (fWantsCmpctWitness) // fProvidesHeaderAndIDs is used to "lock in" version of compact blocks we send (fWantsCmpctWitness)
if (!State(pfrom.GetId())->fProvidesHeaderAndIDs) { if (!State(pfrom.GetId())->fProvidesHeaderAndIDs) {
@@ -2899,7 +2902,6 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
if (!State(pfrom.GetId())->fSupportsDesiredCmpctVersion) { if (!State(pfrom.GetId())->fSupportsDesiredCmpctVersion) {
State(pfrom.GetId())->fSupportsDesiredCmpctVersion = (nCMPCTBLOCKVersion == 2); State(pfrom.GetId())->fSupportsDesiredCmpctVersion = (nCMPCTBLOCKVersion == 2);
} }
}
return; return;
} }
+8
View File
@@ -179,6 +179,7 @@ class CompactBlocksTest(BitcoinTestFramework):
# Test "sendcmpct" (between peers preferring the same version): # Test "sendcmpct" (between peers preferring the same version):
# - No compact block announcements unless sendcmpct is sent. # - No compact block announcements unless sendcmpct is sent.
# - If sendcmpct is sent with version = 1, the message is ignored.
# - If sendcmpct is sent with version > 2, the message is ignored. # - If sendcmpct is sent with version > 2, the message is ignored.
# - If sendcmpct is sent with boolean 0, then block announcements are not # - If sendcmpct is sent with boolean 0, then block announcements are not
# made with compact blocks. # made with compact blocks.
@@ -221,6 +222,13 @@ class CompactBlocksTest(BitcoinTestFramework):
# Before each test, sync the headers chain. # Before each test, sync the headers chain.
test_node.request_headers_and_sync(locator=[tip]) test_node.request_headers_and_sync(locator=[tip])
# Now try a SENDCMPCT message with too-low version
test_node.send_and_ping(msg_sendcmpct(announce=True, version=1))
check_announcement_of_new_block(node, test_node, lambda p: "cmpctblock" not in p.last_message)
# Headers sync before next test.
test_node.request_headers_and_sync(locator=[tip])
# Now try a SENDCMPCT message with too-high version # Now try a SENDCMPCT message with too-high version
test_node.send_and_ping(msg_sendcmpct(announce=True, version=3)) test_node.send_and_ping(msg_sendcmpct(announce=True, version=3))
check_announcement_of_new_block(node, test_node, lambda p: "cmpctblock" not in p.last_message) check_announcement_of_new_block(node, test_node, lambda p: "cmpctblock" not in p.last_message)