Merge pull request #128 from stakwork/vls-multi-signer

Vls multi signer
This commit is contained in:
Evan Feenstra
2023-09-19 11:28:03 -07:00
committed by GitHub
16 changed files with 140 additions and 122 deletions

26
Cargo.lock generated
View File

@@ -249,7 +249,7 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bolt-derive"
version = "0.2.0"
source = "git+https://gitlab.com/irriden/validating-lightning-signer.git?rev=ce04684b312c95fa7a62329ff198092a50e9a088#ce04684b312c95fa7a62329ff198092a50e9a088"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=0370e6a124ac5f64c91b755d7ab1a9e9cc27597d#0370e6a124ac5f64c91b755d7ab1a9e9cc27597d"
dependencies = [
"proc-macro2",
"quote",
@@ -818,8 +818,8 @@ dependencies = [
[[package]]
name = "fsdb"
version = "0.1.17"
source = "git+https://github.com/Evanfeenstra/fsdb.git?rev=634125776c14be45ab0618f2fa2b7f1aff4adb85#634125776c14be45ab0618f2fa2b7f1aff4adb85"
version = "0.1.18"
source = "git+https://github.com/Evanfeenstra/fsdb.git?rev=7d0db454133bf37b16d9cf5500111491e67c81e5#7d0db454133bf37b16d9cf5500111491e67c81e5"
dependencies = [
"rmp-serde",
"serde",
@@ -1219,7 +1219,7 @@ checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4"
[[package]]
name = "lss-connector"
version = "0.1.0"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=af50ee91e3600b7b4862e8f00772601c8a342110#af50ee91e3600b7b4862e8f00772601c8a342110"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=768189358fd8ea647e34b250c396daf3479ebbfe#768189358fd8ea647e34b250c396daf3479ebbfe"
dependencies = [
"anyhow",
"log",
@@ -1591,7 +1591,7 @@ dependencies = [
[[package]]
name = "rmp-utils"
version = "0.1.0"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=af50ee91e3600b7b4862e8f00772601c8a342110#af50ee91e3600b7b4862e8f00772601c8a342110"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=768189358fd8ea647e34b250c396daf3479ebbfe#768189358fd8ea647e34b250c396daf3479ebbfe"
dependencies = [
"anyhow",
"log",
@@ -1798,7 +1798,7 @@ dependencies = [
[[package]]
name = "sphinx-auther"
version = "0.1.12"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=af50ee91e3600b7b4862e8f00772601c8a342110#af50ee91e3600b7b4862e8f00772601c8a342110"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=768189358fd8ea647e34b250c396daf3479ebbfe#768189358fd8ea647e34b250c396daf3479ebbfe"
dependencies = [
"anyhow",
"base64 0.21.2",
@@ -1810,7 +1810,7 @@ dependencies = [
[[package]]
name = "sphinx-crypter"
version = "0.1.0"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=af50ee91e3600b7b4862e8f00772601c8a342110#af50ee91e3600b7b4862e8f00772601c8a342110"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=768189358fd8ea647e34b250c396daf3479ebbfe#768189358fd8ea647e34b250c396daf3479ebbfe"
dependencies = [
"anyhow",
"chacha20poly1305",
@@ -1821,7 +1821,7 @@ dependencies = [
[[package]]
name = "sphinx-glyph"
version = "0.1.2"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=af50ee91e3600b7b4862e8f00772601c8a342110#af50ee91e3600b7b4862e8f00772601c8a342110"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=768189358fd8ea647e34b250c396daf3479ebbfe#768189358fd8ea647e34b250c396daf3479ebbfe"
dependencies = [
"anyhow",
"hex",
@@ -1872,7 +1872,7 @@ dependencies = [
[[package]]
name = "sphinx-signer"
version = "0.1.0"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=af50ee91e3600b7b4862e8f00772601c8a342110#af50ee91e3600b7b4862e8f00772601c8a342110"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=768189358fd8ea647e34b250c396daf3479ebbfe#768189358fd8ea647e34b250c396daf3479ebbfe"
dependencies = [
"anyhow",
"bip39",
@@ -2154,7 +2154,7 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "vls-core"
version = "0.10.0"
source = "git+https://gitlab.com/irriden/validating-lightning-signer.git?rev=ce04684b312c95fa7a62329ff198092a50e9a088#ce04684b312c95fa7a62329ff198092a50e9a088"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=0370e6a124ac5f64c91b755d7ab1a9e9cc27597d#0370e6a124ac5f64c91b755d7ab1a9e9cc27597d"
dependencies = [
"anyhow",
"bitcoin",
@@ -2178,7 +2178,7 @@ dependencies = [
[[package]]
name = "vls-persist"
version = "0.10.0"
source = "git+https://gitlab.com/irriden/validating-lightning-signer.git?rev=ce04684b312c95fa7a62329ff198092a50e9a088#ce04684b312c95fa7a62329ff198092a50e9a088"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=0370e6a124ac5f64c91b755d7ab1a9e9cc27597d#0370e6a124ac5f64c91b755d7ab1a9e9cc27597d"
dependencies = [
"hex",
"log",
@@ -2191,7 +2191,7 @@ dependencies = [
[[package]]
name = "vls-protocol"
version = "0.10.0"
source = "git+https://gitlab.com/irriden/validating-lightning-signer.git?rev=ce04684b312c95fa7a62329ff198092a50e9a088#ce04684b312c95fa7a62329ff198092a50e9a088"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=0370e6a124ac5f64c91b755d7ab1a9e9cc27597d#0370e6a124ac5f64c91b755d7ab1a9e9cc27597d"
dependencies = [
"as-any",
"bitcoin-consensus-derive",
@@ -2204,7 +2204,7 @@ dependencies = [
[[package]]
name = "vls-protocol-signer"
version = "0.10.0"
source = "git+https://gitlab.com/irriden/validating-lightning-signer.git?rev=ce04684b312c95fa7a62329ff198092a50e9a088#ce04684b312c95fa7a62329ff198092a50e9a088"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=0370e6a124ac5f64c91b755d7ab1a9e9cc27597d#0370e6a124ac5f64c91b755d7ab1a9e9cc27597d"
dependencies = [
"bit-vec",
"log",

42
broker/Cargo.lock generated
View File

@@ -442,7 +442,7 @@ dependencies = [
[[package]]
name = "bolt-derive"
version = "0.2.0"
source = "git+https://gitlab.com/irriden/validating-lightning-signer.git?rev=ce04684b312c95fa7a62329ff198092a50e9a088#ce04684b312c95fa7a62329ff198092a50e9a088"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=0370e6a124ac5f64c91b755d7ab1a9e9cc27597d#0370e6a124ac5f64c91b755d7ab1a9e9cc27597d"
dependencies = [
"proc-macro2",
"quote",
@@ -1058,8 +1058,8 @@ dependencies = [
[[package]]
name = "fsdb"
version = "0.1.17"
source = "git+https://github.com/Evanfeenstra/fsdb.git?rev=634125776c14be45ab0618f2fa2b7f1aff4adb85#634125776c14be45ab0618f2fa2b7f1aff4adb85"
version = "0.1.18"
source = "git+https://github.com/Evanfeenstra/fsdb.git?rev=7d0db454133bf37b16d9cf5500111491e67c81e5#7d0db454133bf37b16d9cf5500111491e67c81e5"
dependencies = [
"rmp-serde",
"serde",
@@ -1606,7 +1606,7 @@ dependencies = [
[[package]]
name = "lightning-storage-server"
version = "0.3.0"
source = "git+https://gitlab.com/irriden/validating-lightning-signer.git?rev=ce04684b312c95fa7a62329ff198092a50e9a088#ce04684b312c95fa7a62329ff198092a50e9a088"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=0370e6a124ac5f64c91b755d7ab1a9e9cc27597d#0370e6a124ac5f64c91b755d7ab1a9e9cc27597d"
dependencies = [
"anyhow",
"async-trait",
@@ -1691,7 +1691,7 @@ dependencies = [
[[package]]
name = "lss-connector"
version = "0.1.0"
source = "git+https://github.com/stakwork/sphinx-rs?rev=af50ee91e3600b7b4862e8f00772601c8a342110#af50ee91e3600b7b4862e8f00772601c8a342110"
source = "git+https://github.com/stakwork/sphinx-rs?rev=768189358fd8ea647e34b250c396daf3479ebbfe#768189358fd8ea647e34b250c396daf3479ebbfe"
dependencies = [
"anyhow",
"lightning-storage-server",
@@ -2693,7 +2693,7 @@ dependencies = [
[[package]]
name = "rmp-utils"
version = "0.1.0"
source = "git+https://github.com/stakwork/sphinx-rs?rev=af50ee91e3600b7b4862e8f00772601c8a342110#af50ee91e3600b7b4862e8f00772601c8a342110"
source = "git+https://github.com/stakwork/sphinx-rs?rev=768189358fd8ea647e34b250c396daf3479ebbfe#768189358fd8ea647e34b250c396daf3479ebbfe"
dependencies = [
"anyhow",
"log",
@@ -3268,7 +3268,7 @@ dependencies = [
[[package]]
name = "sphinx-auther"
version = "0.1.12"
source = "git+https://github.com/stakwork/sphinx-rs?rev=af50ee91e3600b7b4862e8f00772601c8a342110#af50ee91e3600b7b4862e8f00772601c8a342110"
source = "git+https://github.com/stakwork/sphinx-rs?rev=768189358fd8ea647e34b250c396daf3479ebbfe#768189358fd8ea647e34b250c396daf3479ebbfe"
dependencies = [
"anyhow",
"base64 0.21.2",
@@ -3280,7 +3280,7 @@ dependencies = [
[[package]]
name = "sphinx-glyph"
version = "0.1.2"
source = "git+https://github.com/stakwork/sphinx-rs?rev=af50ee91e3600b7b4862e8f00772601c8a342110#af50ee91e3600b7b4862e8f00772601c8a342110"
source = "git+https://github.com/stakwork/sphinx-rs?rev=768189358fd8ea647e34b250c396daf3479ebbfe#768189358fd8ea647e34b250c396daf3479ebbfe"
dependencies = [
"anyhow",
"hex",
@@ -3326,7 +3326,7 @@ dependencies = [
[[package]]
name = "sphinx-signer"
version = "0.1.0"
source = "git+https://github.com/stakwork/sphinx-rs?rev=af50ee91e3600b7b4862e8f00772601c8a342110#af50ee91e3600b7b4862e8f00772601c8a342110"
source = "git+https://github.com/stakwork/sphinx-rs?rev=768189358fd8ea647e34b250c396daf3479ebbfe#768189358fd8ea647e34b250c396daf3479ebbfe"
dependencies = [
"anyhow",
"bip39",
@@ -4006,6 +4006,15 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
[[package]]
name = "uuid"
version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79daa5ed5740825c40b389c5e50312b9c86df53fccd33f281df655642b43869d"
dependencies = [
"getrandom",
]
[[package]]
name = "valuable"
version = "0.1.0"
@@ -4021,7 +4030,7 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "vls-core"
version = "0.10.0"
source = "git+https://gitlab.com/irriden/validating-lightning-signer.git?rev=ce04684b312c95fa7a62329ff198092a50e9a088#ce04684b312c95fa7a62329ff198092a50e9a088"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=0370e6a124ac5f64c91b755d7ab1a9e9cc27597d#0370e6a124ac5f64c91b755d7ab1a9e9cc27597d"
dependencies = [
"anyhow",
"backtrace",
@@ -4047,7 +4056,7 @@ dependencies = [
[[package]]
name = "vls-frontend"
version = "0.10.0"
source = "git+https://gitlab.com/irriden/validating-lightning-signer.git?rev=ce04684b312c95fa7a62329ff198092a50e9a088#ce04684b312c95fa7a62329ff198092a50e9a088"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=0370e6a124ac5f64c91b755d7ab1a9e9cc27597d#0370e6a124ac5f64c91b755d7ab1a9e9cc27597d"
dependencies = [
"async-trait",
"lightning-storage-server",
@@ -4061,7 +4070,7 @@ dependencies = [
[[package]]
name = "vls-persist"
version = "0.10.0"
source = "git+https://gitlab.com/irriden/validating-lightning-signer.git?rev=ce04684b312c95fa7a62329ff198092a50e9a088#ce04684b312c95fa7a62329ff198092a50e9a088"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=0370e6a124ac5f64c91b755d7ab1a9e9cc27597d#0370e6a124ac5f64c91b755d7ab1a9e9cc27597d"
dependencies = [
"hex",
"log",
@@ -4069,13 +4078,14 @@ dependencies = [
"serde",
"serde_json",
"serde_with",
"uuid",
"vls-core",
]
[[package]]
name = "vls-protocol"
version = "0.10.0"
source = "git+https://gitlab.com/irriden/validating-lightning-signer.git?rev=ce04684b312c95fa7a62329ff198092a50e9a088#ce04684b312c95fa7a62329ff198092a50e9a088"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=0370e6a124ac5f64c91b755d7ab1a9e9cc27597d#0370e6a124ac5f64c91b755d7ab1a9e9cc27597d"
dependencies = [
"as-any",
"bitcoin-consensus-derive",
@@ -4088,7 +4098,7 @@ dependencies = [
[[package]]
name = "vls-protocol-client"
version = "0.10.0"
source = "git+https://gitlab.com/irriden/validating-lightning-signer.git?rev=ce04684b312c95fa7a62329ff198092a50e9a088#ce04684b312c95fa7a62329ff198092a50e9a088"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=0370e6a124ac5f64c91b755d7ab1a9e9cc27597d#0370e6a124ac5f64c91b755d7ab1a9e9cc27597d"
dependencies = [
"anyhow",
"async-trait",
@@ -4103,7 +4113,7 @@ dependencies = [
[[package]]
name = "vls-protocol-signer"
version = "0.10.0"
source = "git+https://gitlab.com/irriden/validating-lightning-signer.git?rev=ce04684b312c95fa7a62329ff198092a50e9a088#ce04684b312c95fa7a62329ff198092a50e9a088"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=0370e6a124ac5f64c91b755d7ab1a9e9cc27597d#0370e6a124ac5f64c91b755d7ab1a9e9cc27597d"
dependencies = [
"bit-vec",
"log",
@@ -4114,7 +4124,7 @@ dependencies = [
[[package]]
name = "vls-proxy"
version = "0.10.0"
source = "git+https://gitlab.com/irriden/validating-lightning-signer.git?rev=ce04684b312c95fa7a62329ff198092a50e9a088#ce04684b312c95fa7a62329ff198092a50e9a088"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git?rev=0370e6a124ac5f64c91b755d7ab1a9e9cc27597d#0370e6a124ac5f64c91b755d7ab1a9e9cc27597d"
dependencies = [
"anyhow",
"as-any",

View File

@@ -30,17 +30,17 @@ thiserror = "1.0.31"
toml = "0.5.9"
url = { version = "2.2" }
vls-frontend = { git = "https://gitlab.com/irriden/validating-lightning-signer.git", rev = "ce04684b312c95fa7a62329ff198092a50e9a088" }
vls-protocol = { git = "https://gitlab.com/irriden/validating-lightning-signer.git", rev = "ce04684b312c95fa7a62329ff198092a50e9a088" }
vls-protocol-client = { git = "https://gitlab.com/irriden/validating-lightning-signer.git", rev = "ce04684b312c95fa7a62329ff198092a50e9a088" }
vls-proxy = { git = "https://gitlab.com/irriden/validating-lightning-signer.git", rev = "ce04684b312c95fa7a62329ff198092a50e9a088" }
vls-frontend = { git = "https://gitlab.com/lightning-signer/validating-lightning-signer.git", rev = "0370e6a124ac5f64c91b755d7ab1a9e9cc27597d" }
vls-protocol = { git = "https://gitlab.com/lightning-signer/validating-lightning-signer.git", rev = "0370e6a124ac5f64c91b755d7ab1a9e9cc27597d" }
vls-protocol-client = { git = "https://gitlab.com/lightning-signer/validating-lightning-signer.git", rev = "0370e6a124ac5f64c91b755d7ab1a9e9cc27597d" }
vls-proxy = { git = "https://gitlab.com/lightning-signer/validating-lightning-signer.git", rev = "0370e6a124ac5f64c91b755d7ab1a9e9cc27597d" }
# 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 = "af50ee91e3600b7b4862e8f00772601c8a342110" }
sphinx-signer = { git = "https://github.com/stakwork/sphinx-rs", rev = "af50ee91e3600b7b4862e8f00772601c8a342110" }
lss-connector = { git = "https://github.com/stakwork/sphinx-rs", rev = "768189358fd8ea647e34b250c396daf3479ebbfe" }
sphinx-signer = { git = "https://github.com/stakwork/sphinx-rs", rev = "768189358fd8ea647e34b250c396daf3479ebbfe" }
# lss-connector = { path = "../../sphinx-rs/lss-connector" }
# sphinx-signer = { path = "../../sphinx-rs/signer" }

View File

@@ -49,7 +49,7 @@ impl MqttSignerPort {
if res_topic == topics::LSS_RES {
// send LSS instead
let lss_reply = self.send_lss(res).await?;
let (res_topic2, res2) = self.send_request_wait(topics::LSS_MSG, lss_reply).await?;
let (res_topic2, res2) = self.send_request_wait(&lss_reply.0, lss_reply.1).await?;
if res_topic2 != topics::VLS_RES {
log::warn!("ChainTracker got a topic NOT on {}", topics::VLS_RES);
}
@@ -70,8 +70,8 @@ impl MqttSignerPort {
Ok((reply.topic_end, reply.reply))
}
async fn send_lss(&self, message: Vec<u8>) -> Result<Vec<u8>> {
let (request, reply_rx) = LssReq::new(message);
async fn send_lss(&self, message: Vec<u8>) -> Result<(String, Vec<u8>)> {
let (request, reply_rx) = LssReq::new(topics::LSS_MSG.to_string(), message);
self.lss_tx.send(request).await?;
let res = reply_rx.await?;
Ok(res)

View File

@@ -143,13 +143,14 @@ impl ChannelReply {
/// Responses are received on the oneshot sender
#[derive(Debug)]
pub struct LssReq {
pub topic: String,
pub message: Vec<u8>,
pub reply_tx: oneshot::Sender<Vec<u8>>,
pub reply_tx: oneshot::Sender<(String, Vec<u8>)>,
}
impl LssReq {
pub fn new(message: Vec<u8>) -> (Self, oneshot::Receiver<Vec<u8>>) {
pub fn new(topic: String, message: Vec<u8>) -> (Self, oneshot::Receiver<(String, Vec<u8>)>) {
let (reply_tx, reply_rx) = oneshot::channel();
let cr = Self { message, reply_tx };
let cr = Self { topic, message, reply_tx };
(cr, reply_rx)
}
}

View File

@@ -180,12 +180,12 @@ impl<C: 'static + Client> SignerLoop<C> {
log::info!("GOT ON {}", res_topic);
let the_res = if res_topic == topics::LSS_RES {
// send reply to LSS to store muts
let lss_reply = self.send_lss(res)?;
log::info!("LSS REPLY LEN {}", &lss_reply.len());
let lss_reply = self.send_lss(topics::LSS_MSG.to_string(), res)?;
log::info!("LSS REPLY LEN {}", &lss_reply.1.len());
// send to signer for HMAC validation, and get final reply
log::info!("SEND ON {}", topics::LSS_MSG);
let (res_topic2, res2) = self.send_request_wait(topics::LSS_MSG, lss_reply)?;
log::info!("GOT ON {}, send to CLN", res_topic2);
log::info!("SEND ON {}", lss_reply.0);
let (res_topic2, res2) = self.send_request_wait(&lss_reply.0, lss_reply.1)?;
log::info!("GOT ON {}, send to CLN?", res_topic2);
if res_topic2 != topics::VLS_RES {
log::warn!("got a topic NOT on {}", topics::VLS_RES);
}
@@ -237,9 +237,9 @@ impl<C: 'static + Client> SignerLoop<C> {
Ok((reply.topic_end, reply.reply))
}
fn send_lss(&mut self, message: Vec<u8>) -> Result<Vec<u8>> {
fn send_lss(&mut self, topic: String, message: Vec<u8>) -> Result<(String, Vec<u8>)> {
// Send a request to the LSS server
let (request, reply_rx) = LssReq::new(message);
let (request, reply_rx) = LssReq::new(topic, message);
self.lss_tx.blocking_send(request).map_err(|_| Error::Eof)?;
let res = reply_rx.blocking_recv().map_err(|_| Error::Eof)?;
Ok(res)

View File

@@ -112,7 +112,7 @@ async fn dance_step_2(
) -> Result<()> {
let state_bytes = lss_conn.get_created_state_msg(ir).await?;
let cr = send_created(cid, state_bytes, mqtt_tx).await?;
lss_conn.handle(Response::Created(cr)).await?;
lss_conn.handle(Response::Created(cr)).await;
Ok(())
}

View File

@@ -22,7 +22,6 @@ pub fn start_broker(
) -> anyhow::Result<()> {
let conf = config(settings);
// println!("CONF {:?}", conf);
// let client_id = expected_client_id.to_string();
let mut broker = Broker::new(conf);
@@ -266,17 +265,9 @@ fn pub_timeout(
}
fn subs(cid: &str, mut ltx: LinkTx) {
ltx.subscribe(format!("{}/{}", cid, topics::VLS_RES))
.unwrap();
ltx.subscribe(format!("{}/{}", cid, topics::CONTROL_RES))
.unwrap();
ltx.subscribe(format!("{}/{}", cid, topics::ERROR)).unwrap();
ltx.subscribe(format!("{}/{}", cid, topics::LSS_RES))
.unwrap();
ltx.subscribe(format!("{}/{}", cid, topics::INIT_1_RES))
.unwrap();
ltx.subscribe(format!("{}/{}", cid, topics::INIT_2_RES))
.unwrap();
for t in topics::BROKER_SUBS {
ltx.subscribe(format!("{}/{}", cid, t)).unwrap();
}
}
fn unsubs(_cid: &str, mut _ltx: LinkTx) {

View File

@@ -20,9 +20,9 @@ serde_urlencoded = "0.7.1"
url = "2"
# sphinx-rs
lss-connector = { git = "https://github.com/stakwork/sphinx-rs.git", default-features = false, rev = "af50ee91e3600b7b4862e8f00772601c8a342110" }
sphinx-crypter = { git = "https://github.com/stakwork/sphinx-rs.git", rev = "af50ee91e3600b7b4862e8f00772601c8a342110" }
sphinx-signer = { git = "https://github.com/stakwork/sphinx-rs.git", optional = true, rev = "af50ee91e3600b7b4862e8f00772601c8a342110" }
lss-connector = { git = "https://github.com/stakwork/sphinx-rs.git", default-features = false, rev = "768189358fd8ea647e34b250c396daf3479ebbfe" }
sphinx-crypter = { git = "https://github.com/stakwork/sphinx-rs.git", rev = "768189358fd8ea647e34b250c396daf3479ebbfe" }
sphinx-signer = { git = "https://github.com/stakwork/sphinx-rs.git", optional = true, rev = "768189358fd8ea647e34b250c396daf3479ebbfe" }
# local
# lss-connector = { path = "../../sphinx-rs/lss-connector", default-features = false }
# sphinx-crypter = { path = "../../sphinx-rs/crypter" }

View File

@@ -20,7 +20,7 @@ use std::sync::{Arc, Mutex};
use std::thread;
use std::time::Duration;
const ID_LEN: usize = 12;
const ID_LEN: usize = 16;
fn main() -> anyhow::Result<()> {
esp_idf_sys::link_patches();

View File

@@ -17,7 +17,7 @@ use std::fs;
use std::path::Path;
pub const ROOT_STORE: &str = "/sdcard/store";
pub const ID_LEN: usize = 8usize;
pub const ID_LEN: usize = 16usize;
fn main() -> anyhow::Result<()> {
// NvsDefault::new();

View File

@@ -18,14 +18,16 @@ pub const QOS: QoS = QoS::AtMostOnce;
pub fn make_client(
broker: &str,
client_id: &str,
signer_id: &[u8; 16],
username: &str,
password: &str,
tx: mpsc::Sender<CoreEvent>,
) -> Result<EspMqttClient<ConnState<MessageImpl, EspError>>> {
let client_id = hex::encode(signer_id);
log::info!("make_client with id {}", client_id);
let mut conf = MqttClientConfiguration {
client_id: Some(client_id),
client_id: Some(&client_id),
buffer_size: 4096,
task_stack: 12288,
username: Some(username),
@@ -119,6 +121,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::LSS_CONFLICT)
{
log::debug!("received data len {}", data.len());
tx.send(CoreEvent::LssMessage(data))

View File

@@ -79,18 +79,17 @@ impl ControlPersist for FlashPersister {
self.0.remove(FlashKey::Seed.as_str())?;
Ok(())
}
fn write_id(&mut self, id: String) -> Result<()> {
let id = id.into_bytes();
fn write_id(&mut self, id: [u8; ID_LEN]) -> Result<()> {
self.0.set_raw(FlashKey::Id.as_str(), &id[..])?;
Ok(())
}
fn read_id(&self) -> Result<String> {
fn read_id(&self) -> Result<[u8; ID_LEN]> {
let mut buf = [0u8; ID_LEN];
let existing = self
.0
.get_raw(FlashKey::Id.as_str(), &mut buf)?
.ok_or(anyhow!("no existing id"))?;
Ok(String::from_utf8(existing.to_vec())?)
Ok(existing.try_into()?)
}
fn read_policy(&self) -> Result<Policy> {
let mut buf = [0u8; 250];

View File

@@ -39,14 +39,6 @@ pub enum Event {
pub const ROOT_STORE: &str = "/sdcard/store";
pub const SUB_TOPICS: &[&str] = &[
topics::INIT_1_MSG,
topics::INIT_2_MSG,
topics::LSS_MSG,
topics::VLS,
topics::CONTROL,
];
fn mqtt_sub(
mqtt: &mut EspMqttClient<ConnState<MessageImpl, EspError>>,
client_id: &str,
@@ -84,23 +76,25 @@ pub fn make_event_loop(
policy: &Policy,
velocity: &Option<Velocity>,
mut ctrlr: Controller,
client_id: &str,
signer_id: &[u8; 16],
node_id: &PublicKey,
) -> Result<()> {
let client_id = hex::encode(signer_id);
while let Ok(event) = rx.recv() {
log::info!("BROKER IP AND PORT: {}", config.broker);
// wait for a Connection first.
match event {
Event::Connected => {
mqtt_sub(&mut mqtt, client_id, SUB_TOPICS);
mqtt_sub(&mut mqtt, &client_id, topics::SIGNER_SUBS);
break;
}
_ => (),
}
}
let kvv_store = FsKVVStore::new(&ROOT_STORE, None).0;
let msg_store = FsKVVStore::new(&ROOT_STORE, None).0;
let kvv_store = FsKVVStore::new(&ROOT_STORE, signer_id.clone(), None).0;
let msg_store = FsKVVStore::new(&ROOT_STORE, signer_id.clone(), None).0;
let fs_persister = CloudKVVStore::new(kvv_store);
let _ = fs_persister.enter();
@@ -138,9 +132,9 @@ pub fn make_event_loop(
thread::sleep(std::time::Duration::from_secs(1));
// send the initial HELLO
mqtt_pub(&mut mqtt, client_id, topics::HELLO, &[]);
mqtt_pub(&mut mqtt, &client_id, topics::HELLO, &[]);
let (root_handler, lss_signer) = match lss::init_lss(client_id, &rx, rhb, &mut mqtt) {
let (root_handler, lss_signer) = match lss::init_lss(signer_id, &rx, rhb, &mut mqtt) {
Ok(rl) => rl,
Err(e) => {
log::error!("failed to init lss {:?}", e);
@@ -149,7 +143,7 @@ pub fn make_event_loop(
};
// store the previous msgs processed, for LSS last step
let mut msgs: Option<(Vec<u8>, Vec<u8>)> = None;
let mut msgs: Option<(Vec<u8>, [u8; 32])> = None;
// signing loop
log::info!("=> starting the main signing loop...");
@@ -159,10 +153,10 @@ pub fn make_event_loop(
match event {
Event::Connected => {
log::info!("GOT A Event::Connected msg!");
mqtt_sub(&mut mqtt, client_id, SUB_TOPICS);
mqtt_sub(&mut mqtt, &client_id, topics::SIGNER_SUBS);
thread::sleep(std::time::Duration::from_secs(1));
// send the initial HELLO again
mqtt_pub(&mut mqtt, client_id, topics::HELLO, &[]);
mqtt_pub(&mut mqtt, &client_id, topics::HELLO, &[]);
led_tx.send(Status::Connected).unwrap();
}
Event::Disconnected => {
@@ -180,24 +174,28 @@ pub fn make_event_loop(
expected_sequence,
do_log,
) {
Ok((vls_b, lss_b, sequence, _cmd)) => {
if lss_b.len() == 0 {
// no muts, respond directly back!
mqtt_pub(&mut mqtt, client_id, topics::VLS_RES, &vls_b);
restart_esp_if_memory_low();
} else {
Ok((vls_b, lss_b, sequence, _cmd, server_hmac_opt)) => {
if let Some(server_hmac) = server_hmac_opt {
// muts! send LSS first!
mqtt_pub(&mut mqtt, client_id, topics::LSS_RES, &lss_b);
mqtt_pub(&mut mqtt, &client_id, topics::LSS_RES, &lss_b);
msg_store
.put("vls_b", &vls_b)
.set_raw("vls_b", &vls_b)
.map_err(|_e| anyhow::anyhow!("failed to put vls_b"))?;
msg_store
.put("lss_b", &lss_b)
.set_raw("lss_b", &server_hmac)
.map_err(|_e| anyhow::anyhow!("failed to put lss_b"))?;
msgs = Some((vls_b, lss_b));
msgs = Some((vls_b, server_hmac));
} else {
// no muts, respond directly back!
mqtt_pub(&mut mqtt, &client_id, topics::VLS_RES, &vls_b);
// and commit
if let Err(e) = root_handler.node().get_persister().commit() {
log::error!("LOCAL COMMIT ERROR! {:?}", e);
unsafe { esp_idf_sys::esp_restart() };
}
restart_esp_if_memory_low();
}
expected_sequence = Some(sequence + 1);
root_handler.commit();
}
Err(e) => match e {
VlsHandlerError::BadSequence(current, expected) => unsafe {
@@ -207,12 +205,12 @@ pub fn make_event_loop(
expected
);
log::info!("restarting esp!");
esp_idf_sys::esp_restart();
unsafe { esp_idf_sys::esp_restart() };
},
_ => {
let err_msg = GlyphError::new(1, &e.to_string());
log::error!("HANDLE FAILED {:?}", e);
mqtt_pub(&mut mqtt, client_id, topics::ERROR, &err_msg.to_vec()[..]);
mqtt_pub(&mut mqtt, &client_id, topics::ERROR, &err_msg.to_vec()[..]);
}
},
};
@@ -230,32 +228,41 @@ pub fn make_event_loop(
if msgs.is_none() {
log::warn!("Restoring previous message from sd card");
let vls_b = msg_store
.get("vls_b")
.map_err(|e| anyhow::anyhow!("failed to get vls_b: {:?}", e))?
.ok_or(anyhow::anyhow!("vls_b is none"))?
.1;
.get_raw("vls_b")
.map_err(|e| anyhow::anyhow!("failed to get vls_b: {:?}", e))?;
let lss_b = msg_store
.get("lss_b")
.map_err(|e| anyhow::anyhow!("failed to get lss_b: {:?}", e))?
.ok_or(anyhow::anyhow!("lss_b is none"))?
.1;
msgs = Some((vls_b, lss_b));
.get_raw("lss_b")
.map_err(|e| anyhow::anyhow!("failed to get lss_b: {:?}", e))?;
let server_hmac: [u8; 32] = lss_b
.try_into()
.map_err(|e| anyhow::anyhow!("lss_b is not 32 bytes: {:?}", e))?;
msgs = Some((vls_b, server_hmac));
}
match lss::handle_lss_msg(&msg_bytes, msgs, &lss_signer) {
Ok((ret_topic, bytes)) => {
// set msgs back to None
msgs = None;
mqtt_pub(&mut mqtt, client_id, &ret_topic, &bytes);
mqtt_pub(&mut mqtt, &client_id, &ret_topic, &bytes);
if ret_topic == topics::VLS_RES {
log::info!("HMACs matched! commit now...");
// and commit
if let Err(e) = root_handler.node().get_persister().commit() {
log::error!("LOCAL COMMIT ERROR AFTER LSS! {:?}", e);
unsafe { esp_idf_sys::esp_restart() };
}
restart_esp_if_memory_low();
}
if ret_topic == topics::LSS_CONFLICT_RES {
log::error!("LSS PUT CONFLICT! RESTART...");
unsafe { esp_idf_sys::esp_restart() };
}
}
Err(e) => {
log::error!("LSS MESSAGE FAILED!");
log::error!("{}", &e.to_string());
msgs = None;
let err_msg = GlyphError::new(1, &e.to_string());
mqtt_pub(&mut mqtt, client_id, topics::ERROR, &err_msg.to_vec()[..]);
mqtt_pub(&mut mqtt, &client_id, topics::ERROR, &err_msg.to_vec()[..]);
}
}
}
@@ -267,7 +274,7 @@ pub fn make_event_loop(
{
let mut bb = ByteBuf::new();
serialize_controlresponse(&mut bb, &res).expect("failed serialize_lssresponse");
mqtt_pub(&mut mqtt, client_id, topics::CONTROL_RES, bb.as_slice());
mqtt_pub(&mut mqtt, &client_id, topics::CONTROL_RES, bb.as_slice());
}
}
}

View File

@@ -14,11 +14,13 @@ use std::time::Duration;
pub use lss_connector::handle_lss_msg;
pub fn init_lss(
client_id: &str,
signer_id: &[u8; 16],
rx: &mpsc::Receiver<Event>,
handler_builder: RootHandlerBuilder,
mqtt: &mut EspMqttClient<ConnState<MessageImpl, EspError>>,
) -> Result<(RootHandler, LssSigner)> {
let client_id = hex::encode(signer_id);
let server_pubkey = loop {
let event = rx.recv_timeout(Duration::from_secs(30))?;
match server_pubkey_from_event(event) {

View File

@@ -25,7 +25,7 @@ use std::thread;
use std::time::Duration;
use std::time::SystemTime;
const ID_LEN: usize = 12;
const ID_LEN: usize = 16;
fn main() -> Result<()> {
// Temporary. Will disappear once ESP-IDF 4.4 is released, but for now it is necessary to call this function once,
@@ -137,9 +137,7 @@ fn main() -> Result<()> {
Some(s) => flash.write_seed(s).expect("could not store seed"),
None => panic!("SEED REQUIRED!!!"),
}
flash
.write_id(random_word(ID_LEN))
.expect("could not store id");
flash.write_id(random_16()).expect("could not store id");
}
drop(flash);
println!("CONFIG SAVED");
@@ -158,7 +156,7 @@ fn main() -> Result<()> {
fn make_and_launch_client(
config: Config,
seed: [u8; 32],
client_id: String,
signer_id: [u8; ID_LEN],
policy: &Policy,
velocity: &Option<Velocity>,
led_tx: mpsc::Sender<Status>,
@@ -184,7 +182,7 @@ fn make_and_launch_client(
log::info!("PUBKEY {} TOKEN {}", &pubkey_str, &token);
let mqtt_client =
conn::mqtt::make_client(&config.broker, &client_id, &pubkey_str, &token, tx.clone())?;
conn::mqtt::make_client(&config.broker, &signer_id, &pubkey_str, &token, tx.clone())?;
// let mqtt_client = conn::mqtt::start_listening(mqtt, connection, tx)?;
// this blocks forever... the "main thread"
@@ -204,7 +202,7 @@ fn make_and_launch_client(
policy,
velocity,
ctrlr,
&client_id,
&signer_id,
&pubkey,
)?;
Ok(())
@@ -218,3 +216,10 @@ pub fn random_word(n: usize) -> String {
.map(char::from)
.collect()
}
pub fn random_16() -> [u8; 16] {
use sphinx_crypter::secp256k1::rand::{thread_rng, RngCore};
let mut signer_id = [0u8; 16];
thread_rng().fill_bytes(&mut signer_id);
signer_id
}