@@ -1224,13 +1224,24 @@ static ChainstateLoadResult InitAndLoadChainstate(
1224
1224
const kernel::CacheSizes& cache_sizes,
1225
1225
const ArgsManager& args)
1226
1226
{
1227
+ // This function may be called twice, so any dirty state must be reset.
1228
+ node.notifications .reset (); // Drop state, such as a cached tip block
1229
+ node.mempool .reset ();
1230
+ node.chainman .reset (); // Drop state, such as an initialized m_block_tree_db
1231
+
1227
1232
const CChainParams& chainparams = Params ();
1233
+
1234
+ Assert (!node.notifications ); // Was reset above
1235
+ node.notifications = std::make_unique<KernelNotifications>(Assert (node.shutdown_request ), node.exit_status , *Assert (node.warnings ));
1236
+ ReadNotificationArgs (args, *node.notifications );
1237
+
1228
1238
CTxMemPool::Options mempool_opts{
1229
1239
.check_ratio = chainparams.DefaultConsistencyChecks () ? 1 : 0 ,
1230
1240
.signals = node.validation_signals .get (),
1231
1241
};
1232
1242
Assert (ApplyArgsManOptions (args, chainparams, mempool_opts)); // no error can happen, already checked in AppInitParameterInteraction
1233
1243
bilingual_str mempool_error;
1244
+ Assert (!node.mempool ); // Was reset above
1234
1245
node.mempool = std::make_unique<CTxMemPool>(mempool_opts, mempool_error);
1235
1246
if (!mempool_error.empty ()) {
1236
1247
return {ChainstateLoadStatus::FAILURE_FATAL, mempool_error};
@@ -1259,6 +1270,7 @@ static ChainstateLoadResult InitAndLoadChainstate(
1259
1270
// Creating the chainstate manager internally creates a BlockManager, opens
1260
1271
// the blocks tree db, and wipes existing block files in case of a reindex.
1261
1272
// The coinsdb is opened at a later point on LoadChainstate.
1273
+ Assert (!node.chainman ); // Was reset above
1262
1274
try {
1263
1275
node.chainman = std::make_unique<ChainstateManager>(*Assert (node.shutdown_signal ), chainman_opts, blockman_opts);
1264
1276
} catch (dbwrapper_error& e) {
@@ -1696,10 +1708,6 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
1696
1708
1697
1709
// ********************************************************* Step 7: load block chain
1698
1710
1699
- node.notifications = std::make_unique<KernelNotifications>(Assert (node.shutdown_request ), node.exit_status , *Assert (node.warnings ));
1700
- auto & kernel_notifications{*node.notifications };
1701
- ReadNotificationArgs (args, kernel_notifications);
1702
-
1703
1711
// cache size calculations
1704
1712
const auto [index_cache_sizes, kernel_cache_sizes] = CalculateCacheSizes (args, g_enabled_filter_types.size ());
1705
1713
@@ -1759,6 +1767,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
1759
1767
}
1760
1768
1761
1769
ChainstateManager& chainman = *Assert (node.chainman );
1770
+ auto & kernel_notifications{*Assert (node.notifications )};
1762
1771
1763
1772
assert (!node.peerman );
1764
1773
node.peerman = PeerManager::make (*node.connman , *node.addrman ,
0 commit comments