feat: add optional argument to ignore ChainLocks for reconsiderblocks RPC

Co-Authored-By: UdjinM6 <UdjinM6@users.noreply.github.com>
This commit is contained in:
Konstantin Akimov 2024-12-21 02:00:50 +07:00
parent ad7a373529
commit 64817da0e3
No known key found for this signature in database
GPG Key ID: 2176C4A5D01EA524
4 changed files with 21 additions and 8 deletions

View File

@ -2125,6 +2125,7 @@ static RPCHelpMan reconsiderblock()
"This can be used to undo the effects of invalidateblock.\n",
{
{"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "the hash of the block to reconsider"},
{"ignore_chainlocks", RPCArg::Type::BOOL, RPCArg::Default{false}, "if true, existing chainlocks will be ignored"},
},
RPCResult{RPCResult::Type::NONE, "", ""},
RPCExamples{
@ -2137,6 +2138,7 @@ static RPCHelpMan reconsiderblock()
CChainState& active_chainstate = chainman.ActiveChainstate();
uint256 hash(ParseHashV(request.params[0], "blockhash"));
const bool ignore_chainlocks{request.params[1].isNull() ? false : request.params[1].get_bool()};
{
LOCK(cs_main);
@ -2145,7 +2147,7 @@ static RPCHelpMan reconsiderblock()
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
}
active_chainstate.ResetBlockFailureFlags(pblockindex);
active_chainstate.ResetBlockFailureFlags(pblockindex, ignore_chainlocks);
}
BlockValidationState state;

View File

@ -75,6 +75,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "waitforblockheight", 0, "height" },
{ "waitforblockheight", 1, "timeout" },
{ "waitforblock", 1, "timeout" },
{ "reconsiderblock", 1, "ignore_chainlocks" },
{ "waitfornewblock", 0, "timeout" },
{ "listtransactions", 1, "count" },
{ "listtransactions", 2, "skip" },

View File

@ -3410,7 +3410,7 @@ bool CChainState::MarkConflictingBlock(BlockValidationState& state, CBlockIndex
return true;
}
void CChainState::ResetBlockFailureFlags(CBlockIndex *pindex) {
void CChainState::ResetBlockFailureFlags(CBlockIndex *pindex, bool ignore_chainlocks) {
AssertLockHeld(cs_main);
if (!pindex) {
@ -3429,10 +3429,15 @@ void CChainState::ResetBlockFailureFlags(CBlockIndex *pindex) {
for (auto& [_, block_index] : m_blockman.m_block_index) {
if (!block_index.IsValid() && block_index.GetAncestor(nHeight) == pindex) {
block_index.nStatus &= ~BLOCK_FAILED_MASK;
if (ignore_chainlocks) {
block_index.nStatus &= ~BLOCK_CONFLICT_CHAINLOCK;
}
m_blockman.m_dirty_blockindex.insert(&block_index);
if (block_index.IsValid(BLOCK_VALID_TRANSACTIONS) && !(block_index.nStatus & BLOCK_CONFLICT_CHAINLOCK) && block_index.HaveTxsDownloaded() && setBlockIndexCandidates.value_comp()(m_chain.Tip(), &block_index)) {
if (block_index.IsValid(BLOCK_VALID_TRANSACTIONS) && block_index.HaveTxsDownloaded() && setBlockIndexCandidates.value_comp()(m_chain.Tip(), &block_index)) {
if (ignore_chainlocks || !(block_index.nStatus & BLOCK_CONFLICT_CHAINLOCK)) {
setBlockIndexCandidates.insert(&block_index);
}
}
if (&block_index == m_chainman.m_best_invalid) {
// Reset invalid block marker if it was pointing to one of those.
m_chainman.m_best_invalid = nullptr;
@ -3443,12 +3448,17 @@ void CChainState::ResetBlockFailureFlags(CBlockIndex *pindex) {
// Remove the invalidity flag from all ancestors too.
while (pindex != nullptr) {
if (pindex->nStatus & BLOCK_FAILED_MASK) {
if (pindex->nStatus & (BLOCK_FAILED_MASK | BLOCK_CONFLICT_CHAINLOCK)) {
pindex->nStatus &= ~BLOCK_FAILED_MASK;
if (ignore_chainlocks) {
pindex->nStatus &= ~BLOCK_CONFLICT_CHAINLOCK;
}
m_blockman.m_dirty_blockindex.insert(pindex);
if (pindex->IsValid(BLOCK_VALID_TRANSACTIONS) && !(pindex->nStatus & BLOCK_CONFLICT_CHAINLOCK) && pindex->HaveTxsDownloaded() && setBlockIndexCandidates.value_comp()(m_chain.Tip(), pindex)) {
if (pindex->IsValid(BLOCK_VALID_TRANSACTIONS) && pindex->HaveTxsDownloaded() && setBlockIndexCandidates.value_comp()(m_chain.Tip(), pindex)) {
if (ignore_chainlocks || !(pindex->nStatus & BLOCK_CONFLICT_CHAINLOCK)) {
setBlockIndexCandidates.insert(pindex);
}
}
if (pindex == m_chainman.m_best_invalid) {
// Reset invalid block marker if it was pointing to one of those.
m_chainman.m_best_invalid = nullptr;

View File

@ -713,7 +713,7 @@ public:
LOCKS_EXCLUDED(::cs_main);
/** Remove invalidity status from a block and its descendants. */
void ResetBlockFailureFlags(CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
void ResetBlockFailureFlags(CBlockIndex* pindex, bool ignore_chainlocks = false) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
/** Replay blocks that aren't fully applied to the database. */
bool ReplayBlocks();