Merge branch 'master' into feat/leds

This commit is contained in:
Evan Feenstra
2022-06-28 17:27:43 -07:00
8 changed files with 70 additions and 32 deletions

View File

@@ -6,22 +6,25 @@ default-run = "sphinx-key-broker"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
vls-protocol = { git = "https://gitlab.com/Evanfeenstra/validating-lightning-signer", branch = "partial-std" }
vls-proxy = { git = "https://gitlab.com/Evanfeenstra/validating-lightning-signer", branch = "partial-std" }
# vls-protocol = { path = "../../../evanf/validating-lightning-signer/vls-protocol" }
# vls-proxy = { path = "../../../evanf/validating-lightning-signer/vls-proxy" }
rumqttd = { git = "https://github.com/Evanfeenstra/rumqtt", branch = "metrics" }
pretty_env_logger = "0.4.0"
confy = "0.4.0"
tokio = { version = "1.4.0", features = ["rt", "rt-multi-thread", "macros"] }
vls-protocol = { git = "https://gitlab.com/Evanfeenstra/validating-lightning-signer", branch = "partial-std" }
vls-proxy = { git = "https://gitlab.com/Evanfeenstra/validating-lightning-signer", branch = "partial-std" }
sphinx-key-parser = { path = "../parser" }
secp256k1 = { version = "0.20", features = ["rand-std", "bitcoin_hashes"] }
anyhow = {version = "1", features = ["backtrace"]}
log = "0.4"
fern = { version = "0.6", features = ["colored"] }
rumqttc = "0.12.0"
clap = "=3.0.0-beta.2"
clap_derive = "=3.0.0-beta.5"
clap = "3.2.6"
clap_derive = "3.2.6"
chrono = "0.4"
once_cell = "1.12.0"
bitcoin = "0.28.1"
[features]
default = ["std"]

View File

@@ -5,9 +5,10 @@ use tokio::sync::{mpsc, oneshot};
use vls_protocol::model::Secret;
use vls_protocol::{msgs, serde_bolt::WireString};
use vls_proxy::util::{read_allowlist, read_integration_test_seed};
use bitcoin::Network;
pub fn blocking_connect(tx: mpsc::Sender<ChannelRequest>) {
let init_msg_2 = crate::init::make_init_msg().expect("could make init msg");
pub fn blocking_connect(tx: mpsc::Sender<ChannelRequest>, network: Network) {
let init_msg_2 = crate::init::make_init_msg(network).expect("couldnt make init msg");
let (reply_tx, reply_rx) = oneshot::channel();
// Send a request to the MQTT handler to send to signer
let request = ChannelRequest {
@@ -16,12 +17,12 @@ pub fn blocking_connect(tx: mpsc::Sender<ChannelRequest>) {
};
tx.blocking_send(request).expect("could not blocking send");
let res = reply_rx.blocking_recv().expect("couldnt receive");
let reply = parser::response_from_bytes(res.reply, 0).expect("could parse init receive");
let reply = parser::response_from_bytes(res.reply, 0).expect("couldnt parse init receive");
println!("REPLY {:?}", reply);
}
pub async fn _connect(tx: mpsc::Sender<ChannelRequest>) {
let init_msg_2 = crate::init::make_init_msg().expect("could make init msg");
pub async fn _connect(tx: mpsc::Sender<ChannelRequest>, network: Network) {
let init_msg_2 = crate::init::make_init_msg(network).expect("could make init msg");
let (reply_tx, reply_rx) = oneshot::channel();
// Send a request to the MQTT handler to send to signer
let request = ChannelRequest {
@@ -34,19 +35,23 @@ pub async fn _connect(tx: mpsc::Sender<ChannelRequest>) {
println!("REPLY {:?}", reply);
}
pub fn make_init_msg() -> anyhow::Result<Vec<u8>> {
pub fn make_init_msg(network: Network) -> anyhow::Result<Vec<u8>> {
let allowlist = read_allowlist()
.into_iter()
.map(|s| WireString(s.as_bytes().to_vec()))
.collect::<Vec<_>>();
let seed = read_integration_test_seed()
.map(|s| Secret(s))
.or(Some(Secret([1; 32])));
let seed = if network==Network::Bitcoin {
Some(Secret([0x8c, 0xe8, 0x62, 0xab, 0xd5, 0x6b, 0xb4, 0x6a, 0x61, 0x7f, 0xaf, 0x13, 0x50, 0xc1, 0xca, 0xf5, 0xb1, 0xee, 0x02, 0x97, 0xbf, 0xf3, 0xb8, 0xc9, 0x56, 0x63, 0x58, 0x9f, 0xec, 0x8c, 0x45, 0x79]))
} else {
read_integration_test_seed()
.map(|s| Secret(s))
.or(Some(Secret([1; 32])))
};
// FIXME remove this
log::info!("allowlist {:?} seed {:?}", allowlist, seed);
let init = msgs::HsmdInit2 {
derivation_style: 0,
network_name: WireString("testnet".as_bytes().to_vec()),
network_name: WireString(network.to_string().as_bytes().to_vec()),
dev_seed: seed,
dev_allowlist: allowlist,
};

View File

@@ -7,11 +7,12 @@ mod util;
use crate::mqtt::start_broker;
use crate::unix_fd::SignerLoop;
use clap::{App, AppSettings, Arg};
use clap::{App, AppSettings, Arg, arg};
use std::env;
use tokio::sync::{mpsc, oneshot};
use vls_proxy::client::UnixClient;
use vls_proxy::connection::{open_parent_fd, UnixConnection};
use bitcoin::Network;
pub struct Channel {
pub sequence: u16,
@@ -39,15 +40,35 @@ fn main() -> anyhow::Result<()> {
.setting(AppSettings::NoAutoVersion)
.about("CLN:mqtt - connects to an embedded VLS over a MQTT connection")
.arg(
Arg::new("--dev-disconnect")
.about("ignored dev flag")
Arg::new("dev-disconnect")
.help("ignored dev flag")
.long("dev-disconnect")
.takes_value(true),
)
.arg(Arg::from("--log-io ignored dev flag"))
.arg(Arg::from("--version show a dummy version"))
.arg(Arg::from("--test run a test against the embedded device"));
.arg(arg!(--"log-io" "ignored dev flag"))
.arg(arg!(--version "show a dummy version"))
.arg(arg!(--test "run a test against the embedded device"))
.arg(
Arg::new("network")
.help("bitcoin network")
.long("network")
.value_parser(["regtest", "signet", "testnet", "mainnet", "bitcoin"])
.default_value("regtest")
);
let matches = app.get_matches();
let network_string: &String = matches.get_one("network").expect("expected a network");
let network: Network = match network_string.as_str() {
"bitcoin" => Network::Bitcoin,
"mainnet" => Network::Bitcoin,
"testnet" => Network::Testnet,
"signet" => Network::Signet,
"regtest" => Network::Regtest,
_ => Network::Regtest,
};
if matches.is_present("version") {
// Pretend to be the right version, given to us by an env var
let version =
@@ -56,6 +77,7 @@ fn main() -> anyhow::Result<()> {
return Ok(());
}
log::info!("NETWORK: {}", network.to_string());
if matches.is_present("test") {
run_test::run_test();
} else {
@@ -69,7 +91,7 @@ fn main() -> anyhow::Result<()> {
log::info!("=> connection status: {}", status);
assert_eq!(status, true, "expected connected = true");
// runtime.block_on(async {
init::blocking_connect(tx.clone());
init::blocking_connect(tx.clone(), network);
log::info!("=====> sent seed!");
// listen to reqs from CLN

View File

@@ -85,4 +85,4 @@ pub async fn iteration(
}
}
Ok(())
}
}

View File

@@ -4,6 +4,7 @@ version = "0.1.0"
edition = "2021"
[dependencies]
# vls-protocol = { path = "../../../evanf/validating-lightning-signer/vls-protocol" }
vls-protocol = { git = "https://gitlab.com/Evanfeenstra/validating-lightning-signer", branch = "partial-std" }
serde = { version = "1.0", default-features = false }
serde_bolt = { version = "0.2", default-features = false }

View File

@@ -49,6 +49,7 @@ fn main() -> Result<()> {
esp_idf_svc::log::EspLogger::initialize_default();
thread::sleep(Duration::from_secs(1));
log::info!("Network set to {:?}", network);
let (led_tx, led_rx) = mpsc::channel();
// LED control thread

View File

@@ -14,7 +14,7 @@ log = "0.4"
rumqttc = "0.12.0"
tokio = { version = "1.4.0", features = ["rt", "rt-multi-thread", "macros"] }
pretty_env_logger = "0.4.0"
clap = "=3.0.0-beta.2"
clap_derive = "=3.0.0-beta.5"
clap = "3.2.6"
clap_derive = "3.2.6"
fern = { version = "0.6", features = ["colored"] }
chrono = "0.4"

View File

@@ -1,15 +1,15 @@
use sphinx_key_parser as parser;
use sphinx_key_signer::lightning_signer::bitcoin::Network;
use clap::{App, AppSettings, Arg};
use clap::{arg, App, AppSettings};
use rumqttc::{self, AsyncClient, Event, MqttOptions, Packet, QoS};
use sphinx_key_signer::{self, InitResponse};
use sphinx_key_signer::vls_protocol::model::PubKey;
use sphinx_key_signer::{self, InitResponse};
use std::env;
use std::error::Error;
use std::str::FromStr;
use std::time::Duration;
use vls_protocol::msgs;
use std::env;
use std::str::FromStr;
const SUB_TOPIC: &str = "sphinx";
const PUB_TOPIC: &str = "sphinx-return";
@@ -23,8 +23,8 @@ async fn main() -> Result<(), Box<dyn Error>> {
let app = App::new("tester")
.setting(AppSettings::NoAutoVersion)
.about("CLN:mqtt-tester - MQTT client signer")
.arg(Arg::from("--test run a test against the embedded device"))
.arg(Arg::from("--log log each VLS message"));
.arg(arg!(--test "run a test against the embedded device"))
.arg(arg!(--log "log each VLS message"));
let matches = app.get_matches();
let is_test = matches.is_present("test");
let is_log = matches.is_present("log");
@@ -102,7 +102,8 @@ async fn main() -> Result<(), Box<dyn Error>> {
let InitResponse {
root_handler,
init_reply,
} = sphinx_key_signer::init(init_msg_bytes, Network::Regtest).expect("failed to init signer");
} = sphinx_key_signer::init(init_msg_bytes, Network::Regtest)
.expect("failed to init signer");
client
.publish(PUB_TOPIC, QoS::AtMostOnce, false, init_reply)
.await
@@ -123,7 +124,12 @@ async fn main() -> Result<(), Box<dyn Error>> {
Ok(event) => {
let dummy_peer = PubKey([0; 33]);
if let Some(msg_bytes) = incoming_bytes(event) {
match sphinx_key_signer::handle(rh, msg_bytes, dummy_peer.clone(), is_log) {
match sphinx_key_signer::handle(
rh,
msg_bytes,
dummy_peer.clone(),
is_log,
) {
Ok(b) => client
.publish(PUB_TOPIC, QoS::AtMostOnce, false, b)
.await