From dbeeb2a0a25fe37ca191912060b565da0e01a74b Mon Sep 17 00:00:00 2001 From: irriden Date: Tue, 5 Sep 2023 20:08:22 +0000 Subject: [PATCH] sphinx-key: save previous msgs to sd card --- Cargo.lock | 12 ++++++------ sphinx-key/Cargo.toml | 6 +++--- sphinx-key/src/core/events.rs | 13 +++++++++++++ 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0c5f110..66b0549 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1219,7 +1219,7 @@ checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" [[package]] name = "lss-connector" 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 = [ "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=0d5c40f4087adde7e32e789a88900c5c9ba3b5ab#0d5c40f4087adde7e32e789a88900c5c9ba3b5ab" +source = "git+https://github.com/stakwork/sphinx-rs.git?rev=8a4c7acf4c82688b7bc009cbd9b5ced3fbb6c46d#8a4c7acf4c82688b7bc009cbd9b5ced3fbb6c46d" 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=0d5c40f4087adde7e32e789a88900c5c9ba3b5ab#0d5c40f4087adde7e32e789a88900c5c9ba3b5ab" +source = "git+https://github.com/stakwork/sphinx-rs.git?rev=8a4c7acf4c82688b7bc009cbd9b5ced3fbb6c46d#8a4c7acf4c82688b7bc009cbd9b5ced3fbb6c46d" 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=0d5c40f4087adde7e32e789a88900c5c9ba3b5ab#0d5c40f4087adde7e32e789a88900c5c9ba3b5ab" +source = "git+https://github.com/stakwork/sphinx-rs.git?rev=8a4c7acf4c82688b7bc009cbd9b5ced3fbb6c46d#8a4c7acf4c82688b7bc009cbd9b5ced3fbb6c46d" 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=0d5c40f4087adde7e32e789a88900c5c9ba3b5ab#0d5c40f4087adde7e32e789a88900c5c9ba3b5ab" +source = "git+https://github.com/stakwork/sphinx-rs.git?rev=8a4c7acf4c82688b7bc009cbd9b5ced3fbb6c46d#8a4c7acf4c82688b7bc009cbd9b5ced3fbb6c46d" 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=0d5c40f4087adde7e32e789a88900c5c9ba3b5ab#0d5c40f4087adde7e32e789a88900c5c9ba3b5ab" +source = "git+https://github.com/stakwork/sphinx-rs.git?rev=8a4c7acf4c82688b7bc009cbd9b5ced3fbb6c46d#8a4c7acf4c82688b7bc009cbd9b5ced3fbb6c46d" dependencies = [ "anyhow", "bip39", diff --git a/sphinx-key/Cargo.toml b/sphinx-key/Cargo.toml index 1734f9e..41f5ef9 100644 --- a/sphinx-key/Cargo.toml +++ b/sphinx-key/Cargo.toml @@ -19,11 +19,11 @@ serde_json = { version = "1.0.81", default-features = false } serde_urlencoded = "0.7.1" 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 } -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-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 } anyhow.workspace = true diff --git a/sphinx-key/src/core/events.rs b/sphinx-key/src/core/events.rs index 4fc694d..2871484 100644 --- a/sphinx-key/src/core/events.rs +++ b/sphinx-key/src/core/events.rs @@ -144,6 +144,8 @@ pub fn make_event_loop( // store the previous msgs processed, for LSS last step let mut msgs: Option<(Vec, Vec)> = None; + // persist them to sd card in case of crash + let msgs_persister = FsPersister::new(&ROOT_STORE, Some(8)); // signing loop log::info!("=> starting the main signing loop..."); @@ -182,6 +184,7 @@ pub fn make_event_loop( } else { // muts! send LSS first! 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)); } expected_sequence = Some(sequence + 1); @@ -214,6 +217,14 @@ pub fn make_event_loop( } } 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) { Ok((ret_topic, bytes)) => { // set msgs back to None @@ -224,6 +235,8 @@ pub fn make_event_loop( } } 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()[..]);