Skip to content

Commit

Permalink
Merge pull request #31 from EthanYuan/fix-reorg
Browse files Browse the repository at this point in the history
fix: remove check `partial_chain_work` when reorg
  • Loading branch information
jjyr authored Oct 11, 2024
2 parents 5125606 + 1a1a0aa commit 6453e4c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion checksums.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
6bbea4820329050e1fc65f9c15cab5948b824c73aa3430d7d92b793c53ca66b6 build/release/can-update-without-ownership-lock
eaa9e3aeb1205e611078a819e960c33f4934ea49029aab3445a241955e696ee1 build/release/ckb-bitcoin-spv-type-lock
cd553a3858df32dbf051957ec97014200e632fed016084b28b25fcbbc49863d1 build/release/ckb-bitcoin-spv-type-lock
22 changes: 15 additions & 7 deletions contracts/ckb-bitcoin-spv-type-lock/src/operations/reorg.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use alloc::vec::Vec;

use ckb_bitcoin_spv_verifier::types::{
core::{SpvClient, SpvInfo, U256},
core::{BitcoinChainType, SpvClient, SpvInfo, U256},
packed::{self, SpvClientReader, SpvInfoReader, SpvTypeArgsReader, SpvUpdateReader},
prelude::*,
};
Expand Down Expand Up @@ -53,12 +53,20 @@ pub(crate) fn reorg_clients(inputs: &[usize], outputs: &[usize], script_hash: &[
let (output_client, output_info_index) =
load_outputs(outputs, &expected_info, expected_client_ids)?;
{
let new_chain_work: U256 = output_client
.headers_mmr_root()
.partial_chain_work()
.unpack();
if previous_chain_work >= new_chain_work {
return Err(InternalError::ReorgNotBetterChain.into());
// Due to the block storm issue on testnet 3, a large number of blocks may be rolled back
// during a reorg, making it necessary to limit the update height.
// If there is a limit on the number of headers to update,
// the current chain work might not be sufficient but still remain on the main chain.
// Therefore, in this case, we no longer check the chain work.
// This handling is specific to testnet 3 to address the frequent block storm reorgs.
if BitcoinChainType::Testnet != flags.into() {
let new_chain_work: U256 = output_client
.headers_mmr_root()
.partial_chain_work()
.unpack();
if previous_chain_work >= new_chain_work {
return Err(InternalError::ReorgNotBetterChain.into());
}
}
}
// Finds the only one index of cell deps which use current script.
Expand Down

0 comments on commit 6453e4c

Please sign in to comment.