Skip to content

Commit

Permalink
Merge #2818
Browse files Browse the repository at this point in the history
2818: refactor(hardfork): change field "hash_type" to an enumerated type r=quake,driftluo a=yangby-cryptape

This PR doesn't revert the edition feature for spec files  and config files.
We can do it later, in next PR, after discussions.

**BREAKING CHANGES**: Revert breaking changes which were introduced in #2756.

Co-authored-by: Boyu Yang <yangby@cryptape.com>
  • Loading branch information
bors[bot] and chaoticlonghair authored Jul 10, 2021
2 parents c66a441 + 4aadeb9 commit fa49dc5
Show file tree
Hide file tree
Showing 41 changed files with 202 additions and 629 deletions.
2 changes: 0 additions & 2 deletions 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 benches/benches/benchmarks/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ lazy_static! {
let script = Script::new_builder()
.code_hash(CellOutput::calc_data_hash(&data))
.args(Bytes::from(PUBKEY_HASH.as_bytes()).pack())
.hash_type(ScriptHashType::Data(0).into())
.hash_type(ScriptHashType::Data.into())
.build();

(cell, data, script)
Expand Down
2 changes: 1 addition & 1 deletion chain/src/tests/block_assembler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn start_chain(consensus: Option<Consensus>) -> (ChainController, Shared) {
let config = BlockAssemblerConfig {
code_hash: h256!("0x0"),
args: Default::default(),
hash_type: ScriptHashType::Data { vm_version: 0 },
hash_type: ScriptHashType::Data,
message: Default::default(),
};
let (shared, mut pack) = builder
Expand Down
4 changes: 2 additions & 2 deletions chain/src/tests/reward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,14 @@ fn finalize_reward() {
let bob = ScriptBuilder::default()
.args(bob_args)
.code_hash(always_success_script.code_hash())
.hash_type(ScriptHashType::Data(0).into())
.hash_type(ScriptHashType::Data.into())
.build();

let alice_args: packed::Bytes = Bytes::from(b"a11ce".to_vec()).pack();
let alice = ScriptBuilder::default()
.args(alice_args)
.code_hash(always_success_script.code_hash())
.hash_type(ScriptHashType::Data(0).into())
.hash_type(ScriptHashType::Data.into())
.build();

for i in 1..23 {
Expand Down
2 changes: 1 addition & 1 deletion chain/src/tests/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub(crate) fn start_chain(consensus: Option<Consensus>) -> (ChainController, Sha
let config = BlockAssemblerConfig {
code_hash: h256!("0x0"),
args: Default::default(),
hash_type: ScriptHashType::Data { vm_version: 0 },
hash_type: ScriptHashType::Data,
message: Default::default(),
};

Expand Down
73 changes: 18 additions & 55 deletions ckb-bin/src/subcommand/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::io::{self, Read};
use crate::helper::prompt;
use ckb_app_config::{cli, AppConfig, ExitCode, InitArgs};
use ckb_chain_spec::ChainSpec;
use ckb_jsonrpc_types::{ScriptHashTypeKind, VmVersion};
use ckb_jsonrpc_types::ScriptHashType;
use ckb_resource::{
Resource, TemplateContext, AVAILABLE_SPECS, CKB_CONFIG_FILE_NAME, DB_OPTIONS_FILE_NAME,
MINER_CONFIG_FILE_NAME, SPEC_DEV_FILE_NAME,
Expand Down Expand Up @@ -57,27 +57,15 @@ pub fn init(args: InitArgs) -> Result<(), ExitCode> {
.map(|s| s.to_string())
.collect::<Vec<String>>();

args.block_assembler_hash_type_kind =
match serde_plain::from_str::<ScriptHashTypeKind>(in_hash_type.trim()).ok() {
args.block_assembler_hash_type =
match serde_plain::from_str::<ScriptHashType>(in_hash_type.trim()).ok() {
Some(hash_type) => hash_type,
None => {
eprintln!("Invalid block assembler hash type");
return Err(ExitCode::Failure);
}
};

if args.block_assembler_hash_type_kind == ScriptHashTypeKind::Data {
let in_vm_version = prompt("vm_version: ");
args.block_assembler_hash_type_vm_version =
match serde_plain::from_str::<VmVersion>(in_vm_version.trim()).ok() {
Some(vm_version) => Some(vm_version),
None => {
eprintln!("Invalid block assembler vm version");
return Err(ExitCode::Failure);
}
};
}

let in_message = prompt("message: ");
args.block_assembler_message = Some(in_message.trim().to_string());
}
Expand Down Expand Up @@ -106,11 +94,11 @@ pub fn init(args: InitArgs) -> Result<(), ExitCode> {
let block_assembler = match block_assembler_code_hash {
Some(hash) => {
if let Some(default_code_hash) = &default_code_hash_option {
if ScriptHashTypeKind::Type != args.block_assembler_hash_type_kind {
if ScriptHashType::Type != args.block_assembler_hash_type {
eprintln!(
"WARN: the default lock should use hash type `{}`, you are using `{}`.\n\
It will require `ckb run --ba-advanced` to enable this block assembler",
DEFAULT_LOCK_SCRIPT_HASH_TYPE, args.block_assembler_hash_type_kind
DEFAULT_LOCK_SCRIPT_HASH_TYPE, args.block_assembler_hash_type
);
} else if *default_code_hash != *hash {
eprintln!(
Expand All @@ -127,43 +115,18 @@ pub fn init(args: InitArgs) -> Result<(), ExitCode> {
);
}
}
if let Some(vm_version) = &args.block_assembler_hash_type_vm_version {
if ScriptHashTypeKind::Type == args.block_assembler_hash_type_kind {
eprintln!("VM version is not allowed for hash-type \"type\".");
return Err(ExitCode::Failure);
}
format!(
"[block_assembler]\n\
code_hash = \"{}\"\n\
args = \"{}\"\n\
hash_type.kind = \"{}\"\n\
hash_type.vm_version = {}\n\
message = \"{}\"",
hash,
args.block_assembler_args.join("\", \""),
args.block_assembler_hash_type_kind,
vm_version,
args.block_assembler_message
.unwrap_or_else(|| "0x".to_string()),
)
} else {
if ScriptHashTypeKind::Data == args.block_assembler_hash_type_kind {
eprintln!("VM version should be provided for hash-type \"data\".");
return Err(ExitCode::Failure);
}
format!(
"[block_assembler]\n\
code_hash = \"{}\"\n\
args = \"{}\"\n\
hash_type.kind = \"{}\"\n\
message = \"{}\"",
hash,
args.block_assembler_args.join("\", \""),
args.block_assembler_hash_type_kind,
args.block_assembler_message
.unwrap_or_else(|| "0x".to_string()),
)
}
format!(
"[block_assembler]\n\
code_hash = \"{}\"\n\
args = \"{}\"\n\
hash_type = \"{}\"\n\
message = \"{}\"",
hash,
args.block_assembler_args.join("\", \""),
args.block_assembler_hash_type,
args.block_assembler_message
.unwrap_or_else(|| "0x".to_string()),
)
}
None => {
eprintln!("WARN: mining feature is disabled because of lacking the block assembler config options");
Expand All @@ -172,7 +135,7 @@ pub fn init(args: InitArgs) -> Result<(), ExitCode> {
# [block_assembler]\n\
# code_hash = \"{}\"\n\
# args = \"ckb-cli util blake2b --prefix-160 <compressed-pubkey>\"\n\
# hash_type.kind = \"{}\"\n\
# hash_type = \"{}\"\n\
# message = \"A 0x-prefixed hex string\"",
default_code_hash_option.unwrap_or_default(),
DEFAULT_LOCK_SCRIPT_HASH_TYPE,
Expand Down
8 changes: 4 additions & 4 deletions docs/hashes.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Spec: ckb
[ckb]
spec_hash = "0x3fe86931c2cf5dfa6d7b9447561b5e547937fe4699787bb7ae906218b3f1e6c5"
spec_hash = "0xc1d2eae53dbb7bedb2ecbb39b1663952226c1a2b147158ce85b1d5780a63bc96"
genesis = "0x92b197aa1fba0f63633922c61c92375c9c074a93e85963554f5499fe1450d0e5"
cellbase = "0xe2fb199810d49a4d8beec56718ba2593b665db9d52299a0f9e6e75416d73ff5c"

Expand Down Expand Up @@ -46,7 +46,7 @@ index = 1

# Spec: ckb_testnet
[ckb_testnet]
spec_hash = "0xdde420d56c10a06749e79701b152ed1f532f4bdf0696b5896dfd97fbc821e231"
spec_hash = "0xe0e6adeaadc8d93ea7e3103722fb9344a19a97971f694b090260e76abb4d1c2d"
genesis = "0x10639e0895502b5688a6be8cf69460d76541bfa4821629d86d62ba0aae3f9606"
cellbase = "0x8f8c79eb6671709633fe6a46de93c0fedc9c1b8a6527a18d3983879542635c9f"

Expand Down Expand Up @@ -90,7 +90,7 @@ index = 1

# Spec: ckb_staging
[ckb_staging]
spec_hash = "0x2d96bd61335be33418befa47f1c5ead53a0546b57a6d79719f0f999fa954dde4"
spec_hash = "0x7ce187802e11bbdd074546f882d2608574ac20869baafcc1059a77d871e82733"
genesis = "0xbc081e6b2e31149c1dc39007f161ed0a0b63d5d30b3b771acc6a3b622133fcc0"
cellbase = "0x7295631c414e50a8d9bb73d9845231ac212d10404045c96de7f149ec874ac6b7"

Expand Down Expand Up @@ -134,7 +134,7 @@ index = 1

# Spec: ckb_dev
[ckb_dev]
spec_hash = "0x03af7cc46cb8e26e219d26e68bc7a58ef21210286e63eb17d8232f9aabe1cbcc"
spec_hash = "0xa41b449367d9ca60a5dad4c30804641af8a7284114a867baeec136e87633f290"
genesis = "0x823b2ff5785b12da8b1363cac9a5cbe566d8b715a4311441b119c39a0367488c"
cellbase = "0xa563884b3686078ec7e7677a5f86449b15cf2693f3c1241766c6996f206cc541"

Expand Down
15 changes: 6 additions & 9 deletions resource/specs/dev.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ message = "ckb_dev" # {{
[genesis.genesis_cell.lock]
code_hash = "0x0000000000000000000000000000000000000000000000000000000000000000"
args = "0x"
hash_type.kind = "data"
hash_type.vm_version = 0
hash_type = "data"

# An array list paths to system cell files, which is absolute or relative to
# the directory containing this config file.
Expand All @@ -47,8 +46,7 @@ capacity = 100_000_0000_0000
[genesis.system_cells_lock]
code_hash = "0x0000000000000000000000000000000000000000000000000000000000000000"
args = "0x"
hash_type.kind = "data"
hash_type.vm_version = 0
hash_type = "data"

# Dep group cells
[[genesis.dep_groups]]
Expand All @@ -68,29 +66,28 @@ files = [
[genesis.bootstrap_lock]
code_hash = "0x0000000000000000000000000000000000000000000000000000000000000000"
args = "0x"
hash_type.kind = "type"
hash_type = "type"

# Burn
[[genesis.issued_cells]]
capacity = 8_400_000_000_00000000
lock.code_hash = "0x0000000000000000000000000000000000000000000000000000000000000000"
lock.args = "0x62e907b15cbf27d5425399ebf6f0fb50ebb88f18"
lock.hash_type.kind = "data"
lock.hash_type.vm_version = 0
lock.hash_type = "data"

# issue for random generated private key: d00c06bfd800d27397002dca6fb0993d5ba6399b4238b2f29ee9deb97593d2bc
[[genesis.issued_cells]]
capacity = 20_000_000_000_00000000
lock.code_hash = "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8"
lock.args = "0xc8328aabcd9b9e8e64fbc566c4385c3bdeb219d7"
lock.hash_type.kind = "type"
lock.hash_type = "type"

# issue for random generated private key: 63d86723e08f0f813a36ce6aa123bb2289d90680ae1e99d4de8cdb334553f24d
[[genesis.issued_cells]]
capacity = 5_198_735_037_00000000
lock.code_hash = "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8"
lock.args = "0x470dcdc5e44064909650113a274b3b36aecb6dc7"
lock.hash_type.kind = "type"
lock.hash_type = "type"

[params]
initial_primary_epoch_reward = 1_917_808_21917808
Expand Down
Loading

0 comments on commit fa49dc5

Please sign in to comment.