Skip to content

Commit 6453e4c

Browse files
authored
Merge pull request #31 from EthanYuan/fix-reorg
fix: remove check `partial_chain_work` when reorg
2 parents 5125606 + 1a1a0aa commit 6453e4c

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
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-
eaa9e3aeb1205e611078a819e960c33f4934ea49029aab3445a241955e696ee1 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

+15-7
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
};
@@ -53,12 +53,20 @@ 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-
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+
}
6270
}
6371
}
6472
// Finds the only one index of cell deps which use current script.

0 commit comments

Comments
 (0)