mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-05-05 17:30:59 +02:00
[net processing] Tolerate sendheaders and sendcmpct messages before verack
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.
This commit is contained in:
parent
b103fdcb3b
commit
b316dcb758
@ -2503,6 +2503,39 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg_type == NetMsgType::SENDHEADERS) {
|
||||
LOCK(cs_main);
|
||||
State(pfrom.GetId())->fPreferHeaders = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg_type == NetMsgType::SENDCMPCT) {
|
||||
bool fAnnounceUsingCMPCTBLOCK = false;
|
||||
uint64_t nCMPCTBLOCKVersion = 0;
|
||||
vRecv >> fAnnounceUsingCMPCTBLOCK >> nCMPCTBLOCKVersion;
|
||||
if (nCMPCTBLOCKVersion == 1 || ((pfrom.GetLocalServices() & NODE_WITNESS) && nCMPCTBLOCKVersion == 2)) {
|
||||
LOCK(cs_main);
|
||||
// fProvidesHeaderAndIDs is used to "lock in" version of compact blocks we send (fWantsCmpctWitness)
|
||||
if (!State(pfrom.GetId())->fProvidesHeaderAndIDs) {
|
||||
State(pfrom.GetId())->fProvidesHeaderAndIDs = true;
|
||||
State(pfrom.GetId())->fWantsCmpctWitness = nCMPCTBLOCKVersion == 2;
|
||||
}
|
||||
if (State(pfrom.GetId())->fWantsCmpctWitness == (nCMPCTBLOCKVersion == 2)) { // ignore later version announces
|
||||
State(pfrom.GetId())->fPreferHeaderAndIDs = fAnnounceUsingCMPCTBLOCK;
|
||||
// save whether peer selects us as BIP152 high-bandwidth peer
|
||||
// (receiving sendcmpct(1) signals high-bandwidth, sendcmpct(0) low-bandwidth)
|
||||
pfrom.m_bip152_highbandwidth_from = fAnnounceUsingCMPCTBLOCK;
|
||||
}
|
||||
if (!State(pfrom.GetId())->fSupportsDesiredCmpctVersion) {
|
||||
if (pfrom.GetLocalServices() & NODE_WITNESS)
|
||||
State(pfrom.GetId())->fSupportsDesiredCmpctVersion = (nCMPCTBLOCKVersion == 2);
|
||||
else
|
||||
State(pfrom.GetId())->fSupportsDesiredCmpctVersion = (nCMPCTBLOCKVersion == 1);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Feature negotiation of wtxidrelay must happen between VERSION and VERACK
|
||||
// to avoid relay problems from switching after a connection is up.
|
||||
if (msg_type == NetMsgType::WTXIDRELAY) {
|
||||
@ -2600,39 +2633,6 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg_type == NetMsgType::SENDHEADERS) {
|
||||
LOCK(cs_main);
|
||||
State(pfrom.GetId())->fPreferHeaders = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg_type == NetMsgType::SENDCMPCT) {
|
||||
bool fAnnounceUsingCMPCTBLOCK = false;
|
||||
uint64_t nCMPCTBLOCKVersion = 0;
|
||||
vRecv >> fAnnounceUsingCMPCTBLOCK >> nCMPCTBLOCKVersion;
|
||||
if (nCMPCTBLOCKVersion == 1 || ((pfrom.GetLocalServices() & NODE_WITNESS) && nCMPCTBLOCKVersion == 2)) {
|
||||
LOCK(cs_main);
|
||||
// fProvidesHeaderAndIDs is used to "lock in" version of compact blocks we send (fWantsCmpctWitness)
|
||||
if (!State(pfrom.GetId())->fProvidesHeaderAndIDs) {
|
||||
State(pfrom.GetId())->fProvidesHeaderAndIDs = true;
|
||||
State(pfrom.GetId())->fWantsCmpctWitness = nCMPCTBLOCKVersion == 2;
|
||||
}
|
||||
if (State(pfrom.GetId())->fWantsCmpctWitness == (nCMPCTBLOCKVersion == 2)) { // ignore later version announces
|
||||
State(pfrom.GetId())->fPreferHeaderAndIDs = fAnnounceUsingCMPCTBLOCK;
|
||||
// save whether peer selects us as BIP152 high-bandwidth peer
|
||||
// (receiving sendcmpct(1) signals high-bandwidth, sendcmpct(0) low-bandwidth)
|
||||
pfrom.m_bip152_highbandwidth_from = fAnnounceUsingCMPCTBLOCK;
|
||||
}
|
||||
if (!State(pfrom.GetId())->fSupportsDesiredCmpctVersion) {
|
||||
if (pfrom.GetLocalServices() & NODE_WITNESS)
|
||||
State(pfrom.GetId())->fSupportsDesiredCmpctVersion = (nCMPCTBLOCKVersion == 2);
|
||||
else
|
||||
State(pfrom.GetId())->fSupportsDesiredCmpctVersion = (nCMPCTBLOCKVersion == 1);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg_type == NetMsgType::INV) {
|
||||
std::vector<CInv> vInv;
|
||||
vRecv >> vInv;
|
||||
|
Loading…
x
Reference in New Issue
Block a user