mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-11 12:22:39 -03:00
p2p, refactoring: use CInv helpers in net_processing.cpp
to simplify the code and reach less from it into the CInv class internals
This commit is contained in:
parent
4254cd9f8f
commit
c251d710a4
1 changed files with 10 additions and 11 deletions
|
@ -1445,9 +1445,9 @@ bool static AlreadyHave(const CInv& inv, const CTxMemPool& mempool) EXCLUSIVE_LO
|
||||||
|
|
||||||
{
|
{
|
||||||
LOCK(g_cs_orphans);
|
LOCK(g_cs_orphans);
|
||||||
if (inv.type != MSG_WTX && mapOrphanTransactions.count(inv.hash)) {
|
if (!inv.IsMsgWtx() && mapOrphanTransactions.count(inv.hash)) {
|
||||||
return true;
|
return true;
|
||||||
} else if (inv.type == MSG_WTX && g_orphans_by_wtxid.count(inv.hash)) {
|
} else if (inv.IsMsgWtx() && g_orphans_by_wtxid.count(inv.hash)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1457,8 +1457,7 @@ bool static AlreadyHave(const CInv& inv, const CTxMemPool& mempool) EXCLUSIVE_LO
|
||||||
if (g_recent_confirmed_transactions->contains(inv.hash)) return true;
|
if (g_recent_confirmed_transactions->contains(inv.hash)) return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool by_wtxid = (inv.type == MSG_WTX);
|
return recentRejects->contains(inv.hash) || mempool.exists(inv.hash, inv.IsMsgWtx());
|
||||||
return recentRejects->contains(inv.hash) || mempool.exists(inv.hash, by_wtxid);
|
|
||||||
}
|
}
|
||||||
case MSG_BLOCK:
|
case MSG_BLOCK:
|
||||||
case MSG_WITNESS_BLOCK:
|
case MSG_WITNESS_BLOCK:
|
||||||
|
@ -1719,7 +1718,7 @@ void static ProcessGetData(CNode& pfrom, const CChainParams& chainparams, CConnm
|
||||||
// Process as many TX items from the front of the getdata queue as
|
// Process as many TX items from the front of the getdata queue as
|
||||||
// possible, since they're common and it's efficient to batch process
|
// possible, since they're common and it's efficient to batch process
|
||||||
// them.
|
// them.
|
||||||
while (it != pfrom.vRecvGetData.end() && (it->type == MSG_TX || it->type == MSG_WITNESS_TX || it->type == MSG_WTX)) {
|
while (it != pfrom.vRecvGetData.end() && it->IsGenTxMsg()) {
|
||||||
if (interruptMsgProc) return;
|
if (interruptMsgProc) return;
|
||||||
// The send buffer provides backpressure. If there's no space in
|
// The send buffer provides backpressure. If there's no space in
|
||||||
// the buffer, pause processing until the next call.
|
// the buffer, pause processing until the next call.
|
||||||
|
@ -1732,10 +1731,10 @@ void static ProcessGetData(CNode& pfrom, const CChainParams& chainparams, CConnm
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
CTransactionRef tx = FindTxForGetData(pfrom, inv.hash, inv.type == MSG_WTX, mempool_req, now);
|
CTransactionRef tx = FindTxForGetData(pfrom, inv.hash, inv.IsMsgWtx(), mempool_req, now);
|
||||||
if (tx) {
|
if (tx) {
|
||||||
// WTX and WITNESS_TX imply we serialize with witness
|
// WTX and WITNESS_TX imply we serialize with witness
|
||||||
int nSendFlags = (inv.type == MSG_TX ? SERIALIZE_TRANSACTION_NO_WITNESS : 0);
|
int nSendFlags = (inv.IsMsgTx() ? SERIALIZE_TRANSACTION_NO_WITNESS : 0);
|
||||||
connman.PushMessage(&pfrom, msgMaker.Make(nSendFlags, NetMsgType::TX, *tx));
|
connman.PushMessage(&pfrom, msgMaker.Make(nSendFlags, NetMsgType::TX, *tx));
|
||||||
mempool.RemoveUnbroadcastTx(tx->GetHash());
|
mempool.RemoveUnbroadcastTx(tx->GetHash());
|
||||||
// As we're going to send tx, make sure its unconfirmed parents are made requestable.
|
// As we're going to send tx, make sure its unconfirmed parents are made requestable.
|
||||||
|
@ -2654,15 +2653,15 @@ void ProcessMessage(
|
||||||
|
|
||||||
// ignore INVs that don't match wtxidrelay setting
|
// ignore INVs that don't match wtxidrelay setting
|
||||||
if (State(pfrom.GetId())->m_wtxid_relay) {
|
if (State(pfrom.GetId())->m_wtxid_relay) {
|
||||||
if (inv.type == MSG_TX) continue;
|
if (inv.IsMsgTx()) continue;
|
||||||
} else {
|
} else {
|
||||||
if (inv.type == MSG_WTX) continue;
|
if (inv.IsMsgWtx()) continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool fAlreadyHave = AlreadyHave(inv, mempool);
|
bool fAlreadyHave = AlreadyHave(inv, mempool);
|
||||||
LogPrint(BCLog::NET, "got inv: %s %s peer=%d\n", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom.GetId());
|
LogPrint(BCLog::NET, "got inv: %s %s peer=%d\n", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom.GetId());
|
||||||
|
|
||||||
if (inv.type == MSG_TX) {
|
if (inv.IsMsgTx()) {
|
||||||
inv.type |= nFetchFlags;
|
inv.type |= nFetchFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3694,7 +3693,7 @@ void ProcessMessage(
|
||||||
vRecv >> vInv;
|
vRecv >> vInv;
|
||||||
if (vInv.size() <= MAX_PEER_TX_IN_FLIGHT + MAX_BLOCKS_IN_TRANSIT_PER_PEER) {
|
if (vInv.size() <= MAX_PEER_TX_IN_FLIGHT + MAX_BLOCKS_IN_TRANSIT_PER_PEER) {
|
||||||
for (CInv &inv : vInv) {
|
for (CInv &inv : vInv) {
|
||||||
if (inv.type == MSG_TX || inv.type == MSG_WITNESS_TX || inv.type == MSG_WTX) {
|
if (inv.IsGenTxMsg()) {
|
||||||
// If we receive a NOTFOUND message for a txid we requested, erase
|
// If we receive a NOTFOUND message for a txid we requested, erase
|
||||||
// it from our data structures for this peer.
|
// it from our data structures for this peer.
|
||||||
auto in_flight_it = state->m_tx_download.m_tx_in_flight.find(inv.hash);
|
auto in_flight_it = state->m_tx_download.m_tx_in_flight.find(inv.hash);
|
||||||
|
|
Loading…
Reference in a new issue