Skip to content

Commit b486f72

Browse files
committed
[net processing] Remove fWantsCmpctWitness
It is now completely redundant with fProvidesHeadersAndIDs.
1 parent a45d53c commit b486f72

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

src/net_processing.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,6 @@ struct CNodeState {
375375
bool fProvidesHeaderAndIDs{false};
376376
//! Whether this peer can give us witnesses
377377
bool fHaveWitness{false};
378-
//! Whether this peer wants witnesses in cmpctblocks/blocktxns
379-
bool fWantsCmpctWitness{false};
380378

381379
/** State used to enforce CHAIN_SYNC_TIMEOUT and EXTRA_PEER_CHECK_INTERVAL logic.
382380
*
@@ -1656,7 +1654,7 @@ void PeerManagerImpl::NewPoWValidBlock(const CBlockIndex *pindex, const std::sha
16561654
CNodeState &state = *State(pnode->GetId());
16571655
// If the peer has, or we announced to them the previous block already,
16581656
// but we don't think they have this one, go ahead and announce it
1659-
if (state.fPreferHeaderAndIDs && (!fWitnessEnabled || state.fWantsCmpctWitness) &&
1657+
if (state.fPreferHeaderAndIDs && (!fWitnessEnabled || state.fProvidesHeaderAndIDs) &&
16601658
!PeerHasHeader(&state, pindex) && PeerHasHeader(&state, pindex->pprev)) {
16611659

16621660
LogPrint(BCLog::NET, "%s sending header-and-ids %s to peer=%d\n", "PeerManager::NewPoWValidBlock",
@@ -1970,7 +1968,7 @@ void PeerManagerImpl::ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv&
19701968
// they won't have a useful mempool to match against a compact block,
19711969
// and we don't feel like constructing the object for them, so
19721970
// instead we respond with the full, non-compact block.
1973-
bool fPeerWantsWitness = State(pfrom.GetId())->fWantsCmpctWitness;
1971+
bool fPeerWantsWitness = State(pfrom.GetId())->fProvidesHeaderAndIDs;
19741972
int nSendFlags = fPeerWantsWitness ? 0 : SERIALIZE_TRANSACTION_NO_WITNESS;
19751973
if (CanDirectFetch() && pindex->nHeight >= m_chainman.ActiveChain().Height() - MAX_CMPCTBLOCK_DEPTH) {
19761974
if ((fPeerWantsWitness || !fWitnessesPresentInARecentCompactBlock) && a_recent_compact_block && a_recent_compact_block->header.GetHash() == pindex->GetBlockHash()) {
@@ -2141,7 +2139,7 @@ void PeerManagerImpl::SendBlockTransactions(CNode& pfrom, const CBlock& block, c
21412139
}
21422140
LOCK(cs_main);
21432141
const CNetMsgMaker msgMaker(pfrom.GetCommonVersion());
2144-
int nSendFlags = State(pfrom.GetId())->fWantsCmpctWitness ? 0 : SERIALIZE_TRANSACTION_NO_WITNESS;
2142+
int nSendFlags = State(pfrom.GetId())->fProvidesHeaderAndIDs ? 0 : SERIALIZE_TRANSACTION_NO_WITNESS;
21452143
m_connman.PushMessage(&pfrom, msgMaker.Make(nSendFlags, NetMsgType::BLOCKTXN, resp));
21462144
}
21472145

@@ -2881,12 +2879,10 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
28812879
if (nCMPCTBLOCKVersion != CMPCTBLOCKS_VERSION) return;
28822880

28832881
LOCK(cs_main);
2884-
// fProvidesHeaderAndIDs is used to "lock in" version of compact blocks we send (fWantsCmpctWitness)
28852882
if (!State(pfrom.GetId())->fProvidesHeaderAndIDs) {
28862883
State(pfrom.GetId())->fProvidesHeaderAndIDs = true;
2887-
State(pfrom.GetId())->fWantsCmpctWitness = true;
28882884
}
2889-
if (State(pfrom.GetId())->fWantsCmpctWitness) {
2885+
if (State(pfrom.GetId())->fProvidesHeaderAndIDs) {
28902886
State(pfrom.GetId())->fPreferHeaderAndIDs = fAnnounceUsingCMPCTBLOCK;
28912887
// save whether peer selects us as BIP152 high-bandwidth peer
28922888
// (receiving sendcmpct(1) signals high-bandwidth, sendcmpct(0) low-bandwidth)
@@ -3241,7 +3237,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
32413237
// actually receive all the data read from disk over the network.
32423238
LogPrint(BCLog::NET, "Peer %d sent us a getblocktxn for a block > %i deep\n", pfrom.GetId(), MAX_BLOCKTXN_DEPTH);
32433239
CInv inv;
3244-
WITH_LOCK(cs_main, inv.type = State(pfrom.GetId())->fWantsCmpctWitness ? MSG_WITNESS_BLOCK : MSG_BLOCK);
3240+
WITH_LOCK(cs_main, inv.type = State(pfrom.GetId())->fProvidesHeaderAndIDs ? MSG_WITNESS_BLOCK : MSG_BLOCK);
32453241
inv.hash = req.blockhash;
32463242
WITH_LOCK(peer->m_getdata_requests_mutex, peer->m_getdata_requests.push_back(inv));
32473243
// The message processing loop will go around again (without pausing) and we'll respond then
@@ -4771,16 +4767,16 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
47714767
LogPrint(BCLog::NET, "%s sending header-and-ids %s to peer=%d\n", __func__,
47724768
vHeaders.front().GetHash().ToString(), pto->GetId());
47734769

4774-
int nSendFlags = state.fWantsCmpctWitness ? 0 : SERIALIZE_TRANSACTION_NO_WITNESS;
4770+
int nSendFlags = state.fProvidesHeaderAndIDs ? 0 : SERIALIZE_TRANSACTION_NO_WITNESS;
47754771

47764772
bool fGotBlockFromCache = false;
47774773
{
47784774
LOCK(m_most_recent_block_mutex);
47794775
if (m_most_recent_block_hash == pBestIndex->GetBlockHash()) {
4780-
if (state.fWantsCmpctWitness || !m_most_recent_compact_block_has_witnesses)
4776+
if (state.fProvidesHeaderAndIDs || !m_most_recent_compact_block_has_witnesses)
47814777
m_connman.PushMessage(pto, msgMaker.Make(nSendFlags, NetMsgType::CMPCTBLOCK, *m_most_recent_compact_block));
47824778
else {
4783-
CBlockHeaderAndShortTxIDs cmpctblock(*m_most_recent_block, state.fWantsCmpctWitness);
4779+
CBlockHeaderAndShortTxIDs cmpctblock(*m_most_recent_block, state.fProvidesHeaderAndIDs);
47844780
m_connman.PushMessage(pto, msgMaker.Make(nSendFlags, NetMsgType::CMPCTBLOCK, cmpctblock));
47854781
}
47864782
fGotBlockFromCache = true;
@@ -4790,7 +4786,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
47904786
CBlock block;
47914787
bool ret = ReadBlockFromDisk(block, pBestIndex, consensusParams);
47924788
assert(ret);
4793-
CBlockHeaderAndShortTxIDs cmpctblock(block, state.fWantsCmpctWitness);
4789+
CBlockHeaderAndShortTxIDs cmpctblock(block, state.fProvidesHeaderAndIDs);
47944790
m_connman.PushMessage(pto, msgMaker.Make(nSendFlags, NetMsgType::CMPCTBLOCK, cmpctblock));
47954791
}
47964792
state.pindexBestHeaderSent = pBestIndex;

0 commit comments

Comments
 (0)