Skip to content

Commit f6895c1

Browse files
committed
refactor: drop circular dependency over evo/chainhelper.h
1 parent 0690bdf commit f6895c1

File tree

10 files changed

+40
-28
lines changed

10 files changed

+40
-28
lines changed

src/evo/chainhelper.cpp

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

77
#include <consensus/params.h>
88
#include <evo/specialtxman.h>
9-
#include <index/txindex.h>
109
#include <llmq/chainlocks.h>
1110
#include <llmq/instantsend.h>
1211
#include <masternode/payments.h>
13-
#include <node/transaction.h>
14-
#include <txmempool.h>
1512

1613
CChainstateHelper::CChainstateHelper(CCreditPoolManager& cpoolman, CDeterministicMNManager& dmnman,
1714
CMNHFManager& mnhfman, CGovernanceManager& govman, llmq::CInstantSendManager& isman,
@@ -62,9 +59,3 @@ bool CChainstateHelper::RemoveConflictingISLockByTx(const CTransaction& tx)
6259

6360
bool CChainstateHelper::ShouldInstantSendRejectConflicts() const { return isman.RejectConflictingBlocks(); }
6461

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: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ class CGovernanceManager;
1818
class CSpecialTxProcessor;
1919
class CSporkManager;
2020
class CTransaction;
21-
class CTxMemPool;
2221
class uint256;
2322

2423
namespace Consensus { struct Params; }
@@ -30,8 +29,6 @@ class CQuorumManager;
3029
class CQuorumSnapshotManager;
3130
}
3231

33-
using CTransactionRef = std::shared_ptr<const CTransaction>;
34-
3532
class CChainstateHelper
3633
{
3734
private:
@@ -66,8 +63,4 @@ class CChainstateHelper
6663
const std::unique_ptr<CSpecialTxProcessor> special_tx;
6764
};
6865

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-
7366
#endif // BITCOIN_EVO_CHAINHELPER_H

src/evo/deterministicmns.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
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>
65
#include <evo/deterministicmns.h>
76
#include <evo/dmn_types.h>
87
#include <evo/dmnstate.h>
@@ -27,6 +26,10 @@
2726
#include <optional>
2827
#include <memory>
2928

29+
// Forward declaration to break dependency over node/transaction.h
30+
class CTxMemPool;
31+
std::pair<CTransactionRef, uint256> GetTransactionBlock(const uint256& hash, const CTxMemPool* const mempool);
32+
3033
static const std::string DB_LIST_SNAPSHOT = "dmn_S3";
3134
static const std::string DB_LIST_DIFF = "dmn_D3";
3235

@@ -50,7 +53,7 @@ UniValue CDeterministicMN::ToJson() const
5053
obj.pushKV("collateralHash", collateralOutpoint.hash.ToString());
5154
obj.pushKV("collateralIndex", (int)collateralOutpoint.n);
5255

53-
auto [collateralTx, _] = GetTransactionBlock(collateralOutpoint.hash);
56+
auto [collateralTx, _] = GetTransactionBlock(collateralOutpoint.hash, nullptr);
5457
if (collateralTx) {
5558
CTxDestination dest;
5659
if (ExtractDestination(collateralTx->vout[collateralOutpoint.n].scriptPubKey, dest)) {

src/governance/object.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
#include <bls/bls.h>
88
#include <chainparams.h>
99
#include <core_io.h>
10-
#include <evo/chainhelper.h>
1110
#include <evo/deterministicmns.h>
1211
#include <governance/governance.h>
1312
#include <governance/validators.h>
13+
#include <index/txindex.h>
1414
#include <masternode/meta.h>
1515
#include <masternode/node.h>
1616
#include <masternode/sync.h>
@@ -453,8 +453,15 @@ bool CGovernanceObject::IsCollateralValid(const ChainstateManager& chainman, std
453453
fMissingConfirmations = false;
454454
uint256 nExpectedHash = GetHash();
455455

456-
// RETRIEVE TRANSACTION IN QUESTION
457-
auto [txCollateral, nBlockHash] = GetTransactionBlock(m_obj.collateralHash);
456+
CTransactionRef txCollateral;
457+
uint256 nBlockHash;
458+
if (g_txindex) {
459+
g_txindex->FindTx(m_obj.collateralHash, nBlockHash, txCollateral);
460+
} else {
461+
strError = "TxIndex is not available";
462+
return false;
463+
}
464+
458465
if (!txCollateral) {
459466
strError = strprintf("Can't find collateral tx %s", m_obj.collateralHash.ToString());
460467
LogPrintf("CGovernanceObject::IsCollateralValid -- %s\n", strError);

src/llmq/chainlocks.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <chain.h>
1111
#include <chainparams.h>
1212
#include <consensus/validation.h>
13-
#include <evo/chainhelper.h>
1413
#include <masternode/sync.h>
1514
#include <node/blockstorage.h>
1615
#include <node/interface_ui.h>
@@ -24,6 +23,9 @@
2423
#include <validation.h>
2524
#include <validationinterface.h>
2625

26+
// Forward declaration to break dependency over node/transaction.h
27+
std::pair<CTransactionRef, uint256> GetTransactionBlock(const uint256& hash, const CTxMemPool* const mempool);
28+
2729
static bool ChainLocksSigningEnabled(const CSporkManager& sporkman)
2830
{
2931
return sporkman.GetSporkValue(SPORK_19_CHAINLOCKS_ENABLED) == 0;

src/llmq/instantsend.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include <chainparams.h>
1414
#include <consensus/validation.h>
1515
#include <dbwrapper.h>
16-
#include <evo/chainhelper.h>
1716
#include <index/txindex.h>
1817
#include <masternode/sync.h>
1918
#include <net_processing.h>
@@ -28,6 +27,9 @@
2827

2928
#include <cxxtimer.hpp>
3029

30+
// Forward declaration to break dependency over node/transaction.h
31+
std::pair<CTransactionRef, uint256> GetTransactionBlock(const uint256& hash, const CTxMemPool* const mempool);
32+
3133
namespace llmq
3234
{
3335

src/node/transaction.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,10 @@ 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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,13 @@ 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+
6069
#endif // BITCOIN_NODE_TRANSACTION_H

src/validation.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ int64_t nMaxTipAge = DEFAULT_MAX_TIP_AGE;
117117
uint256 hashAssumeValid;
118118
arith_uint256 nMinimumChainWork;
119119

120+
// Forward declaration to break dependency over node/transaction.h
121+
std::pair<CTransactionRef, uint256> GetTransactionBlock(const uint256& hash, const CTxMemPool* const mempool);
122+
120123
const CBlockIndex* CChainState::FindForkInGlobalIndex(const CBlockLocator& locator) const
121124
{
122125
AssertLockHeld(cs_main);

test/lint/lint-circular-dependencies.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,7 @@
3838
"dsnotificationinterface -> llmq/chainlocks -> node/blockstorage -> dsnotificationinterface",
3939
"evo/assetlocktx -> llmq/signing -> net_processing -> txmempool -> evo/assetlocktx",
4040
"evo/cbtx -> evo/simplifiedmns -> evo/cbtx",
41-
"evo/chainhelper -> evo/specialtxman -> evo/deterministicmns -> evo/chainhelper",
4241
"evo/chainhelper -> evo/specialtxman -> validation -> evo/chainhelper",
43-
"evo/chainhelper -> llmq/chainlocks -> evo/chainhelper",
44-
"evo/chainhelper -> llmq/instantsend -> evo/chainhelper",
45-
"evo/chainhelper -> masternode/payments -> governance/classes -> governance/object -> evo/chainhelper",
46-
"evo/chainhelper -> node/transaction -> node/context -> evo/chainhelper",
4742
"evo/deterministicmns -> llmq/commitment -> evo/deterministicmns",
4843
"evo/deterministicmns -> llmq/commitment -> validation -> evo/deterministicmns",
4944
"evo/deterministicmns -> llmq/commitment -> validation -> txmempool -> evo/deterministicmns",

0 commit comments

Comments
 (0)