diff --git a/Cargo.lock b/Cargo.lock index 3e1dc2f1..67f45ca1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -88,9 +88,9 @@ dependencies = [ [[package]] name = "alloy-chains" -version = "0.1.49" +version = "0.1.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830045a4421ee38d3ab570d36d4d2b5152c066e72797139224da8de5d5981fd0" +checksum = "d4e0f0136c085132939da6b753452ebed4efaa73fe523bb855b10c199c2ebfaf" dependencies = [ "alloy-primitives", "num_enum", @@ -555,7 +555,7 @@ checksum = "5a833d97bf8a5f0f878daf2c8451fff7de7f9de38baa5a45d936ec718d81255a" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.91", ] [[package]] @@ -743,7 +743,7 @@ dependencies = [ "proc-macro-error2", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.91", ] [[package]] @@ -760,7 +760,7 @@ dependencies = [ "proc-macro-error2", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.91", "syn-solidity", "tiny-keccak", ] @@ -778,7 +778,7 @@ dependencies = [ "proc-macro2", "quote", "serde_json", - "syn 2.0.90", + "syn 2.0.91", "syn-solidity", ] @@ -876,9 +876,9 @@ dependencies = [ [[package]] name = "alloy-trie" -version = "0.7.6" +version = "0.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a5fd8fea044cc9a8c8a50bb6f28e31f0385d820f116c5b98f6f4e55d6e5590b" +checksum = "1e428104b2445a4f929030891b3dbf8c94433a8349ba6480946bf6af7975c2f6" dependencies = [ "alloy-primitives", "alloy-rlp", @@ -941,9 +941,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.94" +version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1fd03a028ef38ba2276dce7e33fcd6369c158a1bca17946c4b1b701891c1ff7" +checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04" [[package]] name = "ark-ff" @@ -1086,7 +1086,7 @@ checksum = "3b43422f69d8ff38f95f1b2bb76517c91589a924d1559a0e935d7c8ce0274c11" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.91", ] [[package]] @@ -1108,7 +1108,7 @@ checksum = "c7c24de15d275a1ecfd47a380fb4d5ec9bfe0933f309ed5e705b775596a3574d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.91", ] [[package]] @@ -1119,7 +1119,7 @@ checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.91", ] [[package]] @@ -1130,7 +1130,7 @@ checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.91", ] [[package]] @@ -1191,7 +1191,7 @@ dependencies = [ "regex", "rustc-hash 1.1.0", "shlex", - "syn 2.0.90", + "syn 2.0.91", "which", ] @@ -1462,7 +1462,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.91", ] [[package]] @@ -1628,7 +1628,7 @@ checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.91", "unicode-xid", ] @@ -1661,7 +1661,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.91", ] [[package]] @@ -1908,7 +1908,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.91", ] [[package]] @@ -2310,7 +2310,7 @@ checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.91", ] [[package]] @@ -2351,7 +2351,7 @@ checksum = "a0eb5a3343abf848c0984fe4604b2b105da9539376e24fc0a3b0007411ae4fd9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.91", ] [[package]] @@ -2664,14 +2664,14 @@ checksum = "af1844ef2428cc3e1cb900be36181049ef3d3193c63e43026cfe202983b27a56" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.91", ] [[package]] name = "nybbles" -version = "0.2.1" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95f06be0417d97f81fe4e5c86d7d01b392655a9cac9c19a848aa033e18937b23" +checksum = "55a62e678a89501192cc5ebf47dcbc656b608ae5e1c61c9251fe35230f119fe3" dependencies = [ "alloy-rlp", "const-hex", @@ -2718,7 +2718,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.91", ] [[package]] @@ -2828,7 +2828,7 @@ checksum = "3c0f5fad0874fc7abcd4d750e76917eaebbecaa2c20bde22e1dbeeba8beb758c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.91", ] [[package]] @@ -2875,7 +2875,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "64d1ec885c64d0457d564db4ec299b2dae3f9c02808b8ad9c3a089c591b18033" dependencies = [ "proc-macro2", - "syn 2.0.90", + "syn 2.0.91", ] [[package]] @@ -2917,7 +2917,7 @@ dependencies = [ "proc-macro-error-attr2", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.91", ] [[package]] @@ -3009,9 +3009,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.37" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" dependencies = [ "proc-macro2", ] @@ -3534,7 +3534,7 @@ checksum = "46f859dbbf73865c6627ed570e78961cd3ac92407a2d117204c49232485da55e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.91", ] [[package]] @@ -3709,7 +3709,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.90", + "syn 2.0.91", ] [[package]] @@ -3731,9 +3731,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.90" +version = "2.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "919d3b74a5dd0ccd15aeb8f93e7006bd9e14c295087c9896a110f490752bcf31" +checksum = "d53cbcb5a243bd33b7858b1d7f4aca2153490815872d86d955d6ea29f743c035" dependencies = [ "proc-macro2", "quote", @@ -3749,7 +3749,7 @@ dependencies = [ "paste", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.91", ] [[package]] @@ -3769,7 +3769,7 @@ checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.91", ] [[package]] @@ -3817,7 +3817,7 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.91", ] [[package]] @@ -3828,7 +3828,7 @@ checksum = "7b50fa271071aae2e6ee85f842e2e28ba8cd2c5fb67f11fcb1fd70b276f9e7d4" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.91", ] [[package]] @@ -3900,7 +3900,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.91", ] [[package]] @@ -4010,7 +4010,7 @@ checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.91", ] [[package]] @@ -4168,7 +4168,7 @@ dependencies = [ "log", "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.91", "wasm-bindgen-shared", ] @@ -4203,7 +4203,7 @@ checksum = "30d7a95b763d3c45903ed6c81f156801839e5ee968bb07e534c44df0fcd330c2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.91", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -4431,7 +4431,7 @@ checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.91", "synstructure", ] @@ -4453,7 +4453,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.91", ] [[package]] @@ -4473,7 +4473,7 @@ checksum = "595eed982f7d355beb85837f651fa22e90b3c044842dc7f2c2842c086f295808" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.91", "synstructure", ] @@ -4494,7 +4494,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.91", ] [[package]] @@ -4516,5 +4516,5 @@ checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.90", + "syn 2.0.91", ] diff --git a/cartesi-rollups/contracts/bindings-rs/Cargo.toml b/cartesi-rollups/contracts/bindings-rs/Cargo.toml index b84e4107..b05bb5a4 100644 --- a/cartesi-rollups/contracts/bindings-rs/Cargo.toml +++ b/cartesi-rollups/contracts/bindings-rs/Cargo.toml @@ -15,5 +15,5 @@ readme = "README.md" repository = "https://github.com/cartesi/dave" [dependencies] -alloy = { version = "0.8.0", features = ["sol-types", "contract"] } +alloy = { workspace = true, features = ["sol-types", "contract"] } diff --git a/cartesi-rollups/node/compute-runner/src/lib.rs b/cartesi-rollups/node/compute-runner/src/lib.rs index 39fcb2b8..04064f5d 100644 --- a/cartesi-rollups/node/compute-runner/src/lib.rs +++ b/cartesi-rollups/node/compute-runner/src/lib.rs @@ -1,5 +1,6 @@ use alloy::primitives::Address; use log::error; +use std::path::PathBuf; use std::result::Result; use std::{str::FromStr, sync::Arc, time::Duration}; @@ -15,6 +16,7 @@ pub struct ComputeRunner { config: BlockchainConfig, sleep_duration: Duration, state_manager: Arc, + state_dir: PathBuf, } impl ComputeRunner @@ -26,12 +28,14 @@ where config: &BlockchainConfig, state_manager: Arc, sleep_duration: u64, + state_dir: PathBuf, ) -> Self { Self { arena_sender, config: config.clone(), sleep_duration: Duration::from_secs(sleep_duration), state_manager, + state_dir, } } @@ -54,7 +58,7 @@ where .state_manager .machine_state_hashes(last_sealed_epoch.epoch_number)?; let mut player = Player::new( - Some(inputs.into_iter().map(|i| Input(i)).collect()), + Some(inputs.into_iter().map(Input).collect()), leafs .into_iter() .map(|l| { @@ -70,6 +74,7 @@ where snapshot, Address::from_str(&last_sealed_epoch.root_tournament) .expect("fail to convert tournament address"), + self.state_dir.clone(), ) .expect("fail to initialize compute player"); let _ = player diff --git a/cartesi-rollups/node/dave-rollups/src/lib.rs b/cartesi-rollups/node/dave-rollups/src/lib.rs index 40d7b153..ba74fb9f 100644 --- a/cartesi-rollups/node/dave-rollups/src/lib.rs +++ b/cartesi-rollups/node/dave-rollups/src/lib.rs @@ -7,6 +7,7 @@ use rollups_compute_runner::ComputeRunner; use rollups_epoch_manager::EpochManager; use rollups_machine_runner::MachineRunner; use rollups_state_manager::persistent_state_access::PersistentStateAccess; +use std::path::PathBuf; use std::sync::Arc; use tokio::task::JoinHandle; use tokio::task::{spawn, spawn_blocking}; @@ -28,8 +29,8 @@ pub struct DaveParameters { sleep_duration: u64, #[arg(long, env, default_value_t = SNAPSHOT_DURATION)] snapshot_duration: u64, - #[arg(long, env)] - pub path_to_db: String, + #[arg(long, env)] // TODO: add default + pub state_dir: PathBuf, } pub fn create_blockchain_reader_task( @@ -69,6 +70,7 @@ pub fn create_compute_runner_task( ¶ms.blockchain_config, state_manager, params.sleep_duration, + params.state_dir, ); compute_runner @@ -115,6 +117,7 @@ pub fn create_machine_runner_task( params.machine_path.as_str(), params.sleep_duration, params.snapshot_duration, + params.state_dir.clone(), ) .inspect_err(|e| error!("{e}")) .unwrap(); diff --git a/cartesi-rollups/node/dave-rollups/src/main.rs b/cartesi-rollups/node/dave-rollups/src/main.rs index 19b65d8a..13b77a6f 100644 --- a/cartesi-rollups/node/dave-rollups/src/main.rs +++ b/cartesi-rollups/node/dave-rollups/src/main.rs @@ -18,7 +18,7 @@ async fn main() -> Result<()> { let parameters = DaveParameters::parse(); let state_manager = Arc::new(PersistentStateAccess::new(Connection::open( - ¶meters.path_to_db, + parameters.state_dir.join("state.db"), )?)?); let arena_sender = EthArenaSender::new(¶meters.blockchain_config)?; diff --git a/cartesi-rollups/node/machine-runner/src/lib.rs b/cartesi-rollups/node/machine-runner/src/lib.rs index 40f9a3a1..b0dd69d9 100644 --- a/cartesi-rollups/node/machine-runner/src/lib.rs +++ b/cartesi-rollups/node/machine-runner/src/lib.rs @@ -16,7 +16,7 @@ use cartesi_machine::{break_reason, configuration::RuntimeConfig, htif, machine: use cartesi_prt_core::machine::constants::{LOG2_EMULATOR_SPAN, LOG2_INPUT_SPAN, LOG2_UARCH_SPAN}; use rollups_state_manager::{InputId, StateManager}; -// gap of each leaf in the commitment tree, should use the same value as CanonicalConstants.sol:log2step(0) +// gap of each leaf in the commitment tree, should use the same value as CanonicalConstants.sol:log2step(0)a const LOG2_STRIDE: u64 = 44; pub struct MachineRunner { @@ -24,6 +24,7 @@ pub struct MachineRunner { sleep_duration: Duration, state_manager: Arc, _snapshot_frequency: Duration, + state_dir: PathBuf, epoch_number: u64, next_input_index_in_epoch: u64, @@ -39,6 +40,7 @@ where initial_machine: &str, sleep_duration: u64, snapshot_frequency: u64, + state_dir: PathBuf, ) -> Result { let (snapshot, epoch_number, next_input_index_in_epoch) = match state_manager .latest_snapshot() @@ -55,6 +57,8 @@ where sleep_duration: Duration::from_secs(sleep_duration), state_manager, _snapshot_frequency: Duration::from_secs(snapshot_frequency), + state_dir, + epoch_number, next_input_index_in_epoch, state_hash_index_in_epoch: 0, @@ -131,7 +135,7 @@ where .map_err(|e| MachineRunnerError::StateManagerError(e))?; let stride_count_in_epoch = 1 << (LOG2_INPUT_SPAN + LOG2_EMULATOR_SPAN + LOG2_UARCH_SPAN - LOG2_STRIDE); - if state_hashes.len() == 0 { + if state_hashes.is_empty() { // no inputs in current epoch, add machine state hash repeatedly self.add_state_hash(stride_count_in_epoch)?; state_hashes.push(( @@ -229,14 +233,20 @@ where } fn take_snapshot(&self) -> Result<(), SM> { - let epoch_path = PathBuf::from(format!("/rollups_data/{}", self.epoch_number)); + let epoch_path = self + .state_dir + .join("snapshots") + .join(self.epoch_number.to_string()); + + if !epoch_path.exists() { + fs::create_dir_all(&epoch_path)?; + } + let snapshot_path = epoch_path.join(format!( "{}", self.next_input_index_in_epoch << LOG2_EMULATOR_SPAN )); - if !epoch_path.exists() { - fs::create_dir_all(&epoch_path)?; - } + if !snapshot_path.exists() { self.state_manager .add_snapshot( @@ -523,7 +533,7 @@ mod tests { state_manager .machine_state_hashes .push(machine_state_hashes); - let mut runner = MachineRunner::new(Arc::new(state_manager), "/app/echo", 10, 10)?; + let mut runner = MachineRunner::new(Arc::new(state_manager), "/app/echo", 10, 10, ".")?; runner.advance_epoch()?; assert_eq!( diff --git a/cartesi-rollups/node/state-manager/src/lib.rs b/cartesi-rollups/node/state-manager/src/lib.rs index 0305eb2f..51ec5948 100644 --- a/cartesi-rollups/node/state-manager/src/lib.rs +++ b/cartesi-rollups/node/state-manager/src/lib.rs @@ -9,21 +9,12 @@ use std::error::Error; pub type Blob = Vec; -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Default)] pub struct InputId { pub epoch_number: u64, pub input_index_in_epoch: u64, } -impl Default for InputId { - fn default() -> Self { - Self { - epoch_number: 0, - input_index_in_epoch: 0, - } - } -} - impl InputId { pub fn increment_index(self) -> Self { Self { diff --git a/machine/rust-bindings/cartesi-machine-sys/build.rs b/machine/rust-bindings/cartesi-machine-sys/build.rs index 675e716a..5dda2d56 100644 --- a/machine/rust-bindings/cartesi-machine-sys/build.rs +++ b/machine/rust-bindings/cartesi-machine-sys/build.rs @@ -1,7 +1,6 @@ use std::{ env, fs, - path::Path, - path::PathBuf, + path::{Path, PathBuf}, process::{Command, Stdio}, }; @@ -37,7 +36,7 @@ fn main() { let libdir_path = machine_dir_path.join("src"); // clean build artifacts and start from scratch - clean(&machine_dir_path); + // clean(&machine_dir_path); // // Get uarch @@ -62,25 +61,25 @@ fn main() { // build dependencies Command::new("make") - .args(&["submodules"]) + .args(["submodules"]) .current_dir(&machine_dir_path) .status() .expect("Failed to run setup `make submodules`"); Command::new("make") - .args(&["bundle-boost"]) + .args(["bundle-boost"]) .current_dir(&machine_dir_path) .status() .expect("Failed to run `make bundle-boost`"); // build `libcartesi.a`, release, no `libslirp` Command::new("make") - .args(&[ + .args([ "-C", "src", "release=yes", "slirp=no", "libcartesi.a", - "libcartesi_jsonrpc.a", + // "libcartesi_jsonrpc.a", ]) .current_dir(&machine_dir_path) .status() @@ -89,16 +88,18 @@ fn main() { // copy `libcartesi.a` to OUT_DIR let libcartesi_path = libdir_path.join("libcartesi.a"); let libcartesi_new_path = out_path.join("libcartesi.a"); - fs::copy(&libcartesi_path, &libcartesi_new_path).expect(&format!( - "Failed to copy `libcartesi.a` {:?} to OUT_DIR {:?}", - libcartesi_path, libcartesi_new_path - )); + fs::copy(&libcartesi_path, &libcartesi_new_path).unwrap_or_else(|_| { + panic!( + "Failed to copy `libcartesi.a` {:?} to OUT_DIR {:?}", + libcartesi_path, libcartesi_new_path + ) + }); // copy `libcartesi_jsonrpc.a` to OUT_DIR - let libcartesi_jsonrpc_path = libdir_path.join("libcartesi_jsonrpc.a"); - let libcartesi_jsonrpc_new_path = out_path.join("libcartesi_jsonrpc.a"); - fs::copy(libcartesi_jsonrpc_path, libcartesi_jsonrpc_new_path) - .expect("Failed to move `libcartesi_jsonrpc.a` to OUT_DIR"); + // let libcartesi_jsonrpc_path = libdir_path.join("libcartesi_jsonrpc.a"); + // let libcartesi_jsonrpc_new_path = out_path.join("libcartesi_jsonrpc.a"); + // fs::copy(libcartesi_jsonrpc_path, libcartesi_jsonrpc_new_path) + // .expect("Failed to move `libcartesi_jsonrpc.a` to OUT_DIR"); // tell Cargo where to look for libraries println!("cargo:rustc-link-search={}", out_path.to_str().unwrap()); @@ -174,7 +175,7 @@ fn copy_uarch(uarch_path: &PathBuf) { } #[cfg(feature = "download_uarch")] -fn download_uarch(machine_dir_path: &PathBuf) { +fn download_uarch(machine_dir_path: &Path) { // apply git patche for 0.18.1 let patch_file = machine_dir_path.join("add-generated-files.diff"); @@ -182,7 +183,7 @@ fn download_uarch(machine_dir_path: &PathBuf) { apply_git_patch(&patch_file, machine_dir_path); } -fn download_git_patch(patch_file: &PathBuf, target_tag: &str) { +fn download_git_patch(patch_file: &Path, target_tag: &str) { let emulator_git_url = "https://github.com/cartesi/machine-emulator"; let patch_url = format!( @@ -236,23 +237,25 @@ fn write_bytes_to_file(path: &str, data: Bytes) -> io::Result<()> { let mut file = OpenOptions::new() .write(true) .create(true) + .truncate(true) .open(path) - .expect(&format!("failed to open file {}", path)); + .unwrap_or_else(|_| panic!("failed to open file {}", path)); file.write_all(&data)?; file.flush() // Ensure all data is written to disk } +#[allow(dead_code)] fn clean(path: &PathBuf) { // clean build artifacts Command::new("make") - .args(&["clean", "depclean ", "distclean"]) + .args(["clean", "depclean ", "distclean"]) .current_dir(path) .status() .expect("Failed to run setup `make clean depclean distclean`"); Command::new("rm") - .args(&["src/*o.tmp"]) + .args(["src/*o.tmp"]) .current_dir(path) .status() .expect("Failed to delete src/*.o.tmp files"); diff --git a/prt/client-lua/player/reader.lua b/prt/client-lua/player/reader.lua index bd2a0321..7368787a 100644 --- a/prt/client-lua/player/reader.lua +++ b/prt/client-lua/player/reader.lua @@ -142,7 +142,7 @@ function Reader._get_block(block) error(string.format("Cast block failed:\n%s", str)) end - ret = str:match("timestamp (%d+)") + ret = str:match("number%s+(%d+)") handle:close() return ret diff --git a/prt/client-rs/src/arena/arena.rs b/prt/client-rs/src/arena/arena.rs index 84b87852..7ce36f83 100644 --- a/prt/client-rs/src/arena/arena.rs +++ b/prt/client-rs/src/arena/arena.rs @@ -65,7 +65,7 @@ pub struct CommitmentState { pub struct ClockState { pub allowance: u64, pub start_instant: u64, - pub block_time: u64, + pub block_number: u64, } impl ClockState { @@ -73,7 +73,7 @@ impl ClockState { if self.start_instant == 0 { true } else { - self.deadline() > self.block_time + self.deadline() > self.block_number } } @@ -81,7 +81,7 @@ impl ClockState { if self.start_instant == 0 { 0 } else { - self.block_time - self.deadline() + self.block_number - self.deadline() } } @@ -96,7 +96,7 @@ impl std::fmt::Display for ClockState { if self.start_instant == 0 { write!(f, "clock paused, {} seconds left", self.allowance) } else { - let time_elapsed = self.block_time - self.start_instant; + let time_elapsed = self.block_number - self.start_instant; if self.allowance >= time_elapsed { write!( f, diff --git a/prt/client-rs/src/arena/reader.rs b/prt/client-rs/src/arena/reader.rs index df53b8de..15e55cbe 100644 --- a/prt/client-rs/src/arena/reader.rs +++ b/prt/client-rs/src/arena/reader.rs @@ -161,17 +161,17 @@ impl StateReader { .call() .await?; - let block_time = self + let block_number = self .client .get_block(Latest.into(), BlockTransactionsKind::Hashes) .await? .expect("cannot get last block") .header - .timestamp; + .number; let clock_state = ClockState { allowance: commitment_return._0.allowance, start_instant: commitment_return._0.startInstant, - block_time, + block_number, }; Ok(CommitmentState { clock: clock_state, diff --git a/prt/client-rs/src/db/compute_state_access.rs b/prt/client-rs/src/db/compute_state_access.rs index 69c5ed8a..dc29a490 100644 --- a/prt/client-rs/src/db/compute_state_access.rs +++ b/prt/client-rs/src/db/compute_state_access.rs @@ -49,13 +49,13 @@ impl ComputeStateAccess { inputs: Option>, leafs: Vec, root_tournament: String, - compute_data_path: &str, + compute_data_path: PathBuf, ) -> Result { // initialize the database if it doesn't exist // fill the database from a json-format file, or the parameters // the database should be "/compute_data/0x_root_tournament_address/db" // the json file should be "/compute_data/0x_root_tournament_address/inputs_and_leafs.json" - let work_dir = format!("{compute_data_path}/{root_tournament}"); + let work_dir = compute_data_path.join(root_tournament); let work_path = PathBuf::from(work_dir); if !work_path.exists() { fs::create_dir_all(&work_path)?; diff --git a/prt/client-rs/src/strategy/gc.rs b/prt/client-rs/src/strategy/gc.rs index 74e9762a..ad51684f 100644 --- a/prt/client-rs/src/strategy/gc.rs +++ b/prt/client-rs/src/strategy/gc.rs @@ -19,7 +19,7 @@ impl GarbageCollector { arena_sender: &'a impl ArenaSender, tournament_states: &TournamentStateMap, ) -> Result<()> { - self.react_tournament(arena_sender, self.root_tournamet, &tournament_states) + self.react_tournament(arena_sender, self.root_tournamet, tournament_states) .await } @@ -59,10 +59,16 @@ impl GarbageCollector { tournament_state.level ); - arena_sender - .eliminate_match(tournament_address, m.id) - .await - .expect("fail to eliminate match"); + let elim = arena_sender.eliminate_match(tournament_address, m.id).await; + if elim.is_err() { + info!( + "failed to eliminate match for commitment {} and {} at tournament {} of level {}", + m.id.commitment_one, + m.id.commitment_two, + tournament_address, + tournament_state.level + ); + } } } Ok(()) diff --git a/prt/client-rs/src/strategy/player.rs b/prt/client-rs/src/strategy/player.rs index 0a5bda66..ed69e5b1 100644 --- a/prt/client-rs/src/strategy/player.rs +++ b/prt/client-rs/src/strategy/player.rs @@ -1,4 +1,5 @@ use std::collections::HashMap; +use std::path::PathBuf; use ::log::{debug, error, info}; use alloy::primitives::Address; @@ -40,10 +41,15 @@ impl Player { blockchain_config: &BlockchainConfig, machine_path: String, root_tournament: Address, + state_dir: PathBuf, ) -> Result { - let db = - ComputeStateAccess::new(inputs, leafs, root_tournament.to_string(), "/compute_data")?; - let reader = StateReader::new(&blockchain_config)?; + let db = ComputeStateAccess::new( + inputs, + leafs, + root_tournament.to_string(), + state_dir.join("compute_path"), + )?; + let reader = StateReader::new(blockchain_config)?; let gc = GarbageCollector::new(root_tournament); let commitment_builder = CachingMachineCommitmentBuilder::new(machine_path.clone()); Ok(Self { @@ -100,7 +106,7 @@ impl Player { ) -> Result> { info!("Enter tournament at address: {}", tournament_address); // TODO: print final state one and final state two - let tournament_state = get_tournament_state(&tournament_states, tournament_address); + let tournament_state = get_tournament_state(tournament_states, tournament_address); commitments.insert( tournament_state.address, diff --git a/prt/contracts/bindings-rs/Cargo.toml b/prt/contracts/bindings-rs/Cargo.toml index a1aaef4c..0d11f37a 100644 --- a/prt/contracts/bindings-rs/Cargo.toml +++ b/prt/contracts/bindings-rs/Cargo.toml @@ -15,5 +15,4 @@ readme = "README.md" repository = "https://github.com/cartesi/dave" [dependencies] -alloy = { version = "0.8.0", features = ["sol-types", "contract"] } - +alloy = { workspace = true, features = ["sol-types", "contract"] } diff --git a/prt/contracts/src/tournament/libs/Time.sol b/prt/contracts/src/tournament/libs/Time.sol index 42270a17..c26e9647 100644 --- a/prt/contracts/src/tournament/libs/Time.sol +++ b/prt/contracts/src/tournament/libs/Time.sol @@ -14,7 +14,7 @@ library Time { Duration constant ZERO_DURATION = Duration.wrap(0); function currentTime() internal view returns (Instant) { - return Instant.wrap(uint64(block.timestamp)); + return Instant.wrap(uint64(block.number)); } function add(Instant timestamp, Duration duration) diff --git a/prt/contracts/test/Clock.t.sol b/prt/contracts/test/Clock.t.sol index 0930b55a..d9aef430 100644 --- a/prt/contracts/test/Clock.t.sol +++ b/prt/contracts/test/Clock.t.sol @@ -62,10 +62,10 @@ contract ClockTest is Test { clock1.advanceClock(); assertTrue(clock1.hasTimeLeft(), "clock1 should have time left"); - vm.warp(vm.getBlockTimestamp() + clock1Allowance - 1); + vm.roll(vm.getBlockNumber() + clock1Allowance - 1); assertTrue(clock1.hasTimeLeft(), "clock1 should have time left"); - vm.warp(vm.getBlockTimestamp() + clock1Allowance); + vm.roll(vm.getBlockNumber() + clock1Allowance); assertTrue(!clock1.hasTimeLeft(), "clock1 should run out of time"); vm.expectRevert("can't advance clock with no time left"); diff --git a/prt/contracts/test/MultiTournament.t.sol b/prt/contracts/test/MultiTournament.t.sol index 7376915f..6aa44e02 100644 --- a/prt/contracts/test/MultiTournament.t.sol +++ b/prt/contracts/test/MultiTournament.t.sol @@ -55,11 +55,11 @@ contract MultiTournamentTest is Util, Test { ); // player 0 should win after fast forward time to tournament finishes - uint256 _t = vm.getBlockTimestamp(); + uint256 _t = vm.getBlockNumber(); uint256 _tournamentFinish = _t + Time.Duration.unwrap(ArbitrationConstants.MAX_ALLOWANCE); - vm.warp(_tournamentFinish); + vm.roll(_tournamentFinish); (_finished, _winner, _finalState) = topTournament.arbitrationResult(); uint256 _winnerPlayer = 0; @@ -76,12 +76,12 @@ contract MultiTournamentTest is Util, Test { ); // rewind time in half and pair commitment, expect a match - vm.warp(_t); + vm.roll(_t); // player 1 joins tournament Util.joinTournament(topTournament, 1, 0); // no dangling commitment available, should revert - vm.warp(_tournamentFinish); + vm.roll(_tournamentFinish); (_finished, _winner, _finalState) = topTournament.arbitrationResult(); // tournament not finished when still match going on @@ -298,14 +298,14 @@ contract MultiTournamentTest is Util, Test { assertFalse(_finished, "winner should be zero node"); // player 0 should win after fast forward time to inner tournament finishes - uint256 _t = vm.getBlockTimestamp(); + uint256 _t = vm.getBlockNumber(); // the delay is increased when a match is created uint256 _rootTournamentFinish = _t + Time.Duration.unwrap(ArbitrationConstants.MAX_ALLOWANCE) + Time.Duration.unwrap(ArbitrationConstants.MATCH_EFFORT); Util.joinTournament(middleTournament, 0, 1); - vm.warp(_rootTournamentFinish); + vm.roll(_rootTournamentFinish); (_finished, _winner,) = middleTournament.innerTournamentWinner(); topTournament.winInnerMatch( middleTournament, @@ -370,7 +370,7 @@ contract MultiTournamentTest is Util, Test { (_finished, _winner,) = middleTournament.innerTournamentWinner(); assertTrue(_winner.isZero(), "winner should be zero node"); - _t = vm.getBlockTimestamp(); + _t = vm.getBlockNumber(); // the delay is increased when a match is created _rootTournamentFinish = _t + Time.Duration.unwrap(ArbitrationConstants.MAX_ALLOWANCE); @@ -396,7 +396,7 @@ contract MultiTournamentTest is Util, Test { playerNodes[1][ArbitrationConstants.height(1) - 1] ); - vm.warp( + vm.roll( Time.Instant.unwrap( _player0Clock.startInstant.add(_player0Clock.allowance) ) @@ -410,7 +410,7 @@ contract MultiTournamentTest is Util, Test { _match = middleTournament.getMatch(_matchId.hashFromId()); assertFalse(_match.exists(), "match should be deleted"); - vm.warp(_middleTournamentFinish); + vm.roll(_middleTournamentFinish); (_finished, _winner,) = middleTournament.innerTournamentWinner(); topTournament.winInnerMatch( middleTournament, @@ -419,7 +419,7 @@ contract MultiTournamentTest is Util, Test { ); { - vm.warp(_rootTournamentFinish); + vm.roll(_rootTournamentFinish); (bool _finishedTop, Tree.Node _commitment, Machine.Hash _finalState) = topTournament.arbitrationResult(); @@ -450,17 +450,17 @@ contract MultiTournamentTest is Util, Test { topTournament.getMatch(_matchId.hashFromId()); assertTrue(_match.exists(), "match should exist"); - uint256 _t = vm.getBlockTimestamp(); + uint256 _t = vm.getBlockNumber(); // the delay is increased when a match is created uint256 _rootTournamentFinish = _t + 2 * Time.Duration.unwrap(ArbitrationConstants.MAX_ALLOWANCE); - vm.warp(_rootTournamentFinish - 1); + vm.roll(_rootTournamentFinish - 1); // cannot eliminate match when both blocks still have time vm.expectRevert(Tournament.EliminateByTimeout.selector); topTournament.eliminateMatchByTimeout(_matchId); - vm.warp(_rootTournamentFinish); + vm.roll(_rootTournamentFinish); topTournament.eliminateMatchByTimeout(_matchId); } } diff --git a/prt/contracts/test/Tournament.t.sol b/prt/contracts/test/Tournament.t.sol index 0f7c28db..2f8d0b4a 100644 --- a/prt/contracts/test/Tournament.t.sol +++ b/prt/contracts/test/Tournament.t.sol @@ -61,7 +61,7 @@ contract TournamentTest is Util, Test { function testTimeout() public { topTournament = Util.initializePlayer0Tournament(factory); - uint256 _t = vm.getBlockTimestamp(); + uint256 _t = vm.getBlockNumber(); // the delay is increased when a match is created uint256 _tournamentFinishWithMatch = _t + Time.Duration.unwrap(ArbitrationConstants.MAX_ALLOWANCE) @@ -81,7 +81,7 @@ contract TournamentTest is Util, Test { (Clock.State memory _player0Clock,) = topTournament.getCommitment( playerNodes[0][ArbitrationConstants.height(0)] ); - vm.warp( + vm.roll( Time.Instant.unwrap( _player0Clock.startInstant.add(_player0Clock.allowance) ) @@ -96,7 +96,7 @@ contract TournamentTest is Util, Test { playerNodes[1][ArbitrationConstants.height(0) - 1] ); - vm.warp(_tournamentFinishWithMatch); + vm.roll(_tournamentFinishWithMatch); (bool _finished, Tree.Node _winner, Machine.Hash _finalState) = topTournament.arbitrationResult(); @@ -114,7 +114,7 @@ contract TournamentTest is Util, Test { ); topTournament = Util.initializePlayer0Tournament(factory); - _t = vm.getBlockTimestamp(); + _t = vm.getBlockNumber(); // the delay is increased when a match is created _tournamentFinishWithMatch = _t @@ -138,7 +138,7 @@ contract TournamentTest is Util, Test { (Clock.State memory _player1Clock,) = topTournament.getCommitment( playerNodes[1][ArbitrationConstants.height(0)] ); - vm.warp( + vm.roll( Time.Instant.unwrap( _player1Clock.startInstant.add(_player1Clock.allowance) ) @@ -153,7 +153,7 @@ contract TournamentTest is Util, Test { playerNodes[0][ArbitrationConstants.height(0) - 1] ); - vm.warp(_tournamentFinishWithMatch); + vm.roll(_tournamentFinishWithMatch); (_finished, _winner, _finalState) = topTournament.arbitrationResult(); _winnerPlayer = 0; diff --git a/prt/tests/compute-rs/src/lib.rs b/prt/tests/compute-rs/src/lib.rs index 2886adc4..5ae95ab3 100644 --- a/prt/tests/compute-rs/src/lib.rs +++ b/prt/tests/compute-rs/src/lib.rs @@ -1,3 +1,5 @@ +use std::path::PathBuf; + use alloy::primitives::Address; use cartesi_prt_core::arena::BlockchainConfig; use clap::Parser; @@ -19,4 +21,7 @@ pub struct ComputeConfig { /// Address of root tournament #[arg(long, env, default_value = ANVIL_ROOT_TOURNAMENT)] pub root_tournament: Address, + /// Direcotry where state is stored. + #[arg(long, env, default_value = "_state")] + pub state_dir: PathBuf, } diff --git a/prt/tests/compute-rs/src/main.rs b/prt/tests/compute-rs/src/main.rs index 8412e7ae..4eb7bdd0 100644 --- a/prt/tests/compute-rs/src/main.rs +++ b/prt/tests/compute-rs/src/main.rs @@ -24,13 +24,14 @@ async fn main() -> Result<()> { let config = ComputeConfig::parse(); let blockchain_config = config.blockchain_config; let sender = EthArenaSender::new(&blockchain_config)?; - + let mut player = Player::new( None, Vec::new(), &blockchain_config, config.machine_path, config.root_tournament, + config.state_dir, ) .expect("fail to create player object"); @@ -39,7 +40,7 @@ async fn main() -> Result<()> { Ok(Some(state)) => { info!("Tournament finished, {:?}", state); let finished_path = Path::new(FINISHED_PATH); - touch(&finished_path)?; + touch(finished_path)?; } Err(e) => { error!("{}", e); diff --git a/prt/tests/compute/blockchain/node.lua b/prt/tests/compute/blockchain/node.lua index c7d5ba94..80ca463e 100644 --- a/prt/tests/compute/blockchain/node.lua +++ b/prt/tests/compute/blockchain/node.lua @@ -3,12 +3,22 @@ local helper = require "utils.helper" local default_account_number = 40 -- spawn an anvil node with 40 accounts, auto-mine, and finalize block at height N-2 -local function start_blockchain() +local function start_blockchain(load_state) print(string.format("Starting blockchain with %d accounts...", default_account_number)) - local cmd = string.format( - [[sh -c "echo $$ ; exec anvil --block-time 1 --slots-in-an-epoch 1 -a %d > anvil.log 2>&1"]], - default_account_number) + local cmd + if load_state then + cmd = string.format( + [[sh -c "echo $$ ; exec anvil --load-state %s --block-time 1 --slots-in-an-epoch 1 -a %d > anvil.log 2>&1"]], + load_state, + default_account_number + ) + else + cmd = string.format( + [[sh -c "echo $$ ; exec anvil --block-time 1 --slots-in-an-epoch 1 -a %d > anvil.log 2>&1"]], + default_account_number + ) + end local reader = io.popen(cmd) assert(reader, "`popen` returned nil reader") @@ -34,10 +44,10 @@ end local Blockchain = {} Blockchain.__index = Blockchain -function Blockchain:new() +function Blockchain:new(load_state) local blockchain = {} - local handle = start_blockchain() + local handle = start_blockchain(load_state) blockchain.pks, blockchain.endpoint = capture_blockchain_data() blockchain._handle = handle diff --git a/prt/tests/compute/blockchain/utils.lua b/prt/tests/compute/blockchain/utils.lua index 3130dbfe..508fba2f 100644 --- a/prt/tests/compute/blockchain/utils.lua +++ b/prt/tests/compute/blockchain/utils.lua @@ -21,7 +21,6 @@ end local deploy_cmd = [[sh -c "cd %s && ./deploy_anvil.sh"]] local function deploy_contracts(contracts_path) - print(string.format(deploy_cmd, contracts_path)) local reader = io.popen(string.format(deploy_cmd, contracts_path)) assert(reader, "Failed to open process for deploy command: " .. deploy_cmd) local output = reader:read("*a") diff --git a/prt/tests/rollups/.gitignore b/prt/tests/rollups/.gitignore new file mode 100644 index 00000000..36c26874 --- /dev/null +++ b/prt/tests/rollups/.gitignore @@ -0,0 +1,2 @@ +*.log +_state/ diff --git a/prt/tests/rollups/anvil.log b/prt/tests/rollups/anvil.log deleted file mode 100644 index dba9d5c8..00000000 --- a/prt/tests/rollups/anvil.log +++ /dev/null @@ -1,137 +0,0 @@ - - - _ _ - (_) | | - __ _ _ __ __ __ _ | | - / _` | | '_ \ \ \ / / | | | | - | (_| | | | | | \ V / | | | | - \__,_| |_| |_| \_/ |_| |_| - - 0.2.0 (c4fcf12 2024-12-12T00:23:11.566737000Z) - https://github.com/foundry-rs/foundry - -Available Accounts -================== - -(0) 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 (10000.000000000000000000 ETH) -(1) 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 (10000.000000000000000000 ETH) -(2) 0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC (10000.000000000000000000 ETH) -(3) 0x90F79bf6EB2c4f870365E785982E1f101E93b906 (10000.000000000000000000 ETH) -(4) 0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65 (10000.000000000000000000 ETH) -(5) 0x9965507D1a55bcC2695C58ba16FB37d819B0A4dc (10000.000000000000000000 ETH) -(6) 0x976EA74026E726554dB657fA54763abd0C3a0aa9 (10000.000000000000000000 ETH) -(7) 0x14dC79964da2C08b23698B3D3cc7Ca32193d9955 (10000.000000000000000000 ETH) -(8) 0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f (10000.000000000000000000 ETH) -(9) 0xa0Ee7A142d267C1f36714E4a8F75612F20a79720 (10000.000000000000000000 ETH) -(10) 0xBcd4042DE499D14e55001CcbB24a551F3b954096 (10000.000000000000000000 ETH) -(11) 0x71bE63f3384f5fb98995898A86B02Fb2426c5788 (10000.000000000000000000 ETH) -(12) 0xFABB0ac9d68B0B445fB7357272Ff202C5651694a (10000.000000000000000000 ETH) -(13) 0x1CBd3b2770909D4e10f157cABC84C7264073C9Ec (10000.000000000000000000 ETH) -(14) 0xdF3e18d64BC6A983f673Ab319CCaE4f1a57C7097 (10000.000000000000000000 ETH) -(15) 0xcd3B766CCDd6AE721141F452C550Ca635964ce71 (10000.000000000000000000 ETH) -(16) 0x2546BcD3c84621e976D8185a91A922aE77ECEc30 (10000.000000000000000000 ETH) -(17) 0xbDA5747bFD65F08deb54cb465eB87D40e51B197E (10000.000000000000000000 ETH) -(18) 0xdD2FD4581271e230360230F9337D5c0430Bf44C0 (10000.000000000000000000 ETH) -(19) 0x8626f6940E2eb28930eFb4CeF49B2d1F2C9C1199 (10000.000000000000000000 ETH) -(20) 0x09DB0a93B389bEF724429898f539AEB7ac2Dd55f (10000.000000000000000000 ETH) -(21) 0x02484cb50AAC86Eae85610D6f4Bf026f30f6627D (10000.000000000000000000 ETH) -(22) 0x08135Da0A343E492FA2d4282F2AE34c6c5CC1BbE (10000.000000000000000000 ETH) -(23) 0x5E661B79FE2D3F6cE70F5AAC07d8Cd9abb2743F1 (10000.000000000000000000 ETH) -(24) 0x61097BA76cD906d2ba4FD106E757f7Eb455fc295 (10000.000000000000000000 ETH) -(25) 0xDf37F81dAAD2b0327A0A50003740e1C935C70913 (10000.000000000000000000 ETH) -(26) 0x553BC17A05702530097c3677091C5BB47a3a7931 (10000.000000000000000000 ETH) -(27) 0x87BdCE72c06C21cd96219BD8521bDF1F42C78b5e (10000.000000000000000000 ETH) -(28) 0x40Fc963A729c542424cD800349a7E4Ecc4896624 (10000.000000000000000000 ETH) -(29) 0x9DCCe783B6464611f38631e6C851bf441907c710 (10000.000000000000000000 ETH) -(30) 0x1BcB8e569EedAb4668e55145Cfeaf190902d3CF2 (10000.000000000000000000 ETH) -(31) 0x8263Fce86B1b78F95Ab4dae11907d8AF88f841e7 (10000.000000000000000000 ETH) -(32) 0xcF2d5b3cBb4D7bF04e3F7bFa8e27081B52191f91 (10000.000000000000000000 ETH) -(33) 0x86c53Eb85D0B7548fea5C4B4F82b4205C8f6Ac18 (10000.000000000000000000 ETH) -(34) 0x1aac82773CB722166D7dA0d5b0FA35B0307dD99D (10000.000000000000000000 ETH) -(35) 0x2f4f06d218E426344CFE1A83D53dAd806994D325 (10000.000000000000000000 ETH) -(36) 0x1003ff39d25F2Ab16dBCc18EcE05a9B6154f65F4 (10000.000000000000000000 ETH) -(37) 0x9eAF5590f2c84912A08de97FA28d0529361Deb9E (10000.000000000000000000 ETH) -(38) 0x11e8F3eA3C6FcF12EcfF2722d75CEFC539c51a1C (10000.000000000000000000 ETH) -(39) 0x7D86687F980A56b832e9378952B738b614A99dc6 (10000.000000000000000000 ETH) - -Private Keys -================== - -(0) 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 -(1) 0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d -(2) 0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a -(3) 0x7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6 -(4) 0x47e179ec197488593b187f80a00eb0da91f1b9d0b13f8733639f19c30a34926a -(5) 0x8b3a350cf5c34c9194ca85829a2df0ec3153be0318b5e2d3348e872092edffba -(6) 0x92db14e403b83dfe3df233f83dfa3a0d7096f21ca9b0d6d6b8d88b2b4ec1564e -(7) 0x4bbbf85ce3377467afe5d46f804f221813b2bb87f24d81f60f1fcdbf7cbf4356 -(8) 0xdbda1821b80551c9d65939329250298aa3472ba22feea921c0cf5d620ea67b97 -(9) 0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6 -(10) 0xf214f2b2cd398c806f84e317254e0f0b801d0643303237d97a22a48e01628897 -(11) 0x701b615bbdfb9de65240bc28bd21bbc0d996645a3dd57e7b12bc2bdf6f192c82 -(12) 0xa267530f49f8280200edf313ee7af6b827f2a8bce2897751d06a843f644967b1 -(13) 0x47c99abed3324a2707c28affff1267e45918ec8c3f20b8aa892e8b065d2942dd -(14) 0xc526ee95bf44d8fc405a158bb884d9d1238d99f0612e9f33d006bb0789009aaa -(15) 0x8166f546bab6da521a8369cab06c5d2b9e46670292d85c875ee9ec20e84ffb61 -(16) 0xea6c44ac03bff858b476bba40716402b03e41b8e97e276d1baec7c37d42484a0 -(17) 0x689af8efa8c651a91ad287602527f3af2fe9f6501a7ac4b061667b5a93e037fd -(18) 0xde9be858da4a475276426320d5e9262ecfc3ba460bfac56360bfa6c4c28b4ee0 -(19) 0xdf57089febbacf7ba0bc227dafbffa9fc08a93fdc68e1e42411a14efcf23656e -(20) 0xeaa861a9a01391ed3d587d8a5a84ca56ee277629a8b02c22093a419bf240e65d -(21) 0xc511b2aa70776d4ff1d376e8537903dae36896132c90b91d52c1dfbae267cd8b -(22) 0x224b7eb7449992aac96d631d9677f7bf5888245eef6d6eeda31e62d2f29a83e4 -(23) 0x4624e0802698b9769f5bdb260a3777fbd4941ad2901f5966b854f953497eec1b -(24) 0x375ad145df13ed97f8ca8e27bb21ebf2a3819e9e0a06509a812db377e533def7 -(25) 0x18743e59419b01d1d846d97ea070b5a3368a3e7f6f0242cf497e1baac6972427 -(26) 0xe383b226df7c8282489889170b0f68f66af6459261f4833a781acd0804fafe7a -(27) 0xf3a6b71b94f5cd909fb2dbb287da47badaa6d8bcdc45d595e2884835d8749001 -(28) 0x4e249d317253b9641e477aba8dd5d8f1f7cf5250a5acadd1229693e262720a19 -(29) 0x233c86e887ac435d7f7dc64979d7758d69320906a0d340d2b6518b0fd20aa998 -(30) 0x85a74ca11529e215137ccffd9c95b2c72c5fb0295c973eb21032e823329b3d2d -(31) 0xac8698a440d33b866b6ffe8775621ce1a4e6ebd04ab7980deb97b3d997fc64fb -(32) 0xf076539fbce50f0513c488f32bf81524d30ca7a29f400d68378cc5b1b17bc8f2 -(33) 0x5544b8b2010dbdbef382d254802d856629156aba578f453a76af01b81a80104e -(34) 0x47003709a0a9a4431899d4e014c1fd01c5aad19e873172538a02370a119bae11 -(35) 0x9644b39377553a920edc79a275f45fa5399cbcf030972f771d0bca8097f9aad3 -(36) 0xcaa7b4a2d30d1d565716199f068f69ba5df586cf32ce396744858924fdf827f0 -(37) 0xfc5a028670e1b6381ea876dd444d3faaee96cffae6db8d93ca6141130259247c -(38) 0x5b92c5fe82d4fabee0bc6d95b4b8a3f9680a0ed7801f631035528f32c9eb2ad5 -(39) 0xb68ac4aa2137dd31fd0732436d8e59e959bb62b4db2e6107b15f594caf0f405f - -Wallet -================== -Mnemonic: test test test test test test test test test test test junk -Derivation path: m/44'/60'/0'/0/ - - -Chain ID -================== - -31337 - -Base Fee -================== - -1000000000 - -Gas Limit -================== - -30000000 - -Genesis Timestamp -================== - -1734900611 - -Listening on 127.0.0.1:8545 - - Block Number: 1 - Block Hash: 0xe5edf67afba28918f38da1ed1f83eb07d0dc36ccb09a9f2b8c7ff1df9b908209 - Block Time: "Sun, 22 Dec 2024 20:50:12 +0000" - - - Block Number: 2 - Block Hash: 0xb2e8dd2ca69fe5311805c07c2997c8ecbf9157088456ce2568f083c563850d11 - Block Time: "Sun, 22 Dec 2024 20:50:13 +0000" - diff --git a/prt/tests/rollups/dave/node.lua b/prt/tests/rollups/dave/node.lua index 4dcdf953..b08cb878 100644 --- a/prt/tests/rollups/dave/node.lua +++ b/prt/tests/rollups/dave/node.lua @@ -2,10 +2,10 @@ local helper = require "utils.helper" local function start_dave_node(machine_path, db_path, sleep_duration, verbosity, trace_level) local cmd = string.format( - [[sh -c "echo $$ ; exec env MACHINE_PATH='%s' PATH_TO_DB='%s' \ + [[sh -c "echo $$ ; exec env MACHINE_PATH='%s' STATE_DIR='%s' \ SLEEP_DURATION=%d RUST_BACKTRACE='%s' \ RUST_LOG='none',cartesi_prt_core='%s',rollups_compute_runner='%s',rollups_epoch_manager='%s' \ - ./dave-rollups > dave.log 2>&1"]], + cargo run --bin dave-rollups > dave.log 2>&1"]], machine_path, db_path, sleep_duration, trace_level, verbosity, verbosity, verbosity) local reader = io.popen(cmd) @@ -29,8 +29,9 @@ Dave.__index = Dave function Dave:new(machine_path, sleep_duration, verbosity, trace_level) local n = {} + os.execute "rm -rf _state && mkdir _state" - local handle = start_dave_node(machine_path, "./dave.db", sleep_duration, verbosity, trace_level) + local handle = start_dave_node(machine_path, "_state/", sleep_duration, verbosity, trace_level) n._handle = handle diff --git a/prt/tests/rollups/program/.dockerignore b/prt/tests/rollups/program/.dockerignore deleted file mode 100644 index 643b3a57..00000000 --- a/prt/tests/rollups/program/.dockerignore +++ /dev/null @@ -1 +0,0 @@ -**/*tar.gz diff --git a/prt/tests/rollups/program/.gitignore b/prt/tests/rollups/program/.gitignore deleted file mode 100644 index 643b3a57..00000000 --- a/prt/tests/rollups/program/.gitignore +++ /dev/null @@ -1 +0,0 @@ -**/*tar.gz diff --git a/prt/tests/rollups/program/echo/.gitignore b/prt/tests/rollups/program/echo/.gitignore deleted file mode 100644 index 15336dbe..00000000 --- a/prt/tests/rollups/program/echo/.gitignore +++ /dev/null @@ -1 +0,0 @@ -echo-program/ diff --git a/prt/tests/rollups/program/echo/Dockerfile b/prt/tests/rollups/program/echo/Dockerfile deleted file mode 100644 index 9361a52b..00000000 --- a/prt/tests/rollups/program/echo/Dockerfile +++ /dev/null @@ -1,13 +0,0 @@ -FROM cartesi/machine-emulator:0.18.1 -USER root -RUN apt-get update && \ - apt-get install -y wget - -RUN wget https://github.com/cartesi/image-kernel/releases/download/v0.20.0/linux-6.5.13-ctsi-1-v0.20.0.bin \ - -O ./linux.bin -RUN wget https://github.com/cartesi/machine-emulator-tools/releases/download/v0.16.1/rootfs-tools-v0.16.1.ext2 \ - -O ./rootfs.ext2 - -COPY ./gen_machine_echo.sh . -RUN chmod +x gen_machine_echo.sh -RUN ./gen_machine_echo.sh && tar -zvcf /echo-program.tar.gz echo-program diff --git a/prt/tests/rollups/program/echo/Makefile b/prt/tests/rollups/program/echo/Makefile deleted file mode 100644 index 584e9e30..00000000 --- a/prt/tests/rollups/program/echo/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -ECHO_MACHINE_PATH := "/root/program/echo-program" - -help: - @echo ' build-echo - build echo machine image' - -build-echo: - @docker build -t echo:test . - @docker cp $(shell docker create echo:test):/echo-program.tar.gz . - -.PHONY: help build-echo diff --git a/prt/tests/rollups/program/echo/README.md b/prt/tests/rollups/program/echo/README.md deleted file mode 100644 index f726fb17..00000000 --- a/prt/tests/rollups/program/echo/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# Simple echo program - -## Generate program - -From this directory, run the following: - -``` -docker build -t echo:test . -docker cp $(docker create echo:test):/echo-program.tar.gz . -``` diff --git a/prt/tests/rollups/program/echo/gen_machine_echo.sh b/prt/tests/rollups/program/echo/gen_machine_echo.sh deleted file mode 100755 index 99252fff..00000000 --- a/prt/tests/rollups/program/echo/gen_machine_echo.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -cartesi-machine --ram-image=./linux.bin \ - --flash-drive=label:root,filename:./rootfs.ext2 \ - --no-rollback --store=./echo-program \ - -- "ioctl-echo-loop --vouchers=1 --notices=1 --reports=1 --verbose=1" diff --git a/prt/tests/rollups/prt_rollups.lua b/prt/tests/rollups/prt_rollups.lua index e827a306..1f90ec17 100755 --- a/prt/tests/rollups/prt_rollups.lua +++ b/prt/tests/rollups/prt_rollups.lua @@ -1,5 +1,12 @@ require "setup_path" + +-- TODO load from deployment file `addresses` +-- consensus contract address in anvil deployment +local CONSENSUS_ADDRESS = "0x0165878a594ca255338adfa4d48449f69242eb8f" +-- input contract address in anvil deployment +local INPUT_BOX_ADDRESS = "0x5FbDB2315678afecb367f032d93F642f64180aa3"; + -- amount of time sleep between each react local SLEEP_TIME = 2 -- amount of time to fastforward if `IDLE_LIMIT` is reached @@ -12,10 +19,6 @@ local NODE_DELAY = 3 local FAKE_COMMITMENT_COUNT = 1 -- number of idle players local IDLE_PLAYER_COUNT = 0 --- consensus contract address in anvil deployment -local CONSENSUS_ADDRESS = "0x0165878A594ca255338adfa4d48449f69242Eb8F" --- input contract address in anvil deployment -local INPUT_BOX_ADDRESS = "0x5FbDB2315678afecb367f032d93F642f64180aa3"; -- app contract address in anvil deployment local APP_ADDRESS = "0x0000000000000000000000000000000000000000"; -- Hello from Dave! @@ -49,7 +52,7 @@ local Reader = require "dave.reader" local Sender = require "dave.sender" local ROOT_LEAFS_QUERY = -[[sqlite3 /compute_data/%s/db 'select level,base_cycle,compute_leaf_index,repetitions,HEX(compute_leaf) +[[sqlite3 ./_state/compute_path/%s/db 'select level,base_cycle,compute_leaf_index,repetitions,HEX(compute_leaf) from compute_leafs where level=0 ORDER BY compute_leaf_index ASC']] local function build_root_commitment_from_db(machine_path, root_tournament) local builder = MerkleBuilder:new() @@ -80,7 +83,7 @@ local function build_root_commitment_from_db(machine_path, root_tournament) end local INPUTS_QUERY = -[[sqlite3 /compute_data/%s/db 'select HEX(input) +[[sqlite3 ./_state/compute_path/%s/db 'select HEX(input) from inputs ORDER BY input_index ASC']] local function get_inputs_from_db(root_tournament) local handle = io.popen(string.format(INPUTS_QUERY, root_tournament)) @@ -168,19 +171,21 @@ local function run_players(player_coroutines) end -- Main Execution -local rollups_machine_path = os.getenv("MACHINE_PATH") +local rpath = assert(io.popen("realpath " .. assert(os.getenv("MACHINE_PATH")))) +local rollups_machine_path = assert(rpath:read()) +rpath:close() -local blockchain_node = Blockchain:new() +local blockchain_node = Blockchain:new(rollups_machine_path .. "/anvil_state.json") time.sleep(NODE_DELAY) -blockchain_utils.deploy_contracts("../../../cartesi-rollups/contracts") -time.sleep(NODE_DELAY) +-- blockchain_utils.deploy_contracts("../../../cartesi-rollups/contracts") +-- time.sleep(NODE_DELAY) -- trace, debug, info, warn, error local verbosity = os.getenv("VERBOSITY") or 'debug' -- 0, 1, full local trace_level = os.getenv("TRACE_LEVEL") or 'full' -local dave_node = Dave:new(rollups_machine_path, SLEEP_TIME, verbosity, trace_level) +local dave_node = Dave:new(rollups_machine_path .. "/machine-image", SLEEP_TIME, verbosity, trace_level) time.sleep(NODE_DELAY) local reader = Reader:new(blockchain_constants.endpoint) @@ -201,11 +206,11 @@ while true do -- react to last sealed epoch local root_tournament = sealed_epochs[#sealed_epochs].tournament - local work_path = string.format("/compute_data/%s", root_tournament) + local work_path = string.format("./_state/compute_path/%s", root_tournament) if helper.exists(work_path) then print(string.format("sybil player attacking epoch %d", last_sealed_epoch.epoch_number)) - local epoch_machine_path = string.format("/rollups_data/%d/0", last_sealed_epoch.epoch_number) + local epoch_machine_path = string.format("./_state/snapshots/%d/0", last_sealed_epoch.epoch_number) local player_coroutines = setup_players(root_tournament, epoch_machine_path) run_players(player_coroutines) end diff --git a/test/programs/echo/.gitkeep b/test/programs/echo/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/test/programs/justfile b/test/programs/justfile index b8be0c20..8064e9a6 100644 --- a/test/programs/justfile +++ b/test/programs/justfile @@ -10,4 +10,12 @@ clean-deps: echo: + cartesi-machine --ram-image=./linux.bin \ + --flash-drive=label:root,filename:./rootfs.ext2 \ + --no-rollback --store=./echo/machine-image \ + -- "ioctl-echo-loop --vouchers=1 --notices=1 --reports=1 --verbose=1" ./build_anvil_state.sh "echo" + +clean-echo: + rm -f echo/_anvil.log echo/addresses echo/anvil_state.json + rm -rf echo/machine-image