Skip to content

Commit 145650d

Browse files
sdaftuarFabcien
authored andcommitted
Just pass a TxId to AddInventoryKnown, rename to AddKnownTx
Summary: ``` Since it's only used for transactions, there's no need to pass in an inv type. ``` Backport of core [[bitcoin/bitcoin#18044 | PR18044]]. Since thie PR is Segwit related, there is not much left. Full commits: - bitcoin/bitcoin@60f0acd - bitcoin/bitcoin@dd78d1d Only the CInv equality operator in messages.py is relevant: - bitcoin/bitcoin@9a5392f Test Plan: ninja all check-all Reviewers: #bitcoin_abc, jasonbcox Reviewed By: #bitcoin_abc, jasonbcox Differential Revision: https://reviews.bitcoinabc.org/D8501
1 parent 7577f72 commit 145650d

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

src/net.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1018,10 +1018,10 @@ class CNode {
10181018
}
10191019
}
10201020

1021-
void AddInventoryKnown(const CInv &inv) {
1021+
void AddKnownTx(const TxId &txid) {
10221022
if (m_tx_relay != nullptr) {
10231023
LOCK(m_tx_relay->cs_tx_inventory);
1024-
m_tx_relay->filterInventoryKnown.insert(inv.hash);
1024+
m_tx_relay->filterInventoryKnown.insert(txid);
10251025
}
10261026
}
10271027

src/net_processing.cpp

+8-11
Original file line numberDiff line numberDiff line change
@@ -2897,18 +2897,18 @@ bool ProcessMessage(const Config &config, CNode &pfrom,
28972897
pfrom.GetId());
28982898
}
28992899
} else {
2900-
pfrom.AddInventoryKnown(inv);
2900+
const TxId txid(inv.hash);
2901+
pfrom.AddKnownTx(txid);
29012902
if (fBlocksOnly) {
29022903
LogPrint(BCLog::NET,
29032904
"transaction (%s) inv sent in violation of "
29042905
"protocol, disconnecting peer=%d\n",
2905-
inv.hash.ToString(), pfrom.GetId());
2906+
txid.ToString(), pfrom.GetId());
29062907
pfrom.fDisconnect = true;
29072908
return true;
29082909
} else if (!fAlreadyHave && !fImporting && !fReindex &&
29092910
!::ChainstateActive().IsInitialBlockDownload()) {
2910-
RequestTx(State(pfrom.GetId()), TxId(inv.hash),
2911-
current_time);
2911+
RequestTx(State(pfrom.GetId()), txid, current_time);
29122912
}
29132913
}
29142914
}
@@ -3175,9 +3175,7 @@ bool ProcessMessage(const Config &config, CNode &pfrom,
31753175
vRecv >> ptx;
31763176
const CTransaction &tx = *ptx;
31773177
const TxId &txid = tx.GetId();
3178-
3179-
CInv inv(MSG_TX, txid);
3180-
pfrom.AddInventoryKnown(inv);
3178+
pfrom.AddKnownTx(txid);
31813179

31823180
LOCK2(cs_main, g_cs_orphans);
31833181

@@ -3188,7 +3186,7 @@ bool ProcessMessage(const Config &config, CNode &pfrom,
31883186
nodestate->m_tx_download.m_tx_in_flight.erase(txid);
31893187
EraseTxRequest(txid);
31903188

3191-
if (!AlreadyHave(inv) &&
3189+
if (!AlreadyHave(CInv(MSG_TX, txid)) &&
31923190
AcceptToMemoryPool(config, g_mempool, state, ptx,
31933191
false /* bypass_limits */,
31943192
Amount::zero() /* nAbsurdFee */)) {
@@ -3231,9 +3229,8 @@ bool ProcessMessage(const Config &config, CNode &pfrom,
32313229
for (const CTxIn &txin : tx.vin) {
32323230
// FIXME: MSG_TX should use a TxHash, not a TxId.
32333231
const TxId _txid = txin.prevout.GetTxId();
3234-
CInv _inv(MSG_TX, _txid);
3235-
pfrom.AddInventoryKnown(_inv);
3236-
if (!AlreadyHave(_inv)) {
3232+
pfrom.AddKnownTx(_txid);
3233+
if (!AlreadyHave(CInv(MSG_TX, _txid))) {
32373234
RequestTx(State(pfrom.GetId()), _txid, current_time);
32383235
}
32393236
}

test/functional/test_framework/messages.py

+4
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,10 @@ def __repr__(self):
266266
return "CInv(type={} hash={:064x})".format(
267267
self.typemap[self.type], self.hash)
268268

269+
def __eq__(self, other):
270+
return isinstance(
271+
other, CInv) and self.hash == other.hash and self.type == other.type
272+
269273

270274
class CBlockLocator:
271275
__slots__ = ("nVersion", "vHave")

0 commit comments

Comments
 (0)