Skip to content

Commit fff7d05

Browse files
author
MarcoFalke
committed
Merge #20599: net processing: Tolerate sendheaders and sendcmpct messages before verack
b316dcb [net processing] Tolerate sendheaders and sendcmpct messages before verack (John Newbery) Pull request description: BIP 130 (sendheaders) and BIP 152 (compact blocks) do not specify at which stage the `sendheaders` or `sendcmpct` messages should be sent. Therefore we should tolerate them being sent before the version-verack handshake is complete. ACKs for top commit: MarcoFalke: review ACK b316dcb 📒 jonatack: Code review re-ACK b316dcb per `git range-diff b103fdc 82d0a43 b316dcb`, rebase only luke-jr: utACK b316dcb, only code movement from after verack check to before Tree-SHA512: a8da3990a786a53c195a33cd278eb9d1b6b09e9a33717674d5bc6ef5629811189216f3eda1a3dd11f6972b9680c7b7a532bf7343b6e7440009dd831bef128e1d
2 parents b103fdc + b316dcb commit fff7d05

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

src/net_processing.cpp

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2503,6 +2503,39 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
25032503
return;
25042504
}
25052505

2506+
if (msg_type == NetMsgType::SENDHEADERS) {
2507+
LOCK(cs_main);
2508+
State(pfrom.GetId())->fPreferHeaders = true;
2509+
return;
2510+
}
2511+
2512+
if (msg_type == NetMsgType::SENDCMPCT) {
2513+
bool fAnnounceUsingCMPCTBLOCK = false;
2514+
uint64_t nCMPCTBLOCKVersion = 0;
2515+
vRecv >> fAnnounceUsingCMPCTBLOCK >> nCMPCTBLOCKVersion;
2516+
if (nCMPCTBLOCKVersion == 1 || ((pfrom.GetLocalServices() & NODE_WITNESS) && nCMPCTBLOCKVersion == 2)) {
2517+
LOCK(cs_main);
2518+
// fProvidesHeaderAndIDs is used to "lock in" version of compact blocks we send (fWantsCmpctWitness)
2519+
if (!State(pfrom.GetId())->fProvidesHeaderAndIDs) {
2520+
State(pfrom.GetId())->fProvidesHeaderAndIDs = true;
2521+
State(pfrom.GetId())->fWantsCmpctWitness = nCMPCTBLOCKVersion == 2;
2522+
}
2523+
if (State(pfrom.GetId())->fWantsCmpctWitness == (nCMPCTBLOCKVersion == 2)) { // ignore later version announces
2524+
State(pfrom.GetId())->fPreferHeaderAndIDs = fAnnounceUsingCMPCTBLOCK;
2525+
// save whether peer selects us as BIP152 high-bandwidth peer
2526+
// (receiving sendcmpct(1) signals high-bandwidth, sendcmpct(0) low-bandwidth)
2527+
pfrom.m_bip152_highbandwidth_from = fAnnounceUsingCMPCTBLOCK;
2528+
}
2529+
if (!State(pfrom.GetId())->fSupportsDesiredCmpctVersion) {
2530+
if (pfrom.GetLocalServices() & NODE_WITNESS)
2531+
State(pfrom.GetId())->fSupportsDesiredCmpctVersion = (nCMPCTBLOCKVersion == 2);
2532+
else
2533+
State(pfrom.GetId())->fSupportsDesiredCmpctVersion = (nCMPCTBLOCKVersion == 1);
2534+
}
2535+
}
2536+
return;
2537+
}
2538+
25062539
// Feature negotiation of wtxidrelay must happen between VERSION and VERACK
25072540
// to avoid relay problems from switching after a connection is up.
25082541
if (msg_type == NetMsgType::WTXIDRELAY) {
@@ -2600,39 +2633,6 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
26002633
return;
26012634
}
26022635

2603-
if (msg_type == NetMsgType::SENDHEADERS) {
2604-
LOCK(cs_main);
2605-
State(pfrom.GetId())->fPreferHeaders = true;
2606-
return;
2607-
}
2608-
2609-
if (msg_type == NetMsgType::SENDCMPCT) {
2610-
bool fAnnounceUsingCMPCTBLOCK = false;
2611-
uint64_t nCMPCTBLOCKVersion = 0;
2612-
vRecv >> fAnnounceUsingCMPCTBLOCK >> nCMPCTBLOCKVersion;
2613-
if (nCMPCTBLOCKVersion == 1 || ((pfrom.GetLocalServices() & NODE_WITNESS) && nCMPCTBLOCKVersion == 2)) {
2614-
LOCK(cs_main);
2615-
// fProvidesHeaderAndIDs is used to "lock in" version of compact blocks we send (fWantsCmpctWitness)
2616-
if (!State(pfrom.GetId())->fProvidesHeaderAndIDs) {
2617-
State(pfrom.GetId())->fProvidesHeaderAndIDs = true;
2618-
State(pfrom.GetId())->fWantsCmpctWitness = nCMPCTBLOCKVersion == 2;
2619-
}
2620-
if (State(pfrom.GetId())->fWantsCmpctWitness == (nCMPCTBLOCKVersion == 2)) { // ignore later version announces
2621-
State(pfrom.GetId())->fPreferHeaderAndIDs = fAnnounceUsingCMPCTBLOCK;
2622-
// save whether peer selects us as BIP152 high-bandwidth peer
2623-
// (receiving sendcmpct(1) signals high-bandwidth, sendcmpct(0) low-bandwidth)
2624-
pfrom.m_bip152_highbandwidth_from = fAnnounceUsingCMPCTBLOCK;
2625-
}
2626-
if (!State(pfrom.GetId())->fSupportsDesiredCmpctVersion) {
2627-
if (pfrom.GetLocalServices() & NODE_WITNESS)
2628-
State(pfrom.GetId())->fSupportsDesiredCmpctVersion = (nCMPCTBLOCKVersion == 2);
2629-
else
2630-
State(pfrom.GetId())->fSupportsDesiredCmpctVersion = (nCMPCTBLOCKVersion == 1);
2631-
}
2632-
}
2633-
return;
2634-
}
2635-
26362636
if (msg_type == NetMsgType::INV) {
26372637
std::vector<CInv> vInv;
26382638
vRecv >> vInv;

0 commit comments

Comments
 (0)