sphinx-key: save previous msgs to sd card

This commit is contained in:
irriden
2023-09-05 20:08:22 +00:00
parent 7ec4a6065b
commit dbeeb2a0a2
3 changed files with 22 additions and 9 deletions

12
Cargo.lock generated
View File

@@ -1219,7 +1219,7 @@ checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4"
[[package]] [[package]]
name = "lss-connector" name = "lss-connector"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=0d5c40f4087adde7e32e789a88900c5c9ba3b5ab#0d5c40f4087adde7e32e789a88900c5c9ba3b5ab" source = "git+https://github.com/stakwork/sphinx-rs.git?rev=8a4c7acf4c82688b7bc009cbd9b5ced3fbb6c46d#8a4c7acf4c82688b7bc009cbd9b5ced3fbb6c46d"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"log", "log",
@@ -1591,7 +1591,7 @@ dependencies = [
[[package]] [[package]]
name = "rmp-utils" name = "rmp-utils"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=0d5c40f4087adde7e32e789a88900c5c9ba3b5ab#0d5c40f4087adde7e32e789a88900c5c9ba3b5ab" source = "git+https://github.com/stakwork/sphinx-rs.git?rev=8a4c7acf4c82688b7bc009cbd9b5ced3fbb6c46d#8a4c7acf4c82688b7bc009cbd9b5ced3fbb6c46d"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"log", "log",
@@ -1798,7 +1798,7 @@ dependencies = [
[[package]] [[package]]
name = "sphinx-auther" name = "sphinx-auther"
version = "0.1.12" version = "0.1.12"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=0d5c40f4087adde7e32e789a88900c5c9ba3b5ab#0d5c40f4087adde7e32e789a88900c5c9ba3b5ab" source = "git+https://github.com/stakwork/sphinx-rs.git?rev=8a4c7acf4c82688b7bc009cbd9b5ced3fbb6c46d#8a4c7acf4c82688b7bc009cbd9b5ced3fbb6c46d"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"base64 0.21.2", "base64 0.21.2",
@@ -1810,7 +1810,7 @@ dependencies = [
[[package]] [[package]]
name = "sphinx-crypter" name = "sphinx-crypter"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=0d5c40f4087adde7e32e789a88900c5c9ba3b5ab#0d5c40f4087adde7e32e789a88900c5c9ba3b5ab" source = "git+https://github.com/stakwork/sphinx-rs.git?rev=8a4c7acf4c82688b7bc009cbd9b5ced3fbb6c46d#8a4c7acf4c82688b7bc009cbd9b5ced3fbb6c46d"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"chacha20poly1305", "chacha20poly1305",
@@ -1821,7 +1821,7 @@ dependencies = [
[[package]] [[package]]
name = "sphinx-glyph" name = "sphinx-glyph"
version = "0.1.2" version = "0.1.2"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=0d5c40f4087adde7e32e789a88900c5c9ba3b5ab#0d5c40f4087adde7e32e789a88900c5c9ba3b5ab" source = "git+https://github.com/stakwork/sphinx-rs.git?rev=8a4c7acf4c82688b7bc009cbd9b5ced3fbb6c46d#8a4c7acf4c82688b7bc009cbd9b5ced3fbb6c46d"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"hex", "hex",
@@ -1872,7 +1872,7 @@ dependencies = [
[[package]] [[package]]
name = "sphinx-signer" name = "sphinx-signer"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=0d5c40f4087adde7e32e789a88900c5c9ba3b5ab#0d5c40f4087adde7e32e789a88900c5c9ba3b5ab" source = "git+https://github.com/stakwork/sphinx-rs.git?rev=8a4c7acf4c82688b7bc009cbd9b5ced3fbb6c46d#8a4c7acf4c82688b7bc009cbd9b5ced3fbb6c46d"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bip39", "bip39",

View File

@@ -19,11 +19,11 @@ serde_json = { version = "1.0.81", default-features = false }
serde_urlencoded = "0.7.1" serde_urlencoded = "0.7.1"
url = "2" url = "2"
lss-connector = { git = "https://github.com/stakwork/sphinx-rs.git", default-features = false, rev = "0d5c40f4087adde7e32e789a88900c5c9ba3b5ab" } lss-connector = { git = "https://github.com/stakwork/sphinx-rs.git", default-features = false, rev = "8a4c7acf4c82688b7bc009cbd9b5ced3fbb6c46d" }
# lss-connector = { path = "../../sphinx-rs/lss-connector", default-features = false } # lss-connector = { path = "../../sphinx-rs/lss-connector", default-features = false }
sphinx-crypter = { git = "https://github.com/stakwork/sphinx-rs.git", rev = "0d5c40f4087adde7e32e789a88900c5c9ba3b5ab" } sphinx-crypter = { git = "https://github.com/stakwork/sphinx-rs.git", rev = "8a4c7acf4c82688b7bc009cbd9b5ced3fbb6c46d" }
# sphinx-crypter = { path = "../../sphinx-rs/crypter" } # sphinx-crypter = { path = "../../sphinx-rs/crypter" }
sphinx-signer = { git = "https://github.com/stakwork/sphinx-rs.git", optional = true, rev = "0d5c40f4087adde7e32e789a88900c5c9ba3b5ab" } sphinx-signer = { git = "https://github.com/stakwork/sphinx-rs.git", optional = true, rev = "8a4c7acf4c82688b7bc009cbd9b5ced3fbb6c46d" }
# sphinx-signer = { path = "../../sphinx-rs/signer", optional = true } # sphinx-signer = { path = "../../sphinx-rs/signer", optional = true }
anyhow.workspace = true anyhow.workspace = true

View File

@@ -144,6 +144,8 @@ pub fn make_event_loop(
// store the previous msgs processed, for LSS last step // store the previous msgs processed, for LSS last step
let mut msgs: Option<(Vec<u8>, Vec<u8>)> = None; let mut msgs: Option<(Vec<u8>, Vec<u8>)> = None;
// persist them to sd card in case of crash
let msgs_persister = FsPersister::new(&ROOT_STORE, Some(8));
// signing loop // signing loop
log::info!("=> starting the main signing loop..."); log::info!("=> starting the main signing loop...");
@@ -182,6 +184,7 @@ pub fn make_event_loop(
} else { } else {
// muts! send LSS first! // 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);
msgs_persister.set_prevs(&vls_b, &lss_b);
msgs = Some((vls_b, lss_b)); msgs = Some((vls_b, lss_b));
} }
expected_sequence = Some(sequence + 1); expected_sequence = Some(sequence + 1);
@@ -214,6 +217,14 @@ pub fn make_event_loop(
} }
} }
Event::LssMessage(msg_bytes) => { Event::LssMessage(msg_bytes) => {
if msgs.is_none() {
log::warn!("Restoring previous message from sd card");
msgs = Some(
msgs_persister
.read_prevs()
.map_err(|e| anyhow::anyhow!("{:?}", e))?,
)
}
match lss::handle_lss_msg(&msg_bytes, msgs, &lss_signer) { match lss::handle_lss_msg(&msg_bytes, msgs, &lss_signer) {
Ok((ret_topic, bytes)) => { Ok((ret_topic, bytes)) => {
// set msgs back to None // set msgs back to None
@@ -224,6 +235,8 @@ pub fn make_event_loop(
} }
} }
Err(e) => { Err(e) => {
log::error!("LSS MESSAGE FAILED!");
log::error!("{}", &e.to_string());
msgs = None; msgs = None;
let err_msg = GlyphError::new(1, &e.to_string()); 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()[..]);