Skip to content

Commit

Permalink
feat: adapt node manager add command for evm network
Browse files Browse the repository at this point in the history
BREAKING CHANGE: services configured by the node manager are no longer compatible with networks that
are not EVM.

The node manager `add` command now supports the following EVM arguments:

* The subcommand for selecting the network type is appended.
* The `evm-custom` subcommand makes the `--data-payments-address`, `--payment-token-address` and
  `--rpc-url` arguments available.
* The `--rewards-address` argument is provided.

The `CustomNetwork` type was modified to enable it to be serialized in the node manager registry.
  • Loading branch information
jacderida committed Oct 14, 2024
1 parent c276fb2 commit e6a0f41
Show file tree
Hide file tree
Showing 15 changed files with 1,729 additions and 28 deletions.
35 changes: 35 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions evmlib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ local = []
alloy = { version = "0.4.2", default-features = false, features = ["std", "reqwest-rustls-tls", "provider-anvil-node", "sol-types", "json", "signers", "contract", "signer-local", "network"] }
dirs-next = "~2.0.0"
serde = "1.0"
serde_with = { version = "3.11.0", features = ["macros"] }
thiserror = "1.0"
tracing = { version = "~0.1.26" }
tokio = "1.38.0"
Expand Down
17 changes: 15 additions & 2 deletions evmlib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use crate::common::{Address, QuoteHash, TxHash, U256};
use crate::transaction::verify_data_payment;
use alloy::primitives::address;
use alloy::transports::http::reqwest;
use serde::{Deserialize, Serialize};
use serde_with::{serde_as, DisplayFromStr};
use std::str::FromStr;
use std::sync::LazyLock;

Expand Down Expand Up @@ -38,8 +40,10 @@ const ARBITRUM_ONE_PAYMENT_TOKEN_ADDRESS: Address =
const ARBITRUM_ONE_DATA_PAYMENTS_ADDRESS: Address =
address!("887930F30EDEb1B255Cd2273C3F4400919df2EFe");

#[derive(Clone, Debug, PartialEq)]
#[serde_as]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct CustomNetwork {
#[serde_as(as = "DisplayFromStr")]
pub rpc_url_http: reqwest::Url,
pub payment_token_address: Address,
pub data_payments_address: Address,
Expand All @@ -57,12 +61,21 @@ impl CustomNetwork {
}
}

#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub enum Network {
ArbitrumOne,
Custom(CustomNetwork),
}

impl std::fmt::Display for Network {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Network::ArbitrumOne => write!(f, "evm-arbitrum-one"),
Network::Custom(_) => write!(f, "evm-custom"),
}
}
}

impl Network {
pub fn new_custom(rpc_url: &str, payment_token_addr: &str, chunk_payments_addr: &str) -> Self {
Self::Custom(CustomNetwork::new(
Expand Down
1 change: 1 addition & 0 deletions node-launchpad/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ serde = { version = "1.0.188", features = ["derive"] }
serde_json = "1.0.107"
signal-hook = "0.3.17"
sn_build_info = { path = "../sn_build_info", version = "0.1.15" }
sn_evm = { path = "../sn_evm", version = "0.1" }
sn-node-manager = { version = "0.10.6", path = "../sn_node_manager" }
sn_peers_acquisition = { version = "0.5.3", path = "../sn_peers_acquisition" }
sn_protocol = { path = "../sn_protocol", version = "0.17.11" }
Expand Down
22 changes: 11 additions & 11 deletions node-launchpad/src/node_mgmt.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
use std::path::PathBuf;

use crate::action::{Action, StatusActions};
use crate::connection_mode::ConnectionMode;
use color_eyre::eyre::{eyre, Error};
use sn_node_manager::{
add_services::config::PortRange, config::get_node_registry_path, VerbosityLevel,
};
use sn_evm::RewardsAddress;
use sn_node_manager::{add_services::config::PortRange, config::get_node_registry_path, VerbosityLevel};
use sn_peers_acquisition::PeersArgs;
use sn_releases::{self, ReleaseType, SafeReleaseRepoActions};
use sn_service_management::NodeRegistry;
use std::{
path::PathBuf,
str::FromStr,
};
use tokio::sync::mpsc::UnboundedSender;

use crate::action::{Action, StatusActions};

use crate::connection_mode::ConnectionMode;

use sn_releases::{self, ReleaseType, SafeReleaseRepoActions};

pub const PORT_MAX: u32 = 65535;
pub const PORT_MIN: u32 = 1024;

Expand Down Expand Up @@ -302,6 +300,7 @@ async fn scale_down_nodes(config: &NodeConfig, count: u16) {
None, // We don't care about the port, as we are scaling down
config.owner.clone(),
config.peers_args.clone(),
RewardsAddress::from_str("0x1111111111111111111111111111111111111111").unwrap(),
None,
None,
config.safenode_path.clone(),
Expand Down Expand Up @@ -375,6 +374,7 @@ async fn add_nodes(
port_range,
config.owner.clone(),
config.peers_args.clone(),
RewardsAddress::from_str("0x1111111111111111111111111111111111111111").unwrap(),
None,
None,
config.safenode_path.clone(),
Expand Down
1 change: 1 addition & 0 deletions sn_evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ 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::CustomNetwork;
pub use evmlib::Network as EvmNetwork;

mod amount;
Expand Down
Loading

0 comments on commit e6a0f41

Please sign in to comment.