-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix: dangling point to cj client #7259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 7 commits
9452854
f61af76
66c8443
721233d
bfc3c02
d9a3c74
646af49
fbf9d09
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,60 +20,6 @@ using wallet::CWallet; | |
| namespace coinjoin { | ||
| namespace { | ||
|
|
||
| class CoinJoinClientImpl : public interfaces::CoinJoin::Client | ||
| { | ||
| CCoinJoinClientManager& m_clientman; | ||
|
|
||
| public: | ||
| explicit CoinJoinClientImpl(CCoinJoinClientManager& clientman) | ||
| : m_clientman(clientman) {} | ||
|
|
||
| void resetCachedBlocks() override | ||
| { | ||
| m_clientman.nCachedNumBlocks = std::numeric_limits<int>::max(); | ||
| } | ||
| void resetPool() override | ||
| { | ||
| m_clientman.ResetPool(); | ||
| } | ||
| void disableAutobackups() override | ||
| { | ||
| m_clientman.fCreateAutoBackups = false; | ||
| } | ||
| int getCachedBlocks() override | ||
| { | ||
| return m_clientman.nCachedNumBlocks; | ||
| } | ||
| void getJsonInfo(UniValue& obj) override | ||
| { | ||
| return m_clientman.GetJsonInfo(obj); | ||
| } | ||
| std::string getSessionDenoms() override | ||
| { | ||
| return m_clientman.GetSessionDenoms(); | ||
| } | ||
| std::vector<std::string> getSessionStatuses() override | ||
| { | ||
| return m_clientman.GetStatuses(); | ||
| } | ||
| void setCachedBlocks(int nCachedBlocks) override | ||
| { | ||
| m_clientman.nCachedNumBlocks = nCachedBlocks; | ||
| } | ||
| bool isMixing() override | ||
| { | ||
| return m_clientman.IsMixing(); | ||
| } | ||
| bool startMixing() override | ||
| { | ||
| return m_clientman.StartMixing(); | ||
| } | ||
| void stopMixing() override | ||
| { | ||
| m_clientman.StopMixing(); | ||
| } | ||
| }; | ||
|
|
||
| class CoinJoinLoaderImpl : public interfaces::CoinJoin::Loader | ||
| { | ||
| private: | ||
|
|
@@ -82,37 +28,32 @@ class CoinJoinLoaderImpl : public interfaces::CoinJoin::Loader | |
| return *Assert(m_node.cj_walletman); | ||
| } | ||
|
|
||
| interfaces::WalletLoader& wallet_loader() | ||
| { | ||
| return *Assert(m_node.wallet_loader); | ||
| } | ||
|
|
||
| public: | ||
| explicit CoinJoinLoaderImpl(NodeContext& node) : | ||
| m_node(node) | ||
| { | ||
| // Enablement will be re-evaluated when a wallet is added or removed | ||
| CCoinJoinClientOptions::SetEnabled(false); | ||
| CCoinJoinClientOptions::SetEnabled(gArgs.GetBoolArg("-enablecoinjoin", true)); | ||
| } | ||
|
Comment on lines
32
to
36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💬 Nitpick:
source: ['claude'] |
||
|
|
||
| void AddWallet(const std::shared_ptr<CWallet>& wallet) override | ||
| { | ||
| manager().addWallet(wallet); | ||
| g_wallet_init_interface.InitCoinJoinSettings(*this, wallet_loader()); | ||
| if (!CCoinJoinClientOptions::IsEnabled()) return; | ||
| manager().doForClient(wallet->GetName(), [](CCoinJoinClientManager& mgr) { | ||
| g_wallet_init_interface.InitCoinJoinSettings(mgr); | ||
| }); | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
Comment on lines
38
to
45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Suggestion:
source: ['claude'] 🤖 Fix this with AI agents |
||
| void RemoveWallet(const std::string& name) override | ||
| { | ||
| manager().removeWallet(name); | ||
| g_wallet_init_interface.InitCoinJoinSettings(*this, wallet_loader()); | ||
| } | ||
| void FlushWallet(const std::string& name) override | ||
| { | ||
| manager().flushWallet(name); | ||
| } | ||
| std::unique_ptr<interfaces::CoinJoin::Client> GetClient(const std::string& name) override | ||
| bool WithClient(const std::string& name, std::function<void(interfaces::CoinJoin::Client&)> func) override | ||
| { | ||
| auto clientman = manager().getClient(name); | ||
| return clientman ? std::make_unique<CoinJoinClientImpl>(*clientman) : nullptr; | ||
| return manager().doForClient(name, [&](CCoinJoinClientManager& mgr) { func(mgr); }); | ||
| } | ||
|
|
||
| NodeContext& m_node; | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -39,7 +39,7 @@ class CJWalletManagerImpl final : public CJWalletManager | |||||||||||||||||
|
|
||||||||||||||||||
| public: | ||||||||||||||||||
| bool hasQueue(const uint256& hash) const override; | ||||||||||||||||||
| CCoinJoinClientManager* getClient(const std::string& name) override EXCLUSIVE_LOCKS_REQUIRED(!cs_wallet_manager_map); | ||||||||||||||||||
| bool doForClient(const std::string& name, const std::function<void(CCoinJoinClientManager&)>& func) override EXCLUSIVE_LOCKS_REQUIRED(!cs_wallet_manager_map); | ||||||||||||||||||
| MessageProcessingResult processMessage(CNode& peer, CChainState& chainstate, CConnman& connman, CTxMemPool& mempool, | ||||||||||||||||||
| std::string_view msg_type, CDataStream& vRecv) override EXCLUSIVE_LOCKS_REQUIRED(!cs_ProcessDSQueue, !cs_wallet_manager_map); | ||||||||||||||||||
| std::optional<CCoinJoinQueue> getQueueFromHash(const uint256& hash) const override; | ||||||||||||||||||
|
|
@@ -140,11 +140,13 @@ bool CJWalletManagerImpl::hasQueue(const uint256& hash) const | |||||||||||||||||
| return false; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| CCoinJoinClientManager* CJWalletManagerImpl::getClient(const std::string& name) | ||||||||||||||||||
| bool CJWalletManagerImpl::doForClient(const std::string& name, const std::function<void(CCoinJoinClientManager&)>& func) | ||||||||||||||||||
| { | ||||||||||||||||||
| LOCK(cs_wallet_manager_map); | ||||||||||||||||||
| auto it = m_wallet_manager_map.find(name); | ||||||||||||||||||
| return (it != m_wallet_manager_map.end()) ? it->second.get() : nullptr; | ||||||||||||||||||
| if (it == m_wallet_manager_map.end()) return false; | ||||||||||||||||||
| func(*it->second); | ||||||||||||||||||
|
Comment on lines
+145
to
+148
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Useful? React with 👍 / 👎.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not, the whole point of PR is doing it under cs_wallet_manager_map mutex, otherwhise wallet maybe destroyed |
||||||||||||||||||
| return true; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| std::optional<CCoinJoinQueue> CJWalletManagerImpl::getQueueFromHash(const uint256& hash) const | ||||||||||||||||||
|
|
@@ -180,9 +182,10 @@ void CJWalletManagerImpl::addWallet(const std::shared_ptr<wallet::CWallet>& wall | |||||||||||||||||
|
|
||||||||||||||||||
| void CJWalletManagerImpl::flushWallet(const std::string& name) | ||||||||||||||||||
| { | ||||||||||||||||||
| auto* clientman = Assert(getClient(name)); | ||||||||||||||||||
| clientman->ResetPool(); | ||||||||||||||||||
| clientman->StopMixing(); | ||||||||||||||||||
| doForClient(name, [](CCoinJoinClientManager& clientman) { | ||||||||||||||||||
| clientman.resetPool(); | ||||||||||||||||||
| clientman.stopMixing(); | ||||||||||||||||||
| }); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| void CJWalletManagerImpl::removeWallet(const std::string& name) | ||||||||||||||||||
|
|
@@ -314,6 +317,6 @@ std::unique_ptr<CJWalletManager> CJWalletManager::make(ChainstateManager& chainm | |||||||||||||||||
| return std::make_unique<CJWalletManagerImpl>(chainman, dmnman, mn_metaman, mempool, mn_sync, isman, relay_txes); | ||||||||||||||||||
| #else | ||||||||||||||||||
| // Cannot be constructed if wallet support isn't built | ||||||||||||||||||
| return nullptr; | ||||||||||||||||||
| assert(false); | ||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
nl -ba src/coinjoin/walletman.cpp | sed -n '311,322p'Repository: dashpay/dash Length of output: 98 🏁 Script executed: sed -n '311,322p' src/coinjoin/walletman.cppRepository: dashpay/dash Length of output: 729 Return after In release builds, 🔧 Minimal fix `#else`
// Cannot be constructed if wallet support isn't built
assert(false);
+ return nullptr;
`#endif` // ENABLE_WALLET
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
| #endif // ENABLE_WALLET | ||||||||||||||||||
| } | ||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.