Skip to content

Commit 711abb2

Browse files
committed
feat: add --with-bootnode flag for combined validator+bootnode mode
- Add --with-bootnode flag to run validator and bootnode in same process - Add --bootnode-port to configure bootnode P2P port (default: 8090) - Add --p2p-port for simpler port configuration (alternative to --listen-addr) - Add P2PConfig::add_listen_addr() to support multiple listen addresses - Update entrypoint.sh with WITH_BOOTNODE and BOOTNODE_PORT env vars Usage: validator-node --with-bootnode --p2p-port 8091 --bootnode-port 8090 This allows running both services in a single container without port conflicts.
1 parent 06909d1 commit 711abb2

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

bins/validator-node/src/main.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,18 @@ struct Args {
194194
#[arg(long)]
195195
bootnode: bool,
196196

197+
/// Also run an embedded bootnode on a separate port (validator + bootnode mode)
198+
#[arg(long)]
199+
with_bootnode: bool,
200+
201+
/// Bootnode P2P port (only used with --with-bootnode)
202+
#[arg(long, env = "BOOTNODE_PORT", default_value = "8090")]
203+
bootnode_port: u16,
204+
205+
/// P2P port (simpler alternative to --listen-addr)
206+
#[arg(long, env = "P2P_PORT")]
207+
p2p_port: Option<u16>,
208+
197209
/// Directory where WASM challenge modules are stored
198210
#[arg(long, env = "WASM_MODULE_DIR", default_value = "./wasm_modules")]
199211
wasm_module_dir: PathBuf,
@@ -234,6 +246,9 @@ impl std::fmt::Debug for Args {
234246
.field("version_key", &self.version_key)
235247
.field("no_bittensor", &self.no_bittensor)
236248
.field("bootnode", &self.bootnode)
249+
.field("with_bootnode", &self.with_bootnode)
250+
.field("bootnode_port", &self.bootnode_port)
251+
.field("p2p_port", &self.p2p_port)
237252
.field("wasm_module_dir", &self.wasm_module_dir)
238253
.field("wasm_max_memory", &self.wasm_max_memory)
239254
.field("wasm_enable_fuel", &self.wasm_enable_fuel)
@@ -280,12 +295,33 @@ async fn main() -> Result<()> {
280295
let storage = Arc::new(storage);
281296
info!("Distributed storage initialized");
282297

298+
// Determine listen address - p2p_port overrides listen_addr if specified
299+
let listen_addr = if let Some(port) = args.p2p_port {
300+
format!("/ip4/0.0.0.0/tcp/{}", port)
301+
} else if args.with_bootnode {
302+
// When running with embedded bootnode, default validator to port 8091
303+
// (bootnode will use 8090)
304+
"/ip4/0.0.0.0/tcp/8091".to_string()
305+
} else {
306+
args.listen_addr.clone()
307+
};
308+
283309
// Build P2P config - use defaults and add any extra bootstrap peers from CLI
284310
let mut p2p_config = P2PConfig::default()
285-
.with_listen_addr(&args.listen_addr)
311+
.with_listen_addr(&listen_addr)
286312
.with_netuid(args.netuid)
287313
.with_min_stake(10_000_000_000_000); // 10000 TAO
288314

315+
// If running with embedded bootnode, add bootnode port as additional listener
316+
if args.with_bootnode {
317+
let bootnode_addr = format!("/ip4/0.0.0.0/tcp/{}", args.bootnode_port);
318+
p2p_config = p2p_config.add_listen_addr(&bootnode_addr);
319+
info!(
320+
"Running validator + bootnode mode: validator on {}, bootnode on {}",
321+
listen_addr, bootnode_addr
322+
);
323+
}
324+
289325
// Set external address if provided (for NAT/Docker environments)
290326
if let Some(ref external_addr) = args.external_addr {
291327
p2p_config = p2p_config.with_external_addrs(vec![external_addr.clone()]);

crates/p2p-consensus/src/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ impl P2PConfig {
7878
self
7979
}
8080

81+
/// Add an additional listen address
82+
pub fn add_listen_addr(mut self, addr: &str) -> Self {
83+
self.listen_addrs.push(addr.to_string());
84+
self
85+
}
86+
8187
/// Add bootstrap peers
8288
pub fn with_bootstrap_peers(mut self, peers: Vec<String>) -> Self {
8389
self.bootstrap_peers = peers;

docker/entrypoint.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ echo "=== Platform Validator ==="
2626
echo "Version: ${VERSION:-unknown}"
2727
echo "P2P Port: ${P2P_PORT:-8090}"
2828
echo "RPC Port: ${RPC_PORT:-8080}"
29+
if [ "$WITH_BOOTNODE" = "true" ]; then
30+
echo "Bootnode Port: ${BOOTNODE_PORT:-8090}"
31+
echo "Mode: Validator + Bootnode"
32+
fi
2933
echo ""
3034

3135
if [ -z "$VALIDATOR_SECRET_KEY" ]; then
@@ -45,7 +49,15 @@ if [ -n "$P2P_PORT" ]; then
4549
fi
4650

4751
if [ -n "$RPC_PORT" ]; then
48-
ARGS+=("--rpc-port" "$RPC_PORT")
52+
ARGS+=("--rpc-addr" "0.0.0.0:$RPC_PORT")
53+
fi
54+
55+
if [ -n "$WITH_BOOTNODE" ] && [ "$WITH_BOOTNODE" = "true" ]; then
56+
ARGS+=("--with-bootnode")
57+
fi
58+
59+
if [ -n "$BOOTNODE_PORT" ]; then
60+
ARGS+=("--bootnode-port" "$BOOTNODE_PORT")
4961
fi
5062

5163
if [ -n "$SUBTENSOR_ENDPOINT" ]; then

0 commit comments

Comments
 (0)