Skip to content

Commit

Permalink
Merge #6501: feat: add optional argument to ignore ChainLocks for rec…
Browse files Browse the repository at this point in the history
…onsiderblocks RPC

64817da feat: add optional argument to ignore ChainLocks for reconsiderblocks RPC (Konstantin Akimov)

Pull request description:

  ## Issue being fixed or feature implemented
  More general way to implement #6500 which can be merged to develop.

  ## What was done?
  It allows removing BLOCK_CONFLICT_CHAINLOCK flag via ResetBlockFailureFlags

  ## How Has This Been Tested?
  N/A

  ## Breaking Changes
  N/A

  ## Checklist:
  - [x] I have performed a self-review of my own code
  - [ ] I have commented my code, particularly in hard-to-understand areas
  - [ ] I have added or updated relevant unit/integration/functional/e2e tests
  - [ ] I have made corresponding changes to the documentation
  - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_

ACKs for top commit:
  UdjinM6:
    utACK 64817da
  PastaPastaPasta:
    utACK 64817da

Tree-SHA512: 06d6024ebb2d6f6f6346c00516e6e1296697484a8cb051f0ca5d0fe4c717cadd60469233cb256365d9c34f221c6bae268b2498995208133e2d52fb806abbbb53
  • Loading branch information
PastaPastaPasta committed Jan 11, 2025
2 parents ae68ed3 + 64817da commit 8debe7b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1724,6 +1724,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{
Expand All @@ -1736,6 +1737,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);
Expand All @@ -1744,7 +1746,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;
Expand Down
1 change: 1 addition & 0 deletions src/rpc/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down
22 changes: 16 additions & 6 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3683,7 +3683,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) {
Expand All @@ -3702,9 +3702,14 @@ 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)) {
setBlockIndexCandidates.insert(&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.
Expand All @@ -3716,11 +3721,16 @@ 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)) {
setBlockIndexCandidates.insert(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.
Expand Down
2 changes: 1 addition & 1 deletion src/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ class CChainState
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();
Expand Down

0 comments on commit 8debe7b

Please sign in to comment.