Skip to content

Commit d84483f

Browse files
Merge #6728: refactor: removed some exceptions for circular dependencies over evo/mnhftx, evo/chainhelper and dsnotificationinterface
1f4a5a6 refactor: replace helper GetTransactionBlock to direct usage of GetTransaction (Konstantin Akimov) 3a83b06 fix: copyright for dsnotificationinterface.h (Konstantin Akimov) c5b941f refactor: nuke dependency of node/blockstorage on evo/deterministicmns and dsnotificationinterface (Konstantin Akimov) 33020e9 refactor: replace GetTransactionBlock to direct usage of txindex (UdjinM6) 696e164 refactor: drop circular dependency over evo/chainhelper.h (Konstantin Akimov) 33f8554 refactor: drop circular dependency over evo/mnhftx.h by removing non-used include (Konstantin Akimov) Pull request description: ## Issue being fixed or feature implemented Addressed some exception from `test/lint/lint-circular-dependencies.py` ## What was done? See commits descriptions. ## How Has This Been Tested? Updated these exception in linter: ``` - "dsnotificationinterface -> llmq/chainlocks -> node/blockstorage -> dsnotificationinterface", - "evo/chainhelper -> evo/specialtxman -> evo/deterministicmns -> evo/chainhelper", - "evo/chainhelper -> llmq/chainlocks -> evo/chainhelper", - "evo/chainhelper -> llmq/instantsend -> evo/chainhelper", - "evo/chainhelper -> masternode/payments -> governance/classes -> governance/object -> evo/chainhelper", - "evo/chainhelper -> node/transaction -> node/context -> evo/chainhelper", - "evo/deterministicmns -> llmq/commitment -> validation -> evo/deterministicmns", - "evo/deterministicmns -> llmq/commitment -> validation -> txmempool -> evo/deterministicmns", - "evo/mnhftx -> validation -> evo/mnhftx", + "evo/deterministicmns -> index/txindex -> validation -> evo/deterministicmns", + "evo/deterministicmns -> index/txindex -> validation -> txmempool -> evo/deterministicmns", ``` ## Breaking Changes N/A ## Checklist: - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone ACKs for top commit: kwvg: utACK 1f4a5a6 UdjinM6: utACK 1f4a5a6 Tree-SHA512: f4f8e674c26d6c0997438b9c740399eef3c4a623b2ff55c6fc12bcbd8a85fb9aedfdd31d46f36dc3e5f4d4b8a5b74e035b33a87a47d2fae0536503095839dc55
2 parents d7e31d6 + 1f4a5a6 commit d84483f

File tree

12 files changed

+81
-80
lines changed

12 files changed

+81
-80
lines changed

src/dsnotificationinterface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2015 The Bitcoin Core developers
1+
// Copyright (c) 2015 The Dash Core developers
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

src/evo/chainhelper.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +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>
15-
16-
using node::GetTransaction;
1712

1813
CChainstateHelper::CChainstateHelper(CCreditPoolManager& cpoolman, CDeterministicMNManager& dmnman,
1914
CMNHFManager& mnhfman, CGovernanceManager& govman, llmq::CInstantSendManager& isman,
@@ -64,9 +59,3 @@ bool CChainstateHelper::RemoveConflictingISLockByTx(const CTransaction& tx)
6459

6560
bool CChainstateHelper::ShouldInstantSendRejectConflicts() const { return isman.RejectConflictingBlocks(); }
6661

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

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: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
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>
98
#include <evo/evodb.h>
109
#include <evo/providertx.h>
1110
#include <evo/specialtx.h>
11+
#include <index/txindex.h>
1212
#include <llmq/commitment.h>
1313
#include <llmq/utils.h>
1414

@@ -50,11 +50,15 @@ UniValue CDeterministicMN::ToJson() const
5050
obj.pushKV("collateralHash", collateralOutpoint.hash.ToString());
5151
obj.pushKV("collateralIndex", (int)collateralOutpoint.n);
5252

53-
auto [collateralTx, _] = GetTransactionBlock(collateralOutpoint.hash);
54-
if (collateralTx) {
55-
CTxDestination dest;
56-
if (ExtractDestination(collateralTx->vout[collateralOutpoint.n].scriptPubKey, dest)) {
57-
obj.pushKV("collateralAddress", EncodeDestination(dest));
53+
if (g_txindex) {
54+
CTransactionRef collateralTx;
55+
uint256 nBlockHash;
56+
g_txindex->FindTx(collateralOutpoint.hash, nBlockHash, collateralTx);
57+
if (collateralTx) {
58+
CTxDestination dest;
59+
if (ExtractDestination(collateralTx->vout[collateralOutpoint.n].scriptPubKey, dest)) {
60+
obj.pushKV("collateralAddress", EncodeDestination(dest));
61+
}
5862
}
5963
}
6064

src/governance/object.cpp

Lines changed: 7 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,12 @@ 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+
}
461+
458462
if (!txCollateral) {
459463
strError = strprintf("Can't find collateral tx %s", m_obj.collateralHash.ToString());
460464
LogPrintf("CGovernanceObject::IsCollateralValid -- %s\n", strError);

src/init.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2327,7 +2327,31 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
23272327
}
23282328

23292329
chainman.m_load_block = std::thread(&util::TraceThread, "loadblk", [=, &args, &chainman, &node] {
2330-
ThreadImport(chainman, *node.dmnman, *g_ds_notification_interface, vImportFiles, node.mn_activeman.get(), args);
2330+
ThreadImport(chainman, vImportFiles, args);
2331+
2332+
// force UpdatedBlockTip to initialize nCachedBlockHeight for DS, MN payments and budgets
2333+
// but don't call it directly to prevent triggering of other listeners like zmq etc.
2334+
// GetMainSignals().UpdatedBlockTip(::ChainActive().Tip());
2335+
g_ds_notification_interface->InitializeCurrentBlockTip();
2336+
2337+
{
2338+
// Get all UTXOs for each MN collateral in one go so that we can fill coin cache early
2339+
// and reduce further locking overhead for cs_main in other parts of code including GUI
2340+
LogPrintf("Filling coin cache with masternode UTXOs...\n");
2341+
LOCK(cs_main);
2342+
const auto start{SteadyClock::now()};
2343+
const auto mnList{node.dmnman->GetListAtChainTip()};
2344+
mnList.ForEachMN(false, [&](auto& dmn) {
2345+
Coin coin;
2346+
GetUTXOCoin(chainman.ActiveChainstate(), dmn.collateralOutpoint, coin);
2347+
});
2348+
LogPrintf("Filling coin cache with masternode UTXOs: done in %dms\n", Ticks<std::chrono::milliseconds>(SteadyClock::now() - start));
2349+
}
2350+
2351+
if (node.mn_activeman != nullptr) {
2352+
node.mn_activeman->Init(chainman.ActiveTip());
2353+
}
2354+
23312355
});
23322356
#ifdef ENABLE_WALLET
23332357
if (!args.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) {

src/llmq/chainlocks.cpp

Lines changed: 10 additions & 3 deletions
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>
@@ -26,6 +25,14 @@
2625

2726
using node::ReadBlockFromDisk;
2827

28+
// Forward declaration to break dependency over node/transaction.h
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;
35+
2936
static bool ChainLocksSigningEnabled(const CSporkManager& sporkman)
3037
{
3138
return sporkman.GetSporkValue(SPORK_19_CHAINLOCKS_ENABLED) == 0;
@@ -638,8 +645,8 @@ void CChainLocksHandler::Cleanup()
638645
}
639646
}
640647
for (auto it = txFirstSeenTime.begin(); it != txFirstSeenTime.end(); ) {
641-
auto [tx, hashBlock] = GetTransactionBlock(it->first, &mempool);
642-
if (!tx) {
648+
uint256 hashBlock;
649+
if (auto tx = GetTransaction(nullptr, &mempool, it->first, Params().GetConsensus(), hashBlock); !tx) {
643650
// tx has vanished, probably due to conflicts
644651
it = txFirstSeenTime.erase(it);
645652
} else if (!hashBlock.IsNull()) {

src/llmq/instantsend.cpp

Lines changed: 15 additions & 4 deletions
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>
@@ -31,6 +30,14 @@
3130
using node::fImporting;
3231
using node::fReindex;
3332

33+
// Forward declaration to break dependency over node/transaction.h
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;
40+
3441
namespace llmq
3542
{
3643

@@ -578,7 +585,8 @@ bool CInstantSendManager::CheckCanLock(const COutPoint& outpoint, bool printDebu
578585
return false;
579586
}
580587

581-
auto [tx, hashBlock] = GetTransactionBlock(outpoint.hash, &mempool);
588+
uint256 hashBlock{};
589+
const auto tx = GetTransaction(nullptr, &mempool, outpoint.hash, params, hashBlock);
582590
// this relies on enabled txindex and won't work if we ever try to remove the requirement for txindex for masternodes
583591
if (!tx) {
584592
if (printDebug) {
@@ -635,7 +643,9 @@ void CInstantSendManager::HandleNewInputLockRecoveredSig(const CRecoveredSig& re
635643
g_txindex->BlockUntilSyncedToCurrentChain();
636644
}
637645

638-
auto [tx, hashBlock] = GetTransactionBlock(txid, &mempool);
646+
647+
uint256 hashBlock{};
648+
const auto tx = GetTransaction(nullptr, &mempool, txid, Params().GetConsensus(), hashBlock);
639649
if (!tx) {
640650
return;
641651
}
@@ -1017,7 +1027,8 @@ void CInstantSendManager::ProcessInstantSendLock(NodeId from, PeerManager& peerm
10171027
return;
10181028
}
10191029

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

src/node/blockstorage.cpp

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@
88
#include <chainparams.h>
99
#include <clientversion.h>
1010
#include <consensus/validation.h>
11-
#include <dsnotificationinterface.h>
12-
#include <evo/deterministicmns.h>
1311
#include <flatfile.h>
1412
#include <fs.h>
1513
#include <hash.h>
16-
#include <masternode/node.h>
1714
#include <pow.h>
1815
#include <shutdown.h>
1916
#include <streams.h>
@@ -825,8 +822,7 @@ struct CImportingNow {
825822
}
826823
};
827824

828-
void ThreadImport(ChainstateManager& chainman, CDeterministicMNManager& dmnman, CDSNotificationInterface& dsnfi,
829-
std::vector<fs::path> vImportFiles, CActiveMasternodeManager* const mn_activeman, const ArgsManager& args)
825+
void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImportFiles, const ArgsManager& args)
830826
{
831827
ScheduleBatchPriority();
832828

@@ -899,29 +895,6 @@ void ThreadImport(ChainstateManager& chainman, CDeterministicMNManager& dmnman,
899895
}
900896
} // End scope of CImportingNow
901897

902-
// force UpdatedBlockTip to initialize nCachedBlockHeight for DS, MN payments and budgets
903-
// but don't call it directly to prevent triggering of other listeners like zmq etc.
904-
// GetMainSignals().UpdatedBlockTip(::ChainActive().Tip());
905-
dsnfi.InitializeCurrentBlockTip();
906-
907-
{
908-
// Get all UTXOs for each MN collateral in one go so that we can fill coin cache early
909-
// and reduce further locking overhead for cs_main in other parts of code including GUI
910-
LogPrintf("Filling coin cache with masternode UTXOs...\n");
911-
LOCK(cs_main);
912-
const auto start{SteadyClock::now()};
913-
auto mnList = dmnman.GetListAtChainTip();
914-
mnList.ForEachMN(false, [&](auto& dmn) {
915-
Coin coin;
916-
GetUTXOCoin(chainman.ActiveChainstate(), dmn.collateralOutpoint, coin);
917-
});
918-
LogPrintf("Filling coin cache with masternode UTXOs: done in %dms\n", Ticks<std::chrono::milliseconds>(SteadyClock::now() - start));
919-
}
920-
921-
if (mn_activeman != nullptr) {
922-
mn_activeman->Init(chainman.ActiveTip());
923-
}
924-
925898
chainman.ActiveChainstate().LoadMempool(args);
926899
}
927900
} // namespace node

src/node/blockstorage.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,13 @@
1818

1919
extern RecursiveMutex cs_main;
2020

21-
class CActiveMasternodeManager;
2221
class ArgsManager;
2322
class BlockValidationState;
2423
class CBlock;
2524
class CBlockUndo;
2625
class CChain;
2726
class CChainParams;
2827
class CChainState;
29-
class CDeterministicMNManager;
30-
class CDSNotificationInterface;
3128
class ChainstateManager;
3229
struct CCheckpointData;
3330
struct FlatFilePos;
@@ -229,8 +226,7 @@ bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex, const Consensus
229226

230227
bool UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex* pindex);
231228

232-
void ThreadImport(ChainstateManager& chainman, CDeterministicMNManager& dmnman, CDSNotificationInterface& dsnfi,
233-
std::vector<fs::path> vImportFiles, CActiveMasternodeManager* const mn_activeman, const ArgsManager& args);
229+
void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImportFiles, const ArgsManager& args);
234230
} // namespace node
235231

236232
#endif // BITCOIN_NODE_BLOCKSTORAGE_H

0 commit comments

Comments
 (0)