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

New spawn with scheduler #4380

Merged
merged 141 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from 81 commits
Commits
Show all changes
141 commits
Select commit Hold shift + click to select a range
8d8ce55
Just copy codes in it
mohanson Mar 4, 2024
a519266
Use scheduler to run tests (#2)
mohanson Mar 4, 2024
10724ba
Add place args to spawn
mohanson Mar 5, 2024
6a1f8a4
Add a todo for ckb_close
mohanson Mar 5, 2024
3584a7c
Remove all old spawn test cases (#3)
XuJiandong Mar 5, 2024
f1d5437
Rename join => wait
mohanson Mar 5, 2024
4df9a03
Adjust pipe_read/write args positions
mohanson Mar 5, 2024
8bc4175
Move argc/argc to spawn_args_t
mohanson Mar 5, 2024
05b532a
Implement close (#4)
mohanson Mar 5, 2024
962620c
Rename instance_id => process_id
mohanson Mar 5, 2024
b577e4c
Add spawn cases
XuJiandong Mar 6, 2024
0041ec1
Enable 2019/2021 test cases (#7)
mohanson Mar 6, 2024
e4d4aa4
Add more spawn cases (#8)
XuJiandong Mar 6, 2024
da968be
Enable 2019/2021 test cases (#9)
mohanson Mar 6, 2024
af11e31
Rewrite some syscalls (#10)
mohanson Mar 7, 2024
e25aa9d
Add more test cases (#11)
XuJiandong Mar 8, 2024
d44371f
Fix EOF issue (#12)
XuJiandong Mar 8, 2024
6be39c2
Rewrite spawn (#13)
mohanson Mar 8, 2024
9b40aef
Max VMs count (#14)
XuJiandong Mar 9, 2024
0481dec
Rewrite load_cell_data (#15)
mohanson Mar 9, 2024
a8b5155
Staged (#16)
mohanson Mar 12, 2024
c5c773b
Merge branch 'new-verify-with-sched' into new_spawn
mohanson Mar 13, 2024
d6aa2a1
Add a fixme in testdata/README.md
mohanson Mar 13, 2024
f29b597
Fix build error
mohanson Mar 13, 2024
04d83ea
fix compiling error with ContextualTransactionVerifier
chenyukang Mar 13, 2024
cce6f65
use scheduler for resumeable vm run
chenyukang Mar 13, 2024
066f42d
use vm scheduler suspend and resume for snapshot
chenyukang Mar 13, 2024
111dae1
cleanup unused code
chenyukang Mar 13, 2024
3b852d3
tunning script test
chenyukang Mar 14, 2024
d4d0014
Use BTreeMap instead of HashMap
mohanson Mar 18, 2024
257be49
fix specs in verify
chenyukang Mar 18, 2024
64711de
Update ckb-vm
mohanson Mar 20, 2024
b6814e7
Fix shared lib
mohanson Mar 21, 2024
7c69ee7
clean lint warnings
chenyukang Mar 21, 2024
4d83bea
merge from new verify
chenyukang Mar 21, 2024
c8b6cf4
fix clippy wanring
chenyukang Mar 21, 2024
bca7c0d
cleanup unused code
chenyukang Mar 21, 2024
0d6aeea
fix spawn specs
chenyukang Mar 21, 2024
a00365f
code refactor for scheduler and syscalls2
chenyukang Mar 21, 2024
cfd998f
Remove println in check_spawn_strcat
mohanson Mar 27, 2024
1773243
verify_until_completed returns error now
mohanson Mar 27, 2024
c5292b3
exec callee pause
mohanson Mar 27, 2024
368124f
Clean
mohanson Mar 27, 2024
16d5aa8
fix test case check_exec_callee_pause
chenyukang Mar 28, 2024
b451b3f
fix test for resume_from_snap
chenyukang Mar 28, 2024
0f76bbe
clean up
chenyukang Mar 28, 2024
a32861d
Fix load_cell_data and load_cell_data_as_code
mohanson Mar 29, 2024
13fb2df
Optimize comments
mohanson Mar 29, 2024
527cd17
Rename utils.h to spawn_utils.h
mohanson Mar 29, 2024
676b796
Add check_spawn_configurable testcase
mohanson Apr 1, 2024
3739f7b
Create up to 64 pipes
mohanson Apr 2, 2024
9ddc661
Add SpawnFrom:Slice to test spawn_configurable
mohanson Apr 2, 2024
7f5697a
Add spawn dag testcase
mohanson Apr 3, 2024
6a7c0b6
Clean codes
mohanson Apr 4, 2024
70ccc7f
Update cargo.lock
mohanson Apr 4, 2024
d511fd7
Add missing ensure_vms_instantiated
mohanson Apr 4, 2024
8f9b967
clang fmt
mohanson Apr 5, 2024
ac8e152
Add test_random_dag
mohanson Apr 6, 2024
6c28298
Support interpreter ckb-vm
mohanson Apr 9, 2024
8f40da9
Add spawn fuzzing test (#17)
XuJiandong Apr 10, 2024
59a6ac1
Adjust cycles charge
mohanson Apr 10, 2024
3a3ff6b
Adjust cycles charge
mohanson Apr 11, 2024
7517bf5
Use yield error
mohanson Apr 11, 2024
8ff30a3
Replace unwrap with error
mohanson Apr 11, 2024
70f9361
Fix clippy error: this loop never actually loops
mohanson Apr 11, 2024
dd261e0
Fix clippy: unneeded return statement
mohanson Apr 11, 2024
a8a30e4
Remove logs
mohanson Apr 12, 2024
a71043f
Add testcase about spawn (#19)
joii2020 Apr 15, 2024
380eb9a
Adjust spawn_cases
mohanson Apr 15, 2024
0f7743e
Rename PipeId to Fd
mohanson Apr 15, 2024
0f32819
Rename MAX_FD_CREATED to MAX_FDS_CREATED
mohanson Apr 15, 2024
b0ced6e
Update ckb-c-stdlib
mohanson Apr 15, 2024
4fc3ad4
Remove spawn_fd_limits
mohanson Apr 15, 2024
5d6a27f
Rename Pipe to Fd
mohanson Apr 15, 2024
9b96f53
Fix previous PR
mohanson Apr 15, 2024
0e653fb
Run make fmt
mohanson Apr 16, 2024
c1ef6b5
MAX_FDS only limit alive fd now
mohanson Apr 16, 2024
80fee9d
Add spawn test case with lots of resume/suspend (#21)
XuJiandong Apr 16, 2024
9c51571
Add tests: about spawn load cells (#22)
joii2020 Apr 17, 2024
3754058
Clean
mohanson Apr 17, 2024
5ddedfd
Charge cycles when vm suspending/resumeing
mohanson Apr 17, 2024
9f816b7
Remove eprintln!
mohanson Apr 18, 2024
7cbc55d
Quick fix previous commit
mohanson Apr 18, 2024
97876b8
Add {current_used} for ScriptError
mohanson Apr 18, 2024
bb1d25f
Add ensure_vms_instantiated for Message::Pipe
mohanson Apr 18, 2024
5fec33c
cleanup test
chenyukang Apr 22, 2024
6f9374d
fix test for chunk count
chenyukang Apr 22, 2024
956047e
add comments
chenyukang Apr 22, 2024
6d32512
cleanup clippy
chenyukang Apr 22, 2024
fb604fe
resolve conflict
chenyukang Apr 22, 2024
dc3bb25
Add spawn cycles testcase
mohanson Apr 22, 2024
7b198a3
Fix previous commit
mohanson Apr 22, 2024
9ca6687
Update spawn_cycles
mohanson Apr 23, 2024
a7acf9f
MAX_VMS_COUNT is now a constant
mohanson Apr 25, 2024
f64d93d
Fix load_cell_data
mohanson Apr 25, 2024
e190794
Use an internal struct for WaitForWrite and WaitForRead
mohanson Apr 25, 2024
3c45fc4
Add a debug_assert_eq to check extra_cycles is 0
mohanson Apr 25, 2024
564cc61
Add test: read\write cycles
joii2020 Apr 25, 2024
985e44f
Clean spawn_io_cycles.c
mohanson Apr 25, 2024
d34ca8e
Use filter_map and collect to refactoring codes
mohanson Apr 25, 2024
63d4dde
Remove unnecessary comments
mohanson Apr 25, 2024
1a83097
Simplify codes with functional
mohanson Apr 25, 2024
de4a7e4
Replace VMError::External(IndexOutOfBound) with VMError::CkbScriptInd…
mohanson Apr 26, 2024
345ace6
Update Cargo.lock
mohanson Apr 26, 2024
b9de30f
Refactoring iterate
mohanson Apr 26, 2024
67cb7a9
Remove unnecessary clone
mohanson Apr 26, 2024
c23f19a
Simplified set_max_cycles
mohanson Apr 26, 2024
de38595
Add a help function ensure_get_instantiated
mohanson Apr 26, 2024
13bf1fe
Rename generate_same_syscalls to generate_syscalls
mohanson Apr 26, 2024
77a2824
Remove snapshot2_context from TransactionScriptsSyscallsGenerator
mohanson Apr 26, 2024
9936a79
Fix clippy
mohanson Apr 26, 2024
4cfe332
Remove inherited_file_descriptors special handling of NULL
mohanson Apr 28, 2024
f9a7c17
Replace + with checked_add
mohanson Apr 29, 2024
e766bb5
add cycles assertions
chenyukang May 6, 2024
72aa9e8
Refactoring data source
mohanson May 8, 2024
fa8ac4a
Update cargo.lock
mohanson May 8, 2024
384d76f
sync up with develop
chenyukang May 8, 2024
e729974
fix clippy
chenyukang May 8, 2024
a4fb1db
Update ckb-vm
mohanson May 15, 2024
73ca9c2
Update Cargo.lock
mohanson May 15, 2024
379684d
lock cargo shear version
chenyukang May 10, 2024
2abad8c
Add test case with spawn saturate memory
XuJiandong May 20, 2024
7494697
Update script/testdata/README.md
mohanson May 20, 2024
4a2f18e
Fix addr overlap
mohanson May 27, 2024
58c8480
Update ckb-vm to v0.24.11
mohanson May 28, 2024
daa0700
Update Cargo.lock
mohanson May 28, 2024
3c59242
Public TxData
mohanson Jun 4, 2024
4003f03
Changes for spawn debugger
mohanson Jun 17, 2024
234f736
Update ckb-vm to v0.24.12
mohanson Jun 21, 2024
0e8e493
sync up with develop branch
chenyukang Jun 21, 2024
d092376
Add missing docs
mohanson Jun 21, 2024
eb62b40
Update molecule to 0.8.0
mohanson Jun 21, 2024
770e9ce
Update cycles
mohanson Jun 22, 2024
e2bc2d5
merge develop
chenyukang Jul 1, 2024
e875acd
bless clippy
chenyukang Jul 1, 2024
e10caea
Add base cycles for exec in script-version-2
mohanson Jul 5, 2024
ed1d4b9
Reduce load elf base cycles to 50k
mohanson Jul 5, 2024
63afcf4
Increase to 75000
mohanson Jul 5, 2024
38279e1
To keep compatible with the old Source::parse_from_u64 behavior
mohanson Jul 18, 2024
ea4aea7
Load cell data before load size
mohanson Jul 19, 2024
af87dd3
Fix source and data_piece_id's inconsistency
mohanson Jul 26, 2024
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
15 changes: 13 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 chain/src/tests/load_code_with_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ fn test_load_code() {
let tx_status = tx_pool.get_tx_status(tx.hash());
assert_eq!(
tx_status.unwrap().unwrap(),
(TxStatus::Pending, Some(11174))
(TxStatus::Pending, Some(11325))
quake marked this conversation as resolved.
Show resolved Hide resolved
);
}

Expand Down
4 changes: 3 additions & 1 deletion script/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ckb-traits = { path = "../traits", version = "= 0.115.0-pre" }
byteorder = "1.3.1"
ckb-types = { path = "../util/types", version = "= 0.115.0-pre" }
ckb-hash = { path = "../util/hash", version = "= 0.115.0-pre" }
ckb-vm = { git = "https://github.com/chenyukang/ckb-vm.git", version = "=0.24.9", default-features = false, branch = "yukang-local-changes"}
ckb-vm = { git = "https://github.com/libraries/ckb-vm", branch = "release-0.24-spawn", default-features = false }
faster-hex = "0.6"
ckb-logger = { path = "../util/logger", version = "= 0.115.0-pre", optional = true }
serde = { version = "1.0", features = ["derive"] }
Expand All @@ -40,3 +40,5 @@ ckb-crypto = { path = "../util/crypto", version = "= 0.115.0-pre" }
ckb-db-schema = { path = "../db-schema", version = "= 0.115.0-pre" }
tempfile.workspace = true
rand = "0.8.4"
daggy = "0.8.0"
molecule = "0.7.5"
1 change: 1 addition & 0 deletions script/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ fn main() {
if cfg!(any(feature = "asm", feature = "detect-asm")) && can_enable_asm {
println!("cargo:rustc-cfg=has_asm");
}
println!("cargo:rerun-if-changed=src");
}
4 changes: 4 additions & 0 deletions script/fuzz/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ target
corpus
artifacts
coverage
flamegraph.svg
perf.data
perf.data.old

6 changes: 6 additions & 0 deletions script/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,9 @@ name = "syscall_exec"
path = "fuzz_targets/syscall_exec.rs"
test = false
doc = false

[[bin]]
name = "syscall_spawn"
path = "fuzz_targets/syscall_spawn.rs"
test = false
doc = false
2 changes: 1 addition & 1 deletion script/fuzz/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ cargo install cargo-fuzz

run fuzz test
```
cargo +nightly fuzz run transaction_scripts_verifier_data1
cargo +nightly fuzz run -j $(nproc) transaction_scripts_verifier_data1
```

generate coverage report
Expand Down
136 changes: 136 additions & 0 deletions script/fuzz/fuzz_targets/syscall_spawn.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#![no_main]
use libfuzzer_sys::fuzz_target;

use ckb_chain_spec::consensus::ConsensusBuilder;
use ckb_script::{TransactionScriptsVerifier, TxVerifyEnv};
use ckb_traits::{CellDataProvider, ExtensionProvider, HeaderProvider};
use ckb_types::{
bytes::Bytes,
core::{
capacity_bytes,
cell::{CellMetaBuilder, ResolvedTransaction},
hardfork::{HardForks, CKB2021, CKB2023},
Capacity, HeaderView, ScriptHashType, TransactionBuilder, TransactionInfo,
},
h256,
packed::{
self, Byte32, CellInput, CellOutput, CellOutputBuilder, OutPoint, Script,
TransactionInfoBuilder, TransactionKeyBuilder,
},
prelude::*,
};

#[derive(Default, PartialEq, Eq, Clone)]
struct MockDataLoader {}

impl CellDataProvider for MockDataLoader {
fn get_cell_data(&self, _out_point: &OutPoint) -> Option<Bytes> {
None
}

fn get_cell_data_hash(&self, _out_point: &OutPoint) -> Option<Byte32> {
None
}
}

impl HeaderProvider for MockDataLoader {
fn get_header(&self, _block_hash: &Byte32) -> Option<HeaderView> {
None
}
}

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

fn mock_transaction_info() -> TransactionInfo {
TransactionInfoBuilder::default()
.block_number(1u64.pack())
.block_epoch(0u64.pack())
.key(
TransactionKeyBuilder::default()
.block_hash(Byte32::zero())
.index(1u32.pack())
.build(),
)
.build()
.unpack()
}

static PROGRAM_DATA: &[u8] = include_bytes!("../../testdata/spawn_fuzzing");

fn run(data: &[u8]) {
if data.len() < 8 {
return;
}
let split_offset = data[0] as usize;
let split_offset = usize::min(split_offset, data.len() - 1);
let parent_witness = Bytes::copy_from_slice(&data[0..split_offset]);
let child_witness = Bytes::copy_from_slice(&data[split_offset..]);
let witnesses = vec![parent_witness.pack(), child_witness.pack()];

let transaction = TransactionBuilder::default()
.input(CellInput::new(OutPoint::null(), 0))
.set_witnesses(witnesses)
.build();

let data: Bytes = (Vec::from(PROGRAM_DATA)).into();
let script = Script::new_builder()
.hash_type(ScriptHashType::Data2.into())
.code_hash(CellOutput::calc_data_hash(&data))
.build();
let dep_cell = CellMetaBuilder::from_cell_output(
CellOutput::new_builder()
.capacity(Capacity::bytes(data.len()).unwrap().pack())
.build(),
data,
)
.transaction_info(mock_transaction_info())
.out_point(OutPoint::new(h256!("0x0").pack(), 0))
.build();

let input_cell = CellMetaBuilder::from_cell_output(
CellOutputBuilder::default()
.capacity(capacity_bytes!(100).pack())
.lock(script)
.build(),
Bytes::new(),
)
.transaction_info(mock_transaction_info())
.build();

let rtx = ResolvedTransaction {
transaction,
resolved_cell_deps: vec![dep_cell],
resolved_inputs: vec![input_cell],
resolved_dep_groups: vec![],
};

let provider = MockDataLoader {};
let hardfork_switch = HardForks {
ckb2021: CKB2021::new_mirana().as_builder().build().unwrap(),
ckb2023: CKB2023::new_mirana()
.as_builder()
.rfc_0049(0)
.build()
.unwrap(),
};
let consensus = ConsensusBuilder::default()
.hardfork_switch(hardfork_switch)
.build();
let tx_verify_env =
TxVerifyEnv::new_submit(&HeaderView::new_advanced_builder().epoch(0.pack()).build());
let verifier = TransactionScriptsVerifier::new(
rtx.into(),
provider,
consensus.into(),
tx_verify_env.into(),
);
let _ = verifier.verify(70_000_000);
}

fuzz_target!(|data: &[u8]| {
run(data);
});
1 change: 1 addition & 0 deletions script/fuzz/programs/exec_caller.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <stdlib.h>
#include <stdint.h>

static inline long __internal_syscall(long n, long _a0, long _a1, long _a2,
Expand Down
6 changes: 3 additions & 3 deletions script/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
//! CKB component to run the type/lock scripts.
pub mod cost_model;
mod error;
mod scheduler;
mod syscalls;
mod type_id;
mod types;
mod verify;
mod verify_env;

pub use crate::error::{ScriptError, TransactionScriptError};
pub use crate::syscalls::spawn::update_caller_machine;
pub use crate::types::{
ChunkCommand, CoreMachine, MachineContext, ResumableMachine, ScriptGroup, ScriptGroupType,
ScriptVersion, TransactionSnapshot, TransactionState, VerifyResult, VmIsa, VmVersion,
ChunkCommand, CoreMachine, ScriptGroup, ScriptGroupType, ScriptVersion, TransactionSnapshot,
TransactionState, VerifyResult, VmIsa, VmVersion,
};
pub use crate::verify::{TransactionScriptsSyscallsGenerator, TransactionScriptsVerifier};
pub use crate::verify_env::TxVerifyEnv;
Loading
Loading