Skip to content

Commit

Permalink
chore: update ckb deps
Browse files Browse the repository at this point in the history
  • Loading branch information
blckngm committed Jul 7, 2023
1 parent cd324ed commit af80f55
Show file tree
Hide file tree
Showing 39 changed files with 304 additions and 297 deletions.
172 changes: 89 additions & 83 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions crates/block-producer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ gw-utils = { path = "../utils" }
gw-polyjuice-sender-recover = { path = "../polyjuice-sender-recover" }
gw-telemetry = { path = "../telemetry" }
gw-metrics = { path = "../metrics" }
ckb-crypto = "0.106"
ckb-fixed-hash = "0.106"
ckb-types = "0.106"
ckb-chain-spec = "0.106"
ckb-crypto = "0.111.0-rc8"
ckb-fixed-hash = "0.111.0-rc8"
ckb-types = "0.111.0-rc8"
ckb-chain-spec = "0.111.0-rc8"
anyhow = "1.0"
serde = { version = "1.0", features = ["derive"] }
async-channel = "1.4.2"
Expand Down
2 changes: 1 addition & 1 deletion crates/builtin-binaries/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ sha2 = "0.10.6"

[build-dependencies]
includedir_codegen = "0.6.0"
ckb-fixed-hash = "0.106"
ckb-fixed-hash = "0.111.0-rc8"
anyhow = "1.0"
sha2 = "0.10.6"
2 changes: 1 addition & 1 deletion crates/chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ gw-jsonrpc-types = { path = "../jsonrpc-types" }
gw-utils = { path = "../utils" }
gw-telemetry = { path = "../telemetry" }
gw-metrics = { path = "../metrics" }
ckb-fixed-hash = "0.106"
ckb-fixed-hash = "0.111.0-rc8"
anyhow = "1.0"
thiserror = "1.0"
lazy_static = "1.4"
Expand Down
10 changes: 5 additions & 5 deletions crates/challenge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ gw-jsonrpc-types = { path = "../jsonrpc-types" }
gw-rpc-client = { path = "../rpc-client" }
gw-traits = { path = "../traits" }
gw-utils = { path = "../utils" }
ckb-fixed-hash = "0.106"
ckb-types = "0.106"
ckb-script = "0.106"
ckb-traits = "0.106"
ckb-chain-spec = "0.106"
ckb-fixed-hash = "0.111.0-rc8"
ckb-types = "0.111.0-rc8"
ckb-script = "0.111.0-rc8"
ckb-traits = "0.111.0-rc8"
ckb-chain-spec = "0.111.0-rc8"
anyhow = "1.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand Down
41 changes: 33 additions & 8 deletions crates/challenge/src/offchain/verify_tx.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use anyhow::{anyhow, bail, Result};
use ckb_fixed_hash::H256;
use ckb_script::TransactionScriptsVerifier;
use ckb_traits::{CellDataProvider, HeaderProvider};
use ckb_script::{TransactionScriptsVerifier, TxVerifyEnv};
use ckb_traits::{CellDataProvider, ExtensionProvider, HeaderProvider};
use ckb_types::{
bytes::Bytes,
core::{
cell::{CellMeta, CellMetaBuilder, ResolvedTransaction},
DepType, HeaderView,
DepType, EpochNumberWithFraction, HeaderView,
},
packed::{Byte32, CellDep, CellOutput, OutPoint, OutPointVec},
prelude::*,
Expand All @@ -17,8 +17,12 @@ use gw_jsonrpc_types::{
};
use gw_types::offchain::InputCellInfo;

use std::collections::{HashMap, HashSet};
use std::{convert::TryFrom, fs::read, path::PathBuf, sync::Arc};
use std::{
collections::{HashMap, HashSet},
fs::read,
path::PathBuf,
sync::Arc,
};

pub struct TxWithContext {
pub cell_deps: Vec<InputCellInfo>,
Expand Down Expand Up @@ -84,9 +88,20 @@ pub fn verify_tx(
data_loader.extend_inputs(tx_with_context.inputs);

let resolved_tx = data_loader.resolve_tx(&tx_with_context.tx)?;
let cycles = TransactionScriptsVerifier::new(&resolved_tx, &data_loader)
.verify(max_cycles)
.map_err(|err| anyhow!("verify tx failed: {}", err))?;
let cycles = TransactionScriptsVerifier::new(
Arc::new(resolved_tx),
data_loader,
// Default consensus uses mirana hardfork.
Default::default(),
Arc::new(TxVerifyEnv::new_submit(
&HeaderView::new_advanced_builder()
.number(10000u64.pack())
.epoch(EpochNumberWithFraction::new(100, 0, 100).pack())
.build(),
)),
)
.verify(max_cycles)
.map_err(|err| anyhow!("verify tx failed: {}", err))?;

Ok(cycles)
}
Expand Down Expand Up @@ -147,6 +162,7 @@ pub fn dump_tx(
Ok(mock_tx)
}

#[derive(Clone)]
struct TxDataLoader {
rollup_cell_deps: Arc<HashMap<OutPoint, CellInfo>>,
headers: HashMap<Byte32, HeaderView>,
Expand Down Expand Up @@ -257,6 +273,15 @@ impl HeaderProvider for TxDataLoader {
}
}

impl ExtensionProvider for TxDataLoader {
fn get_block_extension(
&self,
_hash: &ckb_types::packed::Byte32,
) -> Option<ckb_types::packed::Bytes> {
None
}
}

#[derive(Clone)]
struct CellInfo {
output: CellOutput,
Expand Down
2 changes: 1 addition & 1 deletion crates/config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ no-builtin = ["gw-builtin-binaries/no-builtin"]
[dependencies]
gw-jsonrpc-types = { path = "../jsonrpc-types" }
gw-builtin-binaries = { path = "../builtin-binaries" }
ckb-fixed-hash = "0.106"
ckb-fixed-hash = "0.111.0-rc8"
serde = { version = "1.0", features = ["derive"] }
hex = "0.4"
lazy_static = "1.4"
Expand Down
8 changes: 4 additions & 4 deletions crates/generator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"

[features]
default = ["detect-asm"]
detect-asm = ["ckb-vm/detect-asm", "ckb-vm-aot"]
detect-asm = ["ckb-vm/detect-asm"]
enable-always-success-lock = []

[dependencies]
Expand All @@ -20,11 +20,11 @@ gw-store = { path = "../store" }
gw-traits = { path = "../traits" }
gw-utils = { path = "../utils"}
gw-jsonrpc-types = { path = "../jsonrpc-types" }
ckb-types = "0.106"
ckb-types = "0.111.0-rc8"
anyhow = "1.0"
blake2b-rs = "0.2"
ckb-vm = { version = "=0.22.1", default-features = false }
ckb-vm-aot = { version = "=0.22", optional = true }
# Use crates.io version if our changes are merged.
ckb-vm = { git = "https://github.com/blckngm/ckb-vm.git", branch = "rename-symbols-2" }
thiserror = "1.0"
lazy_static = "1.4"
rlp = "0.5.0"
Expand Down
5 changes: 4 additions & 1 deletion crates/generator/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ fn main() {
let is_windows = target_family == "windows";
let is_unix = target_family == "unix";
let is_x86_64 = target_arch == "x86_64";
let can_enable_asm = is_x86_64 && (is_windows || is_unix);
let is_aarch64 = target_arch == "aarch64";
let x64_asm = is_x86_64 && (is_windows || is_unix);
let aarch64_asm = is_aarch64 && is_unix;
let can_enable_asm = x64_asm || aarch64_asm;

if cfg!(feature = "asm") && (!can_enable_asm) {
panic!("asm feature can only be enabled on x86_64 Linux, macOS and Windows platforms!");
Expand Down
1 change: 1 addition & 0 deletions crates/generator/src/account_lock_manage/eip712/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ impl Withdrawal {
{
ScriptHashType::Data => "data",
ScriptHashType::Data1 => "data1",
ScriptHashType::Data2 => "data2",
ScriptHashType::Type => "type",
};
let address = RegistryAddress::from_address(address)?;
Expand Down
39 changes: 0 additions & 39 deletions crates/generator/src/backend_manage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ use anyhow::{bail, Context, Result};
use gw_config::{content_checksum, BackendConfig, BackendForkConfig, BackendType};
use gw_types::{bytes::Bytes, h256::*};

#[cfg(has_asm)]
use crate::types::vm::AotCode;

#[derive(Clone)]
pub struct Backend {
pub generator: Bytes,
Expand Down Expand Up @@ -91,10 +88,6 @@ pub struct BlockConsensus {
#[derive(Default)]
pub struct BackendManage {
backend_forks: Vec<(u64, BlockConsensus)>,
/// define here not in backends,
/// so we don't need to implement the trait `Clone` of AotCode
#[cfg(has_asm)]
aot_codes: HashMap<H256, AotCode>,
}

impl BackendManage {
Expand Down Expand Up @@ -188,10 +181,6 @@ impl BackendManage {
generator_checksum.into(),
generator_debug,
)?;
#[cfg(has_asm)]
if compile {
self.compile_backend(&backend);
}

log::debug!(
"registry backend {:?}({}) at height {}",
Expand All @@ -210,15 +199,6 @@ impl BackendManage {
Ok(())
}

#[cfg(has_asm)]
fn compile_backend(&mut self, backend: &Backend) {
self.aot_codes.insert(
backend.generator_checksum,
self.aot_compile(&backend.generator)
.expect("Ahead-of-time compile"),
);
}

pub fn get_block_consensus_at_height(
&self,
block_number: u64,
Expand Down Expand Up @@ -252,25 +232,6 @@ impl BackendManage {
backend
})
}

#[cfg(has_asm)]
fn aot_compile(&self, code_bytes: &Bytes) -> Result<AotCode, ckb_vm::Error> {
let vm_version = crate::types::vm::VMVersion::V1;
let mut aot_machine = ckb_vm_aot::AotCompilingMachine::load(
code_bytes,
Some(Box::new(crate::vm_cost_model::instruction_cycles)),
vm_version.vm_isa(),
vm_version.vm_version(),
)?;
aot_machine.compile()
}

/// get aot_code according to special VM version
#[cfg(has_asm)]
pub(crate) fn get_aot_code(&self, code_hash: &H256) -> Option<&AotCode> {
log::debug!("get_aot_code hash: {}", hex::encode(code_hash.as_slice()),);
self.aot_codes.get(code_hash)
}
}

#[cfg(test)]
Expand Down
19 changes: 5 additions & 14 deletions crates/generator/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ impl Generator {
let t = Instant::now();
let core_machine = VMVersion::V1.init_core_machine(max_cycles);
let machine_builder = DefaultMachineBuilder::new(core_machine)
.syscall(Box::new(L2Syscalls {
.context(L2Syscalls {
chain,
state,
block_info,
Expand All @@ -272,21 +272,12 @@ impl Generator {
account_lock_manage: &self.account_lock_manage,
cycles_pool: &mut cycles_pool,
context: &mut context,
}))
.instruction_cycle_func(&instruction_cycles);
})
.instruction_cycle_func(instruction_cycles);
let default_machine = machine_builder.build();

#[cfg(has_asm)]
let aot_code_opt = self
.backend_manage
.get_aot_code(&backend.generator_checksum);
#[cfg(has_asm)]
if aot_code_opt.is_none() {
log::warn!("[machine_run] Not AOT mode!");
}

#[cfg(has_asm)]
let mut machine = ckb_vm_aot::AotMachine::new(default_machine, aot_code_opt);
let mut machine = ckb_vm::machine::asm::AsmMachine::new(default_machine);

#[cfg(not(has_asm))]
let mut machine = TraceMachine::new(default_machine);
Expand Down Expand Up @@ -464,7 +455,7 @@ impl Generator {

/// Apply l2 state transition
#[instrument(skip_all, fields(block = args.l2block.raw().number().unpack(), deposits_count = args.deposit_info_vec.len()))]
pub fn verify_and_apply_block<C: ChainView>(
pub fn verify_and_apply_block<C: ChainView + Sync>(
&self,
db: &mut StoreTransaction,
chain: &C,
Expand Down
10 changes: 3 additions & 7 deletions crates/generator/src/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
use ckb_vm::{
memory::Memory,
registers::{A0, A1, A2, A3, A4, A5, A7},
Error as VMError, Register, SupportMachine, Syscalls,
Error as VMError, ExecutionContext, Register, SupportMachine,
};
use gw_common::{
blake2b::new_blake2b,
Expand Down Expand Up @@ -166,13 +166,9 @@ pub fn store_data<Mac: SupportMachine>(machine: &mut Mac, data: &[u8]) -> Result
Ok(real_size)
}

impl<'a, 'b, S: State + CodeStore + JournalDB, C: ChainView, Mac: SupportMachine> Syscalls<Mac>
for L2Syscalls<'a, 'b, S, C>
impl<'a, 'b, S: State + CodeStore + JournalDB, C: ChainView, Mac: SupportMachine>
ExecutionContext<Mac> for L2Syscalls<'a, 'b, S, C>
{
fn initialize(&mut self, _machine: &mut Mac) -> Result<(), VMError> {
Ok(())
}

fn ecall(&mut self, machine: &mut Mac) -> Result<bool, VMError> {
let code = machine.registers()[A7].to_u64();

Expand Down
3 changes: 0 additions & 3 deletions crates/generator/src/types/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ impl VMVersion {
}
}

#[cfg(has_asm)]
pub(crate) use ckb_vm_aot::AotCode;

#[derive(Debug, Clone, Eq, PartialEq)]
pub struct ChallengeContext {
pub target: ChallengeTarget,
Expand Down
17 changes: 9 additions & 8 deletions crates/generator/src/vm_cost_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ pub fn transferred_byte_cycles(bytes: u64) -> u64 {
pub fn instruction_cycles(i: Instruction) -> u64 {
match extract_opcode(i) {
// IMC
insts::OP_JALR => 3,
insts::OP_LD => 2,
insts::OP_LW => 3,
insts::OP_LH => 3,
insts::OP_LB => 3,
insts::OP_LWU => 3,
insts::OP_LHU => 3,
insts::OP_LBU => 3,
// We are only using version 1 VM.
insts::OP_JALR_VERSION1 => 3,
insts::OP_LD_VERSION1 => 2,
insts::OP_LW_VERSION1 => 3,
insts::OP_LH_VERSION1 => 3,
insts::OP_LB_VERSION1 => 3,
insts::OP_LWU_VERSION1 => 3,
insts::OP_LHU_VERSION1 => 3,
insts::OP_LBU_VERSION1 => 3,
insts::OP_SB => 3,
insts::OP_SH => 3,
insts::OP_SW => 3,
Expand Down
2 changes: 1 addition & 1 deletion crates/godwoken-bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"

[dependencies]
anyhow = "1.0"
ckb-types = "0.106"
ckb-types = "0.111.0-rc8"
clap = { version = "3", features = ["derive"] }
indicatif = "0.16"
gw-block-producer = { path = "../block-producer" }
Expand Down
4 changes: 2 additions & 2 deletions crates/jsonrpc-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ serde = { version = "1.0", features = ["derive"] }
faster-hex = "0.4"
gw-types = { path = "../../gwos/crates/types" }
gw-common = { path = "../../gwos/crates/common" }
ckb-jsonrpc-types = "0.106"
ckb-fixed-hash = "0.106"
ckb-jsonrpc-types = "0.111.0-rc8"
ckb-fixed-hash = "0.111.0-rc8"
anyhow = "1.0"
serde_repr = "0.1.10"
serde_json = "1.0.94"
4 changes: 2 additions & 2 deletions crates/replay-chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ gw-jsonrpc-types = { path = "../jsonrpc-types" }
gw-rpc-client = { path = "../rpc-client" }
gw-utils = { path = "../utils" }
clap = "3"
ckb-fixed-hash = "0.106"
ckb-types = "0.106"
ckb-fixed-hash = "0.111.0-rc8"
ckb-types = "0.111.0-rc8"
anyhow = "1.0"
thiserror = "1.0"
lazy_static = "1.4"
Expand Down
4 changes: 2 additions & 2 deletions crates/rpc-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ gw-common = { path = "../../gwos/crates/common" }
gw-config = { path = "../config" }
gw-types = { path = "../../gwos/crates/types" }
gw-jsonrpc-types = { path = "../jsonrpc-types" }
ckb-fixed-hash = "0.106"
ckb-types = "0.106"
ckb-fixed-hash = "0.111.0-rc8"
ckb-types = "0.111.0-rc8"
anyhow = "1.0"
serde = { version = "1.0", features = ["derive"] }
log = "0.4.14"
Expand Down
Loading

0 comments on commit af80f55

Please sign in to comment.