diff --git a/src/ansible/extra_vars.rs b/src/ansible/extra_vars.rs index d5b381c..9c057b4 100644 --- a/src/ansible/extra_vars.rs +++ b/src/ansible/extra_vars.rs @@ -7,7 +7,7 @@ use crate::inventory::VirtualMachine; use crate::NodeType; use crate::{ansible::provisioning::ProvisionOptions, CloudProvider, EvmNetwork}; -use crate::{BinaryOption, Error, EvmCustomTestnetData, Result}; +use crate::{BinaryOption, Error, Result}; use alloy::hex::ToHexExt; use alloy::signers::local::PrivateKeySigner; use serde_json::Value; @@ -293,7 +293,6 @@ pub fn build_node_extra_vars_doc( bootstrap_multiaddr: Option, node_instance_count: u16, evm_network: EvmNetwork, - evm_testnet_data: Option, ) -> Result { let mut extra_vars = ExtraVarsDocBuilder::default(); extra_vars.add_variable("provider", cloud_provider); @@ -351,10 +350,14 @@ pub fn build_node_extra_vars_doc( extra_vars.add_variable("rewards_address", &options.rewards_address); extra_vars.add_variable("evm_network_type", &evm_network.to_string()); - if let Some(evm_data) = evm_testnet_data { - extra_vars.add_variable("evm_rpc_url", &evm_data.rpc_url); - extra_vars.add_variable("evm_payment_token_address", &evm_data.payment_token_address); - extra_vars.add_variable("evm_data_payments_address", &evm_data.data_payments_address); + if let Some(evm_data_payment_token_address) = &options.evm_data_payments_address { + extra_vars.add_variable("evm_data_payments_address", evm_data_payment_token_address); + } + if let Some(evm_payment_token_address) = &options.evm_payment_token_address { + extra_vars.add_variable("evm_payment_token_address", evm_payment_token_address); + } + if let Some(evm_rpc_url) = &options.evm_rpc_url { + extra_vars.add_variable("evm_rpc_url", evm_rpc_url); } Ok(extra_vars.build()) @@ -377,7 +380,6 @@ pub fn build_uploaders_extra_vars_doc( cloud_provider: &str, options: &ProvisionOptions, genesis_multiaddr: &str, - evm_testnet_data: Option, sk_map: &HashMap>, ) -> Result { let mut extra_vars: ExtraVarsDocBuilder = ExtraVarsDocBuilder::default(); @@ -398,16 +400,14 @@ pub fn build_uploaders_extra_vars_doc( &options.uploaders_count.unwrap_or(1).to_string(), ); extra_vars.add_variable("evm_network_type", &options.evm_network.to_string()); - if let Some(evm_testnet_data) = &evm_testnet_data { - extra_vars.add_variable("evm_rpc_url", &evm_testnet_data.rpc_url); - extra_vars.add_variable( - "evm_payment_token_address", - &evm_testnet_data.payment_token_address, - ); - extra_vars.add_variable( - "evm_data_payments_address", - &evm_testnet_data.data_payments_address, - ); + if let Some(evm_data_payment_token_address) = &options.evm_data_payments_address { + extra_vars.add_variable("evm_data_payments_address", evm_data_payment_token_address); + } + if let Some(evm_payment_token_address) = &options.evm_payment_token_address { + extra_vars.add_variable("evm_payment_token_address", evm_payment_token_address); + } + if let Some(evm_rpc_url) = &options.evm_rpc_url { + extra_vars.add_variable("evm_rpc_url", evm_rpc_url); } let mut serde_map = serde_json::Map::new(); diff --git a/src/ansible/provisioning.rs b/src/ansible/provisioning.rs index 69b4d3b..3afc613 100644 --- a/src/ansible/provisioning.rs +++ b/src/ansible/provisioning.rs @@ -15,8 +15,8 @@ use crate::{ error::{Error, Result}, funding::FundingOptions, inventory::{DeploymentNodeRegistries, VirtualMachine}, - print_duration, BinaryOption, CloudProvider, EvmCustomTestnetData, EvmNetwork, LogFormat, - NodeType, SshClient, UpgradeOptions, + print_duration, BinaryOption, CloudProvider, EvmNetwork, LogFormat, NodeType, SshClient, + UpgradeOptions, }; use evmlib::common::U256; use log::{debug, error, trace}; @@ -41,7 +41,11 @@ pub struct ProvisionOptions { pub chunk_size: Option, pub downloaders_count: u16, pub env_variables: Option>, + pub evm_data_payments_address: Option, pub evm_network: EvmNetwork, + pub evm_payment_token_address: Option, + pub evm_rpc_url: Option, + /// Used to fund the uploaders. pub funding_wallet_secret_key: Option, pub gas_amount: Option, pub interval: Duration, @@ -72,7 +76,10 @@ impl From for ProvisionOptions { chunk_size: bootstrap_options.chunk_size, downloaders_count: 0, env_variables: bootstrap_options.env_variables, + evm_data_payments_address: bootstrap_options.evm_data_payments_address, evm_network: bootstrap_options.evm_network, + evm_payment_token_address: bootstrap_options.evm_payment_token_address, + evm_rpc_url: bootstrap_options.evm_rpc_url, funding_wallet_secret_key: None, gas_amount: None, interval: bootstrap_options.interval, @@ -102,7 +109,10 @@ impl From for ProvisionOptions { chunk_size: deploy_options.chunk_size, downloaders_count: deploy_options.downloaders_count, env_variables: deploy_options.env_variables, + evm_data_payments_address: deploy_options.evm_data_payments_address, evm_network: deploy_options.evm_network, + evm_payment_token_address: deploy_options.evm_payment_token_address, + evm_rpc_url: deploy_options.evm_rpc_url, funding_wallet_secret_key: deploy_options.funding_wallet_secret_key, gas_amount: None, interval: deploy_options.interval, @@ -278,11 +288,7 @@ impl AnsibleProvisioner { Ok(()) } - pub fn provision_genesis_node( - &self, - options: &ProvisionOptions, - evm_testnet_data: Option, - ) -> Result<()> { + pub fn provision_genesis_node(&self, options: &ProvisionOptions) -> Result<()> { let start = Instant::now(); let genesis_inventory = self .ansible_runner @@ -300,7 +306,6 @@ impl AnsibleProvisioner { None, 1, options.evm_network.clone(), - evm_testnet_data, )?), )?; print_duration(start.elapsed()); @@ -344,7 +349,6 @@ impl AnsibleProvisioner { options: &ProvisionOptions, initial_contact_peer: &str, node_type: NodeType, - evm_testnet_data: Option, ) -> Result<()> { let start = Instant::now(); let (inventory_type, node_count) = match &node_type { @@ -393,7 +397,6 @@ impl AnsibleProvisioner { Some(initial_contact_peer.to_string()), node_count, options.evm_network.clone(), - evm_testnet_data, )?), )?; print_duration(start.elapsed()); @@ -404,7 +407,6 @@ impl AnsibleProvisioner { &self, options: &mut ProvisionOptions, initial_contact_peer: &str, - evm_testnet_data: Option, ) -> Result<()> { let start = Instant::now(); @@ -431,12 +433,7 @@ impl AnsibleProvisioner { error!("Failed to generate private node static inv with err: {err:?}") })?; - self.provision_nodes( - options, - initial_contact_peer, - NodeType::Private, - evm_testnet_data, - )?; + self.provision_nodes(options, initial_contact_peer, NodeType::Private)?; print_duration(start.elapsed()); Ok(()) @@ -466,13 +463,14 @@ impl AnsibleProvisioner { &self, options: &ProvisionOptions, genesis_multiaddr: &str, - evm_testnet_data: Option, ) -> Result<()> { let start = Instant::now(); let sk_map = self .deposit_funds_to_uploaders(&FundingOptions { - custom_evm_testnet_data: evm_testnet_data.clone(), + evm_data_payments_address: options.evm_data_payments_address.clone(), + evm_payment_token_address: options.evm_payment_token_address.clone(), + evm_rpc_url: options.evm_rpc_url.clone(), uploaders_count: options.uploaders_count, evm_network: options.evm_network.clone(), funding_wallet_secret_key: options.funding_wallet_secret_key.clone(), @@ -491,7 +489,6 @@ impl AnsibleProvisioner { &self.cloud_provider.to_string(), options, genesis_multiaddr, - evm_testnet_data, &sk_map, )?), )?; diff --git a/src/bootstrap.rs b/src/bootstrap.rs index 2dcf03f..a5a9574 100644 --- a/src/bootstrap.rs +++ b/src/bootstrap.rs @@ -10,7 +10,7 @@ use crate::{ ansible::{inventory::AnsibleInventoryType, provisioning::ProvisionOptions}, error::Result, write_environment_details, BinaryOption, DeploymentType, EnvironmentDetails, EnvironmentType, - EvmCustomTestnetData, EvmNetwork, InfraRunOptions, LogFormat, NodeType, TestnetDeployer, + EvmNetwork, InfraRunOptions, LogFormat, NodeType, TestnetDeployer, }; use colored::Colorize; @@ -21,8 +21,10 @@ pub struct BootstrapOptions { pub chunk_size: Option, pub environment_type: EnvironmentType, pub env_variables: Option>, + pub evm_data_payments_address: Option, pub evm_network: EvmNetwork, - pub evm_custom_testnet_data: Option, + pub evm_payment_token_address: Option, + pub evm_rpc_url: Option, pub interval: Duration, pub log_format: Option, pub max_archived_log_files: u16, @@ -59,7 +61,9 @@ impl TestnetDeployer { deployment_type: DeploymentType::Bootstrap, environment_type: options.environment_type.clone(), evm_network: options.evm_network.clone(), - evm_testnet_data: options.evm_custom_testnet_data.clone(), + evm_data_payments_address: options.evm_data_payments_address.clone(), + evm_payment_token_address: options.evm_payment_token_address.clone(), + evm_rpc_url: options.evm_rpc_url.clone(), funding_wallet_address: None, rewards_address: options.rewards_address.clone(), }, @@ -113,7 +117,6 @@ impl TestnetDeployer { &provision_options, &options.bootstrap_peer, NodeType::Generic, - options.evm_custom_testnet_data.clone(), ) { Ok(()) => { println!("Provisioned normal nodes"); @@ -148,11 +151,10 @@ impl TestnetDeployer { self.ansible_provisioner .print_ansible_run_banner(n, total, "Provision Private Nodes"); - match self.ansible_provisioner.provision_private_nodes( - &mut provision_options, - &options.bootstrap_peer, - options.evm_custom_testnet_data.clone(), - ) { + match self + .ansible_provisioner + .provision_private_nodes(&mut provision_options, &options.bootstrap_peer) + { Ok(()) => { println!("Provisioned private nodes"); } diff --git a/src/deploy.rs b/src/deploy.rs index 316bd17..0125af3 100644 --- a/src/deploy.rs +++ b/src/deploy.rs @@ -8,7 +8,7 @@ use crate::{ ansible::{inventory::AnsibleInventoryType, provisioning::ProvisionOptions}, error::Result, funding::get_address_from_sk, - get_evm_testnet_data, get_genesis_multiaddr, write_environment_details, BinaryOption, + get_genesis_multiaddr, get_local_evm_node_data, write_environment_details, BinaryOption, DeploymentInventory, DeploymentType, EnvironmentDetails, EnvironmentType, EvmNetwork, InfraRunOptions, LogFormat, NodeType, TestnetDeployer, }; @@ -27,7 +27,10 @@ pub struct DeployOptions { pub downloaders_count: u16, pub environment_type: EnvironmentType, pub env_variables: Option>, + pub evm_data_payments_address: Option, pub evm_network: EvmNetwork, + pub evm_payment_token_address: Option, + pub evm_rpc_url: Option, pub evm_node_vm_size: Option, pub funding_wallet_secret_key: Option, pub interval: Duration, @@ -107,7 +110,9 @@ impl TestnetDeployer { deployment_type: DeploymentType::New, environment_type: options.environment_type.clone(), evm_network: options.evm_network.clone(), - evm_testnet_data: None, + evm_data_payments_address: None, + evm_payment_token_address: None, + evm_rpc_url: None, funding_wallet_address: None, rewards_address: options.rewards_address.clone(), }, @@ -115,7 +120,7 @@ impl TestnetDeployer { .await?; let mut provision_options = ProvisionOptions::from(options.clone()); - let evm_testnet_data = if options.evm_network == EvmNetwork::Custom { + let local_evm_node_data = if options.evm_network == EvmNetwork::Custom { self.ansible_provisioner .print_ansible_run_banner(n, total, "Provision EVM Node"); self.ansible_provisioner @@ -127,7 +132,7 @@ impl TestnetDeployer { n += 1; Some( - get_evm_testnet_data(&self.ansible_provisioner.ansible_runner, &self.ssh_client) + get_local_evm_node_data(&self.ansible_provisioner.ansible_runner, &self.ssh_client) .map_err(|err| { println!("Failed to get evm testnet data {err:?}"); err @@ -140,7 +145,7 @@ impl TestnetDeployer { let funding_wallet_address = if let Some(secret_key) = &options.funding_wallet_secret_key { let address = get_address_from_sk(secret_key)?; Some(address.encode_hex()) - } else if let Some(emv_data) = &evm_testnet_data { + } else if let Some(emv_data) = &local_evm_node_data { let address = get_address_from_sk(&emv_data.deployer_wallet_private_key)?; Some(address.encode_hex()) } else { @@ -148,6 +153,16 @@ impl TestnetDeployer { None }; + if let Some(custom_evm) = local_evm_node_data { + provision_options.evm_data_payments_address = + Some(custom_evm.data_payments_address.clone()); + provision_options.evm_payment_token_address = + Some(custom_evm.payment_token_address.clone()); + provision_options.evm_rpc_url = Some(custom_evm.rpc_url.clone()); + provision_options.funding_wallet_secret_key = + Some(custom_evm.deployer_wallet_private_key.clone()); + }; + write_environment_details( &self.s3_repository, &options.name, @@ -155,7 +170,9 @@ impl TestnetDeployer { deployment_type: DeploymentType::New, environment_type: options.environment_type.clone(), evm_network: options.evm_network.clone(), - evm_testnet_data: evm_testnet_data.clone(), + evm_data_payments_address: provision_options.evm_data_payments_address.clone(), + evm_payment_token_address: provision_options.evm_payment_token_address.clone(), + evm_rpc_url: provision_options.evm_rpc_url.clone(), funding_wallet_address, rewards_address: options.rewards_address.clone(), }, @@ -177,7 +194,7 @@ impl TestnetDeployer { self.ansible_provisioner .print_ansible_run_banner(n, total, "Provision Genesis Node"); self.ansible_provisioner - .provision_genesis_node(&provision_options, evm_testnet_data.clone()) + .provision_genesis_node(&provision_options) .map_err(|err| { println!("Failed to provision genesis node {err:?}"); err @@ -198,7 +215,6 @@ impl TestnetDeployer { &provision_options, &genesis_multiaddr, NodeType::Bootstrap, - evm_testnet_data.clone(), ) { Ok(()) => { println!("Provisioned bootstrap nodes"); @@ -216,7 +232,6 @@ impl TestnetDeployer { &provision_options, &genesis_multiaddr, NodeType::Generic, - evm_testnet_data.clone(), ) { Ok(()) => { println!("Provisioned normal nodes"); @@ -252,11 +267,10 @@ impl TestnetDeployer { self.ansible_provisioner .print_ansible_run_banner(n, total, "Provision Private Nodes"); - match self.ansible_provisioner.provision_private_nodes( - &mut provision_options, - &genesis_multiaddr, - evm_testnet_data.clone(), - ) { + match self + .ansible_provisioner + .provision_private_nodes(&mut provision_options, &genesis_multiaddr) + { Ok(()) => { println!("Provisioned private nodes"); } @@ -272,7 +286,7 @@ impl TestnetDeployer { self.ansible_provisioner .print_ansible_run_banner(n, total, "Provision Uploaders"); self.ansible_provisioner - .provision_uploaders(&provision_options, &genesis_multiaddr, evm_testnet_data) + .provision_uploaders(&provision_options, &genesis_multiaddr) .await .map_err(|err| { println!("Failed to provision uploaders {err:?}"); diff --git a/src/funding.rs b/src/funding.rs index bcd1523..90143fe 100644 --- a/src/funding.rs +++ b/src/funding.rs @@ -5,7 +5,6 @@ // Please see the LICENSE file for more details. use crate::error::Result; -use crate::EvmCustomTestnetData; use crate::{ ansible::{inventory::AnsibleInventoryType, provisioning::AnsibleProvisioner}, error::Error, @@ -26,7 +25,12 @@ const DEFAULT_GAS_AMOUNT: &str = "100_000_000_000_000_000"; pub struct FundingOptions { pub evm_network: EvmNetwork, - pub custom_evm_testnet_data: Option, + /// For custom network + pub evm_data_payments_address: Option, + /// For custom network + pub evm_payment_token_address: Option, + /// For custom network + pub evm_rpc_url: Option, pub funding_wallet_secret_key: Option, /// Have to specify during upscale and deploy pub uploaders_count: Option, @@ -317,18 +321,30 @@ impl AnsibleProvisioner { let from_wallet = match &options.evm_network { EvmNetwork::Custom => { - let evm_testnet_data = - options.custom_evm_testnet_data.as_ref().ok_or_else(|| { - error!("Custom Evm testnet data not provided"); - Error::EvmTestnetDataNotFound - })?; - let network = Network::new_custom( - &evm_testnet_data.rpc_url, - &evm_testnet_data.payment_token_address, - &evm_testnet_data.data_payments_address, - ); - let deployer_wallet_sk: PrivateKeySigner = evm_testnet_data - .deployer_wallet_private_key + let network = if let ( + Some(evm_data_payments_address), + Some(evm_payment_token_address), + Some(evm_rpc_url), + ) = ( + options.evm_data_payments_address.as_ref(), + options.evm_payment_token_address.as_ref(), + options.evm_rpc_url.as_ref(), + ) { + Network::new_custom( + evm_rpc_url, + evm_payment_token_address, + evm_data_payments_address, + ) + } else { + error!("Custom evm network data not provided"); + return Err(Error::EvmTestnetDataNotFound); + }; + + let Some(deployer_wallet_sk) = &options.funding_wallet_secret_key else { + error!("Deployer wallet secret key not provided"); + return Err(Error::SecretKeyNotFound); + }; + let deployer_wallet_sk: PrivateKeySigner = deployer_wallet_sk .parse() .map_err(|_| Error::FailedToParseKey)?; diff --git a/src/inventory.rs b/src/inventory.rs index 9a2a9e0..afa7b14 100644 --- a/src/inventory.rs +++ b/src/inventory.rs @@ -983,19 +983,34 @@ impl DeploymentInventory { } } - if let Some(evm_testnet_data) = &self.environment_details.evm_testnet_data { - println!("=================="); - println!("Custom EVM Details"); - println!("=================="); + if self.environment_details.evm_data_payments_address.is_some() + || self.environment_details.evm_payment_token_address.is_some() + || self.environment_details.evm_rpc_url.is_some() + { + println!("==========="); + println!("EVM Details"); + println!("==========="); println!( "EVM data payments address: {}", - evm_testnet_data.data_payments_address + self.environment_details + .evm_data_payments_address + .as_ref() + .map_or("N/A", |addr| addr) ); println!( "EVM payment token address: {}", - evm_testnet_data.payment_token_address + self.environment_details + .evm_payment_token_address + .as_ref() + .map_or("N/A", |addr| addr) + ); + println!( + "EVM RPC URL: {}", + self.environment_details + .evm_rpc_url + .as_ref() + .map_or("N/A", |addr| addr) ); - println!("EVM RPC URL: {}", evm_testnet_data.rpc_url); } Ok(()) diff --git a/src/lib.rs b/src/lib.rs index facc0b8..cf02595 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -84,7 +84,7 @@ pub enum DeploymentType { } #[derive(Debug, Clone, Default, Serialize, Deserialize)] -pub struct EvmCustomTestnetData { +pub struct LocalEvmNodeData { pub data_payments_address: String, pub deployer_wallet_private_key: String, pub payment_token_address: String, @@ -191,7 +191,9 @@ pub struct EnvironmentDetails { pub deployment_type: DeploymentType, pub environment_type: EnvironmentType, pub evm_network: EvmNetwork, - pub evm_testnet_data: Option, + pub evm_data_payments_address: Option, + pub evm_payment_token_address: Option, + pub evm_rpc_url: Option, pub funding_wallet_address: Option, pub rewards_address: String, } @@ -937,10 +939,10 @@ pub fn get_genesis_multiaddr( Ok((multiaddr, genesis_ip)) } -pub fn get_evm_testnet_data( +pub fn get_local_evm_node_data( ansible_runner: &AnsibleRunner, ssh_client: &SshClient, -) -> Result { +) -> Result { let evm_inventory = ansible_runner.get_inventory(AnsibleInventoryType::EvmNodes, true)?; if evm_inventory.is_empty() { return Err(Error::EvmNodeNotFound); @@ -963,7 +965,7 @@ pub fn get_evm_testnet_data( )); } - let evm_testnet_data = EvmCustomTestnetData { + let evm_testnet_data = LocalEvmNodeData { rpc_url: parts[0].trim().to_string(), payment_token_address: parts[1].trim().to_string(), data_payments_address: parts[2].trim().to_string(), diff --git a/src/main.rs b/src/main.rs index 32c6c91..b5120c8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,8 +27,8 @@ use sn_testnet_deploy::{ network_commands, notify_slack, setup::setup_dotenv_file, upscale::UpscaleOptions, - BinaryOption, CloudProvider, EnvironmentType, EvmCustomTestnetData, EvmNetwork, LogFormat, - NodeType, TestnetDeployBuilder, UpgradeOptions, + BinaryOption, CloudProvider, EnvironmentType, EvmNetwork, LogFormat, NodeType, + TestnetDeployBuilder, UpgradeOptions, }; use std::{env, net::IpAddr}; use std::{str::FromStr, time::Duration}; @@ -87,14 +87,9 @@ enum Commands { env_variables: Option>, /// The address of the data payments contract. /// - /// This argument only applies if the EVM network type is 'custom'. + /// This argument must match the same contract address used in the existing network. #[arg(long)] evm_data_payments_address: Option, - /// The private key of the wallet that deployed the contracts. - /// - /// This argument only applies if the EVM network type is 'custom'. - #[arg(long)] - evm_deployer_wallet_private_key: Option, /// The EVM network to use. /// /// Valid values are "arbitrum-one", "arbitrum-sepolia", or "custom". @@ -102,7 +97,7 @@ enum Commands { evm_network_type: EvmNetwork, /// The address of the payment token contract. /// - /// This argument only applies if the EVM network type is 'custom'. + /// This argument must match the same contract address used in the existing network. #[arg(long)] evm_payment_token_address: Option, /// The RPC URL for the EVM network. @@ -322,6 +317,9 @@ enum Commands { /// Example: --env SN_LOG=all,RUST_LOG=libp2p=debug #[clap(name = "env", long, use_value_delimiter = true, value_parser = parse_environment_variables, verbatim_doc_comment)] env_variables: Option>, + /// The address of the data payments contract. + #[arg(long)] + evm_data_payments_address: Option, /// The EVM network type to use for the deployment. /// /// Possible values are 'arbitrum-one' or 'custom'. @@ -329,6 +327,9 @@ enum Commands { /// If not used, the default is 'arbitrum-one'. #[clap(long, default_value = "arbitrum-one", value_parser = parse_evm_network)] evm_network_type: EvmNetwork, + /// The address of the payment token contract. + #[arg(long)] + evm_payment_token_address: Option, /// Override the size of the EVM node VMs. #[clap(long)] evm_node_vm_size: Option, @@ -1336,7 +1337,6 @@ async fn main() -> Result<()> { environment_type, env_variables, evm_data_payments_address, - evm_deployer_wallet_private_key, evm_network_type, evm_payment_token_address, evm_rpc_url, @@ -1363,37 +1363,21 @@ async fn main() -> Result<()> { safenode_manager_version, chunk_size, } => { - let evm_custom_testnet_data = match evm_network_type { - EvmNetwork::Custom => { - if evm_data_payments_address.is_none() - || evm_payment_token_address.is_none() - || evm_rpc_url.is_none() - { - return Err(eyre!( - "When using a custom EVM network, you must supply evm-data-payments-address, evm-payment-token-address, and evm-rpc-url" - )); - } - Some(EvmCustomTestnetData { - data_payments_address: evm_data_payments_address.unwrap(), - deployer_wallet_private_key: evm_deployer_wallet_private_key - .unwrap_or_default(), - payment_token_address: evm_payment_token_address.unwrap(), - rpc_url: evm_rpc_url.unwrap(), - }) - } - _ => { - if evm_data_payments_address.is_some() - || evm_payment_token_address.is_some() - || evm_rpc_url.is_some() - || evm_deployer_wallet_private_key.is_some() - { - return Err(eyre!( - "EVM custom network parameters can only be used with evm-network-type=custom" - )); - } - None - } - }; + if evm_network_type == EvmNetwork::Custom + && (evm_data_payments_address.is_none() + || evm_payment_token_address.is_none() + || evm_rpc_url.is_none()) + { + return Err(eyre!( + "When using a custom EVM network, you must supply evm-data-payments-address, evm-payment-token-address, and evm-rpc-url" + )); + } + + if evm_network_type != EvmNetwork::Custom && evm_rpc_url.is_some() { + return Err(eyre!( + "EVM RPC URL can only be set for a custom EVM network" + )); + } let network_keys = validate_and_get_pks( foundation_pk, @@ -1457,8 +1441,10 @@ async fn main() -> Result<()> { bootstrap_peer, environment_type: environment_type.clone(), env_variables, + evm_data_payments_address, evm_network: evm_network_type, - evm_custom_testnet_data, + evm_payment_token_address, + evm_rpc_url, interval, log_format, name: name.clone(), @@ -1505,7 +1491,9 @@ async fn main() -> Result<()> { downloaders_count, env_variables, environment_type, + evm_data_payments_address, evm_network_type, + evm_payment_token_address, evm_node_vm_size, faucet_version, forks, @@ -1546,6 +1534,14 @@ async fn main() -> Result<()> { payment_forward_pk, )?; + if evm_network_type == EvmNetwork::Custom + && (evm_data_payments_address.is_some() || evm_payment_token_address.is_some()) + { + return Err(eyre!( + "EVM data payments address and payment token address cannot be set for a custom EVM network" + )); + } + if funding_wallet_secret_key.is_some() && evm_network_type == EvmNetwork::Custom { return Err(eyre!( "Wallet secret key only applies to Arbitrum or Sepolia networks" @@ -1632,7 +1628,10 @@ async fn main() -> Result<()> { downloaders_count, environment_type: environment_type.clone(), env_variables, + evm_data_payments_address, evm_network: evm_network_type, + evm_payment_token_address, + evm_rpc_url: None, evm_node_vm_size, funding_wallet_secret_key, interval, @@ -1783,16 +1782,10 @@ async fn main() -> Result<()> { let environment_details = get_environment_details(&name, &inventory_services.s3_repository).await?; - if funding_wallet_secret_key.is_some() - && environment_details.evm_network == EvmNetwork::Custom - { - return Err(eyre!( - "Wallet secret key only applies to Arbitrum or Sepolia networks" - )); - } - let options = FundingOptions { - custom_evm_testnet_data: environment_details.evm_testnet_data, + evm_data_payments_address: environment_details.evm_data_payments_address, + evm_payment_token_address: environment_details.evm_payment_token_address, + evm_rpc_url: environment_details.evm_rpc_url, evm_network: environment_details.evm_network, funding_wallet_secret_key, uploaders_count: None, @@ -1838,15 +1831,25 @@ async fn main() -> Result<()> { EvmNetwork::ArbitrumOne => Network::ArbitrumOne, EvmNetwork::ArbitrumSepolia => Network::ArbitrumSepolia, EvmNetwork::Custom => { - let custom_evm_details = - environment_details.evm_testnet_data.ok_or_else(|| { - eyre!("Custom EVM details not found in the environment details") - })?; - Network::new_custom( - &custom_evm_details.rpc_url, - &custom_evm_details.payment_token_address, - &custom_evm_details.data_payments_address, - ) + if let ( + Some(emv_data_payments_address), + Some(evm_payment_token_address), + Some(evm_rpc_url), + ) = ( + environment_details.evm_data_payments_address, + environment_details.evm_payment_token_address, + environment_details.evm_rpc_url, + ) { + Network::new_custom( + &evm_rpc_url, + &evm_payment_token_address, + &emv_data_payments_address, + ) + } else { + return Err(eyre!( + "Custom EVM details not found in the environment details" + )); + } } }; diff --git a/src/upscale.rs b/src/upscale.rs index 279c3d7..b153722 100644 --- a/src/upscale.rs +++ b/src/upscale.rs @@ -5,8 +5,7 @@ // Please see the LICENSE file for more details. use crate::{ - ansible::inventory::AnsibleInventoryType, - ansible::provisioning::ProvisionOptions, + ansible::{inventory::AnsibleInventoryType, provisioning::ProvisionOptions}, error::{Error, Result}, get_genesis_multiaddr, get_multiaddr, DeploymentInventory, DeploymentType, EvmNetwork, InfraRunOptions, NodeType, TestnetDeployer, @@ -220,6 +219,21 @@ impl TestnetDeployer { .environment_details .evm_network .clone(), + evm_data_payments_address: options + .current_inventory + .environment_details + .evm_data_payments_address + .clone(), + evm_payment_token_address: options + .current_inventory + .environment_details + .evm_payment_token_address + .clone(), + evm_rpc_url: options + .current_inventory + .environment_details + .evm_rpc_url + .clone(), funding_wallet_secret_key: options.funding_wallet_secret_key.clone(), interval: options.interval, log_format: None, @@ -263,12 +277,6 @@ impl TestnetDeployer { }; debug!("Retrieved initial peer {initial_multiaddr}"); - let evm_testnet_data = options - .current_inventory - .environment_details - .evm_testnet_data - .clone(); - let should_provision_private_nodes = desired_private_node_vm_count > 0; let mut n = 1; let mut total = if is_bootstrap_deploy { 3 } else { 4 }; @@ -290,7 +298,6 @@ impl TestnetDeployer { &provision_options, &initial_multiaddr, NodeType::Bootstrap, - evm_testnet_data.clone(), ) { Ok(()) => { println!("Provisioned bootstrap nodes"); @@ -313,7 +320,6 @@ impl TestnetDeployer { &provision_options, &initial_multiaddr, NodeType::Generic, - evm_testnet_data.clone(), ) { Ok(()) => { println!("Provisioned normal nodes"); @@ -356,11 +362,10 @@ impl TestnetDeployer { )?; self.ansible_provisioner .print_ansible_run_banner(n, total, "Provision Private Nodes"); - match self.ansible_provisioner.provision_private_nodes( - &mut provision_options, - &initial_multiaddr, - None, - ) { + match self + .ansible_provisioner + .provision_private_nodes(&mut provision_options, &initial_multiaddr) + { Ok(()) => { println!("Provisioned private nodes"); } @@ -380,7 +385,7 @@ impl TestnetDeployer { self.ansible_provisioner .print_ansible_run_banner(n, total, "Provision Uploaders"); self.ansible_provisioner - .provision_uploaders(&provision_options, &initial_multiaddr, evm_testnet_data) + .provision_uploaders(&provision_options, &initial_multiaddr) .await .map_err(|err| { println!("Failed to provision uploaders {err:?}"); @@ -484,11 +489,26 @@ impl TestnetDeployer { chunk_size: None, downloaders_count: options.downloaders_count, env_variables: None, + evm_data_payments_address: options + .current_inventory + .environment_details + .evm_data_payments_address + .clone(), evm_network: options .current_inventory .environment_details .evm_network .clone(), + evm_payment_token_address: options + .current_inventory + .environment_details + .evm_payment_token_address + .clone(), + evm_rpc_url: options + .current_inventory + .environment_details + .evm_rpc_url + .clone(), funding_wallet_secret_key: options.funding_wallet_secret_key.clone(), interval: options.interval, log_format: None, @@ -515,12 +535,6 @@ impl TestnetDeployer { gas_amount: options.gas_amount, }; - let evm_testnet_data = options - .current_inventory - .environment_details - .evm_testnet_data - .clone(); - self.wait_for_ssh_availability_on_new_machines( AnsibleInventoryType::Uploaders, &options.current_inventory, @@ -528,7 +542,7 @@ impl TestnetDeployer { self.ansible_provisioner .print_ansible_run_banner(1, 1, "Provision Uploaders"); self.ansible_provisioner - .provision_uploaders(&provision_options, &initial_multiaddr, evm_testnet_data) + .provision_uploaders(&provision_options, &initial_multiaddr) .await .map_err(|err| { println!("Failed to provision uploaders {err:?}");