Skip to content

Commit

Permalink
Merge pull request #2 from ckb-cell/feature/disable-diff-checks
Browse files Browse the repository at this point in the history
feat: add an option to disable difficulty (and pow) checks
  • Loading branch information
Flouse authored Mar 20, 2024
2 parents 7a49f8d + 303add7 commit db41f4f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ ckb-hash = "0.114"
[dependencies.ckb-bitcoin-spv-verifier]
version = "0.1.0"
git = "https://github.com/ckb-cell/ckb-bitcoin-spv"
rev = "2464c8f"
rev = "837a307"

[features]
default = ["default-tls"]
Expand Down
19 changes: 18 additions & 1 deletion src/cli/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
use std::{collections::HashMap, path::PathBuf};

use bitcoin::blockdata::constants::DIFFCHANGE_INTERVAL;
use ckb_bitcoin_spv_verifier::types::{core::Hash as BitcoinHash, packed, prelude::Pack as VPack};
use ckb_bitcoin_spv_verifier::{
constants::FLAG_DISABLE_DIFFICULTY_CHECK,
types::{core::Hash as BitcoinHash, packed, prelude::Pack as VPack},
};
use ckb_jsonrpc_types::TransactionView;
use ckb_sdk::{
core::TransactionBuilder,
Expand Down Expand Up @@ -83,6 +86,15 @@ pub struct Args {
#[arg(long, value_parser = value_parsers::AddressValueParser)]
pub(crate) spv_owner: CkbAddress,

/// Disable the on-chain difficulty check.
///
/// Warning
///
/// For testing purpose only.
/// Do NOT enable this flag in production environment.
#[arg(long)]
pub(crate) disable_difficulty_check: bool,

/// Perform all steps without sending.
#[arg(long, hide = true)]
pub(crate) dry_run: bool,
Expand Down Expand Up @@ -164,9 +176,14 @@ impl Args {
let cells_count = usize::from(self.spv_clients_count) + 1;
let type_id_array = calculate_type_id(input0.cell_input(), cells_count);
let type_id = BitcoinHash::from_bytes_ref(&type_id_array);
let mut flags = 0u8;
if self.disable_difficulty_check {
flags |= FLAG_DISABLE_DIFFICULTY_CHECK;
}
let args = packed::SpvTypeArgs::new_builder()
.type_id(type_id.pack())
.clients_count(self.spv_clients_count.into())
.flags(flags.into())
.build();
Script::new_builder()
.code_hash(self.spv_contract_data_hash.pack())
Expand Down

0 comments on commit db41f4f

Please sign in to comment.