Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions src/bitcoin-chainstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,32 +102,30 @@ int main(int argc, char* argv[])

std::unique_ptr<LLMQContext> llmq_ctx;
std::unique_ptr<CChainstateHelper> chain_helper;

node::CacheSizes cache_sizes;
cache_sizes.block_tree_db = 2 << 20;
cache_sizes.coins_db = 2 << 22;
cache_sizes.coins = (450 << 20) - (2 << 20) - (2 << 22);
node::ChainstateLoadOptions options;
options.bls_threads = 1;
options.worker_count = 1;
options.max_recsigs_age = 1;
options.check_interrupt = [] { return false; };
auto [status, error] = node::LoadChainstate(chainman,
metaman,
sporkman,
chainlocks,
mn_sync,
chain_helper,
dmnman,
evodb,
llmq_ctx,
gArgs.GetDataDirNet(),
cache_sizes,
options);
node::ChainstateLoadOptions options{
.chain_helper = chain_helper,
.evodb = evodb,
.dmnman = dmnman,
.llmq_ctx = llmq_ctx,
.data_dir = gArgs.GetDataDirNet(),
.check_interrupt = [] { return false; },
.coins_error_cb =[] { return false; },
};
Comment thread
knst marked this conversation as resolved.
options.mn_metaman = &metaman;
options.sporkman = &sporkman;
options.chainlocks = &chainlocks;
options.mn_sync = &mn_sync;
auto [status, error] = node::LoadChainstate(chainman, cache_sizes, options);
if (status != node::ChainstateLoadStatus::SUCCESS) {
std::cerr << "Failed to load Chain state from your datadir." << std::endl;
goto epilogue;
} else {
std::tie(status, error) = node::VerifyLoadedChainstate(std::ref(chainman), *evodb, options);
std::tie(status, error) = node::VerifyLoadedChainstate(chainman, options);
if (status != node::ChainstateLoadStatus::SUCCESS) {
std::cerr << "Failed to verify loaded Chain state from your datadir." << std::endl;
goto epilogue;
Expand Down Expand Up @@ -284,6 +282,8 @@ int main(int argc, char* argv[])
}
GetMainSignals().UnregisterBackgroundSignalScheduler();
// Tear down Dash kernel objects before kernel::~Context().
node::DashChainstateSetupClose(chain_helper, dmnman, llmq_ctx, /*mempool=*/nullptr);
chain_helper.reset();
llmq_ctx.reset();
dmnman.reset();
evodb.reset();
}
86 changes: 41 additions & 45 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ using kernel::DumpMempool;

using node::CacheSizes;
using node::CalculateCacheSizes;
using node::DashChainstateSetupClose;
using node::DEFAULT_PERSIST_MEMPOOL;
using node::DEFAULT_PRINTPRIORITY;
using node::DEFAULT_STOPAFTERBLOCKIMPORT;
Expand Down Expand Up @@ -429,8 +428,12 @@ void PrepareShutdown(NodeContext& node)
chainstate->ResetCoinsViews();
}
}
DashChainstateSetupClose(node.chain_helper, node.dmnman, node.llmq_ctx,
Assert(node.mempool.get()));
if (node.mempool) {
node.mempool->DisconnectManagers();
}
node.chain_helper.reset();
node.llmq_ctx.reset();
node.dmnman.reset();
node.evodb.reset();
}
for (const auto& client : node.chain_clients) {
Expand Down Expand Up @@ -2021,10 +2024,25 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
*/
node.mn_sync = std::make_unique<CMasternodeSync>(std::make_unique<NodeSyncNotifierImpl>(*node.connman, *node.netfulfilledman));

bilingual_str strLoadError;

node::ChainstateLoadOptions options;
node::ChainstateLoadOptions options{
.chain_helper = node.chain_helper,
.evodb = node.evodb,
.dmnman = node.dmnman,
.llmq_ctx = node.llmq_ctx,
.data_dir = args.GetDataDirNet(),
.check_interrupt = ShutdownRequested,
.coins_error_cb = [] {
uiInterface.ThreadSafeMessageBox(
_("Error reading from database, shutting down."),
"", CClientUIInterface::MSG_ERROR);
}
};
options.mempool = Assert(node.mempool.get());
options.mn_metaman = Assert(node.mn_metaman.get());
options.sporkman = Assert(node.sporkman.get());
options.chainlocks = Assert(node.chainlocks.get());
options.mn_sync = Assert(node.mn_sync.get());

options.reindex = node::fReindex;
options.reindex_chainstate = fReindexChainState;
options.prune = node::fPruneMode;
Expand All @@ -2039,69 +2057,47 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
const int64_t adjusted_threads = std::clamp<int64_t>(threads, 1, int64_t{llmq::MAX_BLSCHECK_THREADS} + 1) - 1;
return static_cast<int8_t>(adjusted_threads);
}();
options.worker_count = llmq::DEFAULT_WORKER_COUNT;
options.max_recsigs_age = args.GetIntArg("-maxrecsigsage", llmq::DEFAULT_MAX_RECOVERED_SIGS_AGE);
options.check_blocks = args.GetIntArg("-checkblocks", DEFAULT_CHECKBLOCKS);
options.check_level = args.GetIntArg("-checklevel", DEFAULT_CHECKLEVEL);
options.check_interrupt = ShutdownRequested;
options.coins_error_cb = [] {
uiInterface.ThreadSafeMessageBox(
_("Error reading from database, shutting down."),
"", CClientUIInterface::MSG_ERROR);
};
options.notify_bls_state = [](bool bls_state) {
LogPrintf("%s: bls_legacy_scheme=%d\n", __func__, bls_state);
};


uiInterface.InitMessage(_("Loading block index…").translated);
const auto load_block_index_start_time{SteadyClock::now()};
auto catch_exceptions = [](auto&& fn) -> node::ChainstateLoadResult {
auto catch_exceptions = [](auto&& f) {
try {
return fn();
return f();
} catch (const std::exception& e) {
LogPrintf("%s\n", e.what());
return {node::ChainstateLoadStatus::FAILURE, _("Error opening block database")};
return std::make_tuple(node::ChainstateLoadStatus::FAILURE, _("Error opening block database"));
}
};
auto [status, error] = catch_exceptions([&] {
return LoadChainstate(chainman,
*node.mn_metaman,
*node.sporkman,
*node.chainlocks,
*node.mn_sync,
node.chain_helper,
node.dmnman,
node.evodb,
node.llmq_ctx,
args.GetDataDirNet(),
cache_sizes,
options);
});
auto [status, error] = catch_exceptions([&]{ return LoadChainstate(chainman, cache_sizes, options); });
if (status == node::ChainstateLoadStatus::SUCCESS) {
uiInterface.InitMessage(_("Verifying blocks…").translated);
if (chainman.m_blockman.m_have_pruned && options.check_blocks > MIN_BLOCKS_TO_KEEP) {
LogWarning("pruned datadir may not have more than %d blocks; only checking available blocks\n",
MIN_BLOCKS_TO_KEEP);
}
std::tie(status, error) = catch_exceptions([&] {
return VerifyLoadedChainstate(chainman, *Assert(node.evodb), options);
});
std::tie(status, error) = catch_exceptions([&]{ return VerifyLoadedChainstate(chainman, options, [](bool bls_state) {
LogPrintf("%s: bls_legacy_scheme=%d\n", __func__, bls_state);
});});
if (status == node::ChainstateLoadStatus::SUCCESS) {
fLoaded = true;
LogPrintf(" block index %15dms\n", Ticks<std::chrono::milliseconds>(SteadyClock::now() - load_block_index_start_time));
}
}
if (status == node::ChainstateLoadStatus::SUCCESS) {
fLoaded = true;
LogPrintf(" block index %15dms\n", Ticks<std::chrono::milliseconds>(SteadyClock::now() - load_block_index_start_time));
} else if (status == node::ChainstateLoadStatus::FAILURE_INCOMPATIBLE_DB) {

if (status == node::ChainstateLoadStatus::FAILURE_INCOMPATIBLE_DB) {
return InitError(error);
} else {
strLoadError = error;
}

if (!fLoaded && !ShutdownRequested()) {
// first suggest a reindex
if (!options.reindex) {
bool fRet = uiInterface.ThreadSafeQuestion(
strLoadError + Untranslated(".\n\n") + _("Do you want to rebuild the block database now?"),
strLoadError.original + ".\nPlease restart with -reindex or -reindex-chainstate to recover.",
error + Untranslated(".\n\n") + _("Do you want to rebuild the block database now?"),
error.original + ".\nPlease restart with -reindex or -reindex-chainstate to recover.",
"", CClientUIInterface::MSG_ERROR | CClientUIInterface::BTN_ABORT);
if (fRet) {
fReindex = true;
Expand All @@ -2111,7 +2107,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
return false;
}
} else {
return InitError(strLoadError);
return InitError(error);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/llmq/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ enum class QvvecSyncMode : int8_t {
OnlyIfTypeMember = 1,
};

// Keep recovered signatures for a week. This is a "-maxrecsigsage" option default.
static constexpr int64_t DEFAULT_MAX_RECOVERED_SIGS_AGE{60 * 60 * 24 * 7};

/** -llmq-data-recovery default */
static constexpr bool DEFAULT_ENABLE_QUORUM_DATA_RECOVERY{true};
/** -watchquorums default, if true, we will connect to all new quorums and watch their communication */
Expand Down
3 changes: 0 additions & 3 deletions src/llmq/signing.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ class CQuorumManager;
class CSigSharesManager;
class SignHash;

// Keep recovered signatures for a week. This is a "-maxrecsigsage" option default.
static constexpr int64_t DEFAULT_MAX_RECOVERED_SIGS_AGE{60 * 60 * 24 * 7};

class CSigBase
{
protected:
Expand Down
Loading