Skip to content

Commit 64817da

Browse files
knstUdjinM6
andcommitted
feat: add optional argument to ignore ChainLocks for reconsiderblocks RPC
Co-Authored-By: UdjinM6 <UdjinM6@users.noreply.github.com>
1 parent ad7a373 commit 64817da

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

src/rpc/blockchain.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2125,6 +2125,7 @@ static RPCHelpMan reconsiderblock()
21252125
"This can be used to undo the effects of invalidateblock.\n",
21262126
{
21272127
{"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "the hash of the block to reconsider"},
2128+
{"ignore_chainlocks", RPCArg::Type::BOOL, RPCArg::Default{false}, "if true, existing chainlocks will be ignored"},
21282129
},
21292130
RPCResult{RPCResult::Type::NONE, "", ""},
21302131
RPCExamples{
@@ -2137,6 +2138,7 @@ static RPCHelpMan reconsiderblock()
21372138
CChainState& active_chainstate = chainman.ActiveChainstate();
21382139

21392140
uint256 hash(ParseHashV(request.params[0], "blockhash"));
2141+
const bool ignore_chainlocks{request.params[1].isNull() ? false : request.params[1].get_bool()};
21402142

21412143
{
21422144
LOCK(cs_main);
@@ -2145,7 +2147,7 @@ static RPCHelpMan reconsiderblock()
21452147
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
21462148
}
21472149

2148-
active_chainstate.ResetBlockFailureFlags(pblockindex);
2150+
active_chainstate.ResetBlockFailureFlags(pblockindex, ignore_chainlocks);
21492151
}
21502152

21512153
BlockValidationState state;

src/rpc/client.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
7575
{ "waitforblockheight", 0, "height" },
7676
{ "waitforblockheight", 1, "timeout" },
7777
{ "waitforblock", 1, "timeout" },
78+
{ "reconsiderblock", 1, "ignore_chainlocks" },
7879
{ "waitfornewblock", 0, "timeout" },
7980
{ "listtransactions", 1, "count" },
8081
{ "listtransactions", 2, "skip" },

src/validation.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3410,7 +3410,7 @@ bool CChainState::MarkConflictingBlock(BlockValidationState& state, CBlockIndex
34103410
return true;
34113411
}
34123412

3413-
void CChainState::ResetBlockFailureFlags(CBlockIndex *pindex) {
3413+
void CChainState::ResetBlockFailureFlags(CBlockIndex *pindex, bool ignore_chainlocks) {
34143414
AssertLockHeld(cs_main);
34153415

34163416
if (!pindex) {
@@ -3429,9 +3429,14 @@ void CChainState::ResetBlockFailureFlags(CBlockIndex *pindex) {
34293429
for (auto& [_, block_index] : m_blockman.m_block_index) {
34303430
if (!block_index.IsValid() && block_index.GetAncestor(nHeight) == pindex) {
34313431
block_index.nStatus &= ~BLOCK_FAILED_MASK;
3432+
if (ignore_chainlocks) {
3433+
block_index.nStatus &= ~BLOCK_CONFLICT_CHAINLOCK;
3434+
}
34323435
m_blockman.m_dirty_blockindex.insert(&block_index);
3433-
if (block_index.IsValid(BLOCK_VALID_TRANSACTIONS) && !(block_index.nStatus & BLOCK_CONFLICT_CHAINLOCK) && block_index.HaveTxsDownloaded() && setBlockIndexCandidates.value_comp()(m_chain.Tip(), &block_index)) {
3434-
setBlockIndexCandidates.insert(&block_index);
3436+
if (block_index.IsValid(BLOCK_VALID_TRANSACTIONS) && block_index.HaveTxsDownloaded() && setBlockIndexCandidates.value_comp()(m_chain.Tip(), &block_index)) {
3437+
if (ignore_chainlocks || !(block_index.nStatus & BLOCK_CONFLICT_CHAINLOCK)) {
3438+
setBlockIndexCandidates.insert(&block_index);
3439+
}
34353440
}
34363441
if (&block_index == m_chainman.m_best_invalid) {
34373442
// Reset invalid block marker if it was pointing to one of those.
@@ -3443,11 +3448,16 @@ void CChainState::ResetBlockFailureFlags(CBlockIndex *pindex) {
34433448

34443449
// Remove the invalidity flag from all ancestors too.
34453450
while (pindex != nullptr) {
3446-
if (pindex->nStatus & BLOCK_FAILED_MASK) {
3451+
if (pindex->nStatus & (BLOCK_FAILED_MASK | BLOCK_CONFLICT_CHAINLOCK)) {
34473452
pindex->nStatus &= ~BLOCK_FAILED_MASK;
3453+
if (ignore_chainlocks) {
3454+
pindex->nStatus &= ~BLOCK_CONFLICT_CHAINLOCK;
3455+
}
34483456
m_blockman.m_dirty_blockindex.insert(pindex);
3449-
if (pindex->IsValid(BLOCK_VALID_TRANSACTIONS) && !(pindex->nStatus & BLOCK_CONFLICT_CHAINLOCK) && pindex->HaveTxsDownloaded() && setBlockIndexCandidates.value_comp()(m_chain.Tip(), pindex)) {
3450-
setBlockIndexCandidates.insert(pindex);
3457+
if (pindex->IsValid(BLOCK_VALID_TRANSACTIONS) && pindex->HaveTxsDownloaded() && setBlockIndexCandidates.value_comp()(m_chain.Tip(), pindex)) {
3458+
if (ignore_chainlocks || !(pindex->nStatus & BLOCK_CONFLICT_CHAINLOCK)) {
3459+
setBlockIndexCandidates.insert(pindex);
3460+
}
34513461
}
34523462
if (pindex == m_chainman.m_best_invalid) {
34533463
// Reset invalid block marker if it was pointing to one of those.

src/validation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ class CChainState
713713
LOCKS_EXCLUDED(::cs_main);
714714

715715
/** Remove invalidity status from a block and its descendants. */
716-
void ResetBlockFailureFlags(CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
716+
void ResetBlockFailureFlags(CBlockIndex* pindex, bool ignore_chainlocks = false) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
717717

718718
/** Replay blocks that aren't fully applied to the database. */
719719
bool ReplayBlocks();

0 commit comments

Comments
 (0)