From 95d6f3105cddc2f7101730b85d257a6c26dacd50 Mon Sep 17 00:00:00 2001 From: Evan Feenstra Date: Mon, 30 May 2022 13:34:30 -0700 Subject: [PATCH] everything compiling, start MsgDriver for VLS signer loop --- riscv.md | 82 +++++------------------------------ signer/Cargo.toml | 16 +++---- signer/build.rs | 5 --- signer/src/lib.rs | 16 +++++++ signer/src/main.rs | 12 ----- signer/src/msg.rs | 39 +++++++++++++++++ signer1/Cargo.toml | 6 --- signer1/src/lib.rs | 3 -- sphinx-key/Cargo.toml | 2 +- sphinx-key/src/conn/mqtt.rs | 4 +- sphinx-key/src/core/events.rs | 14 ++++-- 11 files changed, 87 insertions(+), 112 deletions(-) delete mode 100644 signer/build.rs create mode 100644 signer/src/lib.rs delete mode 100644 signer/src/main.rs create mode 100644 signer/src/msg.rs delete mode 100644 signer1/Cargo.toml delete mode 100644 signer1/src/lib.rs diff --git a/riscv.md b/riscv.md index c4d78f3..119a810 100644 --- a/riscv.md +++ b/riscv.md @@ -1,81 +1,19 @@ +### buid with CC option -### point to local dep +find the path to your `riscv32-esp-elf-gcc` binary withing the `.embuild` dir: -```sh -git clone https://github.com/devrandom/rust-secp256k1.git secp256k1 +`export CC=/Users/evanfeenstra/code/sphinx-key/sphinx-key/signer/.embuild/espressif/tools/riscv32-esp-elf/esp-2021r2-patch3-8.4.0/riscv32-esp-elf/bin/riscv32-esp-elf-gcc` -cd secp256k1 +### to get std features of vls: -# for static precomputation? See vls-signer-stm32 cargo.toml -git checkout 4e745ebe7e4c9cd0a7e9c8d5c42e989522e52f71 +point to local version of validating-lightning-signer: -# DO THIS: for v0.22.0, this is what latest rust-bitcoin uses -git checkout 50b7c256377494d942826705a1275055e6f93925 -# you'll need to change `mod key` to `pub mode key` in lib.rs +in validating-lightning-signer/vls-protocol-signer/Cargo.toml `[features]` -cd secp256k1-sys -``` +add: `vls-std = ["vls-protocol/std"]` -Put the toolchain and config files in BOTH the secp256k1 parent dir, and the secp256k1-sys child dir. +`cargo build` -rust-toolchain.toml: -```yaml -[toolchain] -channel = "nightly" -``` +then in signer Cargo.toml -.cargo/config.toml -```yaml -[build] -target = "riscv32imc-esp-espidf" - -[target.riscv32imc-esp-espidf] -linker = "ldproxy" - -rustflags = ["-C", "default-linker-libraries"] - -[unstable] - -build-std = ["std", "panic_abort"] - -[env] -ESP_IDF_VERSION = { value = "branch:release/v4.4" } -``` - -in build.rs: -```rs -// Actual build -let mut base_config = cc::Build::new(); -// add this with your path to embuild gcc: -base_config.compiler(std::path::PathBuf::from( - "/Users/evanfeenstra/code/sphinx-key/sphinx-key/signer/.embuild/espressif/tools/riscv32-esp-elf/esp-2021r2-patch3-8.4.0/riscv32-esp-elf/bin/riscv32-esp-elf-gcc" -)); -``` - -and use path dep in Cargo.toml -```yaml -secp256k1-sys = { path = "../../secp256k1/secp256k1-sys" } -``` - -### overrides - -validating-lightning-signer -bitcoin -lightning -lightning-invoice - -point each of those to `path` dependencies of each other - -remove `rand-std` feature from every crate dependency - -### issue now: - -no `XOnlyPublicKey` in the root - -need to align the commits on each crate??? - -### path notes (dont do this) - -CC=/usr/local/Cellar/riscv-gnu-toolchain/main/bin/riscv64-unknown-elf-gcc cargo build --target=riscv32imc-esp-espidf - -CC=/Users/evanfeenstra/code/sphinx-key/sphinx-key/signer/.embuild/espressif/tools/riscv32-esp-elf/esp-2021r2-patch3-8.4.0/riscv32-esp-elf/bin/riscv32-esp-elf-gcc-8.4.0 cargo build --target=riscv32imc-esp-espidf +`vls-protocol-signer = { path = "../../vls-og/vls-protocol-signer", default-features = false, features = ["secp-lowmemory", "vls-std"] }` \ No newline at end of file diff --git a/signer/Cargo.toml b/signer/Cargo.toml index 07ec867..1fd3aa5 100644 --- a/signer/Cargo.toml +++ b/signer/Cargo.toml @@ -12,14 +12,12 @@ opt-level = "s" debug = true # Symbols are nice and they don't increase the size on Flash opt-level = "z" -[features] -pio = ["esp-idf-sys/pio"] - [dependencies] -esp-idf-sys = { version = "0.31.5", features = ["binstart"] } -vls-protocol-signer = { path = "../../validating-lightning-signer/vls-protocol-signer", features = ["secp-lowmemory"] } -# secp256k1-sys = { path = "../../rust-secp256k1/secp256k1-sys" } +vls-protocol-signer = { path = "../../validating-lightning-signer/vls-protocol-signer", default-features = false, features = ["secp-lowmemory", "vls-std"] } +anyhow = {version = "1", features = ["backtrace"]} +log = "0.4" + +[patch.crates-io] +# Low-memory version of secp256k1 with static precomputation +secp256k1 = { git = "https://github.com/devrandom/rust-secp256k1.git", rev = "4e745ebe7e4c9cd0a7e9c8d5c42e989522e52f71" } -[build-dependencies] -embuild = "0.29" -anyhow = "1" diff --git a/signer/build.rs b/signer/build.rs deleted file mode 100644 index 4dd5e1f..0000000 --- a/signer/build.rs +++ /dev/null @@ -1,5 +0,0 @@ -// Necessary because of this issue: https://github.com/rust-lang/cargo/issues/9641 -fn main() -> anyhow::Result<()> { - embuild::build::CfgArgs::output_propagated("ESP_IDF")?; - embuild::build::LinkArgs::output_propagated("ESP_IDF") -} diff --git a/signer/src/lib.rs b/signer/src/lib.rs new file mode 100644 index 0000000..c7334c1 --- /dev/null +++ b/signer/src/lib.rs @@ -0,0 +1,16 @@ +pub mod msg; + +use lightning_signer::persist::{DummyPersister, Persist}; +use lightning_signer::Arc; +use vls_protocol::model::PubKey; +use vls_protocol::msgs::{self, read_serial_request_header, write_serial_response_header, Message}; +use vls_protocol::serde_bolt::WireString; +use vls_protocol_signer::handler::{Handler, RootHandler}; +use vls_protocol_signer::lightning_signer; +use vls_protocol_signer::vls_protocol; + +pub fn say_hi() { + let persister: Arc = Arc::new(DummyPersister); + + println!("Hello, world!"); +} diff --git a/signer/src/main.rs b/signer/src/main.rs deleted file mode 100644 index 83be9e4..0000000 --- a/signer/src/main.rs +++ /dev/null @@ -1,12 +0,0 @@ -use esp_idf_sys as _; // If using the `binstart` feature of `esp-idf-sys`, always keep this module imported -// use vls_protocol_signer; - -fn main() { - // Temporary. Will disappear once ESP-IDF 4.4 is released, but for now it is necessary to call this function once, - // or else some patches to the runtime implemented by esp-idf-sys might not link properly. - esp_idf_sys::link_patches(); - - let mut parity: secp256k1_sys::types::c_int = 0; - - println!("Hello, world!"); -} diff --git a/signer/src/msg.rs b/signer/src/msg.rs new file mode 100644 index 0000000..7a78f2d --- /dev/null +++ b/signer/src/msg.rs @@ -0,0 +1,39 @@ + +use anyhow::Result; +use log::*; +use vls_protocol_signer::vls_protocol::serde_bolt::{self, Read, Write}; + +pub struct MsgDriver(Vec); + +impl MsgDriver { + pub fn new(raw: Vec) -> Self { + Self(raw) + } +} + +impl Read for MsgDriver { + type Error = serde_bolt::Error; + + // input: buf to be written. Should already be the right size + fn read(&mut self, mut buf: &mut [u8]) -> serde_bolt::Result { + if buf.is_empty() { + return Ok(0); + } + let len = self.0.len(); + Ok(len) + } + + fn peek(&mut self) -> serde_bolt::Result> { + Ok(Some(0)) + } + +} + +impl Write for MsgDriver { + type Error = serde_bolt::Error; + + fn write_all(&mut self, buf: &[u8]) -> serde_bolt::Result<()> { + + Ok(()) + } +} diff --git a/signer1/Cargo.toml b/signer1/Cargo.toml deleted file mode 100644 index cb5a272..0000000 --- a/signer1/Cargo.toml +++ /dev/null @@ -1,6 +0,0 @@ -[package] -name = "sphinx-key-signer" -version = "0.1.0" -authors = ["Evan Feenstra "] -edition = "2018" -resolver = "2" \ No newline at end of file diff --git a/signer1/src/lib.rs b/signer1/src/lib.rs deleted file mode 100644 index 0cc67da..0000000 --- a/signer1/src/lib.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub fn say_hi() { - println!("hi from signer module!"); -} diff --git a/sphinx-key/Cargo.toml b/sphinx-key/Cargo.toml index ec44def..0eeb12b 100644 --- a/sphinx-key/Cargo.toml +++ b/sphinx-key/Cargo.toml @@ -16,8 +16,8 @@ opt-level = "z" pio = ["esp-idf-sys/pio"] [dependencies] -esp-idf-sys = { version = "0.31.5", features = ["binstart"] } sphinx-key-signer = { path = "../signer" } +esp-idf-sys = { version = "0.31.5", features = ["binstart"] } embedded-svc = { version = "0.21.2" } esp-idf-svc = "0.41" esp-idf-hal = "0.37" diff --git a/sphinx-key/src/conn/mqtt.rs b/sphinx-key/src/conn/mqtt.rs index 474c56c..ba31ac5 100644 --- a/sphinx-key/src/conn/mqtt.rs +++ b/sphinx-key/src/conn/mqtt.rs @@ -24,6 +24,8 @@ pub fn make_client(broker: &str) -> Result<( )> { let conf = MqttClientConfiguration { client_id: Some(CLIENT_ID), + buffer_size: 2048, + task_stack: 12288, // FIXME - mqtts // crt_bundle_attach: Some(esp_idf_sys::esp_crt_bundle_attach), ..Default::default() @@ -54,12 +56,12 @@ pub fn start_listening( Err(e) => info!("MQTT Message ERROR: {}", e), Ok(msg) => { if let Event::Received(msg) = msg { + info!("MQTT MESSAGE RECEIVED!"); if let Ok(m) = Message::new_from_slice(&msg.data()) { if let Err(e) = eventloop.post(&m, None) { warn!("failed to post to eventloop {:?}", e); } } - info!("MQTT Message: {:?}", msg); } }, } diff --git a/sphinx-key/src/core/events.rs b/sphinx-key/src/core/events.rs index f874663..889c6f9 100644 --- a/sphinx-key/src/core/events.rs +++ b/sphinx-key/src/core/events.rs @@ -36,6 +36,9 @@ impl Message { let l = self.0[0] as usize; self.0[1..l+1].to_vec() } + pub fn read_string(&self) -> String { + String::from_utf8_lossy(&self.0).to_string() + } } impl EspTypedEventSource for Message { @@ -66,13 +69,18 @@ pub fn make_eventloop(client: Arc if let Err(err) = m_.publish( RETURN_TOPIC,