broker: send a heartbeat message every ten messages in the root loop

prunes extraneous data on the hardware signer
This commit is contained in:
irriden
2023-09-07 18:56:34 +00:00
committed by irriden
parent e15e8620e5
commit 128a29f298

View File

@@ -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<C: 'static + Client> SignerLoop<C> {
}
fn do_loop(&mut self, settings: Option<Settings>) -> 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<C: 'static + Client> SignerLoop<C> {
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;
}
}