Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add an option to disable difficulty (and pow) checks #2

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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