Skip to content

Commit

Permalink
Remove uint256-typed GenTxid::Txid constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
instagibbs committed Oct 16, 2023
1 parent ea6ae8f commit f592388
Show file tree
Hide file tree
Showing 12 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4205,7 +4205,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
// wtxidrelay peers.
// Eventually we should replace this with an improved
// protocol for getting all unconfirmed parents.
const auto gtxid{GenTxid::Txid(parent_txid)};
const auto gtxid{GenTxid::Txid(Txid::FromUint256(parent_txid))};
AddKnownTx(*peer, parent_txid);
if (!AlreadyHaveTx(gtxid)) AddTxAnnouncement(pfrom, gtxid, current_time);
}
Expand Down
2 changes: 1 addition & 1 deletion src/node/interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ class ChainImpl : public Chain
{
if (!m_node.mempool) return false;
LOCK(m_node.mempool->cs);
return m_node.mempool->exists(GenTxid::Txid(txid));
return m_node.mempool->exists(GenTxid::Txid(Txid::FromUint256(txid)));
}
bool hasDescendantsInMempool(const uint256& txid) override
{
Expand Down
2 changes: 1 addition & 1 deletion src/node/mini_miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ MiniMiner::MiniMiner(const CTxMemPool& mempool, const std::vector<COutPoint>& ou
// Anything that's spent by the mempool is to-be-replaced
// Anything otherwise unavailable just has a bump fee of 0
for (const auto& outpoint : outpoints) {
if (!mempool.exists(GenTxid::Txid(outpoint.hash))) {
if (!mempool.exists(GenTxid::Txid(Txid::FromUint256(outpoint.hash)))) {
// This UTXO is either confirmed or not yet submitted to mempool.
// If it's confirmed, no bump fee is required.
// If it's not yet submitted, we have no information, so return 0.
Expand Down
2 changes: 1 addition & 1 deletion src/policy/rbf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ std::optional<std::string> HasNoNewUnconfirmed(const CTransaction& tx,
if (!parents_of_conflicts.count(tx.vin[j].prevout.hash)) {
// Rather than check the UTXO set - potentially expensive - it's cheaper to just check
// if the new input refers to a tx that's in the mempool.
if (pool.exists(GenTxid::Txid(tx.vin[j].prevout.hash))) {
if (pool.exists(GenTxid::Txid(Txid::FromUint256(tx.vin[j].prevout.hash)))) {
return strprintf("replacement %s adds unconfirmed input, idx %d",
tx.GetHash().ToString(), j);
}
Expand Down
1 change: 0 additions & 1 deletion src/primitives/transaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,6 @@ class GenTxid
public:
static GenTxid Txid(const Txid& txid) { return GenTxid{false, txid.ToUint256()}; }
static GenTxid Wtxid(const Wtxid& txid) { return GenTxid{true, txid.ToUint256()}; }
static GenTxid Txid(const uint256& hash) { return GenTxid{false, hash}; }
bool IsWtxid() const { return m_is_wtxid; }
const uint256& GetHash() const { return m_hash; }
friend bool operator==(const GenTxid& a, const GenTxid& b) { return a.m_is_wtxid == b.m_is_wtxid && a.m_hash == b.m_hash; }
Expand Down
2 changes: 1 addition & 1 deletion src/protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,5 +221,5 @@ std::vector<std::string> serviceFlagsToStr(uint64_t flags)
GenTxid ToGenTxid(const CInv& inv)
{
assert(inv.IsGenTxMsg());
return inv.IsMsgWtx() ? GenTxid::Wtxid(Wtxid::FromUint256(inv.hash)) : GenTxid::Txid(inv.hash);
return inv.IsMsgWtx() ? GenTxid::Wtxid(Wtxid::FromUint256(inv.hash)) : GenTxid::Txid(Txid::FromUint256(inv.hash));
}
2 changes: 1 addition & 1 deletion src/rpc/mempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ static void entryToJSON(const CTxMemPool& pool, UniValue& info, const CTxMemPool
std::set<std::string> setDepends;
for (const CTxIn& txin : tx.vin)
{
if (pool.exists(GenTxid::Txid(txin.prevout.hash)))
if (pool.exists(GenTxid::Txid(Txid::FromUint256(txin.prevout.hash))))
setDepends.insert(txin.prevout.hash.ToString());
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/fuzz/txrequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ class Tester
}

// Call TxRequestTracker's implementation.
m_tracker.ReceivedInv(peer, is_wtxid ? GenTxid::Wtxid(Wtxid::FromUint256(TXHASHES[txhash])) : GenTxid::Txid(TXHASHES[txhash]), preferred, reqtime);
m_tracker.ReceivedInv(peer, is_wtxid ? GenTxid::Wtxid(Wtxid::FromUint256(TXHASHES[txhash])) : GenTxid::Txid(Txid::FromUint256(TXHASHES[txhash])), preferred, reqtime);
}

void RequestedTx(int peer, int txhash, std::chrono::microseconds exptime)
Expand Down Expand Up @@ -252,7 +252,7 @@ class Tester
for (int peer2 = 0; peer2 < MAX_PEERS; ++peer2) {
Announcement& ann2 = m_announcements[txhash][peer2];
if (ann2.m_state == State::REQUESTED && ann2.m_time <= m_now) {
expected_expired.emplace_back(peer2, ann2.m_is_wtxid ? GenTxid::Wtxid(Wtxid::FromUint256(TXHASHES[txhash])) : GenTxid::Txid(TXHASHES[txhash]));
expected_expired.emplace_back(peer2, ann2.m_is_wtxid ? GenTxid::Wtxid(Wtxid::FromUint256(TXHASHES[txhash])) : GenTxid::Txid(Txid::FromUint256(TXHASHES[txhash])));
ann2.m_state = State::COMPLETED;
break;
}
Expand Down
4 changes: 2 additions & 2 deletions src/txmempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ std::vector<CTxMemPool::txiter> CTxMemPool::GetIterVec(const std::vector<uint256
bool CTxMemPool::HasNoInputsOf(const CTransaction &tx) const
{
for (unsigned int i = 0; i < tx.vin.size(); i++)
if (exists(GenTxid::Txid(tx.vin[i].prevout.hash)))
if (exists(GenTxid::Txid(Txid::FromUint256(tx.vin[i].prevout.hash))))
return false;
return true;
}
Expand Down Expand Up @@ -1161,7 +1161,7 @@ void CTxMemPool::TrimToSize(size_t sizelimit, std::vector<COutPoint>* pvNoSpends
if (pvNoSpendsRemaining) {
for (const CTransaction& tx : txn) {
for (const CTxIn& txin : tx.vin) {
if (exists(GenTxid::Txid(txin.prevout.hash))) continue;
if (exists(GenTxid::Txid(Txid::FromUint256(txin.prevout.hash)))) continue;
pvNoSpendsRemaining->push_back(txin.prevout);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/txmempool.h
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ class CTxMemPool
LOCK(cs);
// Sanity check the transaction is in the mempool & insert into
// unbroadcast set.
if (exists(GenTxid::Txid(txid))) m_unbroadcast_txids.insert(txid);
if (exists(GenTxid::Txid(Txid::FromUint256(txid)))) m_unbroadcast_txids.insert(txid);
};

/** Removes a transaction from the unbroadcast set */
Expand Down
2 changes: 1 addition & 1 deletion src/txrequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ std::map<uint256, TxHashInfo> ComputeTxHashInfo(const Index& index, const Priori

GenTxid ToGenTxid(const Announcement& ann)
{
return ann.m_is_wtxid ? GenTxid::Wtxid(Wtxid::FromUint256(ann.m_txhash)) : GenTxid::Txid(ann.m_txhash);
return ann.m_is_wtxid ? GenTxid::Wtxid(Wtxid::FromUint256(ann.m_txhash)) : GenTxid::Txid(Txid::FromUint256(ann.m_txhash));
}

} // namespace
Expand Down
2 changes: 1 addition & 1 deletion src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ bool MemPoolAccept::Finalize(const ATMPArgs& args, Workspace& ws)
AssertLockHeld(cs_main);
AssertLockHeld(m_pool.cs);
const CTransaction& tx = *ws.m_ptx;
const uint256& hash = ws.m_hash;
const Txid& hash = ws.m_hash;
TxValidationState& state = ws.m_state;
const bool bypass_limits = args.m_bypass_limits;

Expand Down

0 comments on commit f592388

Please sign in to comment.