Skip to content

Commit bbf2420

Browse files
committed
add --skip-script-verify and --skip-all-verify for ckb import
Signed-off-by: Eval EXEC <[email protected]>
1 parent 88acb26 commit bbf2420

File tree

8 files changed

+57
-12
lines changed

8 files changed

+57
-12
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ckb-bin/src/cli.rs

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ pub const ARG_FORMAT: &str = "format";
3535
pub const ARG_TARGET: &str = "target";
3636
/// Command line argument `--source`.
3737
pub const ARG_SOURCE: &str = "source";
38+
/// Command line flag: `--skip-script-verify`.
39+
pub const ARG_SKIP_SCRIPT_VERIFY: &str = "skip-script-verify";
40+
/// Command line flag: `--skip-all-verify`.
41+
pub const ARG_SKIP_ALL_VERIFY: &str = "skip-all-verify";
3842
/// Command line argument `--data`.
3943
pub const ARG_DATA: &str = "data";
4044
/// Command line argument `--list-chains`.
@@ -385,14 +389,30 @@ fn export() -> Command {
385389
}
386390

387391
fn import() -> Command {
388-
Command::new(CMD_IMPORT).about("Import CKB data").arg(
389-
Arg::new(ARG_SOURCE)
390-
.index(1)
391-
.value_name("path")
392-
.value_parser(clap::builder::PathBufValueParser::new())
393-
.required(true)
394-
.help("Specify the exported data path"),
395-
)
392+
Command::new(CMD_IMPORT)
393+
.about("Import CKB data")
394+
.arg(
395+
Arg::new(ARG_SOURCE)
396+
.index(1)
397+
.value_name("path")
398+
.value_parser(clap::builder::PathBufValueParser::new())
399+
.required(true)
400+
.help("Specify the exported data path"),
401+
)
402+
.arg(
403+
//
404+
Arg::new(ARG_SKIP_SCRIPT_VERIFY)
405+
.required(false)
406+
.action(clap::ArgAction::SetTrue)
407+
.help("Skip script verification during import"),
408+
)
409+
.arg(
410+
//
411+
Arg::new(ARG_SKIP_ALL_VERIFY)
412+
.action(clap::ArgAction::SetTrue)
413+
.required(false)
414+
.help("Skip all verifications during import"),
415+
)
396416
}
397417

398418
fn migrate() -> Command {

ckb-bin/src/setup.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use ckb_chain_spec::{ChainSpec, consensus::Consensus};
99
use ckb_jsonrpc_types::{Either, ScriptHashType};
1010
use ckb_logger::{error, info};
1111
use ckb_types::{H256, U256, u256};
12+
use ckb_verification_traits::Switch;
1213
use clap::ArgMatches;
1314
use std::{path::PathBuf, str::FromStr};
1415

@@ -222,10 +223,21 @@ H256::from_str(&target[2..]).expect("default assume_valid_target for testnet mus
222223
})?
223224
.clone();
224225

226+
let switch = {
227+
if matches.get_flag(cli::ARG_SKIP_ALL_VERIFY) {
228+
Switch::DISABLE_ALL
229+
} else if matches.get_flag(cli::ARG_SKIP_SCRIPT_VERIFY) {
230+
Switch::DISABLE_SCRIPT
231+
} else {
232+
Switch::NONE
233+
}
234+
};
235+
225236
Ok(ImportArgs {
226237
config,
227238
consensus,
228239
source,
240+
switch,
229241
})
230242
}
231243

ckb-bin/src/subcommand/import.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub fn import(args: ImportArgs, async_handle: Handle) -> Result<(), ExitCode> {
2020
pack.take_tx_pool_builder();
2121
pack.take_relay_tx_receiver();
2222

23-
Import::new(chain_controller, args.source)
23+
Import::new(chain_controller, args.source, args.switch)
2424
.execute()
2525
.map_err(|err| {
2626
eprintln!("Import error: {err:?}");

util/app-config/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ path-clean.workspace = true
1616
ckb-logger.workspace = true
1717
ckb-logger-config.workspace = true
1818
ckb-metrics-config.workspace = true
19+
ckb-verification-traits.workspace = true
1920
ckb-chain-spec.workspace = true
2021
ckb-jsonrpc-types.workspace = true
2122
ckb-pow.workspace = true

util/app-config/src/args.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use ckb_jsonrpc_types::{Either, ScriptHashType};
44
use ckb_pow::PowEngine;
55
use ckb_systemtime::unix_time_as_millis;
66
use ckb_types::packed::Byte32;
7+
use ckb_verification_traits::Switch;
78
use std::path::PathBuf;
89
use std::sync::Arc;
910

@@ -40,6 +41,8 @@ pub struct ImportArgs {
4041
pub consensus: Consensus,
4142
/// The path to the file to be imported.
4243
pub source: PathBuf,
44+
/// The switch to control the verification behavior.
45+
pub switch: Switch,
4346
}
4447

4548
/// Parsed command line arguments for `ckb run`.

util/instrument/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ ckb-store.workspace = true
1515
ckb-chain-iter.workspace = true
1616
ckb-shared.workspace = true
1717
ckb-jsonrpc-types.workspace = true
18+
ckb-verification-traits.workspace = true
1819
serde_json.workspace = true
1920
indicatif = { workspace = true, optional = true }
2021

util/instrument/src/import.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use ckb_chain::ChainController;
22
use ckb_jsonrpc_types::BlockView as JsonBlock;
33
use ckb_types::core;
4+
use ckb_verification_traits::Switch;
45
#[cfg(feature = "progress_bar")]
56
use indicatif::{ProgressBar, ProgressStyle};
67
use std::error::Error;
@@ -15,12 +16,17 @@ pub struct Import {
1516
/// source file contains block data
1617
source: PathBuf,
1718
chain: ChainController,
19+
switch: Switch,
1820
}
1921

2022
impl Import {
2123
/// Creates a new import job.
22-
pub fn new(chain: ChainController, source: PathBuf) -> Self {
23-
Import { chain, source }
24+
pub fn new(chain: ChainController, source: PathBuf, switch: Switch) -> Self {
25+
Import {
26+
chain,
27+
source,
28+
switch,
29+
}
2430
}
2531

2632
/// Executes the import job.
@@ -64,7 +70,7 @@ impl Import {
6470
let block: Arc<core::BlockView> = Arc::new(block.into());
6571
if !block.is_genesis() {
6672
self.chain
67-
.blocking_process_block(block)
73+
.blocking_process_block_with_switch(block, self.switch)
6874
.expect("import occur malformation data");
6975
}
7076
progress_bar.inc(s.len() as u64);

0 commit comments

Comments
 (0)