diff --git a/README.md b/README.md index 2eb45ce..5c89d79 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ These notes were tested for macOS Find the path to your `riscv32-esp-elf-gcc` binary within the `.embuild` dir: -`export CC=$PWD/.embuild/espressif/tools/riscv32-esp-elf/esp-2021r2-patch3-8.4.0/riscv32-esp-elf/bin/riscv32-esp-elf-gcc` +`export CC=$PWD/.embuild/espressif/tools/riscv32-esp-elf/esp-2021r2-8.4.0/riscv32-esp-elf/bin/riscv32-esp-elf-gcc` ### build test diff --git a/broker/src/mqtt.rs b/broker/src/mqtt.rs index c99ea97..5c84bea 100644 --- a/broker/src/mqtt.rs +++ b/broker/src/mqtt.rs @@ -8,7 +8,7 @@ use librumqttd::{ use std::sync::Arc; use std::thread; use std::time::Duration; -use std::{lazy::SyncLazy, sync::Mutex}; +use std::sync::{LazyLock, Mutex}; use tokio::sync::mpsc; use tokio::time::timeout; @@ -19,7 +19,7 @@ const PASSWORD: &str = "sphinx-key-pass"; // must get a reply within this time, or disconnects const REPLY_TIMEOUT_MS: u64 = 10000; -static CONNECTED: SyncLazy> = SyncLazy::new(|| Mutex::new(false)); +static CONNECTED: LazyLock> = LazyLock::new(|| Mutex::new(false)); fn set_connected(b: bool) { *CONNECTED.lock().unwrap() = b; } diff --git a/signer/Cargo.toml b/signer/Cargo.toml index ffbb385..5ebef6e 100644 --- a/signer/Cargo.toml +++ b/signer/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" sphinx-key-parser = { path = "../parser" } # vls-protocol-signer = { path = "../../../evanf/validating-lightning-signer/vls-protocol-signer", default-features = false, features = ["std", "secp-lowmemory"] } # vls-protocol-signer = { git = "https://gitlab.com/lightning-signer/validating-lightning-signer", default-features = false, features = ["secp-lowmemory"] } -vls-protocol-signer = { git = "https://gitlab.com/Evanfeenstra/validating-lightning-signer", branch = "std-signer", default-features = false, features = ["std", "secp-lowmemory"] } +vls-protocol-signer = { git = "https://gitlab.com/Evanfeenstra/validating-lightning-signer", branch = "partial-std", default-features = false, features = ["std", "secp-lowmemory"] } anyhow = {version = "1", features = ["backtrace"]} log = "0.4" diff --git a/signer/src/lib.rs b/signer/src/lib.rs index 1a06662..69d11e7 100644 --- a/signer/src/lib.rs +++ b/signer/src/lib.rs @@ -7,6 +7,7 @@ use vls_protocol::msgs::{self, read_serial_request_header, write_serial_response use vls_protocol::serde_bolt::WireString; use vls_protocol_signer::handler::{Handler, RootHandler}; pub use vls_protocol_signer::lightning_signer; +pub use vls_protocol_signer::lightning_signer::bitcoin::Network; pub use vls_protocol_signer::vls_protocol; pub struct InitResponse { @@ -14,7 +15,7 @@ pub struct InitResponse { pub init_reply: Vec, } -pub fn init(bytes: Vec) -> anyhow::Result { +pub fn init(bytes: Vec, network: Network) -> anyhow::Result { let persister: Arc = Arc::new(DummyPersister); let mut md = MsgDriver::new(bytes); let (sequence, dbid) = read_serial_request_header(&mut md).expect("read init header"); @@ -30,7 +31,7 @@ pub fn init(bytes: Vec) -> anyhow::Result { log::info!("allowlist {:?}", allowlist); let seed = init.dev_seed.as_ref().map(|s| s.0).expect("no seed"); log::info!("create root handler now"); - let root_handler = RootHandler::new(0, Some(seed), persister, allowlist); + let root_handler = RootHandler::new(network, 0, Some(seed), persister, allowlist); log::info!("root_handler created"); let init_reply = root_handler .handle(Message::HsmdInit2(init)) diff --git a/sphinx-key/Cargo.toml b/sphinx-key/Cargo.toml index c2f4b95..5d266b2 100644 --- a/sphinx-key/Cargo.toml +++ b/sphinx-key/Cargo.toml @@ -32,6 +32,11 @@ serde_urlencoded = "0.7.1" serde = { version = "1.0.137", default-features = false } serde_json = { version = "1.0.81", default-features = false } +[patch.crates-io] +# updates the "rand" create to use esp RNG +getrandom = { version = "0.2", git = "https://github.com/esp-rs-compat/getrandom.git" } +secp256k1 = { git = "https://github.com/Evanfeenstra/rust-secp256k1", branch = "v0.22.0-new-rand" } + [build-dependencies] embuild = "0.29" anyhow = "1" diff --git a/sphinx-key/sdkconfig.defaults b/sphinx-key/sdkconfig.defaults index ce0978e..0e8ebf9 100644 --- a/sphinx-key/sdkconfig.defaults +++ b/sphinx-key/sdkconfig.defaults @@ -1,5 +1,5 @@ # Rust often needs a bit of an extra main task stack size compared to C (the default is 3K) -CONFIG_ESP_MAIN_TASK_STACK_SIZE=24000 +CONFIG_ESP_MAIN_TASK_STACK_SIZE=32000 # Use this to set FreeRTOS kernel tick frequency to 1000 Hz (100 Hz by default). # This allows to use 1 ms granuality for thread sleeps (10 ms by default). diff --git a/sphinx-key/src/core/events.rs b/sphinx-key/src/core/events.rs index 252e1de..4c59eb9 100644 --- a/sphinx-key/src/core/events.rs +++ b/sphinx-key/src/core/events.rs @@ -1,6 +1,7 @@ use crate::conn::mqtt::{QOS, RETURN_TOPIC, TOPIC}; use sphinx_key_signer::vls_protocol::model::PubKey; use sphinx_key_signer::{self, InitResponse}; +use sphinx_key_signer::lightning_signer::bitcoin::Network; use std::sync::mpsc; use embedded_svc::httpd::Result; @@ -21,6 +22,7 @@ pub enum Event { pub fn make_event_loop( mut mqtt: EspMqttClient>, rx: mpsc::Receiver, + network: Network, do_log: bool, ) -> Result<()> { // initialize the RootHandler @@ -36,7 +38,7 @@ pub fn make_event_loop( let InitResponse { root_handler, init_reply, - } = sphinx_key_signer::init(msg_bytes.clone()).expect("failed to init signer"); + } = sphinx_key_signer::init(msg_bytes.clone(), network).expect("failed to init signer"); mqtt.publish(RETURN_TOPIC, QOS, false, init_reply) .expect("could not publish init response"); break root_handler; @@ -83,6 +85,7 @@ pub fn make_event_loop( pub fn make_event_loop( mut mqtt: EspMqttClient>, rx: mpsc::Receiver, + _network: Network, do_log: bool, ) -> Result<()> { log::info!("About to subscribe to the mpsc channel"); diff --git a/sphinx-key/src/main.rs b/sphinx-key/src/main.rs index 92264d6..7760ae2 100644 --- a/sphinx-key/src/main.rs +++ b/sphinx-key/src/main.rs @@ -17,6 +17,8 @@ use esp_idf_svc::nvs_storage::EspNvsStorage; use embedded_svc::storage::Storage; use embedded_svc::wifi::Wifi; +use sphinx_key_signer::lightning_signer::bitcoin::Network; + #[cfg(not(feature = "pingpong"))] const CLIENT_ID: &str = "sphinx-1"; @@ -50,7 +52,8 @@ fn main() -> Result<()> { // this blocks forever... the "main thread" log::info!(">>>>>>>>>>> blocking forever..."); let do_log = true; - make_event_loop(mqtt_client, rx, do_log)?; + let net = Network::Regtest; + make_event_loop(mqtt_client, rx, net, do_log)?; let mut blue = Led::new(0x000001, 100); println!("{:?}", wifi.get_status()); diff --git a/sphinx-key/src/periph/led.rs b/sphinx-key/src/periph/led.rs index c6bb927..b6ca157 100644 --- a/sphinx-key/src/periph/led.rs +++ b/sphinx-key/src/periph/led.rs @@ -6,10 +6,9 @@ use esp_idf_hal::peripherals::Peripherals; use esp_idf_hal::rmt::config::TransmitConfig; use esp_idf_hal::rmt::{FixedLengthSignal, PinState, Pulse, Transmit}; -use std::lazy::SyncLazy; -use std::sync::Mutex; +use std::sync::{LazyLock, Mutex}; -static TX: SyncLazy, esp_idf_hal::rmt::CHANNEL0>>> = SyncLazy::new(|| { +static TX: LazyLock, esp_idf_hal::rmt::CHANNEL0>>> = LazyLock::new(|| { let peripherals = Peripherals::take().unwrap(); let led = peripherals.pins.gpio8.into_output().unwrap(); let channel = peripherals.rmt.channel0;