diff --git a/.github/workflows/merge.yml b/.github/workflows/merge.yml index fd11bce681..2a90a5e7ae 100644 --- a/.github/workflows/merge.yml +++ b/.github/workflows/merge.yml @@ -160,11 +160,11 @@ jobs: - uses: Swatinem/rust-cache@v2 - name: Build binaries - run: cargo build --release --bin safenode --bin autonomi_cli + run: cargo build --release --features local --bin safenode --bin autonomi_cli timeout-minutes: 30 - name: Start a local network - uses: maidsafe/sn-local-testnet-action@evm-dev + uses: maidsafe/sn-local-testnet-action@main with: action: start enable-evm-testnet: true @@ -338,7 +338,7 @@ jobs: - name: Stop the local network and upload logs if: always() - uses: maidsafe/sn-local-testnet-action@evm-dev + uses: maidsafe/sn-local-testnet-action@main with: action: stop log_file_prefix: safe_test_logs_e2e @@ -592,7 +592,7 @@ jobs: timeout-minutes: 30 - name: Start a local network - uses: maidsafe/sn-local-testnet-action@evm-dev + uses: maidsafe/sn-local-testnet-action@main with: action: start enable-evm-testnet: true @@ -625,7 +625,7 @@ jobs: - name: Stop the local network and upload logs if: always() - uses: maidsafe/sn-local-testnet-action@evm-dev + uses: maidsafe/sn-local-testnet-action@main with: action: stop log_file_prefix: safe_test_logs_churn @@ -721,7 +721,7 @@ jobs: timeout-minutes: 30 - name: Start a local network - uses: maidsafe/sn-local-testnet-action@evm-dev + uses: maidsafe/sn-local-testnet-action@main with: action: start enable-evm-testnet: true @@ -765,7 +765,7 @@ jobs: - name: Stop the local network and upload logs if: always() - uses: maidsafe/sn-local-testnet-action@evm-dev + uses: maidsafe/sn-local-testnet-action@main with: action: stop log_file_prefix: safe_test_logs_data_location diff --git a/autonomi/Cargo.toml b/autonomi/Cargo.toml index aa5e463ac6..2bc48ca322 100644 --- a/autonomi/Cargo.toml +++ b/autonomi/Cargo.toml @@ -15,7 +15,7 @@ full = ["data", "registers", "vault"] data = [] vault = ["data"] fs = ["tokio/fs", "data"] -local = ["sn_networking/local", "test_utils/local"] +local = ["sn_networking/local", "test_utils/local", "sn_evm/local"] registers = ["data"] loud = [] diff --git a/autonomi/src/lib.rs b/autonomi/src/lib.rs index cfc8d81f72..98921768ce 100644 --- a/autonomi/src/lib.rs +++ b/autonomi/src/lib.rs @@ -36,7 +36,7 @@ pub mod client; #[cfg(feature = "data")] mod self_encryption; -pub use sn_evm::evm; +pub use sn_evm::get_evm_network_from_env; pub use sn_evm::EvmNetwork; pub use sn_evm::EvmWallet as Wallet; diff --git a/autonomi/tests/wallet.rs b/autonomi/tests/wallet.rs index b410f0dd80..5d5be9301e 100644 --- a/autonomi/tests/wallet.rs +++ b/autonomi/tests/wallet.rs @@ -7,7 +7,7 @@ // permissions and limitations relating to use of the SAFE Network Software. use const_hex::traits::FromHex; -use sn_evm::evm::network_from_env; +use sn_evm::get_evm_network_from_env; use sn_evm::EvmWallet; use sn_evm::{Amount, RewardsAddress}; use sn_logging::LogBuilder; @@ -16,7 +16,8 @@ use test_utils::evm::get_funded_wallet; #[tokio::test] async fn from_private_key() { let private_key = "0xdb1049e76a813c94be0df47ec3e20533ca676b1b9fef2ddbce9daa117e4da4aa"; - let network = network_from_env().expect("Could not get EVM network from environment variables"); + let network = + get_evm_network_from_env().expect("Could not get EVM network from environment variables"); let wallet = EvmWallet::new_from_private_key(network, private_key).unwrap(); assert_eq!( @@ -29,7 +30,8 @@ async fn from_private_key() { async fn send_tokens() { let _log_appender_guard = LogBuilder::init_single_threaded_tokio_test("wallet", false); - let network = network_from_env().expect("Could not get EVM network from environment variables"); + let network = + get_evm_network_from_env().expect("Could not get EVM network from environment variables"); let wallet = get_funded_wallet(); let receiving_wallet = EvmWallet::new_with_random_wallet(network); diff --git a/autonomi_cli/Cargo.toml b/autonomi_cli/Cargo.toml index 414cd47149..7b1d0e948b 100644 --- a/autonomi_cli/Cargo.toml +++ b/autonomi_cli/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [features] default = ["metrics"] -local = ["sn_peers_acquisition/local"] +local = ["sn_peers_acquisition/local", "autonomi/local"] metrics = ["sn_logging/process-metrics"] network-contacts = ["sn_peers_acquisition/network-contacts"] diff --git a/autonomi_cli/src/access/keys.rs b/autonomi_cli/src/access/keys.rs index ef06e8c4e1..18310f4831 100644 --- a/autonomi_cli/src/access/keys.rs +++ b/autonomi_cli/src/access/keys.rs @@ -7,7 +7,7 @@ // permissions and limitations relating to use of the SAFE Network Software. use autonomi::client::registers::RegisterSecretKey; -use autonomi::Wallet; +use autonomi::{get_evm_network_from_env, Wallet}; use color_eyre::eyre::{Context, Result}; use color_eyre::Section; use std::env; @@ -24,7 +24,7 @@ const REGISTER_SIGNING_KEY_FILE: &str = "register_signing_key"; pub fn load_evm_wallet() -> Result { let secret_key = get_secret_key().wrap_err("The secret key is required to perform this action")?; - let network = crate::network::get_evm_network_from_env()?; + let network = get_evm_network_from_env()?; let wallet = Wallet::new_from_private_key(network, &secret_key) .wrap_err("Failed to load EVM wallet from key")?; Ok(wallet) diff --git a/autonomi_cli/src/access/network.rs b/autonomi_cli/src/access/network.rs index 2268856581..f7e455dade 100644 --- a/autonomi_cli/src/access/network.rs +++ b/autonomi_cli/src/access/network.rs @@ -6,7 +6,6 @@ // KIND, either express or implied. Please review the Licences for the specific language governing // permissions and limitations relating to use of the SAFE Network Software. -use autonomi::EvmNetwork; use autonomi::Multiaddr; use color_eyre::eyre::Context; use color_eyre::Result; @@ -14,34 +13,9 @@ use color_eyre::Section; use sn_peers_acquisition::PeersArgs; use sn_peers_acquisition::SAFE_PEERS_ENV; -#[cfg(not(feature = "local"))] -use autonomi::evm::{DATA_PAYMENTS_ADDRESS, PAYMENT_TOKEN_ADDRESS, RPC_URL}; - pub async fn get_peers(peers: PeersArgs) -> Result> { peers.get_peers().await .wrap_err("Please provide valid Network peers to connect to") .with_suggestion(|| format!("make sure you've provided network peers using the --peers option or the {SAFE_PEERS_ENV} env var")) .with_suggestion(|| "a peer address looks like this: /ip4/42.42.42.42/udp/4242/quic-v1/p2p/B64nodePeerIDvdjb3FAJF4ks3moreBase64CharsHere") } - -pub fn get_evm_network_from_env() -> Result { - #[cfg(feature = "local")] - { - println!("Getting EVM network from local CSV as the local feature is enabled"); - let network = autonomi::evm::local_evm_network_from_csv() - .wrap_err("Failed to get EVM network from local CSV") - .with_suggestion(|| "make sure you've set up the local EVM network by running `cargo run --bin evm_testnet`")?; - Ok(network) - } - #[cfg(not(feature = "local"))] - { - let network = autonomi::evm::network_from_env() - .wrap_err("Failed to get EVM network from environment variables") - .with_suggestion(|| format!("If connecting to a custom EVM network, make sure you've set the following environment variables: {RPC_URL}, {PAYMENT_TOKEN_ADDRESS} and {DATA_PAYMENTS_ADDRESS}"))?; - if matches!(network, EvmNetwork::Custom(_)) { - println!("Using custom EVM network found from environment variables"); - info!("Using custom EVM network found from environment variables {network:?}"); - } - Ok(network) - } -} diff --git a/evm_testnet/src/main.rs b/evm_testnet/src/main.rs index 1e9ddca501..52df961aab 100644 --- a/evm_testnet/src/main.rs +++ b/evm_testnet/src/main.rs @@ -131,11 +131,11 @@ impl TestnetData { println!("Run the CLI or Node with the following env vars set to manually connect to this network:"); println!( "{}=\"{}\" {}=\"{}\" {}=\"{}\"", - sn_evm::evm::RPC_URL, + sn_evm::RPC_URL, self.rpc_url, - sn_evm::evm::PAYMENT_TOKEN_ADDRESS, + sn_evm::PAYMENT_TOKEN_ADDRESS, self.payment_token_address, - sn_evm::evm::DATA_PAYMENTS_ADDRESS, + sn_evm::DATA_PAYMENTS_ADDRESS, self.data_payments_address ); println!("--------------"); diff --git a/evmlib/Cargo.toml b/evmlib/Cargo.toml index fc101d17eb..fae3cba0cb 100644 --- a/evmlib/Cargo.toml +++ b/evmlib/Cargo.toml @@ -10,6 +10,7 @@ version = "0.1.0" [features] wasm-bindgen = ["alloy/wasm-bindgen"] +local = [] [dependencies] alloy = { version = "0.4.2", default-features = false, features = ["std", "reqwest-rustls-tls", "provider-anvil-node", "sol-types", "json", "signers", "contract", "signer-local", "network"] } diff --git a/evmlib/src/common.rs b/evmlib/src/common.rs index 4897a1e2cf..af210f9285 100644 --- a/evmlib/src/common.rs +++ b/evmlib/src/common.rs @@ -1,3 +1,11 @@ +// Copyright 2024 MaidSafe.net limited. +// +// This SAFE Network Software is licensed to you under The General Public License (GPL), version 3. +// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed +// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. Please review the Licences for the specific language governing +// permissions and limitations relating to use of the SAFE Network Software. + use alloy::primitives::FixedBytes; pub type Address = alloy::primitives::Address; diff --git a/evmlib/src/contract/data_payments/error.rs b/evmlib/src/contract/data_payments/error.rs index 84bd2c6c9a..95ec1c1c27 100644 --- a/evmlib/src/contract/data_payments/error.rs +++ b/evmlib/src/contract/data_payments/error.rs @@ -1,3 +1,11 @@ +// Copyright 2024 MaidSafe.net limited. +// +// This SAFE Network Software is licensed to you under The General Public License (GPL), version 3. +// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed +// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. Please review the Licences for the specific language governing +// permissions and limitations relating to use of the SAFE Network Software. + use crate::contract::network_token; use alloy::transports::{RpcError, TransportErrorKind}; diff --git a/evmlib/src/contract/data_payments/mod.rs b/evmlib/src/contract/data_payments/mod.rs index 22d45f7ed5..352f294581 100644 --- a/evmlib/src/contract/data_payments/mod.rs +++ b/evmlib/src/contract/data_payments/mod.rs @@ -1,3 +1,11 @@ +// Copyright 2024 MaidSafe.net limited. +// +// This SAFE Network Software is licensed to you under The General Public License (GPL), version 3. +// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed +// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. Please review the Licences for the specific language governing +// permissions and limitations relating to use of the SAFE Network Software. + pub mod error; use crate::common; diff --git a/evmlib/src/contract/mod.rs b/evmlib/src/contract/mod.rs index 1a4e070efd..d428880800 100644 --- a/evmlib/src/contract/mod.rs +++ b/evmlib/src/contract/mod.rs @@ -1,2 +1,10 @@ +// Copyright 2024 MaidSafe.net limited. +// +// This SAFE Network Software is licensed to you under The General Public License (GPL), version 3. +// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed +// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. Please review the Licences for the specific language governing +// permissions and limitations relating to use of the SAFE Network Software. + pub mod data_payments; pub mod network_token; diff --git a/evmlib/src/contract/network_token.rs b/evmlib/src/contract/network_token.rs index be9d2bca7f..4c8112e869 100644 --- a/evmlib/src/contract/network_token.rs +++ b/evmlib/src/contract/network_token.rs @@ -1,3 +1,11 @@ +// Copyright 2024 MaidSafe.net limited. +// +// This SAFE Network Software is licensed to you under The General Public License (GPL), version 3. +// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed +// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. Please review the Licences for the specific language governing +// permissions and limitations relating to use of the SAFE Network Software. + use crate::common::{Address, TxHash, U256}; use crate::contract::network_token::NetworkTokenContract::NetworkTokenContractInstance; use alloy::providers::{Network, Provider}; diff --git a/evmlib/src/cryptography.rs b/evmlib/src/cryptography.rs index fea0297a83..ddc0149b43 100644 --- a/evmlib/src/cryptography.rs +++ b/evmlib/src/cryptography.rs @@ -1,3 +1,11 @@ +// Copyright 2024 MaidSafe.net limited. +// +// This SAFE Network Software is licensed to you under The General Public License (GPL), version 3. +// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed +// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. Please review the Licences for the specific language governing +// permissions and limitations relating to use of the SAFE Network Software. + use crate::common::Hash; use alloy::primitives::keccak256; diff --git a/evmlib/src/event.rs b/evmlib/src/event.rs index eff4bdf30e..5cdda3d91e 100644 --- a/evmlib/src/event.rs +++ b/evmlib/src/event.rs @@ -1,3 +1,11 @@ +// Copyright 2024 MaidSafe.net limited. +// +// This SAFE Network Software is licensed to you under The General Public License (GPL), version 3. +// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed +// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. Please review the Licences for the specific language governing +// permissions and limitations relating to use of the SAFE Network Software. + use crate::common::{Address, Hash, U256}; use alloy::primitives::{b256, FixedBytes}; use alloy::rpc::types::Log; diff --git a/evmlib/src/lib.rs b/evmlib/src/lib.rs index cdbbab6b5c..6e29a7f4d5 100644 --- a/evmlib/src/lib.rs +++ b/evmlib/src/lib.rs @@ -1,3 +1,11 @@ +// Copyright 2024 MaidSafe.net limited. +// +// This SAFE Network Software is licensed to you under The General Public License (GPL), version 3. +// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed +// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. Please review the Licences for the specific language governing +// permissions and limitations relating to use of the SAFE Network Software. + use crate::common::{Address, QuoteHash, TxHash, U256}; use crate::transaction::verify_data_payment; use alloy::primitives::address; diff --git a/evmlib/src/testnet.rs b/evmlib/src/testnet.rs index c4db116c2e..93922b539d 100644 --- a/evmlib/src/testnet.rs +++ b/evmlib/src/testnet.rs @@ -1,3 +1,11 @@ +// Copyright 2024 MaidSafe.net limited. +// +// This SAFE Network Software is licensed to you under The General Public License (GPL), version 3. +// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed +// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. Please review the Licences for the specific language governing +// permissions and limitations relating to use of the SAFE Network Software. + use crate::common::Address; use crate::contract::data_payments::DataPaymentsHandler; use crate::contract::network_token::NetworkToken; diff --git a/evmlib/src/transaction.rs b/evmlib/src/transaction.rs index c5c97896e0..dc8609a4d5 100644 --- a/evmlib/src/transaction.rs +++ b/evmlib/src/transaction.rs @@ -1,3 +1,11 @@ +// Copyright 2024 MaidSafe.net limited. +// +// This SAFE Network Software is licensed to you under The General Public License (GPL), version 3. +// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed +// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. Please review the Licences for the specific language governing +// permissions and limitations relating to use of the SAFE Network Software. + use crate::common::{Address, QuoteHash, TxHash, U256}; use crate::event::{ChunkPaymentEvent, DATA_PAYMENT_EVENT_SIGNATURE}; use crate::Network; diff --git a/evmlib/src/utils.rs b/evmlib/src/utils.rs index 0ebf444645..31d13d413a 100644 --- a/evmlib/src/utils.rs +++ b/evmlib/src/utils.rs @@ -1,3 +1,13 @@ +// Copyright 2024 MaidSafe.net limited. +// +// This SAFE Network Software is licensed to you under The General Public License (GPL), version 3. +// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed +// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. Please review the Licences for the specific language governing +// permissions and limitations relating to use of the SAFE Network Software. + +#![allow(dead_code)] + use crate::common::{Address, Hash}; use crate::{CustomNetwork, Network}; use dirs_next::data_dir; @@ -31,8 +41,19 @@ pub fn dummy_hash() -> Hash { Hash::new(rand::rngs::OsRng.gen()) } +pub fn get_evm_testnet_csv_path() -> Result { + let file = data_dir() + .ok_or(Error::FailedToGetEvmNetwork( + "failed to get data dir when fetching evm testnet CSV file".to_string(), + ))? + .join("safe") + .join(EVM_TESTNET_CSV_FILENAME); + Ok(file) +} + /// Get the `Network` from environment variables -pub fn network_from_env() -> Result { +/// Returns an error if the we cannot obtain the network from any means. +pub fn get_evm_network_from_env() -> Result { let evm_vars = [ env::var(RPC_URL) .ok() @@ -52,40 +73,43 @@ pub fn network_from_env() -> Result { }) .collect::, Error>>(); - let use_local_evm = std::env::var("EVM_NETWORK") + let mut use_local_evm = std::env::var("EVM_NETWORK") .map(|v| v == "local") .unwrap_or(false); + if use_local_evm { + info!("Using local EVM network as EVM_NETWORK is set to 'local'"); + } + if cfg!(feature = "local") { + use_local_evm = true; + info!("Using local EVM network as 'local' feature flag is enabled"); + } + let use_arbitrum_one = std::env::var("EVM_NETWORK") .map(|v| v == "arbitrum-one") .unwrap_or(false); - if use_arbitrum_one { - Ok(Network::ArbitrumOne) - } else if use_local_evm { + if use_local_evm { local_evm_network_from_csv() + } else if use_arbitrum_one { + info!("Using Arbitrum One EVM network as EVM_NETWORK is set to 'arbitrum-one'"); + Ok(Network::ArbitrumOne) } else if let Ok(evm_vars) = evm_vars { + info!("Using custom EVM network from environment variables"); Ok(Network::Custom(CustomNetwork::new( &evm_vars[0], &evm_vars[1], &evm_vars[2], ))) } else { - Ok(Network::ArbitrumOne) + error!("Failed to obtain EVM Network through any means"); + Err(Error::FailedToGetEvmNetwork( + "Failed to obtain EVM Network through any means".to_string(), + )) } } -pub fn get_evm_testnet_csv_path() -> Result { - let file = data_dir() - .ok_or(Error::FailedToGetEvmNetwork( - "failed to get data dir when fetching evm testnet CSV file".to_string(), - ))? - .join("safe") - .join(EVM_TESTNET_CSV_FILENAME); - Ok(file) -} - /// Get the `Network::Custom` from the local EVM testnet CSV file -pub fn local_evm_network_from_csv() -> Result { +fn local_evm_network_from_csv() -> Result { // load the csv let csv_path = get_evm_testnet_csv_path()?; diff --git a/evmlib/src/wallet.rs b/evmlib/src/wallet.rs index 2d52bb4690..e758e58eee 100644 --- a/evmlib/src/wallet.rs +++ b/evmlib/src/wallet.rs @@ -1,4 +1,10 @@ -use std::collections::BTreeMap; +// Copyright 2024 MaidSafe.net limited. +// +// This SAFE Network Software is licensed to you under The General Public License (GPL), version 3. +// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed +// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. Please review the Licences for the specific language governing +// permissions and limitations relating to use of the SAFE Network Software. use crate::common::{Address, QuoteHash, QuotePayment, TxHash, U256}; use crate::contract::data_payments::{DataPaymentsHandler, MAX_TRANSFERS_PER_TRANSACTION}; @@ -14,6 +20,7 @@ use alloy::rpc::types::TransactionRequest; use alloy::signers::local::{LocalSigner, PrivateKeySigner}; use alloy::transports::http::{reqwest, Client, Http}; use alloy::transports::{RpcError, TransportErrorKind}; +use std::collections::BTreeMap; #[derive(thiserror::Error, Debug)] pub enum Error { @@ -244,8 +251,9 @@ pub async fn pay_for_quotes>( network: &Network, payments: T, ) -> Result, PayForQuotesError> { - info!("Paying for quotes"); let payments: Vec<_> = payments.into_iter().collect(); + info!("Paying for quotes of len: {}", payments.len()); + let total_amount = payments.iter().map(|(_, _, amount)| amount).sum(); let mut tx_hashes_by_quote = BTreeMap::new(); @@ -268,11 +276,16 @@ pub async fn pay_for_quotes>( for batch in chunks { let batch: Vec = batch.to_vec(); + debug!( + "Paying for batch of quotes of len: {}, {batch:?}", + batch.len() + ); let tx_hash = data_payments .pay_for_quotes(batch.clone()) .await .map_err(|err| PayForQuotesError(Error::from(err), tx_hashes_by_quote.clone()))?; + info!("Paid for batch of quotes with final tx hash: {tx_hash}"); for (quote_hash, _, _) in batch { tx_hashes_by_quote.insert(quote_hash, tx_hash); diff --git a/sn_evm/Cargo.toml b/sn_evm/Cargo.toml index 4ee7753fde..23e9f5c310 100644 --- a/sn_evm/Cargo.toml +++ b/sn_evm/Cargo.toml @@ -12,6 +12,7 @@ version = "0.1.0" [features] test-utils = [] +local = ["evmlib/local"] [dependencies] custom_debug = "~0.6.1" diff --git a/sn_evm/src/evm.rs b/sn_evm/src/evm.rs deleted file mode 100644 index 40fde7dc18..0000000000 --- a/sn_evm/src/evm.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2024 MaidSafe.net limited. -// -// This SAFE Network Software is licensed to you under The General Public License (GPL), version 3. -// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed -// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. Please review the Licences for the specific language governing -// permissions and limitations relating to use of the SAFE Network Software. - -pub use evmlib::utils::{DATA_PAYMENTS_ADDRESS, PAYMENT_TOKEN_ADDRESS, RPC_URL}; - -/// Load the evm network from env -pub use evmlib::utils::network_from_env; - -/// Load the evm network from local CSV -pub use evmlib::utils::local_evm_network_from_csv; diff --git a/sn_evm/src/lib.rs b/sn_evm/src/lib.rs index c48f36b43e..f4c70e04a6 100644 --- a/sn_evm/src/lib.rs +++ b/sn_evm/src/lib.rs @@ -13,6 +13,8 @@ pub use evmlib::common::Address as RewardsAddress; pub use evmlib::common::QuotePayment; pub use evmlib::common::{QuoteHash, TxHash}; pub use evmlib::utils; +pub use evmlib::utils::get_evm_network_from_env; +pub use evmlib::utils::{DATA_PAYMENTS_ADDRESS, PAYMENT_TOKEN_ADDRESS, RPC_URL}; pub use evmlib::wallet::Error as EvmWalletError; pub use evmlib::wallet::Wallet as EvmWallet; pub use evmlib::Network as EvmNetwork; @@ -21,9 +23,6 @@ mod amount; mod data_payments; mod error; -/// EVM network configuration -pub mod evm; - pub use data_payments::{PaymentQuote, ProofOfPayment, QuotingMetrics}; /// Types used in the public API diff --git a/sn_networking/src/event/mod.rs b/sn_networking/src/event/mod.rs index 8cd3f704c7..ad6e1781b6 100644 --- a/sn_networking/src/event/mod.rs +++ b/sn_networking/src/event/mod.rs @@ -22,16 +22,14 @@ use libp2p::{ }; use sn_evm::PaymentQuote; +#[cfg(feature = "open-metrics")] +use sn_protocol::CLOSE_GROUP_SIZE; use sn_protocol::{ messages::{Query, Request, Response}, NetworkAddress, PrettyPrintRecordKey, }; - -#[cfg(feature = "open-metrics")] -use sn_protocol::CLOSE_GROUP_SIZE; #[cfg(feature = "open-metrics")] use std::collections::HashSet; - use std::{ collections::BTreeSet, fmt::{Debug, Formatter}, diff --git a/sn_node/Cargo.toml b/sn_node/Cargo.toml index 980d1efaa3..46a90789d6 100644 --- a/sn_node/Cargo.toml +++ b/sn_node/Cargo.toml @@ -15,7 +15,7 @@ path = "src/bin/safenode/main.rs" [features] default = ["metrics", "upnp", "open-metrics", "encrypt-records"] -local = ["sn_networking/local", "test_utils/local"] +local = ["sn_networking/local", "test_utils/local", "sn_evm/local"] otlp = ["sn_logging/otlp"] metrics = ["sn_logging/process-metrics"] network-contacts = ["sn_peers_acquisition/network-contacts"] diff --git a/sn_node/src/bin/safenode/main.rs b/sn_node/src/bin/safenode/main.rs index 7b5756cd0b..802c6696a8 100644 --- a/sn_node/src/bin/safenode/main.rs +++ b/sn_node/src/bin/safenode/main.rs @@ -17,7 +17,7 @@ use clap::{command, Parser}; use color_eyre::{eyre::eyre, Result}; use const_hex::traits::FromHex; use libp2p::{identity::Keypair, PeerId}; -use sn_evm::{EvmNetwork, RewardsAddress}; +use sn_evm::{get_evm_network_from_env, EvmNetwork, RewardsAddress}; #[cfg(feature = "metrics")] use sn_logging::metrics::init_metrics; use sn_logging::{Level, LogFormat, LogOutputDest, ReloadHandle}; @@ -253,22 +253,12 @@ fn main() -> Result<()> { return Ok(()); } - #[cfg(feature = "local")] - let evm_network = sn_evm::utils::local_evm_network_from_csv()?; - #[cfg(not(feature = "local"))] let evm_network: EvmNetwork = opt .evm_network .as_ref() .cloned() - .map(|v| v.into()) - .unwrap_or_else(|| { - sn_evm::evm::network_from_env() - .expect("Failed to get EVM network from environment variables") - }); - if matches!(evm_network, EvmNetwork::Custom(_)) { - println!("Using custom EVM network"); - info!("Using custom EVM network {evm_network:?}"); - } + .map(|v| Ok(v.into())) + .unwrap_or_else(get_evm_network_from_env)?; println!("EVM network: {evm_network:?}"); let node_socket_addr = SocketAddr::new(opt.ip, opt.port); diff --git a/sn_node_manager/src/bin/cli/subcommands/evm_network.rs b/sn_node_manager/src/bin/cli/subcommands/evm_network.rs index a046609e4e..a77893f609 100644 --- a/sn_node_manager/src/bin/cli/subcommands/evm_network.rs +++ b/sn_node_manager/src/bin/cli/subcommands/evm_network.rs @@ -7,8 +7,8 @@ // permissions and limitations relating to use of the SAFE Network Software. use clap::Subcommand; -use color_eyre::eyre::Result; -use sn_evm::{utils::local_evm_network_from_csv, EvmNetwork}; +use color_eyre::{eyre::Result, Section}; +use sn_evm::{utils::get_evm_network_from_env, EvmNetwork}; #[derive(Subcommand, Clone, Debug)] #[allow(clippy::enum_variant_names)] @@ -42,7 +42,13 @@ impl TryInto for EvmNetworkCommand { match self { Self::EvmArbitrumOne => Ok(EvmNetwork::ArbitrumOne), Self::EvmLocal => { - let network = local_evm_network_from_csv()?; + if !cfg!(feature = "local") { + return Err(color_eyre::eyre::eyre!( + "The 'local' feature flag is not enabled." + )) + .suggestion("Enable the 'local' feature flag to use the local EVM testnet."); + } + let network = get_evm_network_from_env()?; Ok(network) } Self::EvmCustom { diff --git a/test_utils/src/evm.rs b/test_utils/src/evm.rs index b7443df991..1e7731b153 100644 --- a/test_utils/src/evm.rs +++ b/test_utils/src/evm.rs @@ -10,11 +10,12 @@ use color_eyre::{ eyre::{bail, Context}, Result, }; -use evmlib::{utils::network_from_env, wallet::Wallet, Network}; +use evmlib::{utils::get_evm_network_from_env, wallet::Wallet, Network}; use std::env; -pub fn get_funded_wallet() -> Wallet { - let network = network_from_env().expect("Failed to get EVM network from environment variables"); +pub fn get_funded_wallet() -> evmlib::wallet::Wallet { + let network = + get_evm_network_from_env().expect("Failed to get EVM network from environment variables"); if matches!(network, Network::ArbitrumOne) { panic!("You're trying to use ArbitrumOne network. Use a custom network for testing."); } @@ -28,8 +29,8 @@ pub fn get_funded_wallet() -> Wallet { } pub fn get_new_wallet() -> Result { - let network = - network_from_env().wrap_err("Failed to get EVM network from environment variables")?; + let network = get_evm_network_from_env() + .wrap_err("Failed to get EVM network from environment variables")?; if matches!(network, Network::ArbitrumOne) { bail!("You're trying to use ArbitrumOne network. Use a custom network for testing."); }