mirror of
https://github.com/stakwork/sphinx-key.git
synced 2026-02-23 00:24:18 +01:00
everything compiling, start MsgDriver for VLS signer loop
This commit is contained in:
82
riscv.md
82
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"] }`
|
||||
@@ -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"
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
16
signer/src/lib.rs
Normal file
16
signer/src/lib.rs
Normal file
@@ -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<dyn Persist> = Arc::new(DummyPersister);
|
||||
|
||||
println!("Hello, world!");
|
||||
}
|
||||
@@ -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!");
|
||||
}
|
||||
39
signer/src/msg.rs
Normal file
39
signer/src/msg.rs
Normal file
@@ -0,0 +1,39 @@
|
||||
|
||||
use anyhow::Result;
|
||||
use log::*;
|
||||
use vls_protocol_signer::vls_protocol::serde_bolt::{self, Read, Write};
|
||||
|
||||
pub struct MsgDriver(Vec<u8>);
|
||||
|
||||
impl MsgDriver {
|
||||
pub fn new(raw: Vec<u8>) -> 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<usize> {
|
||||
if buf.is_empty() {
|
||||
return Ok(0);
|
||||
}
|
||||
let len = self.0.len();
|
||||
Ok(len)
|
||||
}
|
||||
|
||||
fn peek(&mut self) -> serde_bolt::Result<Option<u8>> {
|
||||
Ok(Some(0))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl Write for MsgDriver {
|
||||
type Error = serde_bolt::Error;
|
||||
|
||||
fn write_all(&mut self, buf: &[u8]) -> serde_bolt::Result<()> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
[package]
|
||||
name = "sphinx-key-signer"
|
||||
version = "0.1.0"
|
||||
authors = ["Evan Feenstra <evanfeenstra@gmail.com>"]
|
||||
edition = "2018"
|
||||
resolver = "2"
|
||||
@@ -1,3 +0,0 @@
|
||||
pub fn say_hi() {
|
||||
println!("hi from signer module!");
|
||||
}
|
||||
@@ -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"
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
@@ -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<Mutex<EspMqttClient<ConnState<MessageImpl, Esp
|
||||
use embedded_svc::event_bus::EventBus;
|
||||
|
||||
info!("About to start a background event loop");
|
||||
let mut eventloop = EspBackgroundEventLoop::new(&Default::default())?;
|
||||
let mut eventloop = EspBackgroundEventLoop::new(
|
||||
&BackgroundLoopConfiguration {
|
||||
task_stack_size: 8192,
|
||||
.. Default::default()
|
||||
},
|
||||
)?;
|
||||
|
||||
info!("About to subscribe to the background event loop");
|
||||
let subscription = eventloop.subscribe(move |message: &Message| {
|
||||
info!("!!! Got message from the event loop"); //: {:?}", message.0);
|
||||
let msg = message.read_bytes();
|
||||
let msg_str = String::from_utf8_lossy(&msg[..]);
|
||||
let msg_str = message.read_string();
|
||||
// let msg_str = String::from_utf8_lossy(&msg[..]);
|
||||
match client.lock() {
|
||||
Ok(mut m_) => if let Err(err) = m_.publish(
|
||||
RETURN_TOPIC,
|
||||
|
||||
Reference in New Issue
Block a user