Skip to content

Commit

Permalink
Merge pull request #2560 from get10101/feat/setup-lnd-and-get-inbound…
Browse files Browse the repository at this point in the history
…-liquidity

feat: Onboarding through a hodl invoice
  • Loading branch information
holzeis authored May 27, 2024
2 parents 2ed0544 + 06909be commit a4f12f7
Show file tree
Hide file tree
Showing 63 changed files with 2,147 additions and 517 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,10 @@ jobs:
run: |
just run-maker-detached
echo "Maker successfully started."
- name: Run lnd-mock
run: |
just run-lnd-mock-detached
echo "Lnd mock successfully started."
- name: Run e2e tests
run: RUST_BACKTRACE=1 ${{ matrix.tests }} --nocapture --ignored
- name: Print maker logs on e2e tests error
Expand Down
110 changes: 102 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion coordinator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ dlc-messages = "0.4.0"
dlc-trie = "0.4.0"
fcm = "0.9.2"
futures = "0.3"
futures-util = "0.3"
hex = "0.4"
lazy_static = "1.4.0"
lightning = { version = "0.0.117", features = ["max_level_trace"] }
local-ip-address = "0.5.1"
lnd-bridge = { path = "../crates/lnd-bridge" }
openssl = { version = "0.10.60", features = ["vendored"] }
opentelemetry = "0.19.0"
opentelemetry-prometheus = "0.12.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
drop table if exists hodl_invoices;
10 changes: 10 additions & 0 deletions coordinator/migrations/2024-05-23-000406_hodl_invoice_table/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
create table if not exists hodl_invoices
(
id SERIAL PRIMARY KEY NOT NULL,
trader_pubkey TEXT NOT NULL REFERENCES users (pubkey),
r_hash TEXT NOT NULL,
amount_sats BIGINT NOT NULL,
pre_image TEXT,
created_at timestamp WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at timestamp WITH TIME ZONE
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE "channel_opening_params"
DROP COLUMN "external_funding";
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE "channel_opening_params"
ADD COLUMN "external_funding" BIGINT;
15 changes: 10 additions & 5 deletions coordinator/src/bin/coordinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use coordinator::trade::websocket::InternalPositionUpdateMessage;
use diesel::r2d2;
use diesel::r2d2::ConnectionManager;
use diesel::PgConnection;
use lnd_bridge::LndBridge;
use rand::thread_rng;
use rand::RngCore;
use std::backtrace::Backtrace;
Expand Down Expand Up @@ -82,6 +83,13 @@ async fn main() -> Result<()> {
let address = opts.p2p_address;
let http_address = opts.http_address;
let network = opts.network();
let oracle_infos = opts
.get_oracle_infos()
.into_iter()
.map(|o| o.into())
.collect();

let lnd_bridge = LndBridge::new(opts.lnd_endpoint, opts.macaroon, opts.secure_lnd);

logger::init_tracing(LevelFilter::DEBUG, opts.json, opts.tokio_console)?;

Expand Down Expand Up @@ -136,10 +144,7 @@ async fn main() -> Result<()> {
seed,
ephemeral_randomness,
settings.xxi.clone(),
opts.get_oracle_infos()
.into_iter()
.map(|o| o.into())
.collect(),
oracle_infos,
XOnlyPublicKey::from_str(&opts.oracle_pubkey).expect("valid public key"),
node_event_handler.clone(),
dlc_event_sender,
Expand Down Expand Up @@ -319,7 +324,6 @@ async fn main() -> Result<()> {
pool.clone(),
settings.clone(),
exporter,
opts.p2p_announcement_addresses(),
NODE_ALIAS,
trading_sender,
tx_orderbook_feed,
Expand All @@ -328,6 +332,7 @@ async fn main() -> Result<()> {
auth_users_notifier.clone(),
notification_service.get_sender(),
user_backup,
lnd_bridge,
);

let sender = notification_service.get_sender();
Expand Down
55 changes: 12 additions & 43 deletions coordinator/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use anyhow::Result;
use bitcoin::secp256k1::XOnlyPublicKey;
use clap::Parser;
use lightning::ln::msgs::SocketAddress;
use local_ip_address::local_ip;
use std::env::current_dir;
use std::net::IpAddr;
use std::net::SocketAddr;
use std::path::PathBuf;
use std::str::FromStr;
Expand All @@ -24,10 +21,6 @@ pub struct Opts {
#[clap(long)]
data_dir: Option<PathBuf>,

/// Will skip announcing the node on the local ip address. Set this flag for production.
#[clap(long)]
skip_local_network_announcement: bool,

#[clap(value_enum, default_value = "regtest")]
pub network: Network,

Expand Down Expand Up @@ -78,6 +71,18 @@ pub struct Opts {
default_value = "16f88cf7d21e6c0f46bcbc983a4e3b19726c6c98858cc31c83551a88fde171c0"
)]
pub oracle_pubkey: String,

/// The endpoint of the lnd rest api
#[clap(long, default_value = "localhost:18080")]
pub lnd_endpoint: String,

/// Defines the macaroon to be used for the lnd http api.
#[clap(long, default_value = "")]
pub macaroon: String,

/// If enabled the coordinator will try to connect to lnd via https, wss.
#[clap(short, long)]
pub secure_lnd: bool,
}

#[derive(Debug, Clone, Copy, clap::ValueEnum)]
Expand Down Expand Up @@ -134,40 +139,4 @@ impl Opts {

Ok(data_dir)
}

/// Returns a list of addresses under which the node can be reached. Note this is used for the
/// node announcements.
pub fn p2p_announcement_addresses(&self) -> Vec<SocketAddress> {
let mut addresses: Vec<SocketAddress> = vec![];
if !self.p2p_address.ip().is_unspecified() {
addresses.push(build_socket_address(
self.p2p_address.ip(),
self.p2p_address.port(),
));
} else {
// Announcing the node on an unspecified ip address does not make any sense.
tracing::debug!("Skipping node announcement on '0.0.0.0'.");
}

if !self.skip_local_network_announcement {
let local_ip = local_ip().expect("to get local ip address");
tracing::info!("Adding node announcement within local network {local_ip}. Do not use for production!");
addresses.push(build_socket_address(local_ip, self.p2p_address.port()));
}

addresses
}
}

fn build_socket_address(ip: IpAddr, port: u16) -> SocketAddress {
match ip {
IpAddr::V4(ip) => SocketAddress::TcpIpV4 {
addr: ip.octets(),
port,
},
IpAddr::V6(ip) => SocketAddress::TcpIpV6 {
addr: ip.octets(),
port,
},
}
}
Loading

0 comments on commit a4f12f7

Please sign in to comment.