Skip to content

Commit 1a1a0aa

Browse files
committed
remove chain work check for testnet 3 only.
1 parent 1c145a4 commit 1a1a0aa

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

checksums.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
6bbea4820329050e1fc65f9c15cab5948b824c73aa3430d7d92b793c53ca66b6 build/release/can-update-without-ownership-lock
2-
cfa7d777f246ebd037af156db73c6c7eab3e8e4e1f6e15783a68d2a164875032 build/release/ckb-bitcoin-spv-type-lock
2+
cd553a3858df32dbf051957ec97014200e632fed016084b28b25fcbbc49863d1 build/release/ckb-bitcoin-spv-type-lock

contracts/ckb-bitcoin-spv-type-lock/src/operations/reorg.rs

+17-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use alloc::vec::Vec;
22

33
use ckb_bitcoin_spv_verifier::types::{
4-
core::{SpvClient, SpvInfo, U256},
4+
core::{BitcoinChainType, SpvClient, SpvInfo, U256},
55
packed::{self, SpvClientReader, SpvInfoReader, SpvTypeArgsReader, SpvUpdateReader},
66
prelude::*,
77
};
@@ -26,7 +26,7 @@ pub(crate) fn reorg_clients(inputs: &[usize], outputs: &[usize], script_hash: &[
2626
expected_info,
2727
expected_tip_client_id,
2828
expected_client_ids,
29-
_previous_chain_work,
29+
previous_chain_work,
3030
fork_client_id,
3131
flags,
3232
) = {
@@ -53,17 +53,21 @@ pub(crate) fn reorg_clients(inputs: &[usize], outputs: &[usize], script_hash: &[
5353
let (output_client, output_info_index) =
5454
load_outputs(outputs, &expected_info, expected_client_ids)?;
5555
{
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+
}
6771
}
6872
// Finds the only one index of cell deps which use current script.
6973
// That cell should be the client which at the fork point.

0 commit comments

Comments
 (0)