Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use weight for setting storage capacity per network #1388

Merged
merged 3 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 45 additions & 62 deletions ethportal-peertest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
pub mod scenarios;
pub mod utils;

use std::{
net::{IpAddr, Ipv4Addr},
path::PathBuf,
thread, time,
};
use std::{net::Ipv4Addr, path::PathBuf, thread, time};

use ethportal_api::{
types::{
Expand Down Expand Up @@ -59,75 +55,62 @@ async fn launch_node(trin_config: TrinConfig) -> anyhow::Result<PeertestNode> {
})
}

fn generate_trin_config(id: u16, bootnode_enr: Option<&Enr>) -> TrinConfig {
let discovery_port: u16 = DEFAULT_DISCOVERY_PORT + id;
let discovery_port: String = discovery_port.to_string();
fn generate_trin_config(
id: u16,
network: &str,
subnetworks: &str,
bootnode_enr: Option<&Enr>,
) -> TrinConfig {
let bootnodes_arg = bootnode_enr
.map(|enr| enr.to_base64())
.unwrap_or("none".to_string());

let ip_addr = bootnode_enr
.map(|enr| enr.ip4().expect("bootnode must have IP"))
.unwrap_or(Ipv4Addr::new(127, 0, 0, 1));
let discovery_port = (DEFAULT_DISCOVERY_PORT + id).to_string();
let external_addr = format!("{ip_addr}:{discovery_port}");

let web3_ipc_path = PathBuf::from(format!("/tmp/ethportal-peertest-buddy-{id}.ipc"));
let web3_ipc_path_str = web3_ipc_path
.to_str()
.expect("web3_ipc_path should be unicode");

// This specific private key scheme is chosen to enforce that the first peer node will be in
// the 256 kbucket of the bootnode, to ensure consistent `FindNodes` tests.
let mut private_key = vec![id as u8; 3];
private_key.append(&mut vec![0u8; 29]);
let private_key = hex_encode(private_key);
match bootnode_enr {
Some(enr) => {
let external_addr = format!(
"{}:{}",
enr.ip4().expect("bootnode must have IP"),
discovery_port
);
let enr_base64 = enr.to_base64();
let web3_ipc_path_str = web3_ipc_path.as_path().display().to_string();
let trin_config_args = vec![
"trin",
"--portal-subnetworks",
"history,beacon,state",
"--external-address",
external_addr.as_str(),
"--bootnodes",
enr_base64.as_str(),
"--discovery-port",
discovery_port.as_str(),
"--web3-ipc-path",
&web3_ipc_path_str[..],
"--unsafe-private-key",
private_key.as_str(),
"--ephemeral",
];
TrinConfig::new_from(trin_config_args.iter()).unwrap()
}
None => {
let ip_addr = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1));
let external_addr = format!("{ip_addr}:{discovery_port}");
let web3_ipc_path_str = web3_ipc_path.as_path().display().to_string();
let trin_config_args = vec![
"trin",
"--portal-subnetworks",
"history,beacon,state",
"--external-address",
external_addr.as_str(),
"--bootnodes",
"none",
"--discovery-port",
discovery_port.as_str(),
"--web3-ipc-path",
&web3_ipc_path_str[..],
"--unsafe-private-key",
private_key.as_str(),
"--ephemeral",
];
TrinConfig::new_from(trin_config_args.iter()).unwrap()
}
}

let trin_config_args = vec![
"trin",
"--network",
network,
"--portal-subnetworks",
subnetworks,
"--bootnodes",
bootnodes_arg.as_str(),
"--discovery-port",
discovery_port.as_str(),
"--external-address",
external_addr.as_str(),
"--web3-ipc-path",
web3_ipc_path_str,
"--unsafe-private-key",
private_key.as_str(),
"--ephemeral",
];
TrinConfig::new_from(trin_config_args.iter()).unwrap()
}

pub async fn launch_peertest_nodes(count: u16) -> Peertest {
pub async fn launch_peertest_nodes(count: u16, network: &str, subnetworks: &str) -> Peertest {
// Bootnode uses a peertest id of 1
let bootnode_config = generate_trin_config(1, None);
let bootnode_config = generate_trin_config(1, network, subnetworks, None);
let bootnode = launch_node(bootnode_config).await.unwrap();
let bootnode_enr = &bootnode.enr;
// All other peertest node ids begin at 2, and increment from there
let nodes = future::try_join_all((2..count + 1).map(|id| {
let node_config = generate_trin_config(id, Some(bootnode_enr));
let nodes = future::try_join_all((2..=count).map(|id| {
let node_config = generate_trin_config(id, network, subnetworks, Some(bootnode_enr));
launch_node(node_config)
}))
.await
Expand Down
8 changes: 4 additions & 4 deletions ethportal-peertest/src/scenarios/basic.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{utils::fixture_header_with_proof, Peertest};
use crate::{utils::fixture_header_with_proof, Peertest, PeertestNode};
use alloy_primitives::{B256, U256};
use ethportal_api::{
types::{distance::Distance, portal_wire::ProtocolId},
Expand Down Expand Up @@ -133,10 +133,10 @@ pub async fn test_ping(protocol: ProtocolId, target: &Client, peertest: &Peertes
assert_eq!(result.enr_seq, 1);
}

pub async fn test_ping_cross_network(target: &Client, peertest: &Peertest) {
pub async fn test_ping_cross_network(mainnet_target: &Client, angelfood_node: &PeertestNode) {
info!("Testing ping for history cross mainnet and angelfood discv5 protocol id");
let bootnode_enr = peertest.bootnode.enr.clone();
if let Ok(pong) = HistoryNetworkApiClient::ping(target, bootnode_enr).await {
let angelfood_enr = angelfood_node.enr.clone();
if let Ok(pong) = HistoryNetworkApiClient::ping(mainnet_target, angelfood_enr).await {
panic!("Expected ping to fail as mainnet/angelfood history nodes shouldn't be able to communicate {pong:?}");
};
}
Expand Down
15 changes: 8 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use tree_hash::TreeHash;
use trin_beacon::initialize_beacon_network;
use trin_history::initialize_history_network;
use trin_state::initialize_state_network;
use trin_storage::PortalStorageConfig;
use trin_storage::PortalStorageConfigFactory;
use trin_utils::version::get_trin_version;
use trin_validation::oracle::HeaderOracle;
use utp_rs::socket::UtpSocket;
Expand Down Expand Up @@ -93,10 +93,11 @@ pub async fn run_trin(
let utp_socket = UtpSocket::with_socket(discv5_utp_socket);
let utp_socket = Arc::new(utp_socket);

let storage_config = PortalStorageConfig::new(
trin_config.mb.into(),
node_data_dir,
let storage_config_factory = PortalStorageConfigFactory::new(
trin_config.mb as u64,
&trin_config.portal_subnetworks,
discovery.local_enr().node_id(),
node_data_dir,
)?;

// Initialize state sub-network service and event handlers, if selected
Expand All @@ -109,7 +110,7 @@ pub async fn run_trin(
&discovery,
utp_socket.clone(),
portalnet_config.clone(),
storage_config.clone(),
storage_config_factory.create(STATE_NETWORK),
header_oracle.clone(),
)
.await?
Expand All @@ -132,7 +133,7 @@ pub async fn run_trin(
&discovery,
utp_socket.clone(),
portalnet_config.clone(),
storage_config.clone(),
storage_config_factory.create(BEACON_NETWORK),
header_oracle.clone(),
)
.await?
Expand All @@ -155,7 +156,7 @@ pub async fn run_trin(
&discovery,
utp_socket.clone(),
portalnet_config.clone(),
storage_config.clone(),
storage_config_factory.create(HISTORY_NETWORK),
header_oracle.clone(),
)
.await?
Expand Down
Loading
Loading