diff --git a/broker/src/looper.rs b/broker/src/looper.rs index a88adf5..2eff097 100644 --- a/broker/src/looper.rs +++ b/broker/src/looper.rs @@ -5,9 +5,11 @@ use log::*; use rocket::tokio::sync::mpsc; use secp256k1::PublicKey; use sphinx_signer::{parser, sphinx_glyph::topics}; +use std::num::Wrapping; use std::sync::atomic::{AtomicU16, Ordering}; use std::thread; use std::time::Duration; +use vls_protocol::msgs::SerBolt; use vls_protocol::{msgs, msgs::Message, Error, Result}; use vls_proxy::client::Client; @@ -96,6 +98,8 @@ impl SignerLoop { } fn do_loop(&mut self, settings: Option) -> Result<()> { + // This counter is only used in the root loop to periodically send heartbeats to the hardware signer + let mut send_heartbeat = Wrapping(0u8); loop { let raw_msg = self.client.read_raw()?; // debug!("loop {}: got raw", self.log_prefix); @@ -141,8 +145,16 @@ impl SignerLoop { let reply = self.handle_message(raw_msg, catch_init)?; // Write the reply to CLN self.client.write_vec(reply)?; + // Only send heartbeat messages from the root loop, as roothandler alone can process them, not channelhandler + // Send it every ten messages to prune extraneous data on hardware signer + if self.client_id.is_none() && send_heartbeat % Wrapping(10u8) == Wrapping(0u8) + { + let beat = msgs::GetHeartbeat {}; + let _ = self.handle_message(beat.as_vec(), false)?; + } } } + send_heartbeat += 1; } }