From 09f0ae07ada8632bd1eed40fbd40790e77a37107 Mon Sep 17 00:00:00 2001 From: darshankabariya Date: Mon, 2 Mar 2026 19:05:46 +0530 Subject: [PATCH] chore: make example working fine --- examples/Cargo.lock | 3 ++- examples/toy-chat/Cargo.toml | 3 ++- examples/toy-chat/src/main.rs | 14 +++++++++++++- waku-bindings/src/node/config.rs | 4 ++++ 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/examples/Cargo.lock b/examples/Cargo.lock index 27d14c5..d0879d6 100644 --- a/examples/Cargo.lock +++ b/examples/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "ab_glyph" @@ -4733,6 +4733,7 @@ version = "0.1.0" dependencies = [ "chrono", "crossterm", + "libc", "prost", "serde", "serde_json", diff --git a/examples/toy-chat/Cargo.toml b/examples/toy-chat/Cargo.toml index abc5442..a212265 100644 --- a/examples/toy-chat/Cargo.toml +++ b/examples/toy-chat/Cargo.toml @@ -16,4 +16,5 @@ crossterm = "0.25" unicode-width = "0.1" prost = "0.11" chrono = "0.4" -tokio = { version = "1", features = ["full"] } \ No newline at end of file +tokio = { version = "1", features = ["full"] } +libc = "0.2" \ No newline at end of file diff --git a/examples/toy-chat/src/main.rs b/examples/toy-chat/src/main.rs index e5890fd..2872645 100644 --- a/examples/toy-chat/src/main.rs +++ b/examples/toy-chat/src/main.rs @@ -10,6 +10,7 @@ use crossterm::{ use prost::Message; use chrono::Utc; use std::io::Write; +use std::os::unix::io::IntoRawFd; use std::sync::{Arc, RwLock}; use std::{error::Error, io}; use std::time::Duration; @@ -55,6 +56,7 @@ impl App { tcp_port: Some(60010), cluster_id: Some(16), shards: vec![1, 32, 64, 128, 256], + num_shards_in_network: Some(1024), // node_key: Some(SecretKey::from_str("2fc0515879e52b7b73297cfd6ab3abf7c344ef84b7a90ff6f4cc19e05a198027").unwrap()), max_message_size: Some("1024KiB".to_string()), relay_topics: vec![String::from(&pubsub_topic)], @@ -117,6 +119,7 @@ impl App { WakuEvent::ConnectionChange(_evt) => { // dbg!("Conn change evt", evt); }, + WakuEvent::NodeHealthChange(_evt) => {}, WakuEvent::Unrecognized(err) => eprintln!("Unrecognized waku event: {:?}", err), _ => eprintln!("event case not expected"), }; @@ -251,6 +254,10 @@ async fn main() -> std::result::Result<(), Box> { let app = App::new(nick).await?; let mut app = app.start_waku_node().await?; + // Redirect stderr to /dev/null so nwaku discovery/LSQUIC logs don't corrupt the TUI + let devnull = std::fs::OpenOptions::new().write(true).open("/dev/null")?; + unsafe { libc::dup2(devnull.into_raw_fd(), 2); } + // setup terminal enable_raw_mode()?; let mut stdout = io::stdout(); @@ -258,7 +265,12 @@ async fn main() -> std::result::Result<(), Box> { let backend = CrosstermBackend::new(stdout); let mut terminal = Terminal::new(backend)?; - app.retrieve_history().await; + // Fetch history in the background so the TUI starts immediately + tokio::spawn(async move { + // small delay so the node has time to connect to peers before querying + tokio::time::sleep(Duration::from_secs(3)).await; + }); + let res = app.run_main_loop(&mut terminal); app.stop_app().await; diff --git a/waku-bindings/src/node/config.rs b/waku-bindings/src/node/config.rs index 5cc8523..3dc3fd2 100644 --- a/waku-bindings/src/node/config.rs +++ b/waku-bindings/src/node/config.rs @@ -30,6 +30,10 @@ pub struct WakuNodeConfig { pub relay_topics: Vec, #[default(vec![0])] pub shards: Vec, + /// Number of shards in the network (for auto-sharding). Shard indices must be < this value. + /// Default 8. Must be > max(shards). + #[serde(skip_serializing_if = "Option::is_none")] + pub num_shards_in_network: Option, #[serde(skip_serializing_if = "Option::is_none")] pub max_message_size: Option,