mirror of
https://github.com/stakwork/sphinx-key.git
synced 2025-12-17 07:14:23 +01:00
dont panic on vls handler error
This commit is contained in:
@@ -2,6 +2,7 @@ mod derive;
|
|||||||
mod policy;
|
mod policy;
|
||||||
mod randomstartingtime;
|
mod randomstartingtime;
|
||||||
|
|
||||||
|
use anyhow::anyhow;
|
||||||
use lightning_signer::bitcoin::blockdata::constants::ChainHash;
|
use lightning_signer::bitcoin::blockdata::constants::ChainHash;
|
||||||
use lightning_signer::node::NodeServices;
|
use lightning_signer::node::NodeServices;
|
||||||
use lightning_signer::persist::Persist;
|
use lightning_signer::persist::Persist;
|
||||||
@@ -109,9 +110,15 @@ pub fn handle(
|
|||||||
}
|
}
|
||||||
let reply = if dbid > 0 {
|
let reply = if dbid > 0 {
|
||||||
let handler = root_handler.for_new_client(dbid, dummy_peer.clone(), dbid);
|
let handler = root_handler.for_new_client(dbid, dummy_peer.clone(), dbid);
|
||||||
handler.handle(message).expect("handle")
|
match handler.handle(message) {
|
||||||
|
Ok(r) => r,
|
||||||
|
Err(e) => return Err(anyhow!("client {} handler error: {:?}", dbid, e)),
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
root_handler.handle(message).expect("handle")
|
match root_handler.handle(message) {
|
||||||
|
Ok(r) => r,
|
||||||
|
Err(e) => return Err(anyhow!("root handler error: {:?}", e)),
|
||||||
|
}
|
||||||
};
|
};
|
||||||
if do_log {
|
if do_log {
|
||||||
log::info!("VLS msg handled");
|
log::info!("VLS msg handled");
|
||||||
|
|||||||
@@ -44,11 +44,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
let pubkey = hex::encode(&ctrlr.pubkey().serialize());
|
let pubkey = hex::encode(&ctrlr.pubkey().serialize());
|
||||||
let token = ctrlr.make_auth_token()?;
|
let token = ctrlr.make_auth_token()?;
|
||||||
|
|
||||||
let client_id = if is_test {
|
let client_id = if is_test { "test-1" } else { "sphinx-1" };
|
||||||
"test-1"
|
|
||||||
} else {
|
|
||||||
"sphinx-1"
|
|
||||||
};
|
|
||||||
let broker: String = env::var("BROKER").unwrap_or("localhost:1883".to_string());
|
let broker: String = env::var("BROKER").unwrap_or("localhost:1883".to_string());
|
||||||
let broker_: Vec<&str> = broker.split(":").collect();
|
let broker_: Vec<&str> = broker.split(":").collect();
|
||||||
let broker_port = broker_[1].parse::<u16>().expect("NaN");
|
let broker_port = broker_[1].parse::<u16>().expect("NaN");
|
||||||
@@ -90,8 +86,14 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn run_main(mut eventloop: EventLoop, client: &AsyncClient, mut ctrlr: Controller, is_log: bool, seed: &[u8], network: Network) {
|
async fn run_main(
|
||||||
|
mut eventloop: EventLoop,
|
||||||
|
client: &AsyncClient,
|
||||||
|
mut ctrlr: Controller,
|
||||||
|
is_log: bool,
|
||||||
|
seed: &[u8],
|
||||||
|
network: Network,
|
||||||
|
) {
|
||||||
let store_path = env::var("STORE_PATH").unwrap_or(ROOT_STORE.to_string());
|
let store_path = env::var("STORE_PATH").unwrap_or(ROOT_STORE.to_string());
|
||||||
|
|
||||||
let seed32: [u8; 32] = seed.try_into().expect("wrong seed");
|
let seed32: [u8; 32] = seed.try_into().expect("wrong seed");
|
||||||
@@ -120,13 +122,22 @@ async fn run_main(mut eventloop: EventLoop, client: &AsyncClient, mut ctrlr: Con
|
|||||||
.publish(topics::VLS_RETURN, QoS::AtMostOnce, false, b)
|
.publish(topics::VLS_RETURN, QoS::AtMostOnce, false, b)
|
||||||
.await
|
.await
|
||||||
.expect("could not publish init response"),
|
.expect("could not publish init response"),
|
||||||
Err(e) => panic!("HANDLE FAILED {:?}", e),
|
Err(e) => client
|
||||||
|
.publish(
|
||||||
|
topics::ERROR,
|
||||||
|
QoS::AtMostOnce,
|
||||||
|
false,
|
||||||
|
e.to_string().as_bytes(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.expect("could not publish init response"),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
topics::CONTROL => {
|
topics::CONTROL => {
|
||||||
match ctrlr.handle(&msg_bytes) {
|
match ctrlr.handle(&msg_bytes) {
|
||||||
Ok((_msg, res)) => {
|
Ok((_msg, res)) => {
|
||||||
let res_data = rmp_serde::to_vec(&res).expect("could not build control response");
|
let res_data = rmp_serde::to_vec(&res)
|
||||||
|
.expect("could not build control response");
|
||||||
client
|
client
|
||||||
.publish(
|
.publish(
|
||||||
topics::CONTROL_RETURN,
|
topics::CONTROL_RETURN,
|
||||||
@@ -153,7 +164,12 @@ async fn run_main(mut eventloop: EventLoop, client: &AsyncClient, mut ctrlr: Con
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn run_test(mut eventloop: EventLoop, client: &AsyncClient, mut ctrlr: Controller, is_log: bool) {
|
async fn run_test(
|
||||||
|
mut eventloop: EventLoop,
|
||||||
|
client: &AsyncClient,
|
||||||
|
mut ctrlr: Controller,
|
||||||
|
is_log: bool,
|
||||||
|
) {
|
||||||
// test handler loop
|
// test handler loop
|
||||||
loop {
|
loop {
|
||||||
match eventloop.poll().await {
|
match eventloop.poll().await {
|
||||||
@@ -163,8 +179,7 @@ async fn run_test(mut eventloop: EventLoop, client: &AsyncClient, mut ctrlr: Con
|
|||||||
match topic.as_str() {
|
match topic.as_str() {
|
||||||
topics::VLS => {
|
topics::VLS => {
|
||||||
let (ping, sequence, dbid): (msgs::Ping, u16, u64) =
|
let (ping, sequence, dbid): (msgs::Ping, u16, u64) =
|
||||||
parser::request_from_bytes(msg_bytes)
|
parser::request_from_bytes(msg_bytes).expect("read ping header");
|
||||||
.expect("read ping header");
|
|
||||||
if is_log {
|
if is_log {
|
||||||
println!("sequence {}", sequence);
|
println!("sequence {}", sequence);
|
||||||
println!("dbid {}", dbid);
|
println!("dbid {}", dbid);
|
||||||
@@ -184,7 +199,8 @@ async fn run_test(mut eventloop: EventLoop, client: &AsyncClient, mut ctrlr: Con
|
|||||||
topics::CONTROL => {
|
topics::CONTROL => {
|
||||||
match ctrlr.handle(&msg_bytes) {
|
match ctrlr.handle(&msg_bytes) {
|
||||||
Ok((_msg, res)) => {
|
Ok((_msg, res)) => {
|
||||||
let res_data = rmp_serde::to_vec(&res).expect("could not build control response");
|
let res_data = rmp_serde::to_vec(&res)
|
||||||
|
.expect("could not build control response");
|
||||||
client
|
client
|
||||||
.publish(
|
.publish(
|
||||||
topics::CONTROL_RETURN,
|
topics::CONTROL_RETURN,
|
||||||
|
|||||||
Reference in New Issue
Block a user