Skip to content

Commit

Permalink
remove chain work check for testnet 3 only.
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanYuan committed Oct 11, 2024
1 parent 1c145a4 commit 1a1a0aa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 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
cfa7d777f246ebd037af156db73c6c7eab3e8e4e1f6e15783a68d2a164875032 build/release/ckb-bitcoin-spv-type-lock
cd553a3858df32dbf051957ec97014200e632fed016084b28b25fcbbc49863d1 build/release/ckb-bitcoin-spv-type-lock
30 changes: 17 additions & 13 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 All @@ -26,7 +26,7 @@ pub(crate) fn reorg_clients(inputs: &[usize], outputs: &[usize], script_hash: &[
expected_info,
expected_tip_client_id,
expected_client_ids,
_previous_chain_work,
previous_chain_work,
fork_client_id,
flags,
) = {
Expand All @@ -53,17 +53,21 @@ 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)?;
{
// If there is a limit on the number of headers to update
// it may cause the current work to be insufficient, but still on the main chain
// so here we no longer check the chain work

// 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.
// That cell should be the client which at the fork point.
Expand Down

0 comments on commit 1a1a0aa

Please sign in to comment.