scripted-diff: Replace GenTxidVariant with GenTxid

-BEGIN VERIFY SCRIPT-
sed -i 's/GenTxidVariant/GenTxid/g' $(git grep -l 'GenTxidVariant')
-END VERIFY SCRIPT-
This commit is contained in:
marcofleon 2025-04-01 12:06:23 +01:00
parent 4a5c30710d
commit 42e78f8f8a
14 changed files with 97 additions and 97 deletions

View file

@ -272,7 +272,7 @@ struct Peer {
* non-wtxid-relay peers, wtxid for wtxid-relay peers). We use the
* mempool to sort transactions in dependency order before relay, so
* this does not have to be sorted. */
std::set<GenTxidVariant> m_tx_inventory_to_send GUARDED_BY(m_tx_inventory_mutex);
std::set<GenTxid> m_tx_inventory_to_send GUARDED_BY(m_tx_inventory_mutex);
/** Whether the peer has requested us to send our complete mempool. Only
* permitted if the peer has NetPermissionFlags::Mempool or we advertise
* NODE_BLOOM. See BIP35. */
@ -826,7 +826,7 @@ private:
std::shared_ptr<const CBlock> m_most_recent_block GUARDED_BY(m_most_recent_block_mutex);
std::shared_ptr<const CBlockHeaderAndShortTxIDs> m_most_recent_compact_block GUARDED_BY(m_most_recent_block_mutex);
uint256 m_most_recent_block_hash GUARDED_BY(m_most_recent_block_mutex);
std::unique_ptr<const std::map<GenTxidVariant, CTransactionRef>> m_most_recent_block_txs GUARDED_BY(m_most_recent_block_mutex);
std::unique_ptr<const std::map<GenTxid, CTransactionRef>> m_most_recent_block_txs GUARDED_BY(m_most_recent_block_mutex);
// Data about the low-work headers synchronization, aggregated from all peers' HeadersSyncStates.
/** Mutex guarding the other m_headers_presync_* variables. */
@ -917,7 +917,7 @@ private:
std::atomic<std::chrono::seconds> m_last_tip_update{0s};
/** Determine whether or not a peer can request a transaction, and return it (or nullptr if not found or not allowed). */
CTransactionRef FindTxForGetData(const Peer::TxRelay& tx_relay, const GenTxidVariant& gtxid)
CTransactionRef FindTxForGetData(const Peer::TxRelay& tx_relay, const GenTxid& gtxid)
EXCLUSIVE_LOCKS_REQUIRED(!m_most_recent_block_mutex, NetEventsInterface::g_msgproc_mutex);
void ProcessGetData(CNode& pfrom, Peer& peer, const std::atomic<bool>& interruptMsgProc)
@ -1995,7 +1995,7 @@ void PeerManagerImpl::NewPoWValidBlock(const CBlockIndex *pindex, const std::sha
std::async(std::launch::deferred, [&] { return NetMsg::Make(NetMsgType::CMPCTBLOCK, *pcmpctblock); })};
{
auto most_recent_block_txs = std::make_unique<std::map<GenTxidVariant, CTransactionRef>>();
auto most_recent_block_txs = std::make_unique<std::map<GenTxid, CTransactionRef>>();
for (const auto& tx : pblock->vtx) {
most_recent_block_txs->emplace(tx->GetHash(), tx);
most_recent_block_txs->emplace(tx->GetWitnessHash(), tx);
@ -2134,7 +2134,7 @@ void PeerManagerImpl::RelayTransaction(const Txid& txid, const Wtxid& wtxid)
// in the announcement.
if (tx_relay->m_next_inv_send_time == 0s) continue;
GenTxidVariant gtxid;
GenTxid gtxid;
if (peer.m_wtxid_relay) {
gtxid = wtxid;
} else {
@ -2365,7 +2365,7 @@ void PeerManagerImpl::ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv&
}
}
CTransactionRef PeerManagerImpl::FindTxForGetData(const Peer::TxRelay& tx_relay, const GenTxidVariant& gtxid)
CTransactionRef PeerManagerImpl::FindTxForGetData(const Peer::TxRelay& tx_relay, const GenTxid& gtxid)
{
// If a tx was in the mempool prior to the last INV for this peer, permit the request.
auto txinfo = m_mempool.info_for_relay(gtxid, tx_relay.m_last_inv_sequence);
@ -3945,7 +3945,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
pfrom.fDisconnect = true;
return;
}
const GenTxidVariant gtxid = ToGenTxid(inv);
const GenTxid gtxid = ToGenTxid(inv);
AddKnownTx(*peer, inv.hash);
if (!m_chainman.IsInitialBlockDownload()) {
@ -4877,7 +4877,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
if (msg_type == NetMsgType::NOTFOUND) {
std::vector<CInv> vInv;
vRecv >> vInv;
std::vector<GenTxidVariant> tx_invs;
std::vector<GenTxid> tx_invs;
if (vInv.size() <= node::MAX_PEER_TX_ANNOUNCEMENTS + MAX_BLOCKS_IN_TRANSIT_PER_PEER) {
for (CInv &inv : vInv) {
if (inv.IsGenTxMsg()) {
@ -5388,7 +5388,7 @@ public:
mp = _mempool;
}
bool operator()(std::set<GenTxidVariant>::iterator a, std::set<GenTxidVariant>::iterator b)
bool operator()(std::set<GenTxid>::iterator a, std::set<GenTxid>::iterator b)
{
/* As std::make_heap produces a max-heap, we want the entries with the
* fewest ancestors/highest fee to sort later. */
@ -5731,9 +5731,9 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
// Determine transactions to relay
if (fSendTrickle) {
// Produce a vector with all candidates for sending
std::vector<std::set<GenTxidVariant>::iterator> vInvTx;
std::vector<std::set<GenTxid>::iterator> vInvTx;
vInvTx.reserve(tx_relay->m_tx_inventory_to_send.size());
for (std::set<GenTxidVariant>::iterator it = tx_relay->m_tx_inventory_to_send.begin(); it != tx_relay->m_tx_inventory_to_send.end(); it++) {
for (std::set<GenTxid>::iterator it = tx_relay->m_tx_inventory_to_send.begin(); it != tx_relay->m_tx_inventory_to_send.end(); it++) {
vInvTx.push_back(it);
}
const CFeeRate filterrate{tx_relay->m_fee_filter_received.load()};
@ -5750,9 +5750,9 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
while (!vInvTx.empty() && nRelayedTransactions < broadcast_max) {
// Fetch the top element from the heap
std::pop_heap(vInvTx.begin(), vInvTx.end(), compareInvMempoolOrder);
std::set<GenTxidVariant>::iterator it = vInvTx.back();
std::set<GenTxid>::iterator it = vInvTx.back();
vInvTx.pop_back();
GenTxidVariant hash = *it;
GenTxid hash = *it;
CInv inv(peer->m_wtxid_relay ? MSG_WTX : MSG_TX, hash.ToUint256());
// Remove it from the to-be-sent set
tx_relay->m_tx_inventory_to_send.erase(it);
@ -5899,7 +5899,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
//
{
LOCK(m_tx_download_mutex);
for (const GenTxidVariant& gtxid : m_txdownloadman.GetRequestsToSend(pto->GetId(), current_time)) {
for (const GenTxid& gtxid : m_txdownloadman.GetRequestsToSend(pto->GetId(), current_time)) {
vGetData.emplace_back(std::holds_alternative<Wtxid>(gtxid) ? MSG_WTX : (MSG_TX | GetFetchFlags(*peer)), gtxid.ToUint256());
if (vGetData.size() >= MAX_GETDATA_SZ) {
MakeAndPushMessage(*pto, NetMsgType::GETDATA, vGetData);

View file

@ -16,7 +16,7 @@
class CBlock;
class CRollingBloomFilter;
class CTxMemPool;
class GenTxidVariant;
class GenTxid;
class TxRequestTracker;
namespace node {
class TxDownloadManagerImpl;
@ -138,13 +138,13 @@ public:
/** Consider adding this tx hash to txrequest. Should be called whenever a new inv has been received.
* Also called internally when a transaction is missing parents so that we can request them.
* Returns true if this was a dropped inv (p2p_inv=true and we already have the tx), false otherwise. */
bool AddTxAnnouncement(NodeId peer, const GenTxidVariant& gtxid, std::chrono::microseconds now);
bool AddTxAnnouncement(NodeId peer, const GenTxid& gtxid, std::chrono::microseconds now);
/** Get getdata requests to send. */
std::vector<GenTxidVariant> GetRequestsToSend(NodeId nodeid, std::chrono::microseconds current_time);
std::vector<GenTxid> GetRequestsToSend(NodeId nodeid, std::chrono::microseconds current_time);
/** Should be called when a notfound for a tx has been received. */
void ReceivedNotFound(NodeId nodeid, const std::vector<GenTxidVariant>& txhashes);
void ReceivedNotFound(NodeId nodeid, const std::vector<GenTxid>& txhashes);
/** Respond to successful transaction submission to mempool */
void MempoolAcceptedTx(const CTransactionRef& tx);

View file

@ -39,15 +39,15 @@ void TxDownloadManager::DisconnectedPeer(NodeId nodeid)
{
m_impl->DisconnectedPeer(nodeid);
}
bool TxDownloadManager::AddTxAnnouncement(NodeId peer, const GenTxidVariant& gtxid, std::chrono::microseconds now)
bool TxDownloadManager::AddTxAnnouncement(NodeId peer, const GenTxid& gtxid, std::chrono::microseconds now)
{
return m_impl->AddTxAnnouncement(peer, gtxid, now);
}
std::vector<GenTxidVariant> TxDownloadManager::GetRequestsToSend(NodeId nodeid, std::chrono::microseconds current_time)
std::vector<GenTxid> TxDownloadManager::GetRequestsToSend(NodeId nodeid, std::chrono::microseconds current_time)
{
return m_impl->GetRequestsToSend(nodeid, current_time);
}
void TxDownloadManager::ReceivedNotFound(NodeId nodeid, const std::vector<GenTxidVariant>& txhashes)
void TxDownloadManager::ReceivedNotFound(NodeId nodeid, const std::vector<GenTxid>& txhashes)
{
m_impl->ReceivedNotFound(nodeid, txhashes);
}
@ -122,7 +122,7 @@ void TxDownloadManagerImpl::BlockDisconnected()
RecentConfirmedTransactionsFilter().reset();
}
bool TxDownloadManagerImpl::AlreadyHaveTx(const GenTxidVariant& gtxid, bool include_reconsiderable)
bool TxDownloadManagerImpl::AlreadyHaveTx(const GenTxid& gtxid, bool include_reconsiderable)
{
bool in_orphanage = std::visit(util::Overloaded{
// Normal query by wtxid.
@ -173,7 +173,7 @@ void TxDownloadManagerImpl::DisconnectedPeer(NodeId nodeid)
}
bool TxDownloadManagerImpl::AddTxAnnouncement(NodeId peer, const GenTxidVariant& gtxid, std::chrono::microseconds now)
bool TxDownloadManagerImpl::AddTxAnnouncement(NodeId peer, const GenTxid& gtxid, std::chrono::microseconds now)
{
// If this is an orphan we are trying to resolve, consider this peer as a orphan resolution candidate instead.
// - is wtxid matching something in orphanage
@ -267,16 +267,16 @@ bool TxDownloadManagerImpl::MaybeAddOrphanResolutionCandidate(const std::vector<
return true;
}
std::vector<GenTxidVariant> TxDownloadManagerImpl::GetRequestsToSend(NodeId nodeid, std::chrono::microseconds current_time)
std::vector<GenTxid> TxDownloadManagerImpl::GetRequestsToSend(NodeId nodeid, std::chrono::microseconds current_time)
{
std::vector<GenTxidVariant> requests;
std::vector<std::pair<NodeId, GenTxidVariant>> expired;
std::vector<GenTxid> requests;
std::vector<std::pair<NodeId, GenTxid>> expired;
auto requestable = m_txrequest.GetRequestable(nodeid, current_time, &expired);
for (const auto& entry : expired) {
LogDebug(BCLog::NET, "timeout of inflight %s %s from peer=%d\n", std::holds_alternative<Wtxid>(entry.second) ? "wtx" : "tx",
entry.second.ToUint256().ToString(), entry.first);
}
for (const GenTxidVariant& gtxid : requestable) {
for (const GenTxid& gtxid : requestable) {
if (!AlreadyHaveTx(gtxid, /*include_reconsiderable=*/false)) {
LogDebug(BCLog::NET, "Requesting %s %s peer=%d\n", std::holds_alternative<Wtxid>(gtxid) ? "wtx" : "tx",
gtxid.ToUint256().ToString(), nodeid);
@ -291,7 +291,7 @@ std::vector<GenTxidVariant> TxDownloadManagerImpl::GetRequestsToSend(NodeId node
return requests;
}
void TxDownloadManagerImpl::ReceivedNotFound(NodeId nodeid, const std::vector<GenTxidVariant>& txhashes)
void TxDownloadManagerImpl::ReceivedNotFound(NodeId nodeid, const std::vector<GenTxid>& txhashes)
{
for (const auto& txhash : txhashes) {
// If we receive a NOTFOUND message for a tx we requested, mark the announcement for it as

View file

@ -155,7 +155,7 @@ public:
* - m_recent_rejects_reconsiderable (if include_reconsiderable = true)
* - m_recent_confirmed_transactions
* */
bool AlreadyHaveTx(const GenTxidVariant& gtxid, bool include_reconsiderable);
bool AlreadyHaveTx(const GenTxid& gtxid, bool include_reconsiderable);
void ConnectedPeer(NodeId nodeid, const TxDownloadConnectionInfo& info);
void DisconnectedPeer(NodeId nodeid);
@ -163,13 +163,13 @@ public:
/** Consider adding this tx hash to txrequest. Should be called whenever a new inv has been received.
* Also called internally when a transaction is missing parents so that we can request them.
*/
bool AddTxAnnouncement(NodeId peer, const GenTxidVariant& gtxid, std::chrono::microseconds now);
bool AddTxAnnouncement(NodeId peer, const GenTxid& gtxid, std::chrono::microseconds now);
/** Get getdata requests to send. */
std::vector<GenTxidVariant> GetRequestsToSend(NodeId nodeid, std::chrono::microseconds current_time);
std::vector<GenTxid> GetRequestsToSend(NodeId nodeid, std::chrono::microseconds current_time);
/** Marks a tx as ReceivedResponse in txrequest. */
void ReceivedNotFound(NodeId nodeid, const std::vector<GenTxidVariant>& txhashes);
void ReceivedNotFound(NodeId nodeid, const std::vector<GenTxid>& txhashes);
/** Look for a child of this transaction in the orphanage to form a 1-parent-1-child package,
* skipping any combinations that have already been tried. Return the resulting package along with

View file

@ -118,7 +118,7 @@ std::vector<std::string> serviceFlagsToStr(uint64_t flags)
return str_flags;
}
GenTxidVariant ToGenTxid(const CInv& inv)
GenTxid ToGenTxid(const CInv& inv)
{
assert(inv.IsGenTxMsg());
if (inv.IsMsgWtx()) {

View file

@ -526,6 +526,6 @@ public:
};
/** Convert a TX/WITNESS_TX/WTX CInv to a GenTxid. */
GenTxidVariant ToGenTxid(const CInv& inv);
GenTxid ToGenTxid(const CInv& inv);
#endif // BITCOIN_PROTOCOL_H

View file

@ -227,7 +227,7 @@ FUZZ_TARGET(txdownloadman, .init = initialize)
Assert(first_time_failure || !todo.m_should_add_extra_compact_tx);
},
[&] {
GenTxidVariant gtxid;
GenTxid gtxid;
if (fuzzed_data_provider.ConsumeBool()) {
rand_tx->GetHash();
} else {
@ -376,7 +376,7 @@ FUZZ_TARGET(txdownloadman_impl, .init = initialize)
if (!reject_contains_wtxid) Assert(todo.m_unique_parents.size() <= rand_tx->vin.size());
},
[&] {
GenTxidVariant gtxid;
GenTxid gtxid;
if (fuzzed_data_provider.ConsumeBool()) {
rand_tx->GetHash();
} else {

View file

@ -20,7 +20,7 @@ constexpr int MAX_TXHASHES = 16;
constexpr int MAX_PEERS = 16;
//! Randomly generated GenTxids used in this test (length is MAX_TXHASHES).
GenTxidVariant TXHASHES[MAX_TXHASHES];
GenTxid TXHASHES[MAX_TXHASHES];
//! Precomputed random durations (positive and negative, each ~exponentially distributed).
std::chrono::microseconds DELAYS[256];
@ -250,7 +250,7 @@ public:
//! list of (sequence number, txhash, is_wtxid) tuples.
std::vector<std::tuple<uint64_t, int, bool>> result;
std::vector<std::pair<NodeId, GenTxidVariant>> expected_expired;
std::vector<std::pair<NodeId, GenTxid>> expected_expired;
for (int txhash = 0; txhash < MAX_TXHASHES; ++txhash) {
// Mark any expired REQUESTED announcements as COMPLETED.
for (int peer2 = 0; peer2 < MAX_PEERS; ++peer2) {
@ -274,7 +274,7 @@ public:
std::sort(expected_expired.begin(), expected_expired.end());
// Compare with TxRequestTracker's implementation.
std::vector<std::pair<NodeId, GenTxidVariant>> expired;
std::vector<std::pair<NodeId, GenTxid>> expired;
const auto actual = m_tracker.GetRequestable(peer, m_now, &expired);
std::sort(expired.begin(), expired.end());
assert(expired == expected_expired);

View file

@ -56,12 +56,12 @@ struct Runner
std::set<NodeId> peerset;
/** Which txhashes have been assigned already (to prevent reuse). */
std::set<GenTxidVariant> txhashset;
std::set<GenTxid> txhashset;
/** Which (peer, gtxid) combinations are known to be expired. These need to be accumulated here instead of
* checked directly in the GetRequestable return value to avoid introducing a dependency between the various
* parallel tests. */
std::multiset<std::pair<NodeId, GenTxidVariant>> expired;
std::multiset<std::pair<NodeId, GenTxid>> expired;
};
std::chrono::microseconds TxRequestTest::RandomTime8s() { return std::chrono::microseconds{1 + m_rng.randbits(23)}; }
@ -100,7 +100,7 @@ public:
}
/** Schedule a ForgetTxHash call at the Scheduler's current time. */
void ForgetTxHash(const GenTxidVariant& txhash)
void ForgetTxHash(const GenTxid& txhash)
{
auto& runner = m_runner;
runner.actions.emplace_back(m_now, [=,&runner]() {
@ -110,7 +110,7 @@ public:
}
/** Schedule a ReceivedInv call at the Scheduler's current time. */
void ReceivedInv(NodeId peer, const GenTxidVariant& gtxid, bool pref, std::chrono::microseconds reqtime)
void ReceivedInv(NodeId peer, const GenTxid& gtxid, bool pref, std::chrono::microseconds reqtime)
{
auto& runner = m_runner;
runner.actions.emplace_back(m_now, [=,&runner]() {
@ -130,7 +130,7 @@ public:
}
/** Schedule a RequestedTx call at the Scheduler's current time. */
void RequestedTx(NodeId peer, const GenTxidVariant& txhash, std::chrono::microseconds exptime)
void RequestedTx(NodeId peer, const GenTxid& txhash, std::chrono::microseconds exptime)
{
auto& runner = m_runner;
runner.actions.emplace_back(m_now, [=,&runner]() {
@ -140,7 +140,7 @@ public:
}
/** Schedule a ReceivedResponse call at the Scheduler's current time. */
void ReceivedResponse(NodeId peer, const GenTxidVariant& txhash)
void ReceivedResponse(NodeId peer, const GenTxid& txhash)
{
auto& runner = m_runner;
runner.actions.emplace_back(m_now, [=,&runner]() {
@ -160,7 +160,7 @@ public:
* @param offset Offset with the current time to use (must be <= 0). This allows simulations of time going
* backwards (but note that the ordering of this event only follows the scenario's m_now.
*/
void Check(NodeId peer, const std::vector<GenTxidVariant>& expected, size_t candidates, size_t inflight,
void Check(NodeId peer, const std::vector<GenTxid>& expected, size_t candidates, size_t inflight,
size_t completed, const std::string& checkname,
std::chrono::microseconds offset = std::chrono::microseconds{0})
{
@ -169,7 +169,7 @@ public:
const auto now = m_now;
assert(offset.count() <= 0);
runner.actions.emplace_back(m_now, [=,&runner]() {
std::vector<std::pair<NodeId, GenTxidVariant>> expired_now;
std::vector<std::pair<NodeId, GenTxid>> expired_now;
auto ret = runner.txrequest.GetRequestable(peer, now + offset, &expired_now);
for (const auto& entry : expired_now) runner.expired.insert(entry);
runner.txrequest.SanityCheck();
@ -189,12 +189,12 @@ public:
*
* Every expected expiration should be accounted for through exactly one call to this function.
*/
void CheckExpired(NodeId peer, GenTxidVariant gtxid)
void CheckExpired(NodeId peer, GenTxid gtxid)
{
const auto& testname = m_testname;
auto& runner = m_runner;
runner.actions.emplace_back(m_now, [=,&runner]() {
auto it = runner.expired.find(std::pair<NodeId, GenTxidVariant>{peer, gtxid});
auto it = runner.expired.find(std::pair<NodeId, GenTxid>{peer, gtxid});
BOOST_CHECK_MESSAGE(it != runner.expired.end(), "[" + testname + "] missing expiration");
if (it != runner.expired.end()) runner.expired.erase(it);
});
@ -208,9 +208,9 @@ public:
* where priority is the predicted internal TxRequestTracker's priority, assuming all announcements
* are within the same preferredness class.
*/
GenTxidVariant NewGTxid(const std::vector<std::vector<NodeId>>& orders = {})
GenTxid NewGTxid(const std::vector<std::vector<NodeId>>& orders = {})
{
GenTxidVariant ret;
GenTxid ret;
bool ok;
do {
uint256 hash = m_rng.rand256();

View file

@ -794,7 +794,7 @@ void CTxMemPool::check(const CCoinsViewCache& active_coins_tip, int64_t spendhei
assert(innerUsage == cachedInnerUsage);
}
bool CTxMemPool::CompareDepthAndScore(const GenTxidVariant& hasha, const GenTxidVariant& hashb)
bool CTxMemPool::CompareDepthAndScore(const GenTxid& hasha, const GenTxid& hashb)
{
/* Return `true` if hasha should be considered sooner than hashb. Namely when:
* a is not in the mempool, but b is
@ -898,7 +898,7 @@ CTransactionRef CTxMemPool::get(const uint256& hash) const
return i->GetSharedTx();
}
TxMempoolInfo CTxMemPool::info(const GenTxidVariant& gtxid) const
TxMempoolInfo CTxMemPool::info(const GenTxid& gtxid) const
{
LOCK(cs);
indexed_transaction_set::const_iterator i = std::visit(util::Overloaded{
@ -911,7 +911,7 @@ TxMempoolInfo CTxMemPool::info(const GenTxidVariant& gtxid) const
return GetInfo(i);
}
TxMempoolInfo CTxMemPool::info_for_relay(const GenTxidVariant& gtxid, uint64_t last_sequence) const
TxMempoolInfo CTxMemPool::info_for_relay(const GenTxid& gtxid, uint64_t last_sequence) const
{
LOCK(cs);
indexed_transaction_set::const_iterator i = std::visit(util::Overloaded{

View file

@ -468,7 +468,7 @@ public:
void removeConflicts(const CTransaction& tx) EXCLUSIVE_LOCKS_REQUIRED(cs);
void removeForBlock(const std::vector<CTransactionRef>& vtx, unsigned int nBlockHeight) EXCLUSIVE_LOCKS_REQUIRED(cs);
bool CompareDepthAndScore(const GenTxidVariant& hasha, const GenTxidVariant& hashb);
bool CompareDepthAndScore(const GenTxid& hasha, const GenTxid& hashb);
bool isSpent(const COutPoint& outpoint) const;
unsigned int GetTransactionsUpdated() const;
void AddTransactionsUpdated(unsigned int n);
@ -646,7 +646,7 @@ public:
return m_total_fee;
}
bool exists(const GenTxidVariant& gtxid) const
bool exists(const GenTxid& gtxid) const
{
LOCK(cs);
return std::visit(util::Overloaded{
@ -663,10 +663,10 @@ public:
AssertLockHeld(cs);
return mapTx.project<0>(mapTx.get<index_by_wtxid>().find(wtxid));
}
TxMempoolInfo info(const GenTxidVariant& gtxid) const;
TxMempoolInfo info(const GenTxid& gtxid) const;
/** Returns info for a transaction if its entry_sequence < last_sequence */
TxMempoolInfo info_for_relay(const GenTxidVariant& gtxid, uint64_t last_sequence) const;
TxMempoolInfo info_for_relay(const GenTxid& gtxid, uint64_t last_sequence) const;
std::vector<CTxMemPoolEntryRef> entryAll() const EXCLUSIVE_LOCKS_REQUIRED(cs);
std::vector<TxMempoolInfo> infoAll() const;

View file

@ -60,7 +60,7 @@ using SequenceNumber = uint64_t;
/** An announcement. This is the data we track for each txid or wtxid that is announced to us by each peer. */
struct Announcement {
/** Txid or wtxid that was announced. */
const GenTxidVariant m_txhash;
const GenTxid m_txhash;
/** For CANDIDATE_{DELAYED,BEST,READY} the reqtime; for REQUESTED the expiry. */
std::chrono::microseconds m_time;
/** What peer the request was from. */
@ -96,7 +96,7 @@ struct Announcement {
}
/** Construct a new announcement from scratch, initially in CANDIDATE_DELAYED state. */
Announcement(const GenTxidVariant& gtxid, NodeId peer, bool preferred, std::chrono::microseconds reqtime,
Announcement(const GenTxid& gtxid, NodeId peer, bool preferred, std::chrono::microseconds reqtime,
SequenceNumber sequence)
: m_txhash(gtxid), m_time(reqtime), m_peer(peer), m_sequence(sequence), m_preferred(preferred) {}
};
@ -115,7 +115,7 @@ public:
m_k0{deterministic ? 0 : FastRandomContext().rand64()},
m_k1{deterministic ? 0 : FastRandomContext().rand64()} {}
Priority operator()(const GenTxidVariant& txhash, NodeId peer, bool preferred) const
Priority operator()(const GenTxid& txhash, NodeId peer, bool preferred) const
{
uint64_t low_bits = CSipHasher(m_k0, m_k1).Write(txhash.ToUint256()).Write(peer).Finalize() >> 1;
return low_bits | uint64_t{preferred} << 63;
@ -141,7 +141,7 @@ public:
// (peer, true, txhash).
// * Finding all CANDIDATE_BEST announcements for a given peer in GetRequestable.
struct ByPeer {};
using ByPeerView = std::tuple<NodeId, bool, const GenTxidVariant&>;
using ByPeerView = std::tuple<NodeId, bool, const GenTxid&>;
struct ByPeerViewExtractor
{
using result_type = ByPeerView;
@ -162,7 +162,7 @@ struct ByPeerViewExtractor
// * Determining when no more non-COMPLETED announcements for a given txhash exist, so the COMPLETED ones can be
// deleted.
struct ByTxHash {};
using ByTxHashView = std::tuple<const GenTxidVariant&, State, Priority>;
using ByTxHashView = std::tuple<const GenTxid&, State, Priority>;
class ByTxHashViewExtractor {
const PriorityComputer& m_computer;
public:
@ -275,9 +275,9 @@ std::unordered_map<NodeId, PeerInfo> RecomputePeerInfo(const Index& index)
}
/** Compute the TxHashInfo map. Only used for sanity checking. */
std::map<GenTxidVariant, TxHashInfo> ComputeTxHashInfo(const Index& index, const PriorityComputer& computer)
std::map<GenTxid, TxHashInfo> ComputeTxHashInfo(const Index& index, const PriorityComputer& computer)
{
std::map<GenTxidVariant, TxHashInfo> ret;
std::map<GenTxid, TxHashInfo> ret;
for (const Announcement& ann : index) {
TxHashInfo& info = ret[ann.m_txhash];
// Classify how many announcements of each state we have for this txhash.
@ -466,7 +466,7 @@ private:
if (IsOnlyNonCompleted(it)) {
// This is the last non-COMPLETED announcement for this txhash. Delete all.
GenTxidVariant txhash = it->m_txhash;
GenTxid txhash = it->m_txhash;
do {
it = Erase<ByTxHash>(it);
} while (it != m_index.get<ByTxHash>().end() && it->m_txhash == txhash);
@ -484,7 +484,7 @@ private:
//! - REQUESTED announcements with expiry <= now are turned into COMPLETED.
//! - CANDIDATE_DELAYED announcements with reqtime <= now are turned into CANDIDATE_{READY,BEST}.
//! - CANDIDATE_{READY,BEST} announcements with reqtime > now are turned into CANDIDATE_DELAYED.
void SetTimePoint(std::chrono::microseconds now, std::vector<std::pair<NodeId, GenTxidVariant>>* expired)
void SetTimePoint(std::chrono::microseconds now, std::vector<std::pair<NodeId, GenTxid>>* expired)
{
if (expired) expired->clear();
@ -532,7 +532,7 @@ public:
void DisconnectedPeer(NodeId peer)
{
auto& index = m_index.get<ByPeer>();
GenTxidVariant lowerzero = Txid::FromUint256(uint256::ZERO);
GenTxid lowerzero = Txid::FromUint256(uint256::ZERO);
auto it = index.lower_bound(ByPeerView{peer, false, lowerzero});
while (it != index.end() && it->m_peer == peer) {
// Check what to continue with after this iteration. 'it' will be deleted in what follows, so we need to
@ -561,7 +561,7 @@ public:
}
}
void ForgetTxHash(const GenTxidVariant& txhash)
void ForgetTxHash(const GenTxid& txhash)
{
auto it = m_index.get<ByTxHash>().lower_bound(ByTxHashView{txhash, State::CANDIDATE_DELAYED, 0});
while (it != m_index.get<ByTxHash>().end() && it->m_txhash == txhash) {
@ -569,7 +569,7 @@ public:
}
}
void GetCandidatePeers(const GenTxidVariant& txhash, std::vector<NodeId>& result_peers) const
void GetCandidatePeers(const GenTxid& txhash, std::vector<NodeId>& result_peers) const
{
auto it = m_index.get<ByTxHash>().lower_bound(ByTxHashView{txhash, State::CANDIDATE_DELAYED, 0});
while (it != m_index.get<ByTxHash>().end() && it->m_txhash == txhash && it->GetState() != State::COMPLETED) {
@ -578,7 +578,7 @@ public:
}
}
void ReceivedInv(NodeId peer, const GenTxidVariant& gtxid, bool preferred,
void ReceivedInv(NodeId peer, const GenTxid& gtxid, bool preferred,
std::chrono::microseconds reqtime)
{
// Bail out if we already have a CANDIDATE_BEST announcement for this (txhash, peer) combination. The case
@ -598,15 +598,15 @@ public:
}
//! Find the GenTxids to request now from peer.
std::vector<GenTxidVariant> GetRequestable(NodeId peer, std::chrono::microseconds now,
std::vector<std::pair<NodeId, GenTxidVariant>>* expired)
std::vector<GenTxid> GetRequestable(NodeId peer, std::chrono::microseconds now,
std::vector<std::pair<NodeId, GenTxid>>* expired)
{
// Move time.
SetTimePoint(now, expired);
// Find all CANDIDATE_BEST announcements for this peer.
std::vector<const Announcement*> selected;
GenTxidVariant lowerzero = Txid::FromUint256(uint256::ZERO);
GenTxid lowerzero = Txid::FromUint256(uint256::ZERO);
auto it_peer = m_index.get<ByPeer>().lower_bound(ByPeerView{peer, true, lowerzero});
while (it_peer != m_index.get<ByPeer>().end() && it_peer->m_peer == peer &&
it_peer->GetState() == State::CANDIDATE_BEST) {
@ -620,7 +620,7 @@ public:
});
// Convert to GenTxid and return.
std::vector<GenTxidVariant> ret;
std::vector<GenTxid> ret;
ret.reserve(selected.size());
std::transform(selected.begin(), selected.end(), std::back_inserter(ret), [](const Announcement* ann) {
return ann->m_txhash;
@ -628,7 +628,7 @@ public:
return ret;
}
void RequestedTx(NodeId peer, const GenTxidVariant& txhash, std::chrono::microseconds expiry)
void RequestedTx(NodeId peer, const GenTxid& txhash, std::chrono::microseconds expiry)
{
auto it = m_index.get<ByPeer>().find(ByPeerView{peer, true, txhash});
if (it == m_index.get<ByPeer>().end()) {
@ -673,7 +673,7 @@ public:
});
}
void ReceivedResponse(NodeId peer, const GenTxidVariant& txhash)
void ReceivedResponse(NodeId peer, const GenTxid& txhash)
{
// We need to search the ByPeer index for both (peer, false, txhash) and (peer, true, txhash).
auto it = m_index.get<ByPeer>().find(ByPeerView{peer, false, txhash});
@ -707,7 +707,7 @@ public:
//! Count how many announcements are being tracked in total across all peers and transactions.
size_t Size() const { return m_index.size(); }
uint64_t ComputePriority(const GenTxidVariant& txhash, NodeId peer, bool preferred) const
uint64_t ComputePriority(const GenTxid& txhash, NodeId peer, bool preferred) const
{
// Return Priority as a uint64_t as Priority is internal.
return uint64_t{m_computer(txhash, peer, preferred)};
@ -720,13 +720,13 @@ TxRequestTracker::TxRequestTracker(bool deterministic) :
TxRequestTracker::~TxRequestTracker() = default;
void TxRequestTracker::ForgetTxHash(const GenTxidVariant& txhash) { m_impl->ForgetTxHash(txhash); }
void TxRequestTracker::ForgetTxHash(const GenTxid& txhash) { m_impl->ForgetTxHash(txhash); }
void TxRequestTracker::DisconnectedPeer(NodeId peer) { m_impl->DisconnectedPeer(peer); }
size_t TxRequestTracker::CountInFlight(NodeId peer) const { return m_impl->CountInFlight(peer); }
size_t TxRequestTracker::CountCandidates(NodeId peer) const { return m_impl->CountCandidates(peer); }
size_t TxRequestTracker::Count(NodeId peer) const { return m_impl->Count(peer); }
size_t TxRequestTracker::Size() const { return m_impl->Size(); }
void TxRequestTracker::GetCandidatePeers(const GenTxidVariant& txhash, std::vector<NodeId>& result_peers) const { return m_impl->GetCandidatePeers(txhash, result_peers); }
void TxRequestTracker::GetCandidatePeers(const GenTxid& txhash, std::vector<NodeId>& result_peers) const { return m_impl->GetCandidatePeers(txhash, result_peers); }
void TxRequestTracker::SanityCheck() const { m_impl->SanityCheck(); }
void TxRequestTracker::PostGetRequestableSanityCheck(std::chrono::microseconds now) const
@ -734,29 +734,29 @@ void TxRequestTracker::PostGetRequestableSanityCheck(std::chrono::microseconds n
m_impl->PostGetRequestableSanityCheck(now);
}
void TxRequestTracker::ReceivedInv(NodeId peer, const GenTxidVariant& gtxid, bool preferred,
void TxRequestTracker::ReceivedInv(NodeId peer, const GenTxid& gtxid, bool preferred,
std::chrono::microseconds reqtime)
{
m_impl->ReceivedInv(peer, gtxid, preferred, reqtime);
}
void TxRequestTracker::RequestedTx(NodeId peer, const GenTxidVariant& txhash, std::chrono::microseconds expiry)
void TxRequestTracker::RequestedTx(NodeId peer, const GenTxid& txhash, std::chrono::microseconds expiry)
{
m_impl->RequestedTx(peer, txhash, expiry);
}
void TxRequestTracker::ReceivedResponse(NodeId peer, const GenTxidVariant& txhash)
void TxRequestTracker::ReceivedResponse(NodeId peer, const GenTxid& txhash)
{
m_impl->ReceivedResponse(peer, txhash);
}
std::vector<GenTxidVariant> TxRequestTracker::GetRequestable(NodeId peer, std::chrono::microseconds now,
std::vector<std::pair<NodeId, GenTxidVariant>>* expired)
std::vector<GenTxid> TxRequestTracker::GetRequestable(NodeId peer, std::chrono::microseconds now,
std::vector<std::pair<NodeId, GenTxid>>* expired)
{
return m_impl->GetRequestable(peer, now, expired);
}
uint64_t TxRequestTracker::ComputePriority(const GenTxidVariant& txhash, NodeId peer, bool preferred) const
uint64_t TxRequestTracker::ComputePriority(const GenTxid& txhash, NodeId peer, bool preferred) const
{
return m_impl->ComputePriority(txhash, peer, preferred);
}

View file

@ -132,7 +132,7 @@ public:
* fetched. The new announcement is given the specified preferred and reqtime values, and takes its is_wtxid
* from the specified gtxid.
*/
void ReceivedInv(NodeId peer, const GenTxidVariant& gtxid, bool preferred,
void ReceivedInv(NodeId peer, const GenTxid& gtxid, bool preferred,
std::chrono::microseconds reqtime);
/** Deletes all announcements for a given peer.
@ -146,7 +146,7 @@ public:
* This should be called when a transaction is no longer needed. The caller should ensure that new announcements
* for the same txhash will not trigger new ReceivedInv calls, at least in the short term after this call.
*/
void ForgetTxHash(const GenTxidVariant& txhash);
void ForgetTxHash(const GenTxid& txhash);
/** Find the txids to request now from peer.
*
@ -164,8 +164,8 @@ public:
* out of order: if multiple dependent transactions are announced simultaneously by one peer, and end up
* being requested from them, the requests will happen in announcement order.
*/
std::vector<GenTxidVariant> GetRequestable(NodeId peer, std::chrono::microseconds now,
std::vector<std::pair<NodeId, GenTxidVariant>>* expired = nullptr);
std::vector<GenTxid> GetRequestable(NodeId peer, std::chrono::microseconds now,
std::vector<std::pair<NodeId, GenTxid>>* expired = nullptr);
/** Marks a transaction as requested, with a specified expiry.
*
@ -175,7 +175,7 @@ public:
* was made (GetRequestable will never advise doing so). In this case it is converted to COMPLETED, as we're
* no longer waiting for a response to it.
*/
void RequestedTx(NodeId peer, const GenTxidVariant& txhash, std::chrono::microseconds expiry);
void RequestedTx(NodeId peer, const GenTxid& txhash, std::chrono::microseconds expiry);
/** Converts a CANDIDATE or REQUESTED announcement to a COMPLETED one. If no such announcement exists for the
* provided peer and txhash, nothing happens.
@ -183,7 +183,7 @@ public:
* It should be called whenever a transaction or NOTFOUND was received from a peer. When the transaction is
* not needed entirely anymore, ForgetTxhash should be called instead of, or in addition to, this call.
*/
void ReceivedResponse(NodeId peer, const GenTxidVariant& txhash);
void ReceivedResponse(NodeId peer, const GenTxid& txhash);
// The operations below inspect the data structure.
@ -201,10 +201,10 @@ public:
/** For some txhash (txid or wtxid), finds all peers with non-COMPLETED announcements and appends them to
* result_peers. Does not try to ensure that result_peers contains no duplicates. */
void GetCandidatePeers(const GenTxidVariant& txhash, std::vector<NodeId>& result_peers) const;
void GetCandidatePeers(const GenTxid& txhash, std::vector<NodeId>& result_peers) const;
/** Access to the internal priority computation (testing only) */
uint64_t ComputePriority(const GenTxidVariant& txhash, NodeId peer, bool preferred) const;
uint64_t ComputePriority(const GenTxid& txhash, NodeId peer, bool preferred) const;
/** Run internal consistency check (testing only). */
void SanityCheck() const;

View file

@ -75,7 +75,7 @@ using Txid = transaction_identifier<false>;
using Wtxid = transaction_identifier<true>;
/** A generic txid reference (txid or wtxid). */
class GenTxidVariant : public std::variant<Txid, Wtxid>
class GenTxid : public std::variant<Txid, Wtxid>
{
public:
using variant::variant;
@ -84,12 +84,12 @@ public:
return std::visit([](const auto& id) -> const uint256& { return id.ToUint256(); }, *this);
}
friend bool operator==(const GenTxidVariant& a, const GenTxidVariant& b) {
friend bool operator==(const GenTxid& a, const GenTxid& b) {
//return a.index() == b.index() && a.ToUint256() == b.ToUint256();
return a.ToUint256() == b.ToUint256();
}
friend bool operator<(const GenTxidVariant& a, const GenTxidVariant& b) {
friend bool operator<(const GenTxid& a, const GenTxid& b) {
//return std::tuple(a.index(), a.ToUint256()) < std::tuple(b.index(), b.ToUint256());
return a.ToUint256() < b.ToUint256();
}