Merge pull request #227 from kinode-dao/dr/enforce-network-at-boot

Enforce same network at boot as node was originally booted on
This commit is contained in:
doria 2024-02-05 19:36:33 -03:00 committed by GitHub
commit fd834d2164
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -140,6 +140,32 @@ async fn main() {
register::KNS_OPTIMISM_ADDRESS 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"))] #[cfg(not(feature = "simulation-mode"))]
let (rpc_url, is_detached) = (matches.get_one::<String>("rpc").unwrap(), false); let (rpc_url, is_detached) = (matches.get_one::<String>("rpc").unwrap(), false);