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(hardfork): ckb2021 hardfork features (vm related part) #2756

Merged
merged 19 commits into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
01ac46c
Bump ckb-vm
mohanson Mar 23, 2021
ca6d22a
feat: new syscalls
mohanson May 20, 2021
0108a6a
redesign exec
mohanson May 26, 2021
323a4b2
Merge branch mohanson/vm (commit: 0108a6a) into branch ckb2021-develop
chaoticlonghair May 27, 2021
ec59a90
chore: new vm and new syscalls: use crates.io; fix compilation, test …
chaoticlonghair May 27, 2021
784fbb0
Merge branch 'develop' into ckb2021-develop
chaoticlonghair Jun 15, 2021
fa40d1c
feat(hardfork): vm version selection, vm version 1 and syscalls 2
chaoticlonghair Jun 15, 2021
e4dac8a
feat(hardfork): reset scripts caches when a new feature enabled which…
chaoticlonghair Jun 15, 2021
21a10f9
Merge branch 'develop' into ckb2021-develop
chaoticlonghair Jun 17, 2021
af792f2
fix(hardfork): `ckb init` will panic when specifies arguments for "bl…
chaoticlonghair Jun 17, 2021
7fc2e6c
chore(deps): bump ckb-vm from 0.20.0-alpha to 0.20.0-alpha2 and ring …
chaoticlonghair Jun 17, 2021
aba1e6d
Merge branch 'develop' into ckb2021-develop
chaoticlonghair Jun 23, 2021
db21824
fix(hardfork): tx-pool drain the proposed in the incorrect order and …
chaoticlonghair Jun 23, 2021
7a0610b
Merge branch 'develop' into ckb2021-develop
chaoticlonghair Jun 28, 2021
db2caca
feat(hardfork): add the "edition" field to all configuration files
chaoticlonghair Jun 29, 2021
40b4497
refactor(hardfork): change field "hash_type" from a "String" to an "O…
chaoticlonghair Jun 29, 2021
f2b9782
refactor(hardfork): disable hardfork feature if not set; set all to e…
chaoticlonghair Jun 29, 2021
59dc192
fix(hardfork): the chain specification name is incorrect
chaoticlonghair Jun 29, 2021
09c7975
feat(hardfork): reject unknown vm versions and add an integration tes…
chaoticlonghair Jun 29, 2021
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
279 changes: 117 additions & 162 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ cov: ## Run code coverage.

.PHONY: wasm-build-test
wasm-build-test: ## Build core packages for wasm target
cp -f Cargo.lock wasm-build-test/
cd wasm-build-test && cargo build --target=wasm32-unknown-unknown

.PHONY: setup-ckb-test
Expand Down
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.into())
.hash_type(ScriptHashType::Data(0).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,
hash_type: ScriptHashType::Data { vm_version: 0 },
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.into())
.hash_type(ScriptHashType::Data(0).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.into())
.hash_type(ScriptHashType::Data(0).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,
hash_type: ScriptHashType::Data { vm_version: 0 },
message: Default::default(),
};

Expand Down
83 changes: 62 additions & 21 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::ScriptHashType;
use ckb_jsonrpc_types::{ScriptHashTypeKind, VmVersion};
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 @@ -48,7 +48,6 @@ pub fn init(args: InitArgs) -> Result<(), ExitCode> {
let in_block_assembler_code_hash = prompt("code hash: ");
let in_args = prompt("args: ");
let in_hash_type = prompt("hash_type: ");
let in_message = prompt("message: ");

args.block_assembler_code_hash = Some(in_block_assembler_code_hash.trim().to_string());

Expand All @@ -58,12 +57,29 @@ pub fn init(args: InitArgs) -> Result<(), ExitCode> {
.map(|s| s.to_string())
.collect::<Vec<String>>();

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

match serde_plain::from_str::<ScriptHashType>(in_hash_type.trim()).ok() {
Some(hash_type) => args.block_assembler_hash_type = hash_type,
None => eprintln!("Invalid block assembler hash type"),
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());
}

// Try to find the default secp256k1 from bundled chain spec.
Expand All @@ -90,11 +106,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 ScriptHashType::Type != args.block_assembler_hash_type {
if ScriptHashTypeKind::Type != args.block_assembler_hash_type_kind {
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
DEFAULT_LOCK_SCRIPT_HASH_TYPE, args.block_assembler_hash_type_kind
);
} else if *default_code_hash != *hash {
eprintln!(
Expand All @@ -111,18 +127,43 @@ pub fn init(args: InitArgs) -> Result<(), ExitCode> {
);
}
}
format!(
"[block_assembler]\n\
code_hash = \"{}\"\n\
args = \"{}\"\n\
hash_type = \"{}\"\n\
message = \"{}\"",
hash,
args.block_assembler_args.join("\", \""),
serde_plain::to_string(&args.block_assembler_hash_type).unwrap(),
args.block_assembler_message
.unwrap_or_else(|| "0x".to_string()),
)
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()),
)
}
}
None => {
eprintln!("WARN: mining feature is disabled because of lacking the block assembler config options");
Expand All @@ -131,7 +172,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 = \"{}\"\n\
# hash_type.kind = \"{}\"\n\
# message = \"A 0x-prefixed hex string\"",
default_code_hash_option.unwrap_or_default(),
DEFAULT_LOCK_SCRIPT_HASH_TYPE,
Expand Down
2 changes: 1 addition & 1 deletion ckb-bin/src/subcommand/list_hashes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pub fn list_hashes(root_dir: PathBuf, matches: &ArgMatches<'_>) -> Result<(), Ex
resource = Resource::bundled_ckb_config();
}

let mut config: CKBAppConfig = toml::from_slice(&resource.get()?)?;
let mut config = CKBAppConfig::load_from_slice(&resource.get()?)?;
config.chain.spec.absolutize(&root_dir);
let chain_spec = ChainSpec::load_from(&config.chain.spec).map_err(to_config_error)?;
let spec_name = chain_spec.name.clone();
Expand Down
3 changes: 2 additions & 1 deletion devtools/doc/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,8 @@ def handle_endtag(self, tag):
if self.variant_parser is not None:
self.variant_parser.handle_endtag(tag)
if self.variant_parser.completed():
self.variants.append((self.next_variant, self.variant_parser))
if self.next_variant not in [v[0] for v in self.variants]:
self.variants.append((self.next_variant, self.variant_parser))
self.next_variant = None
self.variant_parser = None

Expand Down
2 changes: 1 addition & 1 deletion docs/hashes.toml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ index = 1

# Spec: ckb_dev
[ckb_dev]
spec_hash = "0xa8d7ab92196638cd091d49aa76849f6f102d8082eb374f089477d9c50a4bd2f1"
spec_hash = "0xc8dc9b41a93c64daf608231fd2061623c5cd73b10d6deb4ed22390324e358cc8"
genesis = "0x823b2ff5785b12da8b1363cac9a5cbe566d8b715a4311441b119c39a0367488c"
cellbase = "0xa563884b3686078ec7e7677a5f86449b15cf2693f3c1241766c6996f206cc541"

Expand Down
6 changes: 6 additions & 0 deletions resource/ckb-miner.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
# staging => # Config generated by `ckb init --chain staging`
# }}

# Choose the edition, possible values:
# - "2019"
# - "2021"
# The default is "2019", the latest is "2021".
edition = "2021"

data_dir = "data"

[chain]
Expand Down
6 changes: 6 additions & 0 deletions resource/ckb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
# staging => # Config generated by `ckb init --chain staging`
# }}

# Choose the edition, possible values:
# - "2019"
# - "2021"
# The default is "2019", the latest is "2021".
edition = "2021"

data_dir = "data"

[chain]
Expand Down
28 changes: 22 additions & 6 deletions resource/specs/dev.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
name = "ckb_dev"

# Choose the edition, possible values:
# - "2019"
# - "2021"
# The default is "2019", the latest is "2021".
edition = "2021"

[genesis]
version = 0
parent_hash = "0x0000000000000000000000000000000000000000000000000000000000000000"
Expand All @@ -16,7 +22,8 @@ message = "ckb_dev" # {{
[genesis.genesis_cell.lock]
code_hash = "0x0000000000000000000000000000000000000000000000000000000000000000"
args = "0x"
hash_type = "data"
hash_type.kind = "data"
hash_type.vm_version = 0

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

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

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

# 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 = "type"
lock.hash_type.kind = "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 = "type"
lock.hash_type.kind = "type"

[params]
initial_primary_epoch_reward = 1_917_808_21917808
Expand All @@ -95,5 +104,12 @@ genesis_epoch_length = 1000
# Keep difficulty be permanent if the pow is Dummy. (default: false)
permanent_difficulty_in_dummy = true

[params.hardfork]
rfc_pr_0221 = 0
rfc_pr_0222 = 0
rfc_pr_0223 = 0
rfc_pr_0224 = 0
rfc_pr_0237 = 0

[pow]
func = "Dummy"
Loading