Skip to content

Commit 9dba0c7

Browse files
committed
update
Signed-off-by: Eval EXEC <[email protected]>
1 parent 643cd7e commit 9dba0c7

File tree

9 files changed

+135
-25
lines changed

9 files changed

+135
-25
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ ckb-spawn = { path = "util/spawn", version = "=0.202.0-pre" }
182182
ckb-stop-handler = { path = "util/stop-handler", version = "=0.202.0-pre" }
183183
ckb-store = { path = "store", version = "=0.202.0-pre" }
184184
ckb-sync = { path = "sync", version = "=0.202.0-pre" }
185-
ckb-system-scripts = "=0.5.4"
185+
ckb-system-scripts-v0_5_4 = { package="ckb-system-scripts", version="=0.5.4" }
186+
ckb-system-scripts-v0_6_0 = { package="ckb-system-scripts", version="=0.6.0" }
186187
ckb-systemtime = { path = "util/systemtime", version = "=0.202.0-pre" }
187188
ckb-test-chain-utils = { path = "util/test-chain-utils", version = "=0.202.0-pre" }
188189
ckb-traits = { path = "traits", version = "=0.202.0-pre" }

benches/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ ckb-hash.workspace = true
2323
ckb-test-chain-utils.workspace = true
2424
ckb-dao-utils.workspace = true
2525
ckb-dao.workspace = true
26-
ckb-system-scripts.workspace = true
26+
ckb-system-scripts-v0_5_4.workspace = true
2727
ckb-crypto.workspace = true
2828
ckb-jsonrpc-types.workspace = true
2929
ckb-verification.workspace = true

benches/benches/benchmarks/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use ckb_dao::DaoCalculator;
55
use ckb_dao_utils::genesis_dao_data;
66
use ckb_shared::{Shared, SharedBuilder, Snapshot};
77
use ckb_store::ChainStore;
8-
use ckb_system_scripts::BUNDLED_CELL;
8+
use ckb_system_scripts_v0_5_4::BUNDLED_CELL;
99
use ckb_test_chain_utils::always_success_cell;
1010
use ckb_types::{
1111
H160, H256, U256,

resource/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ phf = "0.8.0" # ckb-resource's build script need this, and cargo shear think ckb
1414
includedir.workspace = true
1515
serde = { workspace = true, features = ["derive"] }
1616
ckb-types.workspace = true
17-
ckb-system-scripts.workspace = true
17+
ckb-system-scripts-v0_5_4.workspace = true
18+
ckb-system-scripts-v0_6_0.workspace = true
1819

1920
[build-dependencies]
2021
includedir_codegen.workspace = true
2122
walkdir.workspace = true
2223
ckb-types.workspace = true
23-
ckb-system-scripts.workspace = true
24+
ckb-system-scripts-v0_5_4.workspace = true
25+
ckb-system-scripts-v0_6_0.workspace = true
2426

2527
[dev-dependencies]
2628
tempfile.workspace = true

resource/build.rs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ use std::io::{BufWriter, Write};
77
use std::path::Path;
88
use walkdir::WalkDir;
99

10-
use ckb_system_scripts::{
11-
CODE_HASH_DAO, CODE_HASH_SECP256K1_BLAKE160_MULTISIG_ALL,
12-
CODE_HASH_SECP256K1_BLAKE160_SIGHASH_ALL, CODE_HASH_SECP256K1_DATA,
10+
use ckb_system_scripts_v0_5_4::{
11+
CODE_HASH_DAO, CODE_HASH_SECP256K1_BLAKE160_SIGHASH_ALL, CODE_HASH_SECP256K1_DATA,
1312
};
1413

14+
use ckb_system_scripts_v0_5_4::CODE_HASH_SECP256K1_BLAKE160_MULTISIG_ALL as CODE_HASH_SECP256K1_BLAKE160_MULTISIG_ALL_LEGACY;
15+
use ckb_system_scripts_v0_6_0::CODE_HASH_SECP256K1_BLAKE160_MULTISIG_ALL as CODE_HASH_SECP256K1_BLAKE160_MULTISIG_ALL_V2;
16+
1517
fn main() {
1618
let mut bundled = includedir_codegen::start("BUNDLED");
1719

@@ -58,9 +60,26 @@ fn main() {
5860

5961
writeln!(
6062
&mut out_file,
61-
"/// Data hash of the cell containing secp256k1 blake160 multisig all lock script.\n\
63+
"/// Data hash of the cell containing secp256k1 blake160 multisig(legacy) all lock script. Deprecated.\n\
64+
#[deprecated]
6265
pub const CODE_HASH_SECP256K1_BLAKE160_MULTISIG_ALL: H256 = {:?};",
63-
H256(CODE_HASH_SECP256K1_BLAKE160_MULTISIG_ALL)
66+
H256(CODE_HASH_SECP256K1_BLAKE160_MULTISIG_ALL_LEGACY)
67+
)
68+
.expect("write to code_hashes.rs");
69+
70+
writeln!(
71+
&mut out_file,
72+
"/// Data hash of the cell containing secp256k1 blake160 multisig(legacy) all lock script.\n\
73+
pub const CODE_HASH_SECP256K1_BLAKE160_MULTISIG_ALL_LEGACY: H256 = {:?};",
74+
H256(CODE_HASH_SECP256K1_BLAKE160_MULTISIG_ALL_LEGACY)
75+
)
76+
.expect("write to code_hashes.rs");
77+
78+
writeln!(
79+
&mut out_file,
80+
"/// Data hash of the cell containing secp256k1 blake160 multisig(v1) all lock script.\n\
81+
pub const CODE_HASH_SECP256K1_BLAKE160_MULTISIG_ALL_V2: H256 = {:?};",
82+
H256(CODE_HASH_SECP256K1_BLAKE160_MULTISIG_ALL_V2)
6483
)
6584
.expect("write to code_hashes.rs");
6685

resource/specs/dev.toml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ file = { bundled = "specs/cells/secp256k1_data" }
3333
create_type_id = false
3434
capacity = 1_048_617_0000_0000
3535
[[genesis.system_cells]]
36-
file = { bundled = "specs/cells/secp256k1_blake160_multisig_all" }
36+
file = { version = "v0.5.4", bundled = "specs/cells/secp256k1_blake160_multisig_all" }
37+
create_type_id = true
38+
capacity = 100_000_0000_0000
39+
40+
[[genesis.system_cells]]
41+
file = { version = "v0.6.0", bundled = "specs/cells/secp256k1_blake160_multisig_all" }
3742
create_type_id = true
3843
capacity = 100_000_0000_0000
3944

@@ -53,7 +58,14 @@ files = [
5358
name = "secp256k1_blake160_multisig_all"
5459
files = [
5560
{ bundled = "specs/cells/secp256k1_data" },
56-
{ bundled = "specs/cells/secp256k1_blake160_multisig_all" },
61+
{ version = "v0.5.4", bundled = "specs/cells/secp256k1_blake160_multisig_all" },
62+
]
63+
64+
[[genesis.dep_groups]]
65+
name = "secp256k1_blake160_multisig_all_v2"
66+
files = [
67+
{ bundled = "specs/cells/secp256k1_data" },
68+
{ version = "v0.6.0", bundled = "specs/cells/secp256k1_blake160_multisig_all" },
5769
]
5870

5971
# For first 11 block

resource/src/lib.rs

Lines changed: 71 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ use std::fs;
3636
use std::io::{self, BufReader, Cursor, Read};
3737
use std::path::{Path, PathBuf};
3838

39-
use ckb_system_scripts::BUNDLED_CELL;
39+
use ckb_system_scripts_v0_5_4::BUNDLED_CELL;
40+
/// get multisig_legacy from v_0_5_4
41+
use ckb_system_scripts_v0_5_4::BUNDLED_CELL as BUNDLED_CELL_v0_5_4;
42+
/// get multisg_v1 from v0_6_0
43+
use ckb_system_scripts_v0_6_0::BUNDLED_CELL as BUNDLED_CELL_v0_6_0;
4044

4145
mod bundled {
4246
#![allow(missing_docs, clippy::unreadable_literal)]
@@ -56,13 +60,39 @@ pub const SPEC_DEV_FILE_NAME: &str = "specs/dev.toml";
5660
/// The file name of the generated RocksDB options file.
5761
pub const DB_OPTIONS_FILE_NAME: &str = "default.db-options";
5862

63+
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
64+
pub enum BundledSystemScriptVersion {
65+
/// The bundled resource version is 0.5.4. this version is used before `CKB v0.201.0`
66+
#[serde(rename = "v0.5.4")]
67+
V0_5_4,
68+
/// The bundled resource version is 0.6.0. This version contains multisig v2
69+
#[serde(rename = "v0.6.0")]
70+
V0_6_0,
71+
}
72+
73+
impl std::fmt::Display for BundledSystemScriptVersion {
74+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
75+
match self {
76+
BundledSystemScriptVersion::V0_5_4 => write!(f, "v0.5.4"),
77+
BundledSystemScriptVersion::V0_6_0 => write!(f, "v0.6.0"),
78+
}
79+
}
80+
}
81+
82+
fn default_bundled_version() -> BundledSystemScriptVersion {
83+
BundledSystemScriptVersion::V0_5_4
84+
}
85+
5986
/// Represents a resource, which is either bundled in the CKB binary or resident in the local file
6087
/// system.
6188
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
6289
#[serde(untagged)]
6390
pub enum Resource {
6491
/// A resource that bundled in the CKB binary.
6592
Bundled {
93+
/// The version of the bundled resource. default is v0.5.4
94+
#[serde(default = "default_bundled_version")]
95+
version: BundledSystemScriptVersion,
6696
/// The identifier of the bundled resource.
6797
bundled: String,
6898
},
@@ -81,7 +111,9 @@ pub enum Resource {
81111
impl fmt::Display for Resource {
82112
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
83113
match self {
84-
Resource::Bundled { bundled } => write!(f, "Bundled({bundled})"),
114+
Resource::Bundled { bundled, version } => {
115+
write!(f, "Bundled(bundled: {bundled}, version:{version}))")
116+
}
85117
Resource::FileSystem { file } => write!(f, "FileSystem({})", file.display()),
86118
Resource::Raw { raw } => write!(f, "Raw({})", raw),
87119
}
@@ -91,7 +123,14 @@ impl fmt::Display for Resource {
91123
impl Resource {
92124
/// Creates a reference to the bundled resource.
93125
pub fn bundled(bundled: String) -> Resource {
94-
Resource::Bundled { bundled }
126+
Resource::Bundled {
127+
version: BundledSystemScriptVersion::V0_5_4,
128+
bundled,
129+
}
130+
}
131+
132+
pub fn bundled_with_version(version: BundledSystemScriptVersion, bundled: String) -> Resource {
133+
Resource::Bundled { version, bundled }
95134
}
96135

97136
/// Creates a reference to the resource resident in the file system.
@@ -163,9 +202,15 @@ impl Resource {
163202
/// The file system resource exists only when the file exists.
164203
pub fn exists(&self) -> bool {
165204
match self {
166-
Resource::Bundled { bundled } => {
167-
SourceFiles::new(&BUNDLED_CELL, &BUNDLED).is_available(bundled)
205+
Resource::Bundled { bundled, version } => match version {
206+
BundledSystemScriptVersion::V0_5_4 => {
207+
SourceFiles::new(&BUNDLED_CELL_v0_5_4, &BUNDLED)
208+
}
209+
BundledSystemScriptVersion::V0_6_0 => {
210+
SourceFiles::new(&BUNDLED_CELL_v0_6_0, &BUNDLED)
211+
}
168212
}
213+
.is_available(bundled),
169214
Resource::FileSystem { file } => file.exists(),
170215
Resource::Raw { .. } => true,
171216
}
@@ -195,7 +240,15 @@ impl Resource {
195240
/// Gets resource content.
196241
pub fn get(&self) -> Result<Cow<'static, [u8]>> {
197242
match self {
198-
Resource::Bundled { bundled } => SourceFiles::new(&BUNDLED_CELL, &BUNDLED).get(bundled),
243+
Resource::Bundled { bundled, version } => match version {
244+
BundledSystemScriptVersion::V0_5_4 => {
245+
SourceFiles::new(&BUNDLED_CELL_v0_5_4, &BUNDLED)
246+
}
247+
BundledSystemScriptVersion::V0_6_0 => {
248+
SourceFiles::new(&BUNDLED_CELL_v0_6_0, &BUNDLED)
249+
}
250+
}
251+
.get(bundled),
199252
Resource::FileSystem { file } => Ok(Cow::Owned(fs::read(file)?)),
200253
Resource::Raw { raw } => Ok(Cow::Owned(raw.to_owned().into_bytes())),
201254
}
@@ -204,9 +257,15 @@ impl Resource {
204257
/// Gets resource content via an input stream.
205258
pub fn read(&self) -> Result<Box<dyn Read>> {
206259
match self {
207-
Resource::Bundled { bundled } => {
208-
SourceFiles::new(&BUNDLED_CELL, &BUNDLED).read(bundled)
260+
Resource::Bundled { bundled, version } => match version {
261+
BundledSystemScriptVersion::V0_5_4 => {
262+
SourceFiles::new(&BUNDLED_CELL_v0_5_4, &BUNDLED)
263+
}
264+
BundledSystemScriptVersion::V0_6_0 => {
265+
SourceFiles::new(&BUNDLED_CELL_v0_6_0, &BUNDLED)
266+
}
209267
}
268+
.read(bundled),
210269
Resource::FileSystem { file } => Ok(Box::new(BufReader::new(fs::File::open(file)?))),
211270
Resource::Raw { raw } => Ok(Box::new(Cursor::new(raw.to_owned().into_bytes()))),
212271
}
@@ -222,7 +281,10 @@ impl Resource {
222281
/// See [Template](struct.Template.html).
223282
pub fn export<P: AsRef<Path>>(&self, context: &TemplateContext<'_>, root_dir: P) -> Result<()> {
224283
let key = match self {
225-
Resource::Bundled { bundled } => bundled,
284+
Resource::Bundled {
285+
bundled,
286+
version: _,
287+
} => bundled,
226288
_ => return Ok(()),
227289
};
228290
let target = join_bundled_key(root_dir.as_ref().to_path_buf(), key);

spec/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use ckb_hash::{blake2b_256, new_blake2b};
2222
use ckb_jsonrpc_types::Script;
2323
use ckb_pow::{Pow, PowEngine};
2424
use ckb_resource::{
25-
CODE_HASH_DAO, CODE_HASH_SECP256K1_BLAKE160_MULTISIG_ALL,
25+
CODE_HASH_DAO, CODE_HASH_SECP256K1_BLAKE160_MULTISIG_ALL_LEGACY,
2626
CODE_HASH_SECP256K1_BLAKE160_SIGHASH_ALL, CODE_HASH_SECP256K1_DATA, Resource,
2727
};
2828
use ckb_types::{
@@ -755,7 +755,7 @@ impl ChainSpec {
755755
check_cells_data_hash(
756756
0,
757757
OUTPUT_INDEX_SECP256K1_BLAKE160_MULTISIG_ALL as usize,
758-
&CODE_HASH_SECP256K1_BLAKE160_MULTISIG_ALL,
758+
&CODE_HASH_SECP256K1_BLAKE160_MULTISIG_ALL_LEGACY,
759759
)?;
760760

761761
Ok(())

0 commit comments

Comments
 (0)