Skip to content

Commit

Permalink
Just pass a TxId to AddInventoryKnown, rename to AddKnownTx
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sdaftuar authored and Fabcien committed Nov 24, 2020
1 parent 7577f72 commit 145650d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -1018,10 +1018,10 @@ class CNode {
}
}

void AddInventoryKnown(const CInv &inv) {
void AddKnownTx(const TxId &txid) {
if (m_tx_relay != nullptr) {
LOCK(m_tx_relay->cs_tx_inventory);
m_tx_relay->filterInventoryKnown.insert(inv.hash);
m_tx_relay->filterInventoryKnown.insert(txid);
}
}

Expand Down
19 changes: 8 additions & 11 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2897,18 +2897,18 @@ bool ProcessMessage(const Config &config, CNode &pfrom,
pfrom.GetId());
}
} else {
pfrom.AddInventoryKnown(inv);
const TxId txid(inv.hash);
pfrom.AddKnownTx(txid);
if (fBlocksOnly) {
LogPrint(BCLog::NET,
"transaction (%s) inv sent in violation of "
"protocol, disconnecting peer=%d\n",
inv.hash.ToString(), pfrom.GetId());
txid.ToString(), pfrom.GetId());
pfrom.fDisconnect = true;
return true;
} else if (!fAlreadyHave && !fImporting && !fReindex &&
!::ChainstateActive().IsInitialBlockDownload()) {
RequestTx(State(pfrom.GetId()), TxId(inv.hash),
current_time);
RequestTx(State(pfrom.GetId()), txid, current_time);
}
}
}
Expand Down Expand Up @@ -3175,9 +3175,7 @@ bool ProcessMessage(const Config &config, CNode &pfrom,
vRecv >> ptx;
const CTransaction &tx = *ptx;
const TxId &txid = tx.GetId();

CInv inv(MSG_TX, txid);
pfrom.AddInventoryKnown(inv);
pfrom.AddKnownTx(txid);

LOCK2(cs_main, g_cs_orphans);

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

if (!AlreadyHave(inv) &&
if (!AlreadyHave(CInv(MSG_TX, txid)) &&
AcceptToMemoryPool(config, g_mempool, state, ptx,
false /* bypass_limits */,
Amount::zero() /* nAbsurdFee */)) {
Expand Down Expand Up @@ -3231,9 +3229,8 @@ bool ProcessMessage(const Config &config, CNode &pfrom,
for (const CTxIn &txin : tx.vin) {
// FIXME: MSG_TX should use a TxHash, not a TxId.
const TxId _txid = txin.prevout.GetTxId();
CInv _inv(MSG_TX, _txid);
pfrom.AddInventoryKnown(_inv);
if (!AlreadyHave(_inv)) {
pfrom.AddKnownTx(_txid);
if (!AlreadyHave(CInv(MSG_TX, _txid))) {
RequestTx(State(pfrom.GetId()), _txid, current_time);
}
}
Expand Down
4 changes: 4 additions & 0 deletions test/functional/test_framework/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ def __repr__(self):
return "CInv(type={} hash={:064x})".format(
self.typemap[self.type], self.hash)

def __eq__(self, other):
return isinstance(
other, CInv) and self.hash == other.hash and self.type == other.type


class CBlockLocator:
__slots__ = ("nVersion", "vHave")
Expand Down

0 comments on commit 145650d

Please sign in to comment.