forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: verify and repair evodb diffs automatically at node startup #6999
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
Open
UdjinM6
wants to merge
1
commit into
dashpay:develop
Choose a base branch
from
UdjinM6:fu_6969_2
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+67
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,9 +81,11 @@ | |
| #include <coinjoin/server.h> | ||
| #include <coinjoin/walletman.h> | ||
| #include <dsnotificationinterface.h> | ||
| #include <evo/chainhelper.h> | ||
| #include <evo/deterministicmns.h> | ||
| #include <evo/evodb.h> | ||
| #include <evo/mnhftx.h> | ||
| #include <evo/specialtxman.h> | ||
| #include <flat-database.h> | ||
| #include <governance/governance.h> | ||
| #include <instantsend/instantsend.h> | ||
|
|
@@ -751,6 +753,7 @@ void SetupServerArgs(ArgsManager& argsman) | |
| argsman.AddArg("-checkmempool=<n>", strprintf("Run mempool consistency checks every <n> transactions. Use 0 to disable. (default: %u, regtest: %u)", defaultChainParams->DefaultConsistencyChecks(), regtestChainParams->DefaultConsistencyChecks()), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST); | ||
| argsman.AddArg("-checkpoints", strprintf("Enable rejection of any forks from the known historical chain until block %s (default: %u)", defaultChainParams->Checkpoints().GetHeight(), DEFAULT_CHECKPOINTS_ENABLED), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST); | ||
| argsman.AddArg("-deprecatedrpc=<method>", "Allows deprecated RPC method(s) to be used", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST); | ||
| argsman.AddArg("-forceevodbrepair", "Force evodb masternode list diff verification and repair on startup, even if already repaired (default: 0)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST); | ||
| argsman.AddArg("-limitancestorcount=<n>", strprintf("Do not accept transactions if number of in-mempool ancestors is <n> or more (default: %u)", DEFAULT_ANCESTOR_LIMIT), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST); | ||
| argsman.AddArg("-limitancestorsize=<n>", strprintf("Do not accept transactions whose size with all in-mempool ancestors exceeds <n> kilobytes (default: %u)", DEFAULT_ANCESTOR_SIZE_LIMIT), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST); | ||
| argsman.AddArg("-limitdescendantcount=<n>", strprintf("Do not accept transactions if any ancestor would have <n> or more in-mempool descendants (default: %u)", DEFAULT_DESCENDANT_LIMIT), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST); | ||
|
|
@@ -2408,6 +2411,53 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info) | |
| LogPrintf("Filling coin cache with masternode UTXOs: done in %dms\n", Ticks<std::chrono::milliseconds>(SteadyClock::now() - start)); | ||
| } | ||
|
|
||
| if (fReindex || fReindexChainState) { | ||
| LogPrintf("Skipping evodb repair during reindex\n"); | ||
| node.dmnman->CompleteRepair(); // Mark as repaired since we're rebuilding fresh | ||
| } else if (node.dmnman->IsRepaired() && !args.GetBoolArg("-forceevodbrepair", false)) { | ||
| LogPrintf("Masternode list diffs are already repaired\n"); | ||
| } else { | ||
| const CBlockIndex* start_index; | ||
| const CBlockIndex* stop_index; | ||
| { | ||
| LOCK(cs_main); | ||
| const auto& consensus_params = Params().GetConsensus(); | ||
| start_index = chainman.ActiveChain()[consensus_params.DIP0003Height]; | ||
| stop_index = chainman.ActiveChain().Tip(); | ||
| } | ||
|
|
||
| if (start_index && stop_index && start_index->nHeight < stop_index->nHeight) { | ||
| LogPrintf("Verifying and repairing masternode list diffs...\n"); | ||
| const auto start{SteadyClock::now()}; | ||
| // Create a callback that wraps CSpecialTxProcessor::BuildNewListFromBlock | ||
| auto build_list_func = [&node](const CBlock& block, gsl::not_null<const CBlockIndex*> pindexPrev, | ||
| const CDeterministicMNList& prevList, const CCoinsViewCache& view, | ||
|
Collaborator
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. nit: tab alignment |
||
| bool debugLogs, BlockValidationState& state, | ||
| CDeterministicMNList& mnListRet) -> bool { | ||
| return node.chain_helper->special_tx->RebuildListFromBlock(block, pindexPrev, prevList, view, debugLogs, state, mnListRet); | ||
| }; | ||
| auto result = node.dmnman->RecalculateAndRepairDiffs(start_index, stop_index, chainman, build_list_func, true); | ||
|
|
||
| if (!result.verification_errors.empty()) { | ||
| LogPrintf("WARNING: Verification errors:\n%s\n", Join(result.verification_errors, "\n")); | ||
| } | ||
|
|
||
| if (!result.repair_errors.empty()) { | ||
| // Critical errors occurred - reindex required | ||
| LogPrintf("Failed to repair masternode list diffs. Database corruption detected. " /* Continued */ | ||
| "Please restart with -reindex to rebuild the database.\n" | ||
| "Errors:\n%s\n", | ||
| Join(result.repair_errors, "\n")); | ||
| StartShutdown(); | ||
| return; | ||
| } | ||
| node.dmnman->CompleteRepair(); | ||
| LogPrintf("Successfully repaired %d masternode list diffs, verified %d snapshots in %ds\n", | ||
| result.diffs_recalculated, result.snapshots_verified, | ||
| Ticks<std::chrono::seconds>(SteadyClock::now() - start)); | ||
| } | ||
| } | ||
|
|
||
| if (node.mn_activeman != nullptr) { | ||
| node.mn_activeman->Init(chainman.ActiveTip()); | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit: names too reassuring, consider
IsRepaired()->GetEvoDbRepairFlag()CompleteRepair()->SetEvoDbAsRepaired()