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
} ;
@@ -26,7 +26,7 @@ pub(crate) fn reorg_clients(inputs: &[usize], outputs: &[usize], script_hash: &[
26
26
expected_info,
27
27
expected_tip_client_id,
28
28
expected_client_ids,
29
- _previous_chain_work ,
29
+ previous_chain_work ,
30
30
fork_client_id,
31
31
flags,
32
32
) = {
@@ -53,17 +53,21 @@ 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
- // If there is a limit on the number of headers to update
57
- // it may cause the current work to be insufficient, but still on the main chain
58
- // so here we no longer check the chain work
59
-
60
- // let new_chain_work: U256 = output_client
61
- // .headers_mmr_root()
62
- // .partial_chain_work()
63
- // .unpack();
64
- // if previous_chain_work >= new_chain_work {
65
- // return Err(InternalError::ReorgNotBetterChain.into());
66
- // }
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
+ }
70
+ }
67
71
}
68
72
// Finds the only one index of cell deps which use current script.
69
73
// That cell should be the client which at the fork point.
0 commit comments