update VLS, add bitcoin Network param, patch in esp32 RNG in secp

This commit is contained in:
Evan Feenstra
2022-06-20 13:18:32 -07:00
parent 495459b74e
commit 35601a7c8c
9 changed files with 23 additions and 12 deletions

View File

@@ -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

View File

@@ -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<Mutex<bool>> = SyncLazy::new(|| Mutex::new(false));
static CONNECTED: LazyLock<Mutex<bool>> = LazyLock::new(|| Mutex::new(false));
fn set_connected(b: bool) {
*CONNECTED.lock().unwrap() = b;
}

View File

@@ -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"

View File

@@ -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<u8>,
}
pub fn init(bytes: Vec<u8>) -> anyhow::Result<InitResponse> {
pub fn init(bytes: Vec<u8>, network: Network) -> anyhow::Result<InitResponse> {
let persister: Arc<dyn Persist> = 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<u8>) -> anyhow::Result<InitResponse> {
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))

View File

@@ -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"

View File

@@ -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).

View File

@@ -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<ConnState<MessageImpl, EspError>>,
rx: mpsc::Receiver<Event>,
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<ConnState<MessageImpl, EspError>>,
rx: mpsc::Receiver<Event>,
_network: Network,
do_log: bool,
) -> Result<()> {
log::info!("About to subscribe to the mpsc channel");

View File

@@ -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());

View File

@@ -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<Mutex<Transmit<Gpio8<esp_idf_hal::gpio::Output>, esp_idf_hal::rmt::CHANNEL0>>> = SyncLazy::new(|| {
static TX: LazyLock<Mutex<Transmit<Gpio8<esp_idf_hal::gpio::Output>, 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;