broker, signer: hsmd negotation, more speedups from vls

This commit is contained in:
irriden
2024-02-08 05:32:52 +00:00
parent 9ee17afcea
commit 00d495b84c
15 changed files with 191 additions and 95 deletions

90
broker/Cargo.lock generated
View File

@@ -459,7 +459,7 @@ dependencies = [
[[package]]
name = "bolt-derive"
version = "0.2.0"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=a28153e0f1b6598e6538d32b3c5bfb9c7657d565#a28153e0f1b6598e6538d32b3c5bfb9c7657d565"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=d3c35217d7dcda1f1da2b6978c95be3437d554a6#d3c35217d7dcda1f1da2b6978c95be3437d554a6"
dependencies = [
"proc-macro2",
"quote",
@@ -529,6 +529,33 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa622bd314835eb026b776af471344d0dba94705c937900656a31d0407e53689"
[[package]]
name = "ciborium"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42e69ffd6f0917f5c029256a24d0161db17cea3997d185db0d35926308770f0e"
dependencies = [
"ciborium-io",
"ciborium-ll",
"serde",
]
[[package]]
name = "ciborium-io"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05afea1e0a06c9be33d539b876f1ce3692f4afea2cb41f740e7743225ed1c757"
[[package]]
name = "ciborium-ll"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57663b653d948a338bfb3eeba9bb2fd5fcfaecb9e199e87e1eda4d9e8b240fd9"
dependencies = [
"ciborium-io",
"half",
]
[[package]]
name = "clap"
version = "3.2.25"
@@ -702,6 +729,12 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "crunchy"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7"
[[package]]
name = "crypto-common"
version = "0.1.6"
@@ -1206,9 +1239,13 @@ dependencies = [
[[package]]
name = "half"
version = "1.8.2"
version = "2.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7"
checksum = "bc52e53916c08643f1b56ec082790d1e86a32e58dc5268f897f313fbae7b4872"
dependencies = [
"cfg-if",
"crunchy",
]
[[package]]
name = "hashbrown"
@@ -1664,11 +1701,12 @@ dependencies = [
[[package]]
name = "lightning-storage-server"
version = "0.3.0"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=a28153e0f1b6598e6538d32b3c5bfb9c7657d565#a28153e0f1b6598e6538d32b3c5bfb9c7657d565"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=d3c35217d7dcda1f1da2b6978c95be3437d554a6#d3c35217d7dcda1f1da2b6978c95be3437d554a6"
dependencies = [
"anyhow",
"async-trait",
"bitcoin_hashes",
"ciborium",
"clap 3.2.25",
"ctrlc",
"deadpool-postgres",
@@ -1682,7 +1720,6 @@ dependencies = [
"redb",
"secp256k1",
"serde",
"serde_cbor",
"thiserror",
"time",
"tokio",
@@ -1758,7 +1795,7 @@ dependencies = [
[[package]]
name = "lss-connector"
version = "0.1.0"
source = "git+https://github.com/stakwork/sphinx-rs?rev=b461de86bdd8945254f38410902908f4c798da57#b461de86bdd8945254f38410902908f4c798da57"
source = "git+https://github.com/stakwork/sphinx-rs?rev=1ebddd99878f7fe2452842b813cbd93e4035a898#1ebddd99878f7fe2452842b813cbd93e4035a898"
dependencies = [
"anyhow",
"lightning-storage-server",
@@ -2760,7 +2797,7 @@ dependencies = [
[[package]]
name = "rmp-utils"
version = "0.1.0"
source = "git+https://github.com/stakwork/sphinx-rs?rev=b461de86bdd8945254f38410902908f4c798da57#b461de86bdd8945254f38410902908f4c798da57"
source = "git+https://github.com/stakwork/sphinx-rs?rev=1ebddd99878f7fe2452842b813cbd93e4035a898#1ebddd99878f7fe2452842b813cbd93e4035a898"
dependencies = [
"anyhow",
"log",
@@ -3117,16 +3154,6 @@ dependencies = [
"hex",
]
[[package]]
name = "serde_cbor"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2bef2ebfde456fb76bbcf9f59315333decc4fda0b2b44b420243c11e0f5ec1f5"
dependencies = [
"half",
"serde",
]
[[package]]
name = "serde_derive"
version = "1.0.193"
@@ -3182,9 +3209,9 @@ dependencies = [
[[package]]
name = "serde_with"
version = "3.4.0"
version = "3.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64cd236ccc1b7a29e7e2739f27c0b2dd199804abc4290e32f59f3b68d6405c23"
checksum = "1b0ed1662c5a68664f45b76d18deb0e234aff37207086803165c961eb695e981"
dependencies = [
"base64 0.21.5",
"chrono",
@@ -3197,9 +3224,9 @@ dependencies = [
[[package]]
name = "serde_with_macros"
version = "3.4.0"
version = "3.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93634eb5f75a2323b16de4748022ac4297f9e76b6dced2be287a099f41b5e788"
checksum = "568577ff0ef47b879f736cd66740e022f3672788cdf002a05a4e609ea5a6fb15"
dependencies = [
"darling",
"proc-macro2",
@@ -3339,7 +3366,7 @@ dependencies = [
[[package]]
name = "sphinx-auther"
version = "0.1.12"
source = "git+https://github.com/stakwork/sphinx-rs?rev=b461de86bdd8945254f38410902908f4c798da57#b461de86bdd8945254f38410902908f4c798da57"
source = "git+https://github.com/stakwork/sphinx-rs?rev=1ebddd99878f7fe2452842b813cbd93e4035a898#1ebddd99878f7fe2452842b813cbd93e4035a898"
dependencies = [
"anyhow",
"base64 0.21.5",
@@ -3351,7 +3378,7 @@ dependencies = [
[[package]]
name = "sphinx-glyph"
version = "0.1.2"
source = "git+https://github.com/stakwork/sphinx-rs?rev=b461de86bdd8945254f38410902908f4c798da57#b461de86bdd8945254f38410902908f4c798da57"
source = "git+https://github.com/stakwork/sphinx-rs?rev=1ebddd99878f7fe2452842b813cbd93e4035a898#1ebddd99878f7fe2452842b813cbd93e4035a898"
dependencies = [
"anyhow",
"hex",
@@ -3394,7 +3421,7 @@ dependencies = [
[[package]]
name = "sphinx-signer"
version = "0.1.0"
source = "git+https://github.com/stakwork/sphinx-rs?rev=b461de86bdd8945254f38410902908f4c798da57#b461de86bdd8945254f38410902908f4c798da57"
source = "git+https://github.com/stakwork/sphinx-rs?rev=1ebddd99878f7fe2452842b813cbd93e4035a898#1ebddd99878f7fe2452842b813cbd93e4035a898"
dependencies = [
"anyhow",
"bip39",
@@ -3403,6 +3430,7 @@ dependencies = [
"log",
"lss-connector",
"rand",
"rmp-serde",
"serde",
"sphinx-glyph",
"thiserror",
@@ -4100,7 +4128,7 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "vls-core"
version = "0.11.0-rc.1"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=a28153e0f1b6598e6538d32b3c5bfb9c7657d565#a28153e0f1b6598e6538d32b3c5bfb9c7657d565"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=d3c35217d7dcda1f1da2b6978c95be3437d554a6#d3c35217d7dcda1f1da2b6978c95be3437d554a6"
dependencies = [
"anyhow",
"backtrace",
@@ -4126,7 +4154,7 @@ dependencies = [
[[package]]
name = "vls-frontend"
version = "0.11.0-rc.1"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=a28153e0f1b6598e6538d32b3c5bfb9c7657d565#a28153e0f1b6598e6538d32b3c5bfb9c7657d565"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=d3c35217d7dcda1f1da2b6978c95be3437d554a6#d3c35217d7dcda1f1da2b6978c95be3437d554a6"
dependencies = [
"async-trait",
"lightning-storage-server",
@@ -4141,7 +4169,7 @@ dependencies = [
[[package]]
name = "vls-persist"
version = "0.11.0-rc.1"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=a28153e0f1b6598e6538d32b3c5bfb9c7657d565#a28153e0f1b6598e6538d32b3c5bfb9c7657d565"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=d3c35217d7dcda1f1da2b6978c95be3437d554a6#d3c35217d7dcda1f1da2b6978c95be3437d554a6"
dependencies = [
"hex",
"log",
@@ -4156,7 +4184,7 @@ dependencies = [
[[package]]
name = "vls-protocol"
version = "0.11.0-rc.1"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=a28153e0f1b6598e6538d32b3c5bfb9c7657d565#a28153e0f1b6598e6538d32b3c5bfb9c7657d565"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=d3c35217d7dcda1f1da2b6978c95be3437d554a6#d3c35217d7dcda1f1da2b6978c95be3437d554a6"
dependencies = [
"as-any",
"bitcoin-consensus-derive",
@@ -4170,7 +4198,7 @@ dependencies = [
[[package]]
name = "vls-protocol-client"
version = "0.11.0-rc.1"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=a28153e0f1b6598e6538d32b3c5bfb9c7657d565#a28153e0f1b6598e6538d32b3c5bfb9c7657d565"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=d3c35217d7dcda1f1da2b6978c95be3437d554a6#d3c35217d7dcda1f1da2b6978c95be3437d554a6"
dependencies = [
"anyhow",
"async-trait",
@@ -4185,7 +4213,7 @@ dependencies = [
[[package]]
name = "vls-protocol-signer"
version = "0.11.0-rc.1"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=a28153e0f1b6598e6538d32b3c5bfb9c7657d565#a28153e0f1b6598e6538d32b3c5bfb9c7657d565"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=d3c35217d7dcda1f1da2b6978c95be3437d554a6#d3c35217d7dcda1f1da2b6978c95be3437d554a6"
dependencies = [
"bit-vec",
"log",
@@ -4196,7 +4224,7 @@ dependencies = [
[[package]]
name = "vls-proxy"
version = "0.11.0-rc.1"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=a28153e0f1b6598e6538d32b3c5bfb9c7657d565#a28153e0f1b6598e6538d32b3c5bfb9c7657d565"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=d3c35217d7dcda1f1da2b6978c95be3437d554a6#d3c35217d7dcda1f1da2b6978c95be3437d554a6"
dependencies = [
"anyhow",
"as-any",

View File

@@ -27,17 +27,17 @@ toml = "0.5.9"
triggered = "0.1.2"
url = { version = "2.2" }
vls-frontend = { git = "https://gitlab.com/lightning-signer/validating-lightning-signer.git", rev = "a28153e0f1b6598e6538d32b3c5bfb9c7657d565" }
vls-protocol = { git = "https://gitlab.com/lightning-signer/validating-lightning-signer.git", rev = "a28153e0f1b6598e6538d32b3c5bfb9c7657d565" }
vls-protocol-client = { git = "https://gitlab.com/lightning-signer/validating-lightning-signer.git", rev = "a28153e0f1b6598e6538d32b3c5bfb9c7657d565" }
vls-proxy = { git = "https://gitlab.com/lightning-signer/validating-lightning-signer.git", rev = "a28153e0f1b6598e6538d32b3c5bfb9c7657d565" }
vls-frontend = { git = "https://gitlab.com/lightning-signer/validating-lightning-signer.git", rev = "d3c35217d7dcda1f1da2b6978c95be3437d554a6" }
vls-protocol = { git = "https://gitlab.com/lightning-signer/validating-lightning-signer.git", rev = "d3c35217d7dcda1f1da2b6978c95be3437d554a6" }
vls-protocol-client = { git = "https://gitlab.com/lightning-signer/validating-lightning-signer.git", rev = "d3c35217d7dcda1f1da2b6978c95be3437d554a6" }
vls-proxy = { git = "https://gitlab.com/lightning-signer/validating-lightning-signer.git", rev = "d3c35217d7dcda1f1da2b6978c95be3437d554a6" }
# vls-frontend = { path = "../../vls/vls-frontend" }
# vls-protocol = { path = "../../vls/vls-protocol" }
# vls-protocol-client = { path = "../../vls/vls-protocol-client" }
# vls-proxy = { path = "../../vls/vls-proxy" }
lss-connector = { git = "https://github.com/stakwork/sphinx-rs", rev = "b461de86bdd8945254f38410902908f4c798da57" }
sphinx-signer = { git = "https://github.com/stakwork/sphinx-rs", rev = "b461de86bdd8945254f38410902908f4c798da57" }
lss-connector = { git = "https://github.com/stakwork/sphinx-rs", rev = "1ebddd99878f7fe2452842b813cbd93e4035a898" }
sphinx-signer = { git = "https://github.com/stakwork/sphinx-rs", rev = "1ebddd99878f7fe2452842b813cbd93e4035a898" }
# lss-connector = { path = "../../sphinx-rs/lss-connector" }
# sphinx-signer = { path = "../../sphinx-rs/signer" }

View File

@@ -24,8 +24,7 @@ impl SignerPort for MqttSignerPort {
fn is_ready(&self) -> bool {
let (cid, is_synced) = current_client_and_synced();
let ret = cid.is_some() && is_synced;
ret
cid.is_some() && is_synced
}
}

View File

@@ -7,6 +7,8 @@ use std::sync::Mutex;
pub static CONNS: Lazy<Mutex<Connections>> = Lazy::new(|| Mutex::new(Connections::new()));
pub static HSMD_INIT: Mutex<Vec<u8>> = Mutex::new(Vec::new());
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Connections {
pub pubkey: Option<String>,

View File

@@ -1,6 +1,6 @@
use crate::bitcoin::blockdata::constants::ChainHash;
use crate::bitcoin::Network;
use crate::conn::{ChannelRequest, LssReq};
use crate::conn::{ChannelRequest, LssReq, HSMD_INIT};
use crate::handle::handle_message;
use crate::secp256k1::PublicKey;
use log::*;
@@ -126,6 +126,10 @@ impl<C: 'static + Client> SignerLoop<C> {
} else {
log::error!("No Network provided");
}
let mut hsmd_raw = HSMD_INIT.lock().unwrap();
*hsmd_raw = raw_msg;
drop(hsmd_raw);
continue;
}
// check if we got the same preapprove message less than PREAPPROVE_CACHE_TTL seconds ago
if let Message::PreapproveInvoice(_) | Message::PreapproveKeysend(_) = msg {
@@ -296,6 +300,8 @@ fn vls_cmd(msg: &Message) -> String {
Message::LockOutpointReply(_) => "LockOutpointReply",
Message::ForgetChannel(_) => "ForgetChannel",
Message::ForgetChannelReply(_) => "ForgetChannelReply",
Message::RevokeCommitmentTx(_) => "RevokeCommitmentTx",
Message::RevokeCommitmentTxReply(_) => "RevokeCommitmentTxReply",
};
m.to_string()
}

View File

@@ -1,27 +1,33 @@
use crate::conn::HSMD_INIT;
use crate::conn::{ChannelRequest, LssReq};
use anyhow::{anyhow, Result};
use lss_connector::{InitResponse, LssBroker, Response, SignerMutations};
use rocket::tokio;
use rumqttd::oneshot;
use rumqttd::oneshot as std_oneshot;
use sphinx_signer::parser;
use sphinx_signer::sphinx_glyph::topics;
use tokio::sync::mpsc;
use vls_protocol::msgs::{self, Message, SerBolt};
use vls_proxy::client::{Client, UnixClient};
pub fn lss_tasks(
uri: String,
lss_rx: mpsc::Receiver<LssReq>,
mut conn_rx: mpsc::Receiver<(String, oneshot::Sender<bool>)>,
init_tx: mpsc::Sender<ChannelRequest>,
mut cln_client: UnixClient,
) {
tokio::task::spawn(async move {
// first connection - initializes lssbroker
let lss_conn = loop {
let (lss_conn, hsmd_init_reply) = loop {
let (cid, dance_complete_tx) = conn_rx.recv().await.unwrap();
match try_dance(&cid, &uri, None, &init_tx, dance_complete_tx).await {
Some(broker) => break broker,
Some(ret) => break ret,
None => log::warn!("broker not initialized, try connecting again..."),
}
};
cln_client.write_vec(hsmd_init_reply).unwrap();
spawn_lss_rx(lss_conn.clone(), lss_rx);
// connect handler for all subsequent connections
while let Some((cid, dance_complete_tx)) = conn_rx.recv().await {
@@ -52,12 +58,12 @@ async fn try_dance(
lss_conn: Option<&LssBroker>,
init_tx: &mpsc::Sender<ChannelRequest>,
dance_complete_tx: std_oneshot::Sender<bool>,
) -> Option<LssBroker> {
) -> Option<(LssBroker, Vec<u8>)> {
match connect_dance(cid, uri, lss_conn, init_tx).await {
Ok(broker) => {
Ok(ret) => {
let _ = dance_complete_tx.send(true);
// none if lss_conn is some, some otherwise
broker
ret
}
Err(e) => {
log::warn!("connect_dance failed: {:?}", e);
@@ -70,16 +76,17 @@ async fn try_dance(
async fn connect_dance(
cid: &str,
uri: &str,
lss_conn: Option<&LssBroker>,
lss_conn_opt: Option<&LssBroker>,
mqtt_tx: &mpsc::Sender<ChannelRequest>,
) -> Result<Option<LssBroker>> {
let (new_broker, ir) = dance_step_1(cid, uri, lss_conn, mqtt_tx).await?;
let lss_conn = new_broker.as_ref().xor(lss_conn).ok_or(anyhow!(
) -> Result<Option<(LssBroker, Vec<u8>)>> {
let (new_broker, ir) = dance_step_1(cid, uri, lss_conn_opt, mqtt_tx).await?;
let lss_conn = new_broker.as_ref().xor(lss_conn_opt).ok_or(anyhow!(
"should never happen, either we use the newly initialized, or the one passed in"
))?;
dance_step_2(cid, lss_conn, mqtt_tx, &ir).await?;
// only some when lss_conn is none
Ok(new_broker)
let hsmd_init_reply = dance_step_3(cid, mqtt_tx).await?;
// only some when lss_conn_opt is none
Ok(new_broker.map(|broker| (broker, hsmd_init_reply)))
}
// initializes a new broker in case lss_conn is none
@@ -116,6 +123,37 @@ async fn dance_step_2(
Ok(())
}
async fn dance_step_3(cid: &str, mqtt_tx: &mpsc::Sender<ChannelRequest>) -> Result<Vec<u8>> {
let (hsmd_raw, mut hsmd_init) = loop {
let hsmd_raw = HSMD_INIT.lock().unwrap().clone();
if hsmd_raw.is_empty() {
continue;
}
if let Message::HsmdInit(hsmd_init) = msgs::from_vec(hsmd_raw.clone()).unwrap() {
break (hsmd_raw, hsmd_init);
} else {
panic!("Not a hsmd init message");
}
};
let hsmd_init_bytes = parser::raw_request_from_bytes(hsmd_raw, 0, [0u8; 33], 0)?;
let reply = ChannelRequest::send(cid, topics::INIT_3_MSG, hsmd_init_bytes, mqtt_tx).await?;
if reply.is_empty() {
return Err(anyhow!("Hsmd init failed !"));
}
let hsmd_init_reply = parser::raw_response_from_bytes(reply, 0).unwrap();
// this match is a noop after the first pass
match msgs::from_vec(hsmd_init_reply.clone()) {
Ok(Message::HsmdInitReplyV4(hir)) => {
hsmd_init.hsm_wire_max_version = hir.hsm_version;
let mut hsmd_raw = HSMD_INIT.lock().unwrap();
*hsmd_raw = hsmd_init.as_vec();
drop(hsmd_raw);
}
_ => panic!("Not a hsmd init reply v4"),
};
Ok(hsmd_init_reply)
}
async fn send_init(
cid: &str,
msg_bytes: Vec<u8>,

View File

@@ -78,11 +78,12 @@ fn run_main(parent_fd: i32) -> rocket::Rocket<rocket::Build> {
broker_setup(settings, mqtt_rx, init_rx, conn_tx, error_tx.clone());
let cln_client_a = UnixClient::new(UnixConnection::new(parent_fd));
let (lss_tx, lss_rx) = mpsc::channel::<LssReq>(10000);
// TODO: add a validation here of the uri setting to make sure LSS is running
if let Ok(lss_uri) = env::var("VLS_LSS") {
log::info!("Spawning lss tasks...");
lss::lss_tasks(lss_uri, lss_rx, conn_rx, init_tx);
lss::lss_tasks(lss_uri, lss_rx, conn_rx, init_tx, cln_client_a);
} else {
log::warn!("running without LSS");
}

View File

@@ -110,7 +110,10 @@ pub fn start_broker(
} else {
// VLS, CONTROL, LSS
let pld = f.publish.payload.to_vec();
if topic_end == topics::INIT_1_RES || topic_end == topics::INIT_2_RES {
if topic_end == topics::INIT_1_RES
|| topic_end == topics::INIT_2_RES
|| topic_end == topics::INIT_3_RES
{
if let Err(e) = init_tx.send((cid, topic_end, pld)) {
log::error!("failed to pub to init_tx! {:?}", e);
}

30
sphinx-key/Cargo.lock generated
View File

@@ -237,7 +237,7 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bolt-derive"
version = "0.2.0"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=753024b51bf681695490eff76888a4d63241fd7c#753024b51bf681695490eff76888a4d63241fd7c"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=d3c35217d7dcda1f1da2b6978c95be3437d554a6#d3c35217d7dcda1f1da2b6978c95be3437d554a6"
dependencies = [
"proc-macro2",
"quote",
@@ -1156,7 +1156,7 @@ checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4"
[[package]]
name = "lss-connector"
version = "0.1.0"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=437728607bce0288908fc8979936a850e52560b7#437728607bce0288908fc8979936a850e52560b7"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=1ebddd99878f7fe2452842b813cbd93e4035a898#1ebddd99878f7fe2452842b813cbd93e4035a898"
dependencies = [
"anyhow",
"log",
@@ -1513,7 +1513,7 @@ dependencies = [
[[package]]
name = "rmp-utils"
version = "0.1.0"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=437728607bce0288908fc8979936a850e52560b7#437728607bce0288908fc8979936a850e52560b7"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=1ebddd99878f7fe2452842b813cbd93e4035a898#1ebddd99878f7fe2452842b813cbd93e4035a898"
dependencies = [
"anyhow",
"log",
@@ -1669,9 +1669,9 @@ dependencies = [
[[package]]
name = "serde_with"
version = "3.3.0"
version = "3.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ca3b16a3d82c4088f343b7480a93550b3eabe1a358569c2dfe38bbcead07237"
checksum = "1b0ed1662c5a68664f45b76d18deb0e234aff37207086803165c961eb695e981"
dependencies = [
"base64",
"chrono",
@@ -1684,9 +1684,9 @@ dependencies = [
[[package]]
name = "serde_with_macros"
version = "3.3.0"
version = "3.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e6be15c453eb305019bfa438b1593c731f36a289a7853f7707ee29e870b3b3c"
checksum = "568577ff0ef47b879f736cd66740e022f3672788cdf002a05a4e609ea5a6fb15"
dependencies = [
"darling",
"proc-macro2",
@@ -1703,7 +1703,7 @@ checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3"
[[package]]
name = "sphinx-auther"
version = "0.1.12"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=437728607bce0288908fc8979936a850e52560b7#437728607bce0288908fc8979936a850e52560b7"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=1ebddd99878f7fe2452842b813cbd93e4035a898#1ebddd99878f7fe2452842b813cbd93e4035a898"
dependencies = [
"anyhow",
"base64",
@@ -1715,7 +1715,7 @@ dependencies = [
[[package]]
name = "sphinx-crypter"
version = "0.1.0"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=437728607bce0288908fc8979936a850e52560b7#437728607bce0288908fc8979936a850e52560b7"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=1ebddd99878f7fe2452842b813cbd93e4035a898#1ebddd99878f7fe2452842b813cbd93e4035a898"
dependencies = [
"anyhow",
"chacha20poly1305",
@@ -1726,7 +1726,7 @@ dependencies = [
[[package]]
name = "sphinx-glyph"
version = "0.1.2"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=437728607bce0288908fc8979936a850e52560b7#437728607bce0288908fc8979936a850e52560b7"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=1ebddd99878f7fe2452842b813cbd93e4035a898#1ebddd99878f7fe2452842b813cbd93e4035a898"
dependencies = [
"anyhow",
"hex",
@@ -1758,7 +1758,7 @@ dependencies = [
[[package]]
name = "sphinx-signer"
version = "0.1.0"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=437728607bce0288908fc8979936a850e52560b7#437728607bce0288908fc8979936a850e52560b7"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=1ebddd99878f7fe2452842b813cbd93e4035a898#1ebddd99878f7fe2452842b813cbd93e4035a898"
dependencies = [
"anyhow",
"bip39",
@@ -2010,7 +2010,7 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "vls-core"
version = "0.11.0-rc.1"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=753024b51bf681695490eff76888a4d63241fd7c#753024b51bf681695490eff76888a4d63241fd7c"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=d3c35217d7dcda1f1da2b6978c95be3437d554a6#d3c35217d7dcda1f1da2b6978c95be3437d554a6"
dependencies = [
"anyhow",
"bitcoin",
@@ -2034,7 +2034,7 @@ dependencies = [
[[package]]
name = "vls-persist"
version = "0.11.0-rc.1"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=753024b51bf681695490eff76888a4d63241fd7c#753024b51bf681695490eff76888a4d63241fd7c"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=d3c35217d7dcda1f1da2b6978c95be3437d554a6#d3c35217d7dcda1f1da2b6978c95be3437d554a6"
dependencies = [
"hex",
"log",
@@ -2047,7 +2047,7 @@ dependencies = [
[[package]]
name = "vls-protocol"
version = "0.11.0-rc.1"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=753024b51bf681695490eff76888a4d63241fd7c#753024b51bf681695490eff76888a4d63241fd7c"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=d3c35217d7dcda1f1da2b6978c95be3437d554a6#d3c35217d7dcda1f1da2b6978c95be3437d554a6"
dependencies = [
"as-any",
"bitcoin-consensus-derive",
@@ -2061,7 +2061,7 @@ dependencies = [
[[package]]
name = "vls-protocol-signer"
version = "0.11.0-rc.1"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=753024b51bf681695490eff76888a4d63241fd7c#753024b51bf681695490eff76888a4d63241fd7c"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=d3c35217d7dcda1f1da2b6978c95be3437d554a6#d3c35217d7dcda1f1da2b6978c95be3437d554a6"
dependencies = [
"bit-vec",
"log",

View File

@@ -25,9 +25,9 @@ serde_json = { version = "1.0.81", default-features = false }
serde_urlencoded = "0.7.1"
# sphinx-rs
lss-connector = { git = "https://github.com/stakwork/sphinx-rs.git", default-features = false, rev = "437728607bce0288908fc8979936a850e52560b7" }
sphinx-crypter = { git = "https://github.com/stakwork/sphinx-rs.git", rev = "437728607bce0288908fc8979936a850e52560b7" }
sphinx-signer = { git = "https://github.com/stakwork/sphinx-rs.git", optional = true, rev = "437728607bce0288908fc8979936a850e52560b7" }
lss-connector = { git = "https://github.com/stakwork/sphinx-rs.git", default-features = false, rev = "1ebddd99878f7fe2452842b813cbd93e4035a898" }
sphinx-crypter = { git = "https://github.com/stakwork/sphinx-rs.git", rev = "1ebddd99878f7fe2452842b813cbd93e4035a898" }
sphinx-signer = { git = "https://github.com/stakwork/sphinx-rs.git", optional = true, rev = "1ebddd99878f7fe2452842b813cbd93e4035a898" }
# local
# lss-connector = { path = "../../sphinx-rs/lss-connector", default-features = false }
# sphinx-crypter = { path = "../../sphinx-rs/crypter" }

View File

@@ -109,6 +109,7 @@ pub fn make_client(
} else if topic.ends_with(topics::LSS_MSG)
|| topic.ends_with(topics::INIT_1_MSG)
|| topic.ends_with(topics::INIT_2_MSG)
|| topic.ends_with(topics::INIT_3_MSG)
|| topic.ends_with(topics::LSS_CONFLICT)
{
log::debug!("received data len {}", data.len());

View File

@@ -11,11 +11,13 @@ use glyph::ser::{serialize_controlresponse, ByteBuf};
use glyph::topics;
use lss_connector::secp256k1::PublicKey;
use sphinx_signer::approver::SphinxApprover;
use sphinx_signer::kvv::{CloudKVVStore, FsKVVStore, KVVPersister, RmpFormat};
use sphinx_signer::kvv::{
fs::FsKVVStore, CloudKVVStore, JsonFormat, KVVPersister, MemoryKVVStore, RmpFormat,
};
use sphinx_signer::lightning_signer::persist::Persist;
use sphinx_signer::root::VlsHandlerError;
use sphinx_signer::sphinx_glyph as glyph;
use sphinx_signer::{self, Handler, RootHandler};
use sphinx_signer::{self, Handler, RootHandler, WarningPositiveApprover};
use std::sync::mpsc;
use std::sync::Arc;
use std::thread;
@@ -85,7 +87,8 @@ pub fn make_event_loop(
}
}
let kvv_store = FsKVVStore::new(ROOT_STORE, *signer_id, None);
//let kvv_store = FsKVVStore::new(ROOT_STORE, *signer_id, None);
let kvv_store = MemoryKVVStore::new([0xcc; 16]);
let fs_persister = KVVPersister(CloudKVVStore::new(kvv_store), RmpFormat);
let _ = fs_persister.enter();
@@ -111,7 +114,7 @@ pub fn make_event_loop(
let persister = Arc::new(fs_persister);
// initialize the RootHandler
let (rhb, approver) = sphinx_signer::root::builder(
let (mut rhb, approver) = sphinx_signer::root::builder(
seed,
network,
policy.clone(),
@@ -120,6 +123,7 @@ pub fn make_event_loop(
persister,
)
.expect("failed to init signer");
rhb = rhb.approver(Arc::new(WarningPositiveApprover()));
thread::sleep(std::time::Duration::from_secs(1));
// send the initial HELLO

View File

@@ -7,7 +7,7 @@ use esp_idf_svc::mqtt::client::MessageImpl;
use esp_idf_svc::sys::EspError;
use lss_connector::{secp256k1::PublicKey, BrokerMutations, LssSigner, Msg as LssMsg};
use sphinx_signer::sphinx_glyph::topics;
use sphinx_signer::{self, RootHandler, RootHandlerBuilder};
use sphinx_signer::{self, HandlerBuilder, RootHandler};
use std::sync::mpsc;
use std::time::Duration;
@@ -16,7 +16,7 @@ pub use lss_connector::handle_lss_msg;
pub fn init_lss(
signer_id: &[u8; 16],
rx: &mpsc::Receiver<Event>,
handler_builder: RootHandlerBuilder,
handler_builder: HandlerBuilder,
mqtt: &mut EspMqttClient<ConnState<MessageImpl, EspError>>,
) -> Result<(RootHandler, LssSigner)> {
let client_id = hex::encode(signer_id);
@@ -42,11 +42,24 @@ pub fn init_lss(
}
};
let (root_handler, res2) = lss_signer.build_with_lss(created, handler_builder, None)?;
let (mut init_handler, res2) = lss_signer.build_with_lss(created, handler_builder, None)?;
let lss_res_2_topic = format!("{}/{}", client_id, topics::INIT_2_RES);
mqtt.publish(&lss_res_2_topic, QOS, false, &res2)
.expect("could not publish LSS response 2");
let hsmd_init_bytes = loop {
match rx.recv_timeout(Duration::from_secs(30))? {
Event::LssMessage(hib) => break hib,
_ => log::warn!("not an LSS message"),
}
};
let (res3, init, _cmd) =
sphinx_signer::root::handle_init(&mut init_handler, hsmd_init_bytes, false).unwrap();
let lss_res_3_topic = format!("{}/{}", client_id, topics::INIT_3_RES);
mqtt.publish(&lss_res_3_topic, QOS, false, &res3)
.expect("could not publish LSS response 3");
assert!(init);
let root_handler = init_handler.into_root_handler();
Ok((root_handler, lss_signer))
}

31
tester/Cargo.lock generated
View File

@@ -255,7 +255,7 @@ checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07"
[[package]]
name = "bolt-derive"
version = "0.2.0"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=a28153e0f1b6598e6538d32b3c5bfb9c7657d565#a28153e0f1b6598e6538d32b3c5bfb9c7657d565"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=d3c35217d7dcda1f1da2b6978c95be3437d554a6#d3c35217d7dcda1f1da2b6978c95be3437d554a6"
dependencies = [
"proc-macro2",
"quote",
@@ -1120,7 +1120,7 @@ dependencies = [
[[package]]
name = "lss-connector"
version = "0.1.0"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=b461de86bdd8945254f38410902908f4c798da57#b461de86bdd8945254f38410902908f4c798da57"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=1ebddd99878f7fe2452842b813cbd93e4035a898#1ebddd99878f7fe2452842b813cbd93e4035a898"
dependencies = [
"anyhow",
"log",
@@ -1692,7 +1692,7 @@ dependencies = [
[[package]]
name = "rmp-utils"
version = "0.1.0"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=b461de86bdd8945254f38410902908f4c798da57#b461de86bdd8945254f38410902908f4c798da57"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=1ebddd99878f7fe2452842b813cbd93e4035a898#1ebddd99878f7fe2452842b813cbd93e4035a898"
dependencies = [
"anyhow",
"log",
@@ -2005,9 +2005,9 @@ dependencies = [
[[package]]
name = "serde_with"
version = "3.4.0"
version = "3.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64cd236ccc1b7a29e7e2739f27c0b2dd199804abc4290e32f59f3b68d6405c23"
checksum = "1b0ed1662c5a68664f45b76d18deb0e234aff37207086803165c961eb695e981"
dependencies = [
"base64 0.21.5",
"chrono",
@@ -2020,9 +2020,9 @@ dependencies = [
[[package]]
name = "serde_with_macros"
version = "3.4.0"
version = "3.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93634eb5f75a2323b16de4748022ac4297f9e76b6dced2be287a099f41b5e788"
checksum = "568577ff0ef47b879f736cd66740e022f3672788cdf002a05a4e609ea5a6fb15"
dependencies = [
"darling",
"proc-macro2",
@@ -2086,7 +2086,7 @@ dependencies = [
[[package]]
name = "sphinx-auther"
version = "0.1.12"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=b461de86bdd8945254f38410902908f4c798da57#b461de86bdd8945254f38410902908f4c798da57"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=1ebddd99878f7fe2452842b813cbd93e4035a898#1ebddd99878f7fe2452842b813cbd93e4035a898"
dependencies = [
"anyhow",
"base64 0.21.5",
@@ -2098,7 +2098,7 @@ dependencies = [
[[package]]
name = "sphinx-crypter"
version = "0.1.0"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=b461de86bdd8945254f38410902908f4c798da57#b461de86bdd8945254f38410902908f4c798da57"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=1ebddd99878f7fe2452842b813cbd93e4035a898#1ebddd99878f7fe2452842b813cbd93e4035a898"
dependencies = [
"anyhow",
"chacha20poly1305",
@@ -2109,7 +2109,7 @@ dependencies = [
[[package]]
name = "sphinx-glyph"
version = "0.1.2"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=b461de86bdd8945254f38410902908f4c798da57#b461de86bdd8945254f38410902908f4c798da57"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=1ebddd99878f7fe2452842b813cbd93e4035a898#1ebddd99878f7fe2452842b813cbd93e4035a898"
dependencies = [
"anyhow",
"hex",
@@ -2147,7 +2147,7 @@ dependencies = [
[[package]]
name = "sphinx-signer"
version = "0.1.0"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=b461de86bdd8945254f38410902908f4c798da57#b461de86bdd8945254f38410902908f4c798da57"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=1ebddd99878f7fe2452842b813cbd93e4035a898#1ebddd99878f7fe2452842b813cbd93e4035a898"
dependencies = [
"anyhow",
"bip39",
@@ -2156,6 +2156,7 @@ dependencies = [
"log",
"lss-connector",
"rand",
"rmp-serde",
"serde",
"sphinx-glyph",
"thiserror",
@@ -2687,7 +2688,7 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "vls-core"
version = "0.11.0-rc.1"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=a28153e0f1b6598e6538d32b3c5bfb9c7657d565#a28153e0f1b6598e6538d32b3c5bfb9c7657d565"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=d3c35217d7dcda1f1da2b6978c95be3437d554a6#d3c35217d7dcda1f1da2b6978c95be3437d554a6"
dependencies = [
"anyhow",
"bitcoin",
@@ -2711,7 +2712,7 @@ dependencies = [
[[package]]
name = "vls-persist"
version = "0.11.0-rc.1"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=a28153e0f1b6598e6538d32b3c5bfb9c7657d565#a28153e0f1b6598e6538d32b3c5bfb9c7657d565"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=d3c35217d7dcda1f1da2b6978c95be3437d554a6#d3c35217d7dcda1f1da2b6978c95be3437d554a6"
dependencies = [
"hex",
"log",
@@ -2724,7 +2725,7 @@ dependencies = [
[[package]]
name = "vls-protocol"
version = "0.11.0-rc.1"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=a28153e0f1b6598e6538d32b3c5bfb9c7657d565#a28153e0f1b6598e6538d32b3c5bfb9c7657d565"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=d3c35217d7dcda1f1da2b6978c95be3437d554a6#d3c35217d7dcda1f1da2b6978c95be3437d554a6"
dependencies = [
"as-any",
"bitcoin-consensus-derive",
@@ -2738,7 +2739,7 @@ dependencies = [
[[package]]
name = "vls-protocol-signer"
version = "0.11.0-rc.1"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=a28153e0f1b6598e6538d32b3c5bfb9c7657d565#a28153e0f1b6598e6538d32b3c5bfb9c7657d565"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=d3c35217d7dcda1f1da2b6978c95be3437d554a6#d3c35217d7dcda1f1da2b6978c95be3437d554a6"
dependencies = [
"bit-vec",
"log",

View File

@@ -23,8 +23,8 @@ serde_json = "1.0"
tokio = { version = "1.4.0", features = ["rt", "rt-multi-thread", "macros"] }
urlencoding = "2.1.0"
sphinx-crypter = { git = "https://github.com/stakwork/sphinx-rs.git", rev = "b461de86bdd8945254f38410902908f4c798da57" }
sphinx-signer = { git = "https://github.com/stakwork/sphinx-rs.git", rev = "b461de86bdd8945254f38410902908f4c798da57" }
sphinx-crypter = { git = "https://github.com/stakwork/sphinx-rs.git", rev = "1ebddd99878f7fe2452842b813cbd93e4035a898" }
sphinx-signer = { git = "https://github.com/stakwork/sphinx-rs.git", rev = "1ebddd99878f7fe2452842b813cbd93e4035a898" }
# sphinx-crypter = { path = "../../sphinx-rs/crypter" }
# sphinx-signer = { path = "../../sphinx-rs/signer" }