-
Notifications
You must be signed in to change notification settings - Fork 1.2k
refactor: subsume CoinJoin objects under CJContext, deglobalize coinJoin{ClientQueueManager,Server} #5337
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
refactor: subsume CoinJoin objects under CJContext, deglobalize coinJoin{ClientQueueManager,Server} #5337
Changes from all commits
1fdb695
55abbf9
9603627
1247b20
e568b35
4b35ec0
df72a2b
0a46b62
7b02131
ad5e6a1
8186c9d
15722d7
11637f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // Copyright (c) 2023 The Dash Core developers | ||
| // Distributed under the MIT/X11 software license, see the accompanying | ||
| // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
|
||
| #include <coinjoin/context.h> | ||
|
|
||
| #include <net.h> | ||
| #include <policy/fees.h> | ||
| #include <txmempool.h> | ||
|
|
||
| #ifdef ENABLE_WALLET | ||
| #include <coinjoin/client.h> | ||
| #endif // ENABLE_WALLET | ||
| #include <coinjoin/server.h> | ||
|
|
||
| CJContext::CJContext(CChainState& chainstate, CConnman& connman, CTxMemPool& mempool, const CMasternodeSync& mn_sync, bool relay_txes) : | ||
| #ifdef ENABLE_WALLET | ||
| clientman { | ||
| [&]() -> CJClientManager* const { | ||
| assert(::coinJoinClientManagers == nullptr); | ||
| ::coinJoinClientManagers = std::make_unique<CJClientManager>(connman, mempool, mn_sync, queueman); | ||
| return ::coinJoinClientManagers.get(); | ||
| }() | ||
| }, | ||
| queueman {relay_txes ? std::make_unique<CCoinJoinClientQueueManager>(connman, *clientman, mn_sync) : nullptr}, | ||
| #endif // ENABLE_WALLET | ||
| server{std::make_unique<CCoinJoinServer>(chainstate, connman, mempool, mn_sync)} | ||
| {} | ||
|
|
||
| CJContext::~CJContext() { | ||
| #ifdef ENABLE_WALLET | ||
| ::coinJoinClientManagers.reset(); | ||
| #endif // ENABLE_WALLET | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| // Copyright (c) 2023 The Dash Core developers | ||
| // Distributed under the MIT/X11 software license, see the accompanying | ||
| // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
|
||
| #ifndef BITCOIN_COINJOIN_CONTEXT_H | ||
| #define BITCOIN_COINJOIN_CONTEXT_H | ||
|
|
||
| #if defined(HAVE_CONFIG_H) | ||
| #include <config/bitcoin-config.h> | ||
| #endif | ||
|
|
||
| #include <memory> | ||
|
|
||
| class CBlockPolicyEstimator; | ||
| class CChainState; | ||
| class CCoinJoinServer; | ||
| class CConnman; | ||
| class CMasternodeSync; | ||
| class CTxMemPool; | ||
|
|
||
| #ifdef ENABLE_WALLET | ||
| class CCoinJoinClientQueueManager; | ||
| class CJClientManager; | ||
| #endif // ENABLE_WALLET | ||
|
|
||
| struct CJContext { | ||
| CJContext() = delete; | ||
|
knst marked this conversation as resolved.
Outdated
|
||
| CJContext(const CJContext&) = delete; | ||
| CJContext(CChainState& chainstate, CConnman& connman, CTxMemPool& mempool, const CMasternodeSync& mn_sync, bool relay_txes); | ||
| ~CJContext(); | ||
|
|
||
| #ifdef ENABLE_WALLET | ||
| CJClientManager* const clientman; | ||
|
Member
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. We could just make this a shared_pointer and make the global a shared pointer (they point to the same object) to ensure that we don't get dangling pointers?
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. This is continuation of precedent set with
But yes, the concern of dangling pointers is present, one could reset the global pointer container, with Both cases assume heavily erroneous code and neither case prevents the other. The switch can be done but I don't see the benefit. |
||
| const std::unique_ptr<CCoinJoinClientQueueManager> queueman; | ||
| #endif // ENABLE_WALLET | ||
| const std::unique_ptr<CCoinJoinServer> server; | ||
| }; | ||
|
|
||
| #endif // BITCOIN_COINJOIN_CONTEXT_H | ||
Uh oh!
There was an error while loading. Please reload this page.