Skip to content

Commit c587838

Browse files
committed
refactor: use GetTransactionBlock() as narrow GetTransaction() proxy
Currently, we rely on redefinition to avoid an explosion in reported circular dependencies but that is verboten with `-Wredundant-decls`. To trim down the amount of circular dependencies that would happen once we remove the circular definition, we have to proxy `GetTransaction()` through another function located elsewhere. Since all Dash-specific invocations either rely on the txindex or the mempool, we can safely trim down the number of arguments and add a fast-fail. Since we do (sometimes) care about the block the transaction is in, we return that as well.
1 parent d9828a9 commit c587838

20 files changed

+51
-36
lines changed

src/coinjoin/client.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <coinjoin/client.h>
66

7+
#include <chain.h>
78
#include <chainparams.h>
89
#include <coinjoin/options.h>
910
#include <consensus/validation.h>
@@ -21,7 +22,6 @@
2122
#include <util/ranges.h>
2223
#include <util/system.h>
2324
#include <util/translation.h>
24-
#include <validation.h>
2525
#include <version.h>
2626
#include <wallet/coincontrol.h>
2727
#include <wallet/fees.h>

src/coinjoin/util.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include <policy/fees.h>
88
#include <policy/policy.h>
99
#include <script/sign.h>
10-
#include <validation.h>
1110
#include <wallet/fees.h>
1211
#include <wallet/wallet.h>
1312
#include <util/translation.h>

src/evo/assetlocktx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
#include <consensus/validation.h>
1515
#include <deploymentstatus.h>
1616
#include <logging.h>
17+
#include <node/blockstorage.h>
1718
#include <tinyformat.h>
1819
#include <util/ranges_set.h>
19-
#include <validation.h>
2020

2121
#include <algorithm>
2222

src/evo/cbtx.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include <chainparams.h>
1919
#include <consensus/merkle.h>
2020
#include <deploymentstatus.h>
21-
#include <validation.h>
2221

2322

2423
bool CheckCbTx(const CTransaction& tx, const CBlockIndex* pindexPrev, TxValidationState& state)

src/evo/chainhelper.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66

77
#include <consensus/params.h>
88
#include <evo/specialtxman.h>
9+
#include <index/txindex.h>
910
#include <llmq/chainlocks.h>
1011
#include <llmq/instantsend.h>
1112
#include <masternode/payments.h>
13+
#include <node/transaction.h>
14+
#include <txmempool.h>
1215

1316
CChainstateHelper::CChainstateHelper(CCreditPoolManager& cpoolman, CDeterministicMNManager& dmnman,
1417
CMNHFManager& mnhfman, CGovernanceManager& govman, llmq::CInstantSendManager& isman,
@@ -58,3 +61,10 @@ bool CChainstateHelper::RemoveConflictingISLockByTx(const CTransaction& tx)
5861
}
5962

6063
bool CChainstateHelper::ShouldInstantSendRejectConflicts() const { return isman.RejectConflictingBlocks(); }
64+
65+
std::pair<CTransactionRef, uint256> GetTransactionBlock(const uint256& hash, const CTxMemPool* const mempool)
66+
{
67+
uint256 hashBlock{};
68+
if (!g_txindex && !mempool) return {nullptr, hashBlock}; // Fast-fail as we don't have any other way to search
69+
return {GetTransaction(/*block_index=*/nullptr, mempool, hash, Params().GetConsensus(), hashBlock), hashBlock};
70+
}

src/evo/chainhelper.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class CGovernanceManager;
1818
class CSpecialTxProcessor;
1919
class CSporkManager;
2020
class CTransaction;
21+
class CTxMemPool;
2122
class uint256;
2223

2324
namespace Consensus { struct Params; }
@@ -29,6 +30,8 @@ class CQuorumManager;
2930
class CQuorumSnapshotManager;
3031
}
3132

33+
using CTransactionRef = std::shared_ptr<const CTransaction>;
34+
3235
class CChainstateHelper
3336
{
3437
private:
@@ -63,4 +66,8 @@ class CChainstateHelper
6366
const std::unique_ptr<CSpecialTxProcessor> special_tx;
6467
};
6568

69+
/* Retrieve transaction and block from txindex (or mempool) */
70+
std::pair</*tx=*/CTransactionRef, /*hash_block=*/uint256> GetTransactionBlock(const uint256& hash,
71+
const CTxMemPool* const mempool = nullptr);
72+
6673
#endif // BITCOIN_EVO_CHAINHELPER_H

src/evo/deterministicmns.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5+
#include <evo/chainhelper.h>
56
#include <evo/deterministicmns.h>
67
#include <evo/dmn_types.h>
78
#include <evo/dmnstate.h>
@@ -13,15 +14,15 @@
1314

1415
#include <base58.h>
1516
#include <chainparams.h>
17+
#include <coins.h>
1618
#include <consensus/validation.h>
1719
#include <deploymentstatus.h>
18-
#include <script/standard.h>
19-
#include <validation.h>
20-
#include <validationinterface.h>
21-
#include <univalue.h>
2220
#include <messagesigner.h>
23-
#include <uint256.h>
21+
#include <script/standard.h>
2422
#include <stats/client.h>
23+
#include <uint256.h>
24+
#include <univalue.h>
25+
#include <validationinterface.h>
2526

2627
#include <optional>
2728
#include <memory>
@@ -51,8 +52,7 @@ UniValue CDeterministicMN::ToJson() const
5152
obj.pushKV("collateralHash", collateralOutpoint.hash.ToString());
5253
obj.pushKV("collateralIndex", (int)collateralOutpoint.n);
5354

54-
uint256 tmpHashBlock;
55-
CTransactionRef collateralTx = GetTransaction(/* block_index */ nullptr, /* mempool */ nullptr, collateralOutpoint.hash, Params().GetConsensus(), tmpHashBlock);
55+
auto [collateralTx, _] = GetTransactionBlock(collateralOutpoint.hash);
5656
if (collateralTx) {
5757
CTxDestination dest;
5858
if (ExtractDestination(collateralTx->vout[collateralOutpoint.n].scriptPubKey, dest)) {

src/governance/object.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <bls/bls.h>
88
#include <chainparams.h>
99
#include <core_io.h>
10+
#include <evo/chainhelper.h>
1011
#include <evo/deterministicmns.h>
1112
#include <governance/governance.h>
1213
#include <governance/validators.h>
@@ -467,8 +468,7 @@ bool CGovernanceObject::IsCollateralValid(const ChainstateManager& chainman, std
467468
uint256 nExpectedHash = GetHash();
468469

469470
// RETRIEVE TRANSACTION IN QUESTION
470-
uint256 nBlockHash;
471-
CTransactionRef txCollateral = GetTransaction(/* block_index */ nullptr, /* mempool */ nullptr, m_obj.collateralHash, Params().GetConsensus(), nBlockHash);
471+
auto [txCollateral, nBlockHash] = GetTransactionBlock(m_obj.collateralHash);
472472
if (!txCollateral) {
473473
strError = strprintf("Can't find collateral tx %s", m_obj.collateralHash.ToString());
474474
LogPrintf("CGovernanceObject::IsCollateralValid -- %s\n", strError);

src/governance/vote.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include <timedata.h>
1616
#include <util/string.h>
1717
#include <util/system.h>
18-
#include <validation.h>
1918

2019
#include <evo/deterministicmns.h>
2120

src/llmq/chainlocks.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <chain.h>
1111
#include <chainparams.h>
1212
#include <consensus/validation.h>
13+
#include <evo/chainhelper.h>
1314
#include <masternode/sync.h>
1415
#include <node/blockstorage.h>
1516
#include <node/interface_ui.h>
@@ -635,8 +636,7 @@ void CChainLocksHandler::Cleanup()
635636
}
636637
}
637638
for (auto it = txFirstSeenTime.begin(); it != txFirstSeenTime.end(); ) {
638-
uint256 hashBlock;
639-
CTransactionRef tx = GetTransaction(/* block_index */ nullptr, &mempool, it->first, Params().GetConsensus(), hashBlock);
639+
auto [tx, hashBlock] = GetTransactionBlock(it->first, &mempool);
640640
if (!tx) {
641641
// tx has vanished, probably due to conflicts
642642
it = txFirstSeenTime.erase(it);

0 commit comments

Comments
 (0)