Skip to content

Commit 7297581

Browse files
committed
Dockerfiles: misc improvements
improve comments; use localhost as the bind address for rpc calls and api servers' postgres db; unify argument passing via env vars for wallet and wallet rpc daemon; a bit more logging
1 parent 57c8f28 commit 7297581

File tree

4 files changed

+53
-24
lines changed

4 files changed

+53
-24
lines changed

build-tools/docker/example-mainnet/.env

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,33 @@ API_SERVER_POSTGRES_DB=postgres
2222
# The password for the postgres dbms.
2323
API_SERVER_POSTGRES_PASSWORD=use-strong-password
2424

25-
# The node's rpc and p2p ports will be mapped to these ports on the host machine.
25+
# The node's rpc port will be mapped to this port on the host machine.
26+
# Note that it will only be reachable from localhost and not from other network interfaces.
2627
NODE_RPC_HOST_PORT=3030
27-
NODE_P2P_HOST_PORT=3031
28-
2928
# Username and password for node rpc calls.
3029
NODE_RPC_USERNAME=username
3130
NODE_RPC_PASSWORD=use-another-strong-password
3231

32+
# The node's p2p port will be mapped to this port on the host machine.
33+
# IMPORTANT: changing this port alone won't be enough to make your node discoverable by other nodes
34+
# (or, if it was already discoverable, it may make it not discoverable anymore).
35+
# The reason is that the node will advertise itself to the peers as "your_global_ip_address:the_port_you_specify_here".
36+
# So, if you are behind NAT, you have to also make sure that "the_port_you_specify_here" is open to
37+
# the outside world and mapped to "the_port_you_specify_here" on your host machine.
38+
# On the other hand if you don't care about incoming connections from other nodes, just leave
39+
# this variable as is.
40+
NODE_P2P_HOST_PORT=3031
41+
3342
# Wallet rpc daemon's port will be mapped to this port on the host machine.
43+
# This is reachable only from localhost.
3444
WALLET_RPC_DAEMON_HOST_PORT=3034
3545
# Username and password for wallet rpc calls.
3646
WALLET_RPC_DAEMON_USERNAME=username
3747
WALLET_RPC_DAEMON_PASSWORD=use-yet-another-strong-password
3848

3949
# Host machine's port to which api server's postgres port will be mapped.
4050
# This is only useful if you want to examine the contents of the db yourself, e.g. via PgAdmin.
51+
# Reachable only from localhost.
4152
API_SERVER_POSTGRES_HOST_PORT=5434
4253

4354
# The API web server's port will be mapped to this port on the host machine.

build-tools/docker/example-mainnet/docker-compose.yml

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,27 @@ services:
1616
command: node-daemon mainnet
1717
environment:
1818
<<: *ml-common-env
19-
# Note:
20-
# The default rpc bind address is '127.0.0.1', so it'll only be reachable from the same
21-
# container; to make it reachable from other containers, we need to set it to '0.0.0.0'.
19+
# For rpc, the default rpc bind address is '127.0.0.1', so it'll only be reachable from the
20+
# same container; to make it reachable from other containers or from the host machine, we
21+
# have to set it to '0.0.0.0'.
22+
ML_MAINNET_NODE_RPC_BIND_ADDRESS: 0.0.0.0:3030
2223
# For p2p, the default address is already '0.0.0.0'. But it's better to use the same port
2324
# as the one exposed on the host system, otherwise other nodes won't be able to establish
2425
# outbound connections to this node.
2526
# Details: the node determines its own "public" p2p address by combining its ip address
2627
# as it is seen by a peer with the port that it is listening on; this address is then
2728
# advertised to other peers and propagated through the network. So, if the listening port
2829
# differs from the one exposed on the host, the advertised address will be incorrect.
29-
ML_MAINNET_NODE_RPC_BIND_ADDRESS: 0.0.0.0:3030
3030
ML_MAINNET_NODE_P2P_BIND_ADDRESSES: 0.0.0.0:$NODE_P2P_HOST_PORT
3131
# Rpc username and password.
3232
ML_MAINNET_NODE_RPC_USERNAME: $NODE_RPC_USERNAME
3333
ML_MAINNET_NODE_RPC_PASSWORD: $NODE_RPC_PASSWORD
3434
ports:
3535
# This is only needed if you want to access the node's rpc interface from the host system.
36-
- "$NODE_RPC_HOST_PORT:3030"
36+
# Note that here we also set the ip address to bind to on the host to 127.0.0.1; because of
37+
# this, rpc connections will only be allowed from the host machine and not from the "outside
38+
# world".
39+
- "127.0.0.1:$NODE_RPC_HOST_PORT:3030"
3740
# This is only needed if you want the node to be able to accept incoming p2p connections
3841
# from other nodes.
3942
- "$NODE_P2P_HOST_PORT:$NODE_P2P_HOST_PORT"
@@ -49,7 +52,7 @@ services:
4952
ports:
5053
# This is only needed if you want to examine the contents of the db from the host system,
5154
# e.g. via PgAdmin.
52-
- "$API_SERVER_POSTGRES_HOST_PORT:5432"
55+
- "127.0.0.1:$API_SERVER_POSTGRES_HOST_PORT:5432"
5356
volumes:
5457
# Explicitly mount postgres docker image's mount point to a named volume (without this,
5558
# docker will create an anonymous volume instead).
@@ -102,28 +105,30 @@ services:
102105
- node-daemon
103106
environment:
104107
<<: *ml-common-env
105-
ML_WALLET_RPC_DAEMON_NODE_RPC_ADDRESS: node-daemon:3030
106-
ML_WALLET_RPC_DAEMON_NODE_RPC_USERNAME: $NODE_RPC_USERNAME
107-
ML_WALLET_RPC_DAEMON_NODE_RPC_PASSWORD: $NODE_RPC_PASSWORD
108-
ML_WALLET_RPC_DAEMON_RPC_BIND_ADDRESS: 0.0.0.0:3034
109-
ML_WALLET_RPC_DAEMON_RPC_USERNAME: $WALLET_RPC_DAEMON_USERNAME
110-
ML_WALLET_RPC_DAEMON_RPC_PASSWORD: $WALLET_RPC_DAEMON_PASSWORD
108+
ML_MAINNET_WALLET_RPC_DAEMON_NODE_RPC_ADDRESS: node-daemon:3030
109+
ML_MAINNET_WALLET_RPC_DAEMON_NODE_RPC_USERNAME: $NODE_RPC_USERNAME
110+
ML_MAINNET_WALLET_RPC_DAEMON_NODE_RPC_PASSWORD: $NODE_RPC_PASSWORD
111+
# Same as for the node, the default rpc bind address is '127.0.0.1' here; we need to set it
112+
# to '0.0.0.0' to make it reachable from other containers/host machine.
113+
ML_MAINNET_WALLET_RPC_DAEMON_RPC_BIND_ADDRESS: 0.0.0.0:3034
114+
ML_MAINNET_WALLET_RPC_DAEMON_RPC_USERNAME: $WALLET_RPC_DAEMON_USERNAME
115+
ML_MAINNET_WALLET_RPC_DAEMON_RPC_PASSWORD: $WALLET_RPC_DAEMON_PASSWORD
111116
ports:
112-
- "$WALLET_RPC_DAEMON_HOST_PORT:3034"
117+
- "127.0.0.1:$WALLET_RPC_DAEMON_HOST_PORT:3034"
113118

114119
# wallet-cli is not a real service; we just need a service definition for it in order to be able
115120
# to run it via "docker compose run"
116121
wallet-cli:
117122
<<: *ml-common
118123
image: $DOCKERHUB_USERNAME/wallet-cli:$ML_SOFTWARE_VERSION
119-
command: wallet-cli
124+
command: wallet-cli mainnet
120125
depends_on:
121126
- node-daemon
122127
environment:
123128
<<: *ml-common-env
124-
ML_WALLET_NODE_RPC_ADDRESS: node-daemon:3030
125-
ML_WALLET_NODE_RPC_USERNAME: $NODE_RPC_USERNAME
126-
ML_WALLET_NODE_RPC_PASSWORD: $NODE_RPC_PASSWORD
129+
ML_MAINNET_WALLET_NODE_RPC_ADDRESS: node-daemon:3030
130+
ML_MAINNET_WALLET_NODE_RPC_USERNAME: $NODE_RPC_USERNAME
131+
ML_MAINNET_WALLET_NODE_RPC_PASSWORD: $NODE_RPC_PASSWORD
127132
profiles:
128133
# Put it in a separate profile, so that it's not started automatically by "docker compose up".
129134
- wallet_cli

p2p/src/peer_manager/mod.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ where
317317
/// This won't work for majority of nodes but that should be accepted.
318318
fn discover_own_address(
319319
&mut self,
320+
peer_id: PeerId,
320321
peer_role: PeerRole,
321322
common_services: Services,
322323
node_address_as_seen_by_peer: Option<PeerAddress>,
@@ -366,7 +367,16 @@ where
366367

367368
// Send only one address because of the rate limiter (see `ADDR_RATE_INITIAL_SIZE`).
368369
// Select a random address to give all addresses a chance to be discovered by the network.
369-
discovered_own_addresses.into_iter().choose(&mut make_pseudo_rng())
370+
let chosen_discovered_address =
371+
discovered_own_addresses.iter().choose(&mut make_pseudo_rng()).cloned();
372+
373+
log::debug!(
374+
"Own addresses discovered for peer {peer_id}: {:?}, chosen address: {:?}",
375+
discovered_own_addresses,
376+
chosen_discovered_address
377+
);
378+
379+
chosen_discovered_address
370380
}
371381

372382
/// Send address announcement to the selected peer (if the address is new)
@@ -947,6 +957,7 @@ where
947957
);
948958

949959
let discovered_own_address = self.discover_own_address(
960+
peer_id,
950961
peer_role,
951962
info.common_services,
952963
node_address_as_seen_by_peer,

wallet/wallet-rpc-lib/src/cmdline.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,15 @@ impl WalletRpcDaemonArgs {
4545
#[derive(clap::Subcommand)]
4646
pub enum WalletRpcDaemonCommand {
4747
/// Run the mainnet wallet.
48+
#[clap(mut_args(clap_utils::env_adder("MAINNET_WALLET_RPC_DAEMON")))]
4849
Mainnet(WalletRpcDaemonChainArgs),
4950

5051
/// Run the testnet wallet.
52+
#[clap(mut_args(clap_utils::env_adder("TESTNET_WALLET_RPC_DAEMON")))]
5153
Testnet(WalletRpcDaemonChainArgs),
5254

5355
/// Run the regtest wallet.
56+
#[clap(mut_args(clap_utils::env_adder("REGTEST_WALLET_RPC_DAEMON")))]
5457
Regtest {
5558
#[command(flatten)]
5659
args: WalletRpcDaemonChainArgs,
@@ -76,7 +79,6 @@ impl WalletRpcDaemonCommand {
7679
}
7780

7881
#[derive(clap::Args)]
79-
#[clap(mut_args(clap_utils::env_adder("WALLET_RPC_DAEMON")))]
8082
#[command(
8183
version,
8284
about,
@@ -215,7 +217,7 @@ pub fn make_wallet_config(
215217
rpc_username: Option<String>,
216218
rpc_password: Option<String>,
217219
rpc_no_authentication: bool,
218-
wallet_rpc_address: Option<String>,
220+
wallet_rpc_bind_address: Option<String>,
219221
chain_type: ChainType,
220222
) -> Result<WalletRpcConfig, ConfigError> {
221223
let rpc_config = {
@@ -230,7 +232,7 @@ pub fn make_wallet_config(
230232
_ => panic!("Should not happen due to arg constraints"),
231233
};
232234

233-
let bind_addr = match wallet_rpc_address {
235+
let bind_addr = match wallet_rpc_bind_address {
234236
None => {
235237
let port = WalletRpcConfig::default_port(chain_type);
236238
std::net::SocketAddr::new(std::net::Ipv4Addr::LOCALHOST.into(), port)

0 commit comments

Comments
 (0)