mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-22 06:52:36 +01:00
[net processing] Remove fWantsCmpctWitness
It is now completely redundant with fProvidesHeadersAndIDs.
This commit is contained in:
parent
a45d53cab5
commit
b486f72176
1 changed files with 9 additions and 13 deletions
|
@ -375,8 +375,6 @@ struct CNodeState {
|
|||
bool fProvidesHeaderAndIDs{false};
|
||||
//! Whether this peer can give us witnesses
|
||||
bool fHaveWitness{false};
|
||||
//! Whether this peer wants witnesses in cmpctblocks/blocktxns
|
||||
bool fWantsCmpctWitness{false};
|
||||
|
||||
/** State used to enforce CHAIN_SYNC_TIMEOUT and EXTRA_PEER_CHECK_INTERVAL logic.
|
||||
*
|
||||
|
@ -1656,7 +1654,7 @@ void PeerManagerImpl::NewPoWValidBlock(const CBlockIndex *pindex, const std::sha
|
|||
CNodeState &state = *State(pnode->GetId());
|
||||
// If the peer has, or we announced to them the previous block already,
|
||||
// but we don't think they have this one, go ahead and announce it
|
||||
if (state.fPreferHeaderAndIDs && (!fWitnessEnabled || state.fWantsCmpctWitness) &&
|
||||
if (state.fPreferHeaderAndIDs && (!fWitnessEnabled || state.fProvidesHeaderAndIDs) &&
|
||||
!PeerHasHeader(&state, pindex) && PeerHasHeader(&state, pindex->pprev)) {
|
||||
|
||||
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&
|
|||
// they won't have a useful mempool to match against a compact block,
|
||||
// and we don't feel like constructing the object for them, so
|
||||
// instead we respond with the full, non-compact block.
|
||||
bool fPeerWantsWitness = State(pfrom.GetId())->fWantsCmpctWitness;
|
||||
bool fPeerWantsWitness = State(pfrom.GetId())->fProvidesHeaderAndIDs;
|
||||
int nSendFlags = fPeerWantsWitness ? 0 : SERIALIZE_TRANSACTION_NO_WITNESS;
|
||||
if (CanDirectFetch() && pindex->nHeight >= m_chainman.ActiveChain().Height() - MAX_CMPCTBLOCK_DEPTH) {
|
||||
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
|
|||
}
|
||||
LOCK(cs_main);
|
||||
const CNetMsgMaker msgMaker(pfrom.GetCommonVersion());
|
||||
int nSendFlags = State(pfrom.GetId())->fWantsCmpctWitness ? 0 : SERIALIZE_TRANSACTION_NO_WITNESS;
|
||||
int nSendFlags = State(pfrom.GetId())->fProvidesHeaderAndIDs ? 0 : SERIALIZE_TRANSACTION_NO_WITNESS;
|
||||
m_connman.PushMessage(&pfrom, msgMaker.Make(nSendFlags, NetMsgType::BLOCKTXN, resp));
|
||||
}
|
||||
|
||||
|
@ -2881,12 +2879,10 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
|||
if (nCMPCTBLOCKVersion != CMPCTBLOCKS_VERSION) return;
|
||||
|
||||
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 = true;
|
||||
}
|
||||
if (State(pfrom.GetId())->fWantsCmpctWitness) {
|
||||
if (State(pfrom.GetId())->fProvidesHeaderAndIDs) {
|
||||
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)
|
||||
|
@ -3241,7 +3237,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
|||
// actually receive all the data read from disk over the network.
|
||||
LogPrint(BCLog::NET, "Peer %d sent us a getblocktxn for a block > %i deep\n", pfrom.GetId(), MAX_BLOCKTXN_DEPTH);
|
||||
CInv inv;
|
||||
WITH_LOCK(cs_main, inv.type = State(pfrom.GetId())->fWantsCmpctWitness ? MSG_WITNESS_BLOCK : MSG_BLOCK);
|
||||
WITH_LOCK(cs_main, inv.type = State(pfrom.GetId())->fProvidesHeaderAndIDs ? MSG_WITNESS_BLOCK : MSG_BLOCK);
|
||||
inv.hash = req.blockhash;
|
||||
WITH_LOCK(peer->m_getdata_requests_mutex, peer->m_getdata_requests.push_back(inv));
|
||||
// The message processing loop will go around again (without pausing) and we'll respond then
|
||||
|
@ -4771,16 +4767,16 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
|
|||
LogPrint(BCLog::NET, "%s sending header-and-ids %s to peer=%d\n", __func__,
|
||||
vHeaders.front().GetHash().ToString(), pto->GetId());
|
||||
|
||||
int nSendFlags = state.fWantsCmpctWitness ? 0 : SERIALIZE_TRANSACTION_NO_WITNESS;
|
||||
int nSendFlags = state.fProvidesHeaderAndIDs ? 0 : SERIALIZE_TRANSACTION_NO_WITNESS;
|
||||
|
||||
bool fGotBlockFromCache = false;
|
||||
{
|
||||
LOCK(m_most_recent_block_mutex);
|
||||
if (m_most_recent_block_hash == pBestIndex->GetBlockHash()) {
|
||||
if (state.fWantsCmpctWitness || !m_most_recent_compact_block_has_witnesses)
|
||||
if (state.fProvidesHeaderAndIDs || !m_most_recent_compact_block_has_witnesses)
|
||||
m_connman.PushMessage(pto, msgMaker.Make(nSendFlags, NetMsgType::CMPCTBLOCK, *m_most_recent_compact_block));
|
||||
else {
|
||||
CBlockHeaderAndShortTxIDs cmpctblock(*m_most_recent_block, state.fWantsCmpctWitness);
|
||||
CBlockHeaderAndShortTxIDs cmpctblock(*m_most_recent_block, state.fProvidesHeaderAndIDs);
|
||||
m_connman.PushMessage(pto, msgMaker.Make(nSendFlags, NetMsgType::CMPCTBLOCK, cmpctblock));
|
||||
}
|
||||
fGotBlockFromCache = true;
|
||||
|
@ -4790,7 +4786,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
|
|||
CBlock block;
|
||||
bool ret = ReadBlockFromDisk(block, pBestIndex, consensusParams);
|
||||
assert(ret);
|
||||
CBlockHeaderAndShortTxIDs cmpctblock(block, state.fWantsCmpctWitness);
|
||||
CBlockHeaderAndShortTxIDs cmpctblock(block, state.fProvidesHeaderAndIDs);
|
||||
m_connman.PushMessage(pto, msgMaker.Make(nSendFlags, NetMsgType::CMPCTBLOCK, cmpctblock));
|
||||
}
|
||||
state.pindexBestHeaderSent = pBestIndex;
|
||||
|
|
Loading…
Add table
Reference in a new issue