mirror of
https://github.com/stakwork/sphinx-key.git
synced 2025-12-19 00:04:25 +01:00
broker: send a heartbeat message every ten messages in the root loop
prunes extraneous data on the hardware signer
This commit is contained in:
@@ -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,9 +145,17 @@ 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;
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_message(&mut self, message: Vec<u8>, catch_init: bool) -> Result<Vec<u8>> {
|
||||
|
||||
Reference in New Issue
Block a user