Skip to content

Commit

Permalink
feat(config): Change config for admin interface from port to address (#…
Browse files Browse the repository at this point in the history
…4947)

* feat(config): Allow providing address binding for admin interface config.

* refactor(config): Use `impl Into<SocketAddr>` instead of `SocketAddr` for flexibility

* fix: align quoting in the node yaml config files

---------

Co-authored-by: muXxer <[email protected]>
  • Loading branch information
daria305 and muXxer authored Jan 23, 2025
1 parent 7b2fe6a commit f6605c9
Show file tree
Hide file tree
Showing 16 changed files with 66 additions and 62 deletions.
8 changes: 4 additions & 4 deletions crates/iota-config/data/fullnode-template.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# Update this value to the location you want IOTA to store its database
db-path: "/opt/iota/db"
db-path: /opt/iota/db

# For ipv4, update this to "/ipv4/X.X.X.X/tcp/8080/http"
network-address: "/dns/localhost/tcp/8080/http"
network-address: /dns/localhost/tcp/8080/http
metrics-address: "0.0.0.0:9184"
# this address is also used for web socket connections
json-rpc-address: "0.0.0.0:9000"
enable-event-processing: true

genesis:
# Update this to the location of where the genesis file is stored
genesis-file-location: "/opt/iota/config/genesis.blob"
genesis-file-location: /opt/iota/config/genesis.blob

# Update this to the location of where the migration file is stored
migration-tx-data-path: "/opt/iota/config/migration.blob"
migration-tx-data-path: /opt/iota/config/migration.blob

authority-store-pruning-config:
num-latest-epoch-dbs-to-retain: 3
Expand Down
12 changes: 6 additions & 6 deletions crates/iota-config/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use std::{
collections::{BTreeMap, BTreeSet},
net::SocketAddr,
net::{IpAddr, Ipv4Addr, SocketAddr},
num::NonZeroUsize,
path::{Path, PathBuf},
sync::Arc,
Expand Down Expand Up @@ -84,11 +84,11 @@ pub struct NodeConfig {
#[serde(default = "default_metrics_address")]
pub metrics_address: SocketAddr,

/// The port for the admin interface that is
/// The address for the admin interface that is
/// run in the metrics separate runtime and provides access to
/// admin node commands such as logging and tracing options.
#[serde(default = "default_admin_interface_port")]
pub admin_interface_port: u16,
#[serde(default = "default_admin_interface_address")]
pub admin_interface_address: SocketAddr,

/// Configuration struct for the consensus.
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -343,8 +343,8 @@ fn default_metrics_address() -> SocketAddr {
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 9184)
}

pub fn default_admin_interface_port() -> u16 {
1337
pub fn default_admin_interface_address() -> SocketAddr {
SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 1337)
}

pub fn default_json_rpc_address() -> SocketAddr {
Expand Down
13 changes: 6 additions & 7 deletions crates/iota-node/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
// Modifications Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use std::{
net::{IpAddr, Ipv4Addr, SocketAddr},
str::FromStr,
sync::Arc,
};
use std::{net::SocketAddr, str::FromStr, sync::Arc};

use axum::{
Router,
Expand Down Expand Up @@ -91,7 +87,11 @@ struct AppState {
tracing_handle: TracingHandle,
}

pub async fn run_admin_server(node: Arc<IotaNode>, port: u16, tracing_handle: TracingHandle) {
pub async fn run_admin_server(
node: Arc<IotaNode>,
socket_address: SocketAddr,
tracing_handle: TracingHandle,
) {
let filter = tracing_handle.get_log().unwrap();

let app_state = AppState {
Expand Down Expand Up @@ -126,7 +126,6 @@ pub async fn run_admin_server(node: Arc<IotaNode>, port: u16, tracing_handle: Tr
)
.with_state(Arc::new(app_state));

let socket_address = SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), port);
info!(
filter =% filter,
address =% socket_address,
Expand Down
4 changes: 2 additions & 2 deletions crates/iota-node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ fn main() {

let is_validator = config.consensus_config().is_some();

let admin_interface_port = config.admin_interface_port;
let admin_interface_address = config.admin_interface_address;

// Run node in a separate runtime so that admin/monitoring functions continue to
// work if it deadlocks.
Expand Down Expand Up @@ -164,7 +164,7 @@ fn main() {
))
.unwrap();

iota_node::admin::run_admin_server(node, admin_interface_port, filter_handle).await
iota_node::admin::run_admin_server(node, admin_interface_address, filter_handle).await
});

// wait for SIGINT on the main thread
Expand Down
36 changes: 20 additions & 16 deletions crates/iota-swarm-config/src/node_config_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ impl ValidatorConfigBuilder {
db_path,
network_address,
metrics_address: validator.metrics_address,
admin_interface_port: local_ip_utils::get_available_port(&localhost),
admin_interface_address: local_ip_utils::new_tcp_address_for_testing(&localhost)
.to_socket_addr()
.unwrap(),
json_rpc_address: local_ip_utils::new_tcp_address_for_testing(&localhost)
.to_socket_addr()
.unwrap(),
Expand Down Expand Up @@ -257,7 +259,7 @@ pub struct FullnodeConfigBuilder {
network_address: Option<Multiaddr>,
json_rpc_address: Option<SocketAddr>,
metrics_address: Option<SocketAddr>,
admin_interface_port: Option<u16>,
admin_interface_address: Option<SocketAddr>,
genesis: Option<Genesis>,
p2p_external_address: Option<Multiaddr>,
p2p_listen_address: Option<SocketAddr>,
Expand All @@ -284,9 +286,9 @@ impl FullnodeConfigBuilder {
self
}

pub fn with_rpc_addr(mut self, addr: SocketAddr) -> Self {
pub fn with_rpc_addr(mut self, addr: impl Into<SocketAddr>) -> Self {
assert!(self.rpc_addr.is_none() && self.rpc_port.is_none());
self.rpc_addr = Some(addr);
self.rpc_addr = Some(addr.into());
self
}

Expand Down Expand Up @@ -318,18 +320,21 @@ impl FullnodeConfigBuilder {
self
}

pub fn with_json_rpc_address(mut self, json_rpc_address: SocketAddr) -> Self {
self.json_rpc_address = Some(json_rpc_address);
pub fn with_json_rpc_address(mut self, json_rpc_address: impl Into<SocketAddr>) -> Self {
self.json_rpc_address = Some(json_rpc_address.into());
self
}

pub fn with_metrics_address(mut self, metrics_address: SocketAddr) -> Self {
self.metrics_address = Some(metrics_address);
pub fn with_metrics_address(mut self, metrics_address: impl Into<SocketAddr>) -> Self {
self.metrics_address = Some(metrics_address.into());
self
}

pub fn with_admin_interface_port(mut self, admin_interface_port: u16) -> Self {
self.admin_interface_port = Some(admin_interface_port);
pub fn with_admin_interface_address(
mut self,
admin_interface_address: impl Into<SocketAddr>,
) -> Self {
self.admin_interface_address = Some(admin_interface_address.into());
self
}

Expand All @@ -343,8 +348,8 @@ impl FullnodeConfigBuilder {
self
}

pub fn with_p2p_listen_address(mut self, p2p_listen_address: SocketAddr) -> Self {
self.p2p_listen_address = Some(p2p_listen_address);
pub fn with_p2p_listen_address(mut self, p2p_listen_address: impl Into<SocketAddr>) -> Self {
self.p2p_listen_address = Some(p2p_listen_address.into());
self
}

Expand Down Expand Up @@ -436,7 +441,6 @@ impl FullnodeConfigBuilder {
}
};

let localhost = local_ip_utils::localhost_for_testing();
let json_rpc_address = self.rpc_addr.unwrap_or_else(|| {
let rpc_port = self
.rpc_port
Expand Down Expand Up @@ -467,9 +471,9 @@ impl FullnodeConfigBuilder {
metrics_address: self
.metrics_address
.unwrap_or(local_ip_utils::new_local_tcp_socket_for_testing()),
admin_interface_port: self
.admin_interface_port
.unwrap_or(local_ip_utils::get_available_port(&localhost)),
admin_interface_address: self
.admin_interface_address
.unwrap_or(local_ip_utils::new_local_tcp_socket_for_testing()),
json_rpc_address: self.json_rpc_address.unwrap_or(json_rpc_address),
consensus_config: None,
remove_deprecated_tables: false,
Expand Down
3 changes: 2 additions & 1 deletion crates/iota-swarm-config/tests/snapshot_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ fn network_config_snapshot_matches() {
validator_config.metrics_address = fake_socket;
validator_config.p2p_config.listen_address = fake_socket;
validator_config.p2p_config.external_address = None;
validator_config.admin_interface_port = 8888;
validator_config.admin_interface_address =
SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 8888);
if let Some(consensus_config) = validator_config.consensus_config.as_mut() {
consensus_config.db_path = PathBuf::from("/tmp/foo/");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ validator_configs:
json-rpc-address: "0.0.0.0:1"
enable-rest-api: true
metrics-address: "0.0.0.0:1"
admin-interface-port: 8888
admin-interface-address: "127.0.0.1:8888"
consensus-config:
db-path: /tmp/foo/
db-retention-epochs: ~
Expand Down Expand Up @@ -136,7 +136,7 @@ validator_configs:
json-rpc-address: "0.0.0.0:1"
enable-rest-api: true
metrics-address: "0.0.0.0:1"
admin-interface-port: 8888
admin-interface-address: "127.0.0.1:8888"
consensus-config:
db-path: /tmp/foo/
db-retention-epochs: ~
Expand Down Expand Up @@ -256,7 +256,7 @@ validator_configs:
json-rpc-address: "0.0.0.0:1"
enable-rest-api: true
metrics-address: "0.0.0.0:1"
admin-interface-port: 8888
admin-interface-address: "127.0.0.1:8888"
consensus-config:
db-path: /tmp/foo/
db-retention-epochs: ~
Expand Down Expand Up @@ -376,7 +376,7 @@ validator_configs:
json-rpc-address: "0.0.0.0:1"
enable-rest-api: true
metrics-address: "0.0.0.0:1"
admin-interface-port: 8888
admin-interface-address: "127.0.0.1:8888"
consensus-config:
db-path: /tmp/foo/
db-retention-epochs: ~
Expand Down Expand Up @@ -496,7 +496,7 @@ validator_configs:
json-rpc-address: "0.0.0.0:1"
enable-rest-api: true
metrics-address: "0.0.0.0:1"
admin-interface-port: 8888
admin-interface-address: "127.0.0.1:8888"
consensus-config:
db-path: /tmp/foo/
db-retention-epochs: ~
Expand Down Expand Up @@ -616,7 +616,7 @@ validator_configs:
json-rpc-address: "0.0.0.0:1"
enable-rest-api: true
metrics-address: "0.0.0.0:1"
admin-interface-port: 8888
admin-interface-address: "127.0.0.1:8888"
consensus-config:
db-path: /tmp/foo/
db-retention-epochs: ~
Expand Down Expand Up @@ -736,7 +736,7 @@ validator_configs:
json-rpc-address: "0.0.0.0:1"
enable-rest-api: true
metrics-address: "0.0.0.0:1"
admin-interface-port: 8888
admin-interface-address: "127.0.0.1:8888"
consensus-config:
db-path: /tmp/foo/
db-retention-epochs: ~
Expand Down
2 changes: 1 addition & 1 deletion crates/iota-tool/src/db_tool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ pub fn reset_db_to_genesis(path: &Path) -> anyhow::Result<()> {
// json-rpc-address: "0.0.0.0:9000"
// websocket-address: "0.0.0.0:9001"
// metrics-address: "0.0.0.0:9184"
// admin-interface-port: 1337
// admin-interface-address: "127.0.0.1:1337"
// enable-event-processing: true
// grpc-load-shed: ~
// grpc-concurrency-limit: ~
Expand Down
10 changes: 5 additions & 5 deletions crates/iota/src/iota_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1112,12 +1112,12 @@ async fn genesis(
.with_config_directory(FULL_NODE_DB_PATH.into())
.with_p2p_external_address(ssfn.p2p_address)
.with_network_key_pair(ssfn.network_key_pair)
.with_p2p_listen_address("0.0.0.0:8084".parse().unwrap())
.with_p2p_listen_address(([0, 0, 0, 0], 8084))
.with_db_path(PathBuf::from("/opt/iota/db/authorities_db/full_node_db"))
.with_network_address("/ip4/0.0.0.0/tcp/8080/http".parse().unwrap())
.with_metrics_address("0.0.0.0:9184".parse().unwrap())
.with_admin_interface_port(1337)
.with_json_rpc_address("0.0.0.0:9000".parse().unwrap())
.with_network_address("/ip4/0.0.0.0/tcp/8080/http".parse()?)
.with_metrics_address(([0, 0, 0, 0], 9184))
.with_admin_interface_address(([127, 0, 0, 1], 1337))
.with_json_rpc_address(([0, 0, 0, 0], 9000))
.with_genesis(genesis.clone())
.build_from_parts(&mut OsRng, network_config.validator_configs(), genesis);
ssfn_nodes.push(ssfn_config.clone());
Expand Down
6 changes: 3 additions & 3 deletions dev-tools/iota-network/genesis/overlays/common.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
validator:
network-address: /ip4/0.0.0.0/tcp/8080/http
metrics-address: 0.0.0.0:9184
json-rpc-address: 0.0.0.0:9000
admin-interface-port: 1337
metrics-address: "0.0.0.0:9184"
json-rpc-address: "0.0.0.0:9000"
admin-interface-address: "127.0.0.1:1337"
genesis:
genesis-file-location: /opt/iota/config/genesis.blob
db-path: /opt/iota/db/authorities_db
Expand Down
2 changes: 1 addition & 1 deletion dev-tools/iota-network/genesis/static/fullnode.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ db-path: /opt/iota/db
network-address: /ip4/0.0.0.0/tcp/8080/http
json-rpc-address: "0.0.0.0:9000"
metrics-address: "0.0.0.0:9184"
admin-interface-port: 1337
admin-interface-address: "127.0.0.1:1337"
enable-event-processing: true
grpc-load-shed: ~
grpc-concurrency-limit: ~
Expand Down
2 changes: 1 addition & 1 deletion dev-tools/iota-private-network/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ generate_genesis_files() {
.network-address = $overlay.network-address |
.metrics-address = $overlay.metrics-address |
.json-rpc-address = $overlay.json-rpc-address |
.admin-interface-port = $overlay.admin-interface-port |
.admin-interface-address = $overlay.admin-interface-address |
.genesis.genesis-file-location = $overlay.genesis.genesis-file-location |
.db-path = $overlay.db-path |
.consensus-config.db-path = $overlay.consensus-config.db-path |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ db-path: /opt/iota/db
network-address: /ip4/0.0.0.0/tcp/8080/http
json-rpc-address: "0.0.0.0:9000"
metrics-address: "0.0.0.0:9184"
admin-interface-port: 1337
admin-interface-address: "127.0.0.1:1337"
enable-event-processing: true
grpc-load-shed: ~
grpc-concurrency-limit: ~
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ db-path: /opt/iota/db
network-address: /ip4/0.0.0.0/tcp/8080/http
json-rpc-address: "0.0.0.0:9000"
metrics-address: "0.0.0.0:9184"
admin-interface-port: 1337
admin-interface-address: "127.0.0.1:1337"
enable-event-processing: true
grpc-load-shed: ~
grpc-concurrency-limit: ~
Expand Down
6 changes: 3 additions & 3 deletions dev-tools/iota-private-network/configs/validator-common.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
validator:
network-address: /ip4/0.0.0.0/tcp/8080/http
metrics-address: 0.0.0.0:9184
json-rpc-address: 0.0.0.0:9000
admin-interface-port: 1337
metrics-address: "0.0.0.0:9184"
json-rpc-address: "0.0.0.0:9000"
admin-interface-address: "127.0.0.1:1337"
genesis:
genesis-file-location: /opt/iota/config/genesis.blob
db-path: /opt/iota/db/authorities_db
Expand Down
6 changes: 3 additions & 3 deletions nre/config/validator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ network-key-pair:
path: /opt/iota/key-pairs/network.key
db-path: /opt/iota/db/authorities_db
network-address: /ip4/0.0.0.0/tcp/8080/http
metrics-address: 0.0.0.0:9184
admin-interface-port: 1337
metrics-address: "0.0.0.0:9184"
admin-interface-address: "127.0.0.1:1337"
consensus-config:
db-path: /opt/iota/db/consensus_db
internal-worker-address: null
enable-event-processing: false
p2p-config:
listen-address: 0.0.0.0:8084
listen-address: "0.0.0.0:8084"
external-address: /dns/$HOSTNAME/udp/8084 # UPDATE THIS
anemo-config:
max-concurrent-connections: 0
Expand Down

0 comments on commit f6605c9

Please sign in to comment.