Skip to content

Commit 1f4a5a6

Browse files
committed
refactor: replace helper GetTransactionBlock to direct usage of GetTransaction
1 parent 3a83b06 commit 1f4a5a6

File tree

5 files changed

+28
-25
lines changed

5 files changed

+28
-25
lines changed

src/llmq/chainlocks.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@
2626
using node::ReadBlockFromDisk;
2727

2828
// Forward declaration to break dependency over node/transaction.h
29-
std::pair<CTransactionRef, uint256> GetTransactionBlock(const uint256& hash, const CTxMemPool* const mempool);
29+
namespace node
30+
{
31+
CTransactionRef GetTransaction(const CBlockIndex* const block_index, const CTxMemPool* const mempool,
32+
const uint256& hash, const Consensus::Params& consensusParams, uint256& hashBlock);
33+
} // namespace node
34+
using node::GetTransaction;
3035

3136
static bool ChainLocksSigningEnabled(const CSporkManager& sporkman)
3237
{
@@ -640,8 +645,8 @@ void CChainLocksHandler::Cleanup()
640645
}
641646
}
642647
for (auto it = txFirstSeenTime.begin(); it != txFirstSeenTime.end(); ) {
643-
auto [tx, hashBlock] = GetTransactionBlock(it->first, &mempool);
644-
if (!tx) {
648+
uint256 hashBlock;
649+
if (auto tx = GetTransaction(nullptr, &mempool, it->first, Params().GetConsensus(), hashBlock); !tx) {
645650
// tx has vanished, probably due to conflicts
646651
it = txFirstSeenTime.erase(it);
647652
} else if (!hashBlock.IsNull()) {

src/llmq/instantsend.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ using node::fImporting;
3131
using node::fReindex;
3232

3333
// Forward declaration to break dependency over node/transaction.h
34-
std::pair<CTransactionRef, uint256> GetTransactionBlock(const uint256& hash, const CTxMemPool* const mempool);
34+
namespace node
35+
{
36+
CTransactionRef GetTransaction(const CBlockIndex* const block_index, const CTxMemPool* const mempool,
37+
const uint256& hash, const Consensus::Params& consensusParams, uint256& hashBlock);
38+
} // namespace node
39+
using node::GetTransaction;
3540

3641
namespace llmq
3742
{
@@ -580,7 +585,8 @@ bool CInstantSendManager::CheckCanLock(const COutPoint& outpoint, bool printDebu
580585
return false;
581586
}
582587

583-
auto [tx, hashBlock] = GetTransactionBlock(outpoint.hash, &mempool);
588+
uint256 hashBlock{};
589+
const auto tx = GetTransaction(nullptr, &mempool, outpoint.hash, params, hashBlock);
584590
// this relies on enabled txindex and won't work if we ever try to remove the requirement for txindex for masternodes
585591
if (!tx) {
586592
if (printDebug) {
@@ -637,7 +643,9 @@ void CInstantSendManager::HandleNewInputLockRecoveredSig(const CRecoveredSig& re
637643
g_txindex->BlockUntilSyncedToCurrentChain();
638644
}
639645

640-
auto [tx, hashBlock] = GetTransactionBlock(txid, &mempool);
646+
647+
uint256 hashBlock{};
648+
const auto tx = GetTransaction(nullptr, &mempool, txid, Params().GetConsensus(), hashBlock);
641649
if (!tx) {
642650
return;
643651
}
@@ -1019,7 +1027,8 @@ void CInstantSendManager::ProcessInstantSendLock(NodeId from, PeerManager& peerm
10191027
return;
10201028
}
10211029

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

src/node/transaction.cpp

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

src/node/transaction.h

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

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

src/validation.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,11 @@ uint256 hashAssumeValid;
138138
arith_uint256 nMinimumChainWork;
139139

140140
// Forward declaration to break dependency over node/transaction.h
141-
std::pair<CTransactionRef, uint256> GetTransactionBlock(const uint256& hash, const CTxMemPool* const mempool);
141+
namespace node
142+
{
143+
CTransactionRef GetTransaction(const CBlockIndex* const block_index, const CTxMemPool* const mempool, const uint256& hash, const Consensus::Params& consensusParams, uint256& hashBlock);
144+
} // namespace node
145+
using node::GetTransaction;
142146

143147
const CBlockIndex* CChainState::FindForkInGlobalIndex(const CBlockLocator& locator) const
144148
{
@@ -754,7 +758,8 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)
754758
if (auto conflictLockOpt = m_chain_helper.ConflictingISLockIfAny(tx); conflictLockOpt.has_value()) {
755759
auto& [_, conflict_txid] = conflictLockOpt.value();
756760

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

0 commit comments

Comments
 (0)