Skip to content

Commit

Permalink
Merge pull request #4823 from nervosnetwork/zhangsoledad/backport-200
Browse files Browse the repository at this point in the history
backport rc/0.200.x
  • Loading branch information
doitian authored Feb 26, 2025
2 parents edb517b + b2ad029 commit 197f229
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 19 deletions.
2 changes: 1 addition & 1 deletion devtools/ci/ci_main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ case $GITHUB_WORKFLOW in
;;
ci_cargo_deny*)
echo "ci_security_audit_licenses"
cargo deny --version || cargo +stable install cargo-deny --locked
cargo deny --version || cargo +stable install cargo-deny --locked --version 0.17.0
make security-audit
make check-crates
make check-licenses
Expand Down
1 change: 0 additions & 1 deletion network/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ impl NetworkState {
bootnodes,
peer_registry: RwLock::new(peer_registry),
dialing_addrs: RwLock::new(HashMap::default()),
pending_dns_addrs: RwLock::new(HashMap::default()),
public_addrs: RwLock::new(public_addrs),
listened_addrs: RwLock::new(Vec::new()),
pending_observed_addrs: RwLock::new(HashSet::default()),
Expand Down
4 changes: 2 additions & 2 deletions script/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ pub use crate::error::{ScriptError, TransactionScriptError};
pub use crate::scheduler::{Scheduler, ROOT_VM_ID};
pub use crate::syscalls::generator::generate_ckb_syscalls;
pub use crate::types::{
ChunkCommand, CoreMachine, DataPieceId, RunMode, ScriptGroup, ScriptGroupType, ScriptVersion,
TransactionState, TxData, VerifyResult, VmIsa, VmState, VmVersion,
ChunkCommand, CoreMachine, DataLocation, DataPieceId, RunMode, ScriptGroup, ScriptGroupType,
ScriptVersion, TransactionState, TxData, VerifyResult, VmArgs, VmIsa, VmState, VmVersion,
};
pub use crate::verify::TransactionScriptsVerifier;
pub use crate::verify_env::TxVerifyEnv;
34 changes: 21 additions & 13 deletions script/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::syscalls::{

use crate::types::{
CoreMachineType, DataLocation, DataPieceId, DebugContext, Fd, FdArgs, FullSuspendedState,
Machine, Message, ReadState, RunMode, SgData, VmContext, VmId, VmState, WriteState,
Machine, Message, ReadState, RunMode, SgData, VmArgs, VmContext, VmId, VmState, WriteState,
FIRST_FD_SLOT, FIRST_VM_ID,
};
use ckb_traits::{CellDataProvider, ExtensionProvider, HeaderProvider};
Expand Down Expand Up @@ -240,7 +240,7 @@ where
offset: 0,
length: u64::MAX,
},
None
VmArgs::Vector(vec![]),
)?,
ROOT_VM_ID
);
Expand Down Expand Up @@ -401,7 +401,11 @@ where
&mut new_machine,
&args.location,
program,
Some((vm_id, args.argc, args.argv)),
VmArgs::Reader {
vm_id,
argc: args.argc,
argv: args.argv,
},
)?;
// The insert operation removes the old vm instance and adds the new vm instance.
debug_assert!(self.instantiated.contains_key(&vm_id));
Expand All @@ -419,8 +423,14 @@ where
machine.machine.set_register(A0, MAX_VMS_SPAWNED as u64);
continue;
}
let spawned_vm_id =
self.boot_vm(&args.location, Some((vm_id, args.argc, args.argv)))?;
let spawned_vm_id = self.boot_vm(
&args.location,
VmArgs::Reader {
vm_id,
argc: args.argc,
argv: args.argv,
},
)?;
// Move passed fds from spawner to spawnee
for fd in &args.fds {
self.fds.insert(*fd, spawned_vm_id);
Expand Down Expand Up @@ -811,11 +821,7 @@ where
}

/// Boot a vm by given program and args.
pub fn boot_vm(
&mut self,
location: &DataLocation,
args: Option<(u64, u64, u64)>,
) -> Result<VmId, Error> {
pub fn boot_vm(&mut self, location: &DataLocation, args: VmArgs) -> Result<VmId, Error> {
let id = self.next_vm_id;
self.next_vm_id += 1;
let (context, mut machine) = self.create_dummy_vm(&id)?;
Expand Down Expand Up @@ -848,16 +854,18 @@ where
machine: &mut Machine,
location: &DataLocation,
program: Bytes,
args: Option<(u64, u64, u64)>,
args: VmArgs,
) -> Result<u64, Error> {
let metadata = parse_elf::<u64>(&program, machine.machine.version())?;
let bytes = match args {
Some((vm_id, argc, argv)) => {
VmArgs::Reader { vm_id, argc, argv } => {
let (_, machine_from) = self.ensure_get_instantiated(&vm_id)?;
let argv = FlattenedArgsReader::new(machine_from.machine.memory_mut(), argc, argv);
machine.load_program_with_metadata(&program, &metadata, argv)?
}
None => machine.load_program_with_metadata(&program, &metadata, vec![].into_iter())?,
VmArgs::Vector(data) => {
machine.load_program_with_metadata(&program, &metadata, data.into_iter().map(Ok))?
}
};
let mut sc = context.snapshot2_context.lock().expect("lock");
sc.mark_program(
Expand Down
21 changes: 21 additions & 0 deletions script/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,14 @@ pub enum VmState {
WaitForRead(ReadState),
}

/// Used to specify the location of script data.
#[derive(Clone, Debug)]
pub struct DataLocation {
/// A pointer to the data.
pub data_piece_id: DataPieceId,
/// Data offset.
pub offset: u64,
/// Data length.
pub length: u64,
}

Expand Down Expand Up @@ -1008,6 +1012,23 @@ where
}
}

/// When the vm is initialized, arguments are loaded onto the stack.
/// This enum specifies how to locate these arguments.
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub enum VmArgs {
/// Represents reading arguments from other vm.
Reader {
/// An identifier for the virtual machine/process.
vm_id: u64,
/// The number of arguments provided.
argc: u64,
/// The pointer of the actual arguments.
argv: u64,
},
/// Represents reading arguments from a vector.
Vector(Vec<Bytes>),
}

/// Mutable data at virtual machine level
#[derive(Clone)]
pub struct VmContext<DL>
Expand Down
4 changes: 2 additions & 2 deletions shared/src/shared_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ impl SharedBuilder {
.filter(|&target_hash| {
let exists = snapshot.block_exists(&target_hash.pack());
if exists {
info!("assume valid target 0x{} already exists in db", target_hash);
info!("assume-valid target 0x{} exists in local db", target_hash);
}
!exists
})
Expand All @@ -449,7 +449,7 @@ impl SharedBuilder {
.as_ref()
.is_some_and(|targets| targets.is_empty())
{
info!("all assume valid targets is already in db, CKB will do full verification from now on");
info!("all assume-valid targets synchronized, enter full verification mode");
None
} else {
not_exists_targets
Expand Down

0 comments on commit 197f229

Please sign in to comment.