Skip to content

Commit

Permalink
Merge pull request #14 from ckb-cell/bugfix/overflow-when-add-max
Browse files Browse the repository at this point in the history
fix: overflow when do addition
  • Loading branch information
yangby-cryptape authored Apr 3, 2024
2 parents 14019dc + 50a4ba1 commit 93b5e8c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/cli/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pub struct Args {

/// Don't update all headers in one CKB transaction,
/// to avoid size limit or cycles limit.
/// `0` means no limit.
#[arg(long, default_value = "10")]
pub(crate) spv_headers_update_limit: u32,

Expand Down Expand Up @@ -158,7 +159,7 @@ impl Args {
let spv_tip_height = input.curr.client.headers_mmr_root.max_height;

let (spv_client, spv_update) =
storage.generate_spv_client_and_spv_update(spv_tip_height, u32::MAX)?;
storage.generate_spv_client_and_spv_update(spv_tip_height, 0)?;

let tx_hash =
self.reorg_spv_cells(&spv_service, input, spv_client, spv_update)?;
Expand Down
5 changes: 3 additions & 2 deletions src/components/storage/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,10 @@ pub(crate) trait BitcoinSpvStorage: InternalBitcoinSpvStorage {
limit: u32,
) -> Result<(SpvClient, packed::SpvUpdate)> {
let mut tip_height = self.get_tip_bitcoin_height()?;
if tip_height > prev_height + limit {
tip_height = prev_height + limit;
if limit > 0 && tip_height > prev_height.saturating_add(limit) {
tip_height = prev_height.saturating_add(limit);
}
log::trace!("new tip height will be {tip_height}, prev {prev_height}, limit {limit}",);
let tip_header = self.get_bitcoin_header(tip_height)?;
let (headers_mmr_root, headers_mmr_proof) = {
let (base_height, mmr) = self.chain_root_mmr(tip_height)?;
Expand Down

0 comments on commit 93b5e8c

Please sign in to comment.