Skip to content

Commit 045cf03

Browse files
committed
refactor: replace helper GetTransactionBlock to direct usage of GetTransaction
1 parent fe69e15 commit 045cf03

File tree

5 files changed

+16
-25
lines changed

5 files changed

+16
-25
lines changed

src/llmq/chainlocks.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
#include <validationinterface.h>
2525

2626
// Forward declaration to break dependency over node/transaction.h
27-
std::pair<CTransactionRef, uint256> GetTransactionBlock(const uint256& hash, const CTxMemPool* const mempool);
27+
CTransactionRef GetTransaction(const CBlockIndex* const block_index, const CTxMemPool* const mempool,
28+
const uint256& hash, const Consensus::Params& consensusParams, uint256& hashBlock);
2829

2930
static bool ChainLocksSigningEnabled(const CSporkManager& sporkman)
3031
{
@@ -638,8 +639,8 @@ void CChainLocksHandler::Cleanup()
638639
}
639640
}
640641
for (auto it = txFirstSeenTime.begin(); it != txFirstSeenTime.end(); ) {
641-
auto [tx, hashBlock] = GetTransactionBlock(it->first, &mempool);
642-
if (!tx) {
642+
uint256 hashBlock;
643+
if (auto tx = GetTransaction(nullptr, &mempool, it->first, Params().GetConsensus(), hashBlock); !tx) {
643644
// tx has vanished, probably due to conflicts
644645
it = txFirstSeenTime.erase(it);
645646
} else if (!hashBlock.IsNull()) {

src/llmq/instantsend.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
#include <cxxtimer.hpp>
2929

3030
// Forward declaration to break dependency over node/transaction.h
31-
std::pair<CTransactionRef, uint256> GetTransactionBlock(const uint256& hash, const CTxMemPool* const mempool);
31+
CTransactionRef GetTransaction(const CBlockIndex* const block_index, const CTxMemPool* const mempool,
32+
const uint256& hash, const Consensus::Params& consensusParams, uint256& hashBlock);
3233

3334
namespace llmq
3435
{
@@ -577,7 +578,8 @@ bool CInstantSendManager::CheckCanLock(const COutPoint& outpoint, bool printDebu
577578
return false;
578579
}
579580

580-
auto [tx, hashBlock] = GetTransactionBlock(outpoint.hash, &mempool);
581+
uint256 hashBlock{};
582+
const auto tx = GetTransaction(nullptr, &mempool, outpoint.hash, params, hashBlock);
581583
// this relies on enabled txindex and won't work if we ever try to remove the requirement for txindex for masternodes
582584
if (!tx) {
583585
if (printDebug) {
@@ -634,7 +636,9 @@ void CInstantSendManager::HandleNewInputLockRecoveredSig(const CRecoveredSig& re
634636
g_txindex->BlockUntilSyncedToCurrentChain();
635637
}
636638

637-
auto [tx, hashBlock] = GetTransactionBlock(txid, &mempool);
639+
640+
uint256 hashBlock{};
641+
const auto tx = GetTransaction(nullptr, &mempool, txid, Params().GetConsensus(), hashBlock);
638642
if (!tx) {
639643
return;
640644
}
@@ -1013,7 +1017,8 @@ void CInstantSendManager::ProcessInstantSendLock(NodeId from, PeerManager& peerm
10131017
return;
10141018
}
10151019

1016-
auto [tx, hashBlock] = GetTransactionBlock(islock->txid, &mempool);
1020+
uint256 hashBlock{};
1021+
const auto tx = GetTransaction(nullptr, &mempool, islock->txid, Params().GetConsensus(), hashBlock);
10171022
const CBlockIndex* pindexMined{nullptr};
10181023
// we ignore failure here as we must be able to propagate the lock even if we don't have the TX locally
10191024
if (tx && !hashBlock.IsNull()) {

src/node/transaction.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,3 @@ CTransactionRef GetTransaction(const CBlockIndex* const block_index, const CTxMe
148148
}
149149
return nullptr;
150150
}
151-
152-
std::pair<CTransactionRef, uint256> GetTransactionBlock(const uint256& hash, const CTxMemPool* const mempool)
153-
{
154-
uint256 hashBlock{};
155-
if (!g_txindex && !mempool) return {nullptr, hashBlock}; // Fast-fail as we don't have any other way to search
156-
return {GetTransaction(/*block_index=*/nullptr, mempool, hash, Params().GetConsensus(), hashBlock), hashBlock};
157-
}

src/node/transaction.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,4 @@ static const CFeeRate DEFAULT_MAX_RAW_TX_FEE_RATE{COIN / 10};
5757
*/
5858
CTransactionRef GetTransaction(const CBlockIndex* const block_index, const CTxMemPool* const mempool, const uint256& hash, const Consensus::Params& consensusParams, uint256& hashBlock);
5959

60-
/**
61-
* Retrieve transaction and block from txindex (or mempool)
62-
* That's just a wrapper over GetTransaction to break circular dependencies
63-
* and to simplify caller for case if no block_index
64-
*/
65-
std::pair</*tx=*/CTransactionRef, /*hash_block=*/uint256> GetTransactionBlock(const uint256& hash,
66-
const CTxMemPool* const mempool);
67-
68-
6960
#endif // BITCOIN_NODE_TRANSACTION_H

src/validation.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ uint256 hashAssumeValid;
118118
arith_uint256 nMinimumChainWork;
119119

120120
// Forward declaration to break dependency over node/transaction.h
121-
std::pair<CTransactionRef, uint256> GetTransactionBlock(const uint256& hash, const CTxMemPool* const mempool);
121+
CTransactionRef GetTransaction(const CBlockIndex* const block_index, const CTxMemPool* const mempool, const uint256& hash, const Consensus::Params& consensusParams, uint256& hashBlock);
122122

123123
const CBlockIndex* CChainState::FindForkInGlobalIndex(const CBlockLocator& locator) const
124124
{
@@ -729,7 +729,8 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
729729
if (auto conflictLockOpt = m_chain_helper.ConflictingISLockIfAny(tx); conflictLockOpt.has_value()) {
730730
auto& [_, conflict_txid] = conflictLockOpt.value();
731731

732-
if (auto [txConflict, _] = GetTransactionBlock(conflict_txid, &m_pool); txConflict) {
732+
uint256 hashBlock;
733+
if (auto txConflict = GetTransaction(nullptr, &m_pool, conflict_txid, chainparams.GetConsensus(), hashBlock); txConflict) {
733734
GetMainSignals().NotifyInstantSendDoubleSpendAttempt(ptx, txConflict);
734735
}
735736
LogPrintf("ERROR: AcceptToMemoryPool : Transaction %s conflicts with locked TX %s\n", hash.ToString(), conflict_txid.ToString());

0 commit comments

Comments
 (0)