From e897d4dc60cf2b39b4a5e0370b0fc1580f177b98 Mon Sep 17 00:00:00 2001 From: dr-frmr Date: Mon, 5 Feb 2024 15:47:29 -0300 Subject: [PATCH] enforce --testnet flag if node is booted on testnet --- kinode/src/main.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/kinode/src/main.rs b/kinode/src/main.rs index c1d6c574..065cd446 100644 --- a/kinode/src/main.rs +++ b/kinode/src/main.rs @@ -140,6 +140,32 @@ async fn main() { register::KNS_OPTIMISM_ADDRESS }; + // check .testnet file for true/false in order to enforce testnet mode on subsequent boots of this node + match fs::read(format!("{}/.testnet", home_directory_path)).await { + Ok(contents) => { + if contents == b"true" { + if !on_testnet { + println!("\x1b[38;5;196mfatal: this is a testnet node, and must be booted with the --testnet flag. exiting.\x1b[0m"); + return; + } + } else if contents == b"false" { + if on_testnet { + println!("\x1b[38;5;196mfatal: this is a mainnet node, and must be booted without the --testnet flag. exiting.\x1b[0m"); + return; + } + } else { + panic!("invalid contents of .testnet file"); + } + } + Err(_) => { + let _ = fs::write( + format!("{}/.testnet", home_directory_path), + format!("{}", on_testnet), + ) + .await; + } + } + #[cfg(not(feature = "simulation-mode"))] let (rpc_url, is_detached) = (matches.get_one::("rpc").unwrap(), false);