Skip to content
Merged
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
8 changes: 0 additions & 8 deletions src/evo/deterministicmns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1586,8 +1586,6 @@ CDeterministicMNManager::RecalcDiffsResult CDeterministicMNManager::RecalculateA
const CBlockIndex* start_index, const CBlockIndex* stop_index, ChainstateManager& chainman,
BuildListFromBlockFunc build_list_func, bool repair)
{
AssertLockHeld(::cs_main);

RecalcDiffsResult result;
result.start_height = start_index->nHeight;
result.stop_height = stop_index->nHeight;
Expand Down Expand Up @@ -1696,8 +1694,6 @@ CDeterministicMNManager::RecalcDiffsResult CDeterministicMNManager::RecalculateA
std::vector<const CBlockIndex*> CDeterministicMNManager::CollectSnapshotBlocks(
const CBlockIndex* start_index, const CBlockIndex* stop_index, const Consensus::Params& consensus_params)
{
AssertLockHeld(::cs_main);

std::vector<const CBlockIndex*> snapshot_blocks;

// Add the starting snapshot (find the snapshot at or before start)
Expand Down Expand Up @@ -1749,8 +1745,6 @@ bool CDeterministicMNManager::VerifySnapshotPair(
const CBlockIndex* from_index, const CBlockIndex* to_index, const CDeterministicMNList& from_snapshot,
const CDeterministicMNList& to_snapshot, RecalcDiffsResult& result)
{
AssertLockHeld(::cs_main);

// Verify this snapshot pair by applying all stored diffs sequentially
CDeterministicMNList test_list = from_snapshot;

Expand Down Expand Up @@ -1795,8 +1789,6 @@ std::vector<std::pair<uint256, CDeterministicMNListDiff>> CDeterministicMNManage
const CBlockIndex* from_index, const CBlockIndex* to_index, const CDeterministicMNList& from_snapshot,
const CDeterministicMNList& to_snapshot, BuildListFromBlockFunc build_list_func, RecalcDiffsResult& result)
{
AssertLockHeld(::cs_main);

CDeterministicMNList current_list = from_snapshot;
// Temporary storage for recalculated diffs (one per block in this snapshot interval)
std::vector<std::pair<uint256, CDeterministicMNListDiff>> temp_diffs;
Expand Down
19 changes: 9 additions & 10 deletions src/evo/deterministicmns.h
Original file line number Diff line number Diff line change
Expand Up @@ -740,10 +740,10 @@ class CDeterministicMNManager
BlockValidationState& state,
CDeterministicMNList& mnListRet)>;

[[nodiscard]] RecalcDiffsResult RecalculateAndRepairDiffs(
const CBlockIndex* start_index, const CBlockIndex* stop_index,
ChainstateManager& chainman, BuildListFromBlockFunc build_list_func,
bool repair) EXCLUSIVE_LOCKS_REQUIRED(!cs, ::cs_main);
[[nodiscard]] RecalcDiffsResult RecalculateAndRepairDiffs(const CBlockIndex* start_index,
const CBlockIndex* stop_index, ChainstateManager& chainman,
BuildListFromBlockFunc build_list_func, bool repair)
EXCLUSIVE_LOCKS_REQUIRED(!cs);

// Migration support for nVersion-first CDeterministicMNStateDiff format
[[nodiscard]] bool IsMigrationRequired() const EXCLUSIVE_LOCKS_REQUIRED(!cs, ::cs_main);
Expand All @@ -755,14 +755,13 @@ class CDeterministicMNManager

// Helper methods for RecalculateAndRepairDiffs
std::vector<const CBlockIndex*> CollectSnapshotBlocks(const CBlockIndex* start_index, const CBlockIndex* stop_index,
const Consensus::Params& consensus_params) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
bool VerifySnapshotPair(const CBlockIndex* from_index, const CBlockIndex* to_index, const CDeterministicMNList& from_snapshot,
const CDeterministicMNList& to_snapshot, RecalcDiffsResult& result)
EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
const Consensus::Params& consensus_params);
bool VerifySnapshotPair(const CBlockIndex* from_index, const CBlockIndex* to_index,
const CDeterministicMNList& from_snapshot, const CDeterministicMNList& to_snapshot,
RecalcDiffsResult& result);
std::vector<std::pair<uint256, CDeterministicMNListDiff>> RepairSnapshotPair(
const CBlockIndex* from_index, const CBlockIndex* to_index, const CDeterministicMNList& from_snapshot,
const CDeterministicMNList& to_snapshot, BuildListFromBlockFunc build_list_func, RecalcDiffsResult& result)
EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
const CDeterministicMNList& to_snapshot, BuildListFromBlockFunc build_list_func, RecalcDiffsResult& result);
void WriteRepairedDiffs(const std::vector<std::pair<uint256, CDeterministicMNListDiff>>& recalculated_diffs,
RecalcDiffsResult& result) EXCLUSIVE_LOCKS_REQUIRED(!cs);
};
Expand Down
2 changes: 0 additions & 2 deletions src/evo/specialtxman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,6 @@ bool CSpecialTxProcessor::RebuildListFromBlock(const CBlock& block, gsl::not_nul
bool debugLogs, BlockValidationState& state,
CDeterministicMNList& mnListRet)
{
AssertLockHeld(cs_main);

// Verify that prevList either represents an empty/initial state (default-constructed),
// or it matches the previous block's hash.
assert(prevList == CDeterministicMNList() || prevList.GetBlockHash() == pindexPrev->GetBlockHash());
Expand Down
5 changes: 2 additions & 3 deletions src/evo/specialtxman.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,8 @@ class CSpecialTxProcessor
// Variant that takes an explicit starting list instead of loading from GetListForBlock
// Used for rebuilding diffs from trusted snapshots
bool RebuildListFromBlock(const CBlock& block, gsl::not_null<const CBlockIndex*> pindexPrev,
const CDeterministicMNList& prevList, const CCoinsViewCache& view, bool debugLogs,
BlockValidationState& state, CDeterministicMNList& mnListRet)
EXCLUSIVE_LOCKS_REQUIRED(cs_main);
const CDeterministicMNList& prevList, const CCoinsViewCache& view, bool debugLogs,
BlockValidationState& state, CDeterministicMNList& mnListRet);

private:
bool CheckCreditPoolDiffForBlock(const CBlock& block, const CBlockIndex* pindex, const CCbTx& cbTx,
Expand Down
58 changes: 29 additions & 29 deletions src/rpc/evo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1760,37 +1760,38 @@ static UniValue evodb_verify_or_repair_impl(const JSONRPCRequest& request, bool
CDeterministicMNManager& dmnman = *CHECK_NONFATAL(node.dmnman);
CChainstateHelper& chain_helper = *CHECK_NONFATAL(node.chain_helper);

LOCK(::cs_main);

const CBlockIndex* start_index;
const CBlockIndex* stop_index;

// Default to DIP0003 activation height if startBlock not specified
if (request.params[0].isNull()) {
const auto& consensus_params = Params().GetConsensus();
start_index = chainman.ActiveChain()[consensus_params.DIP0003Height];
if (!start_index) {
throw JSONRPCError(RPC_INTERNAL_ERROR, "Cannot find DIP0003 activation block");
}
} else {
uint256 start_block_hash = ParseBlock(request.params[0], chainman, "startBlock");
start_index = chainman.m_blockman.LookupBlockIndex(start_block_hash);
if (!start_index) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Start block not found");
{
LOCK(::cs_main);
// Default to DIP0003 activation height if startBlock not specified
if (request.params[0].isNull()) {
const auto& consensus_params = Params().GetConsensus();
start_index = chainman.ActiveChain()[consensus_params.DIP0003Height];
if (!start_index) {
throw JSONRPCError(RPC_INTERNAL_ERROR, "Cannot find DIP0003 activation block");
}
} else {
uint256 start_block_hash = ParseBlock(request.params[0], chainman, "startBlock");
start_index = chainman.m_blockman.LookupBlockIndex(start_block_hash);
if (!start_index) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Start block not found");
}
}
}

// Default to chain tip if stopBlock not specified
if (request.params[1].isNull()) {
stop_index = chainman.ActiveChain().Tip();
if (!stop_index) {
throw JSONRPCError(RPC_INTERNAL_ERROR, "Cannot find chain tip");
}
} else {
uint256 stop_block_hash = ParseBlock(request.params[1], chainman, "stopBlock");
stop_index = chainman.m_blockman.LookupBlockIndex(stop_block_hash);
if (!stop_index) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Stop block not found");
// Default to chain tip if stopBlock not specified
if (request.params[1].isNull()) {
stop_index = chainman.ActiveChain().Tip();
if (!stop_index) {
throw JSONRPCError(RPC_INTERNAL_ERROR, "Cannot find chain tip");
}
} else {
uint256 stop_block_hash = ParseBlock(request.params[1], chainman, "stopBlock");
stop_index = chainman.m_blockman.LookupBlockIndex(stop_block_hash);
if (!stop_index) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Stop block not found");
}
}
}

Expand All @@ -1802,12 +1803,11 @@ static UniValue evodb_verify_or_repair_impl(const JSONRPCRequest& request, bool
throw JSONRPCError(RPC_INVALID_PARAMETER, "stopBlock must be >= startBlock");
}

// Create a callback that wraps CSpecialTxProcessor::BuildNewListFromBlock
// NO_THREAD_SAFETY_ANALYSIS: cs_main is held by the calling function (evodb_verify_or_repair_impl)
// Create a callback that wraps CSpecialTxProcessor::RebuildListFromBlock
auto build_list_func = [&chain_helper](const CBlock& block, gsl::not_null<const CBlockIndex*> pindexPrev,
const CDeterministicMNList& prevList, const CCoinsViewCache& view,
bool debugLogs, BlockValidationState& state,
CDeterministicMNList& mnListRet) NO_THREAD_SAFETY_ANALYSIS -> bool {
CDeterministicMNList& mnListRet) -> bool {
return chain_helper.special_tx->RebuildListFromBlock(block, pindexPrev, prevList, view, debugLogs, state, mnListRet);
};

Expand Down
Loading