From 303add7827a2369292b3b592de5e836eb8590045 Mon Sep 17 00:00:00 2001 From: Boyu Yang Date: Wed, 20 Mar 2024 15:37:29 +0800 Subject: [PATCH] feat: add an option to disable difficulty (and pow) checks --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/cli/init.rs | 19 ++++++++++++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 342143d..4d76e8b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -378,7 +378,7 @@ dependencies = [ [[package]] name = "ckb-bitcoin-spv-verifier" version = "0.1.0" -source = "git+https://github.com/ckb-cell/ckb-bitcoin-spv?rev=2464c8f#2464c8fb6059f285e6d1b9157b49fd08f7b6efff" +source = "git+https://github.com/ckb-cell/ckb-bitcoin-spv?rev=837a307#837a307f5b1b9193621f032c2370bb9e91506b81" dependencies = [ "bitcoin", "bitcoin_hashes", diff --git a/Cargo.toml b/Cargo.toml index b7c498f..7de0920 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] diff --git a/src/cli/init.rs b/src/cli/init.rs index 3be3ea7..bbf5005 100644 --- a/src/cli/init.rs +++ b/src/cli/init.rs @@ -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, @@ -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, @@ -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())