|
1 | 1 | use alloc::vec::Vec;
|
2 | 2 |
|
3 | 3 | use ckb_bitcoin_spv_verifier::types::{
|
4 |
| - core::{SpvClient, SpvInfo, U256}, |
| 4 | + core::{BitcoinChainType, SpvClient, SpvInfo, U256}, |
5 | 5 | packed::{self, SpvClientReader, SpvInfoReader, SpvTypeArgsReader, SpvUpdateReader},
|
6 | 6 | prelude::*,
|
7 | 7 | };
|
@@ -53,12 +53,20 @@ pub(crate) fn reorg_clients(inputs: &[usize], outputs: &[usize], script_hash: &[
|
53 | 53 | let (output_client, output_info_index) =
|
54 | 54 | load_outputs(outputs, &expected_info, expected_client_ids)?;
|
55 | 55 | {
|
56 |
| - let new_chain_work: U256 = output_client |
57 |
| - .headers_mmr_root() |
58 |
| - .partial_chain_work() |
59 |
| - .unpack(); |
60 |
| - if previous_chain_work >= new_chain_work { |
61 |
| - return Err(InternalError::ReorgNotBetterChain.into()); |
| 56 | + // Due to the block storm issue on testnet 3, a large number of blocks may be rolled back |
| 57 | + // during a reorg, making it necessary to limit the update height. |
| 58 | + // If there is a limit on the number of headers to update, |
| 59 | + // the current chain work might not be sufficient but still remain on the main chain. |
| 60 | + // Therefore, in this case, we no longer check the chain work. |
| 61 | + // This handling is specific to testnet 3 to address the frequent block storm reorgs. |
| 62 | + if BitcoinChainType::Testnet != flags.into() { |
| 63 | + let new_chain_work: U256 = output_client |
| 64 | + .headers_mmr_root() |
| 65 | + .partial_chain_work() |
| 66 | + .unpack(); |
| 67 | + if previous_chain_work >= new_chain_work { |
| 68 | + return Err(InternalError::ReorgNotBetterChain.into()); |
| 69 | + } |
62 | 70 | }
|
63 | 71 | }
|
64 | 72 | // Finds the only one index of cell deps which use current script.
|
|
0 commit comments