Skip to content

Commit 8debe7b

Browse files
Merge #6501: feat: add optional argument to ignore ChainLocks for reconsiderblocks 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
2 parents ae68ed3 + 64817da commit 8debe7b

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
@@ -1724,6 +1724,7 @@ static RPCHelpMan reconsiderblock()
17241724
"This can be used to undo the effects of invalidateblock.\n",
17251725
{
17261726
{"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "the hash of the block to reconsider"},
1727+
{"ignore_chainlocks", RPCArg::Type::BOOL, RPCArg::Default{false}, "if true, existing chainlocks will be ignored"},
17271728
},
17281729
RPCResult{RPCResult::Type::NONE, "", ""},
17291730
RPCExamples{
@@ -1736,6 +1737,7 @@ static RPCHelpMan reconsiderblock()
17361737
CChainState& active_chainstate = chainman.ActiveChainstate();
17371738

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

17401742
{
17411743
LOCK(cs_main);
@@ -1744,7 +1746,7 @@ static RPCHelpMan reconsiderblock()
17441746
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
17451747
}
17461748

1747-
active_chainstate.ResetBlockFailureFlags(pblockindex);
1749+
active_chainstate.ResetBlockFailureFlags(pblockindex, ignore_chainlocks);
17481750
}
17491751

17501752
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
@@ -3683,7 +3683,7 @@ bool CChainState::MarkConflictingBlock(BlockValidationState& state, CBlockIndex
36833683
return true;
36843684
}
36853685

3686-
void CChainState::ResetBlockFailureFlags(CBlockIndex *pindex) {
3686+
void CChainState::ResetBlockFailureFlags(CBlockIndex *pindex, bool ignore_chainlocks) {
36873687
AssertLockHeld(cs_main);
36883688

36893689
if (!pindex) {
@@ -3702,9 +3702,14 @@ void CChainState::ResetBlockFailureFlags(CBlockIndex *pindex) {
37023702
for (auto& [_, block_index] : m_blockman.m_block_index) {
37033703
if (!block_index.IsValid() && block_index.GetAncestor(nHeight) == pindex) {
37043704
block_index.nStatus &= ~BLOCK_FAILED_MASK;
3705+
if (ignore_chainlocks) {
3706+
block_index.nStatus &= ~BLOCK_CONFLICT_CHAINLOCK;
3707+
}
37053708
m_blockman.m_dirty_blockindex.insert(&block_index);
3706-
if (block_index.IsValid(BLOCK_VALID_TRANSACTIONS) && !(block_index.nStatus & BLOCK_CONFLICT_CHAINLOCK) && block_index.HaveTxsDownloaded() && setBlockIndexCandidates.value_comp()(m_chain.Tip(), &block_index)) {
3707-
setBlockIndexCandidates.insert(&block_index);
3709+
if (block_index.IsValid(BLOCK_VALID_TRANSACTIONS) && block_index.HaveTxsDownloaded() && setBlockIndexCandidates.value_comp()(m_chain.Tip(), &block_index)) {
3710+
if (ignore_chainlocks || !(block_index.nStatus & BLOCK_CONFLICT_CHAINLOCK)) {
3711+
setBlockIndexCandidates.insert(&block_index);
3712+
}
37083713
}
37093714
if (&block_index == m_chainman.m_best_invalid) {
37103715
// Reset invalid block marker if it was pointing to one of those.
@@ -3716,11 +3721,16 @@ void CChainState::ResetBlockFailureFlags(CBlockIndex *pindex) {
37163721

37173722
// Remove the invalidity flag from all ancestors too.
37183723
while (pindex != nullptr) {
3719-
if (pindex->nStatus & BLOCK_FAILED_MASK) {
3724+
if (pindex->nStatus & (BLOCK_FAILED_MASK | BLOCK_CONFLICT_CHAINLOCK)) {
37203725
pindex->nStatus &= ~BLOCK_FAILED_MASK;
3726+
if (ignore_chainlocks) {
3727+
pindex->nStatus &= ~BLOCK_CONFLICT_CHAINLOCK;
3728+
}
37213729
m_blockman.m_dirty_blockindex.insert(pindex);
3722-
if (pindex->IsValid(BLOCK_VALID_TRANSACTIONS) && !(pindex->nStatus & BLOCK_CONFLICT_CHAINLOCK) && pindex->HaveTxsDownloaded() && setBlockIndexCandidates.value_comp()(m_chain.Tip(), pindex)) {
3723-
setBlockIndexCandidates.insert(pindex);
3730+
if (pindex->IsValid(BLOCK_VALID_TRANSACTIONS) && pindex->HaveTxsDownloaded() && setBlockIndexCandidates.value_comp()(m_chain.Tip(), pindex)) {
3731+
if (ignore_chainlocks || !(pindex->nStatus & BLOCK_CONFLICT_CHAINLOCK)) {
3732+
setBlockIndexCandidates.insert(pindex);
3733+
}
37243734
}
37253735
if (pindex == m_chainman.m_best_invalid) {
37263736
// 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
@@ -707,7 +707,7 @@ class CChainState
707707
LOCKS_EXCLUDED(::cs_main);
708708

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

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

0 commit comments

Comments
 (0)