elements/src/rpc
Ava Chow 85bcfeea23
Merge bitcoin/bitcoin#30666: validation: fix m_best_header tracking and BLOCK_FAILED_CHILD assignment
0bd53d913c test: add test for getchaintips behavior with invalid chains (Martin Zumsande)
ccd98ea4c8 test: cleanup rpc_getchaintips.py (Martin Zumsande)
f5149ddb9b validation: mark blocks building on an invalid block as BLOCK_FAILED_CHILD (Martin Zumsande)
783cb7337f validation: call RecalculateBestHeader in InvalidChainFound (Martin Zumsande)
9275e9689a rpc: call RecalculateBestHeader as part of reconsiderblock (Martin Zumsande)
a51e91783a validation: add RecalculateBestHeader() function (Martin Zumsande)

Pull request description:

  `m_best_header` (the most-work header not known to be on an invalid chain) can be wrong in the context of invalidation / reconsideration of blocks. This can happen naturally (a valid header is received and stored in our block tree db; when the full block arrives, it is found to be invalid) or triggered by the user with the `invalidateblock` / `reconsiderblock` rpc.

  We don't currently use `m_best_header` for any critical things (see OP of #16974 for a list that still seems up-to-date), so it being wrong affects mostly rpcs.

  This PR proposes to recalculate it if necessary by looping over the block index and finding the best header. It also suggest to mark headers between an invalidatetd block and the previous `m_best_header` as invalid, so they won't be considered in the recalculation.
  It adds tests to `rpc_invalidateblock.py` and `rpc_getchaintips.py` that fail on master.

  One alternative to this suggested in the past would be to introduce a continuous tracking of header tips (#12138).
  While this might be more performant, it is also more complicated, and situations where we need this data are only be remotely triggerable by paying the cost of creating a valid PoW header for an invalid block.
  Therefore I think it isn't necessary to optimise for performance here, plus the solution in this PR doesn't perform any extra steps in the normal node operation where no invalidated blocks are encountered.

  Fixes  #26245

ACKs for top commit:
  fjahr:
    reACK 0bd53d913c
  achow101:
    ACK 0bd53d913c
  TheCharlatan:
    Re-ACK 0bd53d913c

Tree-SHA512: 23c2fc42d7c7bb4f9b4ba4949646b3d0031dd29ed15484e436afd66cd821ed48e0f16a1d02f45477b5d0d73a006f6e81a56b82d9721e0dee2e924219f528b445
2024-11-14 16:54:41 -05:00
..
blockchain.cpp Merge bitcoin/bitcoin#30666: validation: fix m_best_header tracking and BLOCK_FAILED_CHILD assignment 2024-11-14 16:54:41 -05:00
blockchain.h Replace RPCNotifyBlockChange with waitTipChanged() 2024-09-17 09:27:44 +02:00
client.cpp rpc: disallow boolean verbosity in getorphantxs 2024-10-25 17:53:48 -04:00
client.h refactor: rpc: hide and rename ParseNonRFCJSONValue() 2023-03-23 18:18:46 +00:00
external_signer.cpp scripted-diff: drop config/ subdir for bitcoin-config.h, rename to bitcoin-build-config.h 2024-10-10 12:22:12 +02:00
fees.cpp [rpc, fees]: add more detail on the fee estimation modes 2024-08-02 15:40:43 +01:00
mempool.cpp Merge bitcoin/bitcoin#30592: Remove mempoolfullrbf 2024-11-08 13:51:29 -05:00
mempool.h rpc: Move mempool RPCs to new file 2022-03-11 17:46:58 +01:00
mining.cpp rpc: disallow in-mempool prioritisation of dusty tx 2024-11-12 09:24:54 -05:00
mining.h
net.cpp scripted-diff: get rid of remaining "command" terminology in protocol.{h,cpp} 2024-10-26 23:44:15 +02:00
node.cpp scripted-diff: drop config/ subdir for bitcoin-config.h, rename to bitcoin-build-config.h 2024-10-10 12:22:12 +02:00
output_script.cpp Merge bitcoin/bitcoin#22838: descriptors: Be able to specify change and receiving in a single descriptor string 2024-08-28 15:56:15 +01:00
protocol.h rpc: clarify ALREADY_IN_CHAIN rpc errors 2024-08-05 15:45:58 +01:00
rawtransaction.cpp rpc: disallow boolean verbosity in getorphantxs 2024-10-25 17:53:48 -04:00
rawtransaction_util.cpp Merge bitcoin/bitcoin#28307: rpc, wallet: fix incorrect segwit redeem script size limit 2024-06-04 21:39:49 -04:00
rawtransaction_util.h rpc: bugfix, incorrect segwit redeem script size used in signrawtransactionwithkey 2024-05-03 14:20:45 -03:00
register.h scripted-diff: drop config/ subdir for bitcoin-config.h, rename to bitcoin-build-config.h 2024-10-10 12:22:12 +02:00
request.cpp scripted-diff: LogPrint -> LogDebug 2024-08-29 13:49:57 +02:00
request.h Merge bitcoin/bitcoin#28167: init: Add option for rpccookie permissions (replace 26088) 2024-06-27 17:35:08 -04:00
server.cpp scripted-diff: Rename PACKAGE_* variables to CLIENT_* 2024-10-28 12:36:19 +00:00
server.h refactor: Split up NodeContext shutdown_signal and shutdown_request 2024-10-01 09:10:54 +02:00
server_util.cpp Introduce Mining interface 2024-06-18 18:47:51 +02:00
server_util.h Introduce Mining interface 2024-06-18 18:47:51 +02:00
signmessage.cpp util: move util/message to common/signmessage 2024-05-16 11:16:08 -04:00
txoutproof.cpp rpc: Improve gettxoutproof error when only header is available. 2024-09-13 10:50:49 -04:00
util.cpp Merge bitcoin/bitcoin#31043: rpc: getorphantxs follow-up 2024-10-29 14:49:19 -04:00
util.h rpc: disallow boolean verbosity in getorphantxs 2024-10-25 17:53:48 -04:00