diff --git a/Cargo.lock b/Cargo.lock index 8d3818e70..20d2733f2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8466,8 +8466,11 @@ dependencies = [ "aptos-types", "bcs 0.1.6 (git+https://github.com/movementlabsxyz/bcs.git?rev=bc16d2d39cabafaabd76173dd1b04b2aa170cf0c)", "chrono", + "dot-movement", "futures", "godfig", + "movement-config", + "once_cell", "rand 0.7.3", "serde", "tokio", diff --git a/benches/howzit/Cargo.toml b/benches/howzit/Cargo.toml index 91aa30480..8d352cc35 100644 --- a/benches/howzit/Cargo.toml +++ b/benches/howzit/Cargo.toml @@ -16,21 +16,24 @@ name = "howzit-bench" path = "src/bin/howzit-bench.rs" [dependencies] +anyhow = { workspace = true } +aptos-cached-packages = { workspace = true } +aptos-framework = { workspace = true } aptos-sdk = { workspace = true } aptos-types = { workspace = true } -aptos-framework = { workspace = true } -aptos-cached-packages = { workspace = true } -tokio = { workspace = true } -serde = { workspace = true, features = ["derive"] } -anyhow = { workspace = true } bcs = { workspace = true } +chrono = { workspace = true } +futures = { workspace = true } godfig = { workspace = true } +dot-movement = { workspace = true } +movement-config = { workspace = true } rand = { workspace = true } -futures = { workspace = true } -url = { workspace = true } +serde = { workspace = true, features = ["derive"] } +tokio = { workspace = true } tracing = { workspace = true } tracing-subscriber = { workspace = true } -chrono = { workspace = true } +url = { workspace = true } +once_cell = { workspace = true } [lints] diff --git a/benches/howzit/howzit/Move.toml b/benches/howzit/howzit/Move.toml index d7f8ed030..f09664944 100644 --- a/benches/howzit/howzit/Move.toml +++ b/benches/howzit/howzit/Move.toml @@ -9,8 +9,8 @@ howzit = '_' [dev-addresses] [dependencies.AptosFramework] -git = "https://github.com/aptos-labs/aptos-core.git" -rev = "mainnet" +git = "https://github.com/movementlabsxyz/aptos-core" +rev = "movement" subdir = "aptos-move/framework/aptos-framework" [dev-dependencies] diff --git a/benches/howzit/src/bin/howzit-bench.rs b/benches/howzit/src/bin/howzit-bench.rs index 32f5d7fec..a066d93b8 100644 --- a/benches/howzit/src/bin/howzit-bench.rs +++ b/benches/howzit/src/bin/howzit-bench.rs @@ -1,8 +1,62 @@ use anyhow::Context; -use aptos_sdk::rest_client::{AptosBaseUrl, Client}; use howzit::Howzit; +use once_cell::sync::Lazy; use std::io::Write; -use std::{env, path::PathBuf}; +use std::{env, path::PathBuf, str::FromStr}; +use url::Url; + +static SUZUKA_CONFIG: Lazy = Lazy::new(|| { + let dot_movement = dot_movement::DotMovement::try_from_env().unwrap(); + let config = dot_movement.try_get_config_from_json::().unwrap(); + config +}); + +static NODE_URL: Lazy = Lazy::new(|| { + let mut node_connection_address = SUZUKA_CONFIG + .execution_config + .maptos_config + .client + .maptos_rest_connection_hostname + .clone(); + + if node_connection_address == "0.0.0.0" { + node_connection_address = "127.0.0.1".to_string(); + } + + let node_connection_port = SUZUKA_CONFIG + .execution_config + .maptos_config + .client + .maptos_rest_connection_port + .clone(); + + let node_connection_url = + format!("http://{}:{}", node_connection_address, node_connection_port); + Url::from_str(&node_connection_url).unwrap() +}); + +static FAUCET_URL: Lazy = Lazy::new(|| { + let mut faucet_listen_address = SUZUKA_CONFIG + .execution_config + .maptos_config + .client + .maptos_faucet_rest_connection_hostname + .clone(); + + if faucet_listen_address == "0.0.0.0" { + faucet_listen_address = "127.0.0.1".to_string(); + } + + let faucet_listen_port = SUZUKA_CONFIG + .execution_config + .maptos_config + .client + .maptos_faucet_rest_connection_port + .clone(); + + let faucet_listen_url = format!("http://{}:{}", faucet_listen_address, faucet_listen_port); + Url::from_str(&faucet_listen_url).unwrap() +}); #[tokio::main] pub async fn main() -> Result<(), anyhow::Error> { @@ -14,27 +68,22 @@ pub async fn main() -> Result<(), anyhow::Error> { ) .init(); + let token = std::env::var("AUTH_TOKEN").context("AUTH_TOKEN not set")?; + let crate_path = env!("CARGO_MANIFEST_DIR"); let crate_path_buf = PathBuf::from(crate_path); - let token = std::env::var("AUTH_TOKEN").context("AUTH_TOKEN not set")?; - let rest_url = std::env::var("REST_URL") - .unwrap_or("https://aptos.devnet.suzuka.movementlabs.xyz".to_string()); - let faucet_url = std::env::var("FAUCET_URL") - .unwrap_or("https://faucet.devnet.suzuka.movementlabs.xyz".to_string()); let bench_output_file = std::env::var("BENCH_OUTPUT_FILE").unwrap_or("howzit_bench_output.dat".to_string()); - let rest_client_builder = Client::builder(AptosBaseUrl::Custom(rest_url.parse()?)) - .header("Authorization", format!("Bearer {}", token).as_str())?; - let rest_client = rest_client_builder.build(); - let howzit = Howzit::generate( crate_path_buf.join("howzit"), - rest_client.clone(), - faucet_url.parse()?, + NODE_URL.clone(), + FAUCET_URL.clone(), token, ); + tracing::info!("Generated howzit"); + howzit.build_and_publish().await?; // fund the accounts in an orderly manner diff --git a/benches/howzit/src/howzit.rs b/benches/howzit/src/howzit.rs index c037f7b5d..d5a2d1eb5 100644 --- a/benches/howzit/src/howzit.rs +++ b/benches/howzit/src/howzit.rs @@ -80,21 +80,23 @@ pub struct Howzit { pub rest_client: Client, faucet_client_url: Url, pub faucet_client: FaucetClient, + /// Only required if using on a live network pub faucet_auth_token: String, } impl Clone for Howzit { fn clone(&self) -> Self { + let mut faucet_client = FaucetClient::new_from_rest_client( + self.faucet_client_url.clone(), + self.rest_client.clone(), + ); + faucet_client = faucet_client.with_auth_token(self.faucet_auth_token.clone()); Howzit { howzit_package_path: self.howzit_package_path.clone(), wallet: self.wallet.clone(), rest_client: self.rest_client.clone(), faucet_client_url: self.faucet_client_url.clone(), - faucet_client: FaucetClient::new_from_rest_client( - self.faucet_client_url.clone(), - self.rest_client.clone(), - ) - .with_auth_token(self.faucet_auth_token.clone()), + faucet_client, faucet_auth_token: self.faucet_auth_token.clone(), } } @@ -104,19 +106,20 @@ impl Howzit { /// Generates a new Howzit instance with a random wallet pub fn generate( howzit_package_path: PathBuf, - rest_client: Client, + node_url: Url, faucet_client_url: Url, - faucet_auth_token: String, + token: String, ) -> Self { let wallet = LocalAccount::generate(&mut rand::rngs::OsRng); + let mut faucet_client = FaucetClient::new(faucet_client_url.clone(), node_url.clone()); + faucet_client = faucet_client.with_auth_token(token.clone()); Howzit { howzit_package_path, wallet: Arc::new(RwLock::new(wallet)), - rest_client: rest_client.clone(), - faucet_client_url: faucet_client_url.clone(), - faucet_client: FaucetClient::new_from_rest_client(faucet_client_url, rest_client) - .with_auth_token(faucet_auth_token.clone()), - faucet_auth_token, + rest_client: Client::new(node_url.clone()), + faucet_client_url, + faucet_client, + faucet_auth_token: token, } } @@ -220,7 +223,8 @@ impl Howzit { tracing::info!("Funding Alice"); let start_time = chrono::Utc::now(); match self.faucet_client.fund(alice.address(), 10_000_000_000).await { - Ok(_) => { + Ok(v) => { + tracing::info!("Successfully created Alice account: {:?}", v); let end_time = chrono::Utc::now(); let mut results = results.write().await; results.push(( @@ -249,7 +253,8 @@ impl Howzit { tracing::info!("Funding Bob"); let start_time = chrono::Utc::now(); match self.faucet_client.fund(bob.address(), 10_000_000_000).await { - Ok(_) => { + Ok(v) => { + tracing::info!("Successfully created Bob account: {:?}", v); let end_time = chrono::Utc::now(); let mut results = results.write().await; results.push(( diff --git a/process-compose/movement-full-node/process-compose.bench-howzit-local.yml b/process-compose/movement-full-node/process-compose.bench-howzit-local.yml new file mode 100644 index 000000000..fc0c04963 --- /dev/null +++ b/process-compose/movement-full-node/process-compose.bench-howzit-local.yml @@ -0,0 +1,26 @@ +version: "3" + + +processes: + + # setup: + # environment: + # - APTOS_ACCOUNT_WHITELIST=$DOT_MOVEMENT_PATH/default_signer_address_whitelist + # - MAPTOS_PRIVATE_KEY=random + # + # movement-faucet: + # command : | + # movement-faucet-service run-simple --do-not-delegate + + howzit: + environment: + - "AUTH_TOKEN=notreal" + command: | + cargo run --bin howzit-bench + depends_on: + movement-full-node: + condition: process_healthy + movement-faucet: + condition: process_healthy + availability: + exit_on_end: true diff --git a/process-compose/movement-full-node/process-compose.howzit.yml b/process-compose/movement-full-node/process-compose.howzit.yml deleted file mode 100644 index f3363cfcd..000000000 --- a/process-compose/movement-full-node/process-compose.howzit.yml +++ /dev/null @@ -1,19 +0,0 @@ -version: "3" - - -processes: - - howzit: - environment: - - "AUTH_TOKEN=notrealnotneeded" - - "REST_URL=http://0.0.0.0:30731" - - "FAUCET_URL=http://0.0.0.0:30732" - command: | - cargo run --bin howzit-bench - depends_on: - movement-full-node: - condition: process_healthy - movement-faucet: - condition: process_healthy - availability: - exit_on_end: true \ No newline at end of file