Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions kinode/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ async fn serve_register_fe(
ws_networking: (tokio::net::TcpListener, bool),
http_server_port: u16,
testnet: bool,
maybe_rpc: Option<String>,
) -> (Identity, Vec<u8>, Keyfile) {
// check if we have keys saved on disk, encrypted
// if so, prompt user for "password" to decrypt with
Expand All @@ -67,7 +68,15 @@ async fn serve_register_fe(

let (tx, mut rx) = mpsc::channel::<(Identity, Keyfile, Vec<u8>)>(1);
let (our, decoded_keyfile, encoded_keyfile) = tokio::select! {
_ = register::register(tx, kill_rx, our_ip, ws_networking, http_server_port, disk_keyfile, testnet) => {
_ = register::register(
tx,
kill_rx,
our_ip,
ws_networking,
http_server_port,
disk_keyfile,
testnet,
maybe_rpc) => {
panic!("registration failed")
}
Some((our, decoded_keyfile, encoded_keyfile)) = rx.recv() => {
Expand Down Expand Up @@ -295,6 +304,7 @@ async fn main() {
// booting will fail if the flag was used to select a different port.
// if the flag was not used, the bound port will be dropped in favor of the onchain port.

#[cfg(not(feature = "simulation-mode"))]
let (ws_tcp_handle, flag_used) = if let Some(port) = ws_networking_port {
(
http::utils::find_open_port(*port, port + 1)
Expand Down Expand Up @@ -323,6 +333,7 @@ async fn main() {
(ws_tcp_handle, flag_used),
http_server_port,
on_testnet, // true if testnet mode
matches.get_one::<String>("rpc").cloned(),
)
.await;

Expand All @@ -331,14 +342,7 @@ async fn main() {
None => {
match password {
None => {
serve_register_fe(
&home_directory_path,
our_ip.to_string(),
(ws_tcp_handle, flag_used),
http_server_port,
on_testnet, // true if testnet mode
)
.await
panic!("Fake node must be booted with either a --fake-node-name, --password, or both.");
}
Some(password) => {
match fs::read(format!("{}/.keys", home_directory_path)).await {
Expand Down
14 changes: 12 additions & 2 deletions kinode/src/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ pub async fn register(
http_port: u16,
keyfile: Option<Vec<u8>>,
testnet: bool,
maybe_rpc: Option<String>,
) {
// Networking info is generated and passed to the UI, but not used until confirmed
let (public_key, serialized_networking_keypair) = keygen::generate_networking_key();
Expand Down Expand Up @@ -153,13 +154,22 @@ pub async fn register(
};

// This ETH provider uses public rpc endpoints to verify registration signatures.
let url = if testnet {
let url = if let Some(rpc_url) = maybe_rpc {
rpc_url
} else if testnet {
"wss://ethereum-sepolia-rpc.publicnode.com".to_string()
} else {
"wss://optimism-rpc.publicnode.com".to_string()
};
let connector = WsConnect { url, auth: None };
let client = ClientBuilder::default().ws(connector).await.unwrap();
let Ok(client) = ClientBuilder::default().ws(connector).await else {
panic!(
"Error: runtime could not connect to ETH RPC.\n\
This is necessary in order to verify node identity onchain.\n\
Please make sure you are using a valid WebSockets URL if using \
the --rpc flag, and you are connected to the internet."
);
};

let provider = Arc::new(Provider::new_with_client(client));

Expand Down
3 changes: 1 addition & 2 deletions kinode/src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ pub async fn timer_service(
Some(km) = timer_message_receiver.recv() => {
// ignore Requests sent from other nodes
if km.source.node != our { continue };
// we only handle Requests which contain a little-endian u64 as IPC,
// except for a special "debug" message, which prints the current state
// we only handle Requests
let Message::Request(req) = km.message else { continue };
let Ok(timer_action) = serde_json::from_slice::<TimerAction>(&req.body) else {
let _ = print_tx.send(Printout {
Expand Down