-
Notifications
You must be signed in to change notification settings - Fork 1.2k
test: rebuild peerman and cj_walletman across chainstate reloads #7625
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 all commits
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 |
|---|---|---|
|
|
@@ -326,6 +326,26 @@ void ChainTestingSetup::LoadVerifyActivateChainstate() | |
| { | ||
| auto& chainman{*Assert(m_node.chainman)}; | ||
|
|
||
| // peerman and cj_walletman hold references to llmq_ctx, which | ||
| // LoadChainstate() recreates, and to the mempool and Dash managers, which | ||
| // the reindex path below replaces. Tear them down first and rebuild them | ||
| // afterwards, like AppInitMain constructs them only after the chainstate | ||
| // is loaded. Fixtures that never built them (e.g. plain ChainTestingSetup) | ||
| // are unaffected. | ||
| const bool rebuild_peerman{m_node.peerman != nullptr}; | ||
| if (rebuild_peerman) { | ||
| // Drop connman's raw m_msgproc pointer to the PeerManager destroyed | ||
| // below; it is wired back up after the rebuild. | ||
| CConnman::Options connman_options; | ||
| connman_options.socketEventsMode = ::g_socket_events_mode; | ||
| m_node.connman->Init(connman_options); | ||
| } | ||
| m_node.peerman.reset(); | ||
| #ifdef ENABLE_WALLET | ||
| const bool rebuild_cj_walletman{m_node.cj_walletman != nullptr}; | ||
| m_node.cj_walletman.reset(); | ||
|
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.
When a wallet-enabled fixture has already added a wallet through AGENTS.md reference: AGENTS.md:L15-L17 Useful? React with 👍 / 👎.
Member
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. Addressed in c43e3e4 by documenting the invariant at the rebuild site rather than re-registering: no current fixture has wallets loaded when the chainstate is reloaded (verified all three caller families), and setup_common cannot reach the shared_ptr that addWallet() requires without new plumbing. Details in the thepastaclaw thread on this line. 🤖 Posted autonomously by Claude on behalf of pasta. |
||
| #endif // ENABLE_WALLET | ||
|
|
||
| node::ChainstateLoadOptions options{ChainstateLoadOptionsForTest()}; | ||
|
|
||
| if (options.reindex || options.reindex_chainstate) { | ||
|
|
@@ -358,6 +378,25 @@ void ChainTestingSetup::LoadVerifyActivateChainstate() | |
| if (!chainman.ActiveChainstate().ActivateBestChain(state)) { | ||
| throw std::runtime_error(strprintf("ActivateBestChain failed. (%s)", state.ToString())); | ||
| } | ||
|
|
||
| #ifdef ENABLE_WALLET | ||
| if (rebuild_cj_walletman) { | ||
| // The rebuilt manager starts with an empty wallet map. No present | ||
| // fixture has wallets loaded when the chainstate is reloaded; a future | ||
| // test that does must re-register them with the new manager (see | ||
| // CoinJoinLoaderImpl::AddWallet). | ||
| m_node.cj_walletman = CJWalletManager::make(chainman, *m_node.dmnman, *m_node.mn_metaman, *m_node.mempool, | ||
| *m_node.mn_sync, *m_node.isman, /*relay_txes=*/true); | ||
| } | ||
| #endif // ENABLE_WALLET | ||
| if (rebuild_peerman) { | ||
| m_node.peerman = MakePeerManager(*m_node.connman, m_node, m_node.banman.get(), | ||
| /*ignore_incoming_txs=*/false); | ||
| CConnman::Options connman_options; | ||
| connman_options.m_msgproc = m_node.peerman.get(); | ||
| connman_options.socketEventsMode = ::g_socket_events_mode; | ||
| m_node.connman->Init(connman_options); | ||
|
Comment on lines
+382
to
+398
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: Exercise the rebuilt managers in a regression test The snapshot tests call source: ['codex'] |
||
| } | ||
| } | ||
|
|
||
| TestingSetup::TestingSetup( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why objects should be re-created?
I believe that code should works just fine.
@thepastaclaw can you check it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checked every
LoadVerifyActivateChainstate()caller. You’re right: re-creation is not required by any current test. It was only intended to preserveTestingSetup’s pre-reload “complete environment” and reconnect connman’sm_msgproc; the reload itself only needs the stale owners destroyed. No caller usespeermanorcj_walletmanafter reload (post-reload mining useschainmandirectly), and rebuildingcj_walletmanintroduces empty-wallet-map semantics that cannot be meaningfully preserved or exercised here. Clearing connman’s raw pointer before resettingpeerman, then leaving both managers null as in your diff, fixes the dangling references with less lifecycle policy. I agree with the reset-only version.