Skip to content

Add internal ip cli flag #155

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

Merged
merged 1 commit into from
Oct 27, 2021
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
40 changes: 20 additions & 20 deletions Cargo.lock

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

6 changes: 5 additions & 1 deletion ethportal-peertest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ cd ethportal-peertest
RUST_LOG=debug cargo run -p ethportal-peertest -- --target-node enr:-IS4QBDHCSMoYoC5UziAwKSyTmMPrhMaEpaE52L8DDAkipqvZQe9fgLy2wVuuEJwO9l1KsYrRoFGCsNjylbd0CDNw60BgmlkgnY0gmlwhMCoXUSJc2VjcDI1NmsxoQJPAZUFErHK1DZYRTLjk3SCNgye9sS-MxoQI-gLiUdwc4N1ZHCCIyk
```

# Target Node Config

## IP Address
To make sure the test harness can communicate with the target node, run the target node with the `--internal-ip` flag to avoid using an external ip address.

## Transport selection
Running the test harness will by default test all jsonrpc endpoints over IPC to the target node. To make sure these pass, please make sure that the target node is running with `--web3-transport ipc`. To test jsonrpc over http, use the `--target-transport http` cli argument for the harness, and make sure the target node is running with `--web3-transport http`. Ideally, both transport methods are tested before PRs.

17 changes: 11 additions & 6 deletions ethportal-peertest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let peertest_config = PeertestConfig::default();
let portal_config = PortalnetConfig {
listen_port: peertest_config.listen_port,
internal_ip: true,
..Default::default()
};

Expand Down Expand Up @@ -67,9 +68,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
ProtocolKind::History,
None,
)
.await
.unwrap();
info!("History network Ping result: {:?}", ping_result);
.await;
match ping_result {
Ok(val) => info!("Successful ping to History network: {:?}", val),
Err(msg) => panic!("Invalid ping to History network: {:?}", msg),
}

info!("Pinging {} on state network", target_node);
let ping_result = overlay
Expand All @@ -79,9 +82,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
ProtocolKind::State,
None,
)
.await
.unwrap();
info!("State network Ping result: {:?}", ping_result);
.await;
match ping_result {
Ok(val) => info!("Successful ping to State network: {:?}", val),
Err(msg) => panic!("Invalid ping to State network: {:?}", msg),
}

match peertest_config.target_transport.as_str() {
"ipc" => test_jsonrpc_endpoints_over_ipc(peertest_config.target_ipc_path).await,
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
external_addr: trin_config.external_addr,
private_key: trin_config.private_key.clone(),
listen_port: trin_config.discovery_port,
internal_ip: trin_config.internal_ip,
bootnode_enrs,
..Default::default()
};
Expand Down
13 changes: 13 additions & 0 deletions trin-core/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ pub struct TrinConfig {
)]
pub external_addr: Option<SocketAddr>,

#[structopt(
long = "internal-ip",
help = "(For testing purposes) Use local ip address rather than external via STUN."
)]
pub internal_ip: bool,

#[structopt(
validator(check_private_key_length),
long = "unsafe-private-key",
Expand Down Expand Up @@ -169,6 +175,7 @@ mod test {
pool_size: 2,
web3_transport: "ipc".to_string(),
discovery_port: DEFAULT_DISCOVERY_PORT.parse().unwrap(),
internal_ip: false,
bootnodes: vec![],
external_addr: None,
private_key: None,
Expand All @@ -195,6 +202,7 @@ mod test {
pool_size: 3,
web3_transport: "http".to_string(),
discovery_port: DEFAULT_DISCOVERY_PORT.parse().unwrap(),
internal_ip: false,
bootnodes: vec![],
networks: DEFAULT_SUBNETWORKS
.split(",")
Expand Down Expand Up @@ -232,6 +240,7 @@ mod test {
pool_size: 2,
web3_transport: "ipc".to_string(),
discovery_port: DEFAULT_DISCOVERY_PORT.parse().unwrap(),
internal_ip: false,
bootnodes: vec![],
networks: DEFAULT_SUBNETWORKS
.split(",")
Expand Down Expand Up @@ -265,6 +274,7 @@ mod test {
pool_size: 2,
web3_transport: "ipc".to_string(),
discovery_port: DEFAULT_DISCOVERY_PORT.parse().unwrap(),
internal_ip: false,
bootnodes: vec![],
networks: DEFAULT_SUBNETWORKS
.split(",")
Expand Down Expand Up @@ -322,6 +332,7 @@ mod test {
pool_size: 2,
web3_transport: "ipc".to_string(),
discovery_port: 999,
internal_ip: false,
bootnodes: vec![],
networks: DEFAULT_SUBNETWORKS
.split(",")
Expand All @@ -344,6 +355,7 @@ mod test {
pool_size: 2,
web3_transport: "ipc".to_string(),
discovery_port: DEFAULT_DISCOVERY_PORT.parse().unwrap(),
internal_ip: false,
bootnodes: vec!["enr:-aoeu".to_string(), "enr:-htns".to_string()],
networks: DEFAULT_SUBNETWORKS
.split(",")
Expand Down Expand Up @@ -388,6 +400,7 @@ mod test {
pool_size: 2,
web3_transport: "ipc".to_string(),
discovery_port: DEFAULT_DISCOVERY_PORT.parse().unwrap(),
internal_ip: false,
bootnodes: vec![],
networks: DEFAULT_SUBNETWORKS
.split(",")
Expand Down
16 changes: 10 additions & 6 deletions trin-core/src/portalnet/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,20 @@ impl Discovery {
pub fn new(portal_config: PortalnetConfig) -> Result<Self, String> {
let listen_all_ips = SocketAddr::new("0.0.0.0".parse().unwrap(), portal_config.listen_port);

let external_addr = portal_config
.external_addr
.or_else(|| socket::stun_for_external(&listen_all_ips))
.unwrap_or_else(|| socket::default_local_address(portal_config.listen_port));
let ip_addr = if portal_config.internal_ip {
socket::default_local_address(portal_config.listen_port)
} else {
portal_config
.external_addr
.or_else(|| socket::stun_for_external(&listen_all_ips))
.unwrap_or_else(|| socket::default_local_address(portal_config.listen_port))
};

let config = Config {
discv5_config: Discv5ConfigBuilder::default().build(),
// This is for defining the ENR:
listen_port: external_addr.port(),
listen_address: external_addr.ip(),
listen_port: ip_addr.port(),
listen_address: ip_addr.ip(),
bootnode_enrs: portal_config.bootnode_enrs,
private_key: portal_config.private_key,
..Default::default()
Expand Down
2 changes: 2 additions & 0 deletions trin-core/src/portalnet/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct PortalnetConfig {
pub listen_port: u16,
pub bootnode_enrs: Vec<Enr>,
pub data_radius: U256,
pub internal_ip: bool,
}

impl Default for PortalnetConfig {
Expand All @@ -31,6 +32,7 @@ impl Default for PortalnetConfig {
listen_port: 4242,
bootnode_enrs: Vec::<Enr>::new(),
data_radius: U256::from(u64::MAX), //TODO better data_radius default?
internal_ip: false,
}
}
}
Expand Down