Skip to content

Commit

Permalink
Merge pull request #74 from TheBlueMatt/main
Browse files Browse the repository at this point in the history
Bump LDK to 0.0.121/rust-bitcoin 0.30
  • Loading branch information
arik-so authored Mar 24, 2024
2 parents 47cb2ca + 397da96 commit dc011b8
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
matrix:
toolchain:
- stable
- 1.56.0
- 1.63.0
- beta
runs-on: ubuntu-latest
steps:
Expand Down
13 changes: 7 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ version = "0.1.0"
edition = "2021"

[dependencies]
bitcoin = "0.29"
lightning = { version = "0.0.118" }
lightning-block-sync = { version = "0.0.118", features=["rest-client"] }
lightning-net-tokio = { version = "0.0.118" }
bitcoin = "0.30"
hex-conservative = "0.2"
lightning = { version = "0.0.121" }
lightning-block-sync = { version = "0.0.121", features=["rest-client"] }
lightning-net-tokio = { version = "0.0.121" }
tokio = { version = "1.25", features = ["full"] }
tokio-postgres = { version = "=0.7.5" }
futures = "0.3"

[dev-dependencies]
lightning = { version = "0.0.118", features = ["_test_utils"] }
lightning-rapid-gossip-sync = { version = "0.0.118" }
lightning = { version = "0.0.121", features = ["_test_utils"] }
lightning-rapid-gossip-sync = { version = "0.0.121" }

[profile.dev]
panic = "abort"
Expand Down
60 changes: 34 additions & 26 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,48 +336,56 @@ fn resolve_peer_info(peer_info: &str) -> Result<(PublicKey, SocketAddr), &str> {
#[cfg(test)]
mod tests {
use super::*;
use bitcoin::hashes::hex::ToHex;
use hex_conservative::DisplayHex;
use std::str::FromStr;

#[test]
fn test_resolve_peer_info() {
let wallet_of_satoshi = "035e4ff418fc8b5554c5d9eea66396c227bd429a3251c8cbc711002ba215bfc226@170.75.163.209:9735";
let (pubkey, socket_address) = resolve_peer_info(wallet_of_satoshi).unwrap();
assert_eq!(pubkey.serialize().to_hex(), "035e4ff418fc8b5554c5d9eea66396c227bd429a3251c8cbc711002ba215bfc226");
assert_eq!(
pubkey.serialize().to_lower_hex_string(),
"035e4ff418fc8b5554c5d9eea66396c227bd429a3251c8cbc711002ba215bfc226"
);
assert_eq!(socket_address.to_string(), "170.75.163.209:9735");

let ipv6 = "033d8656219478701227199cbd6f670335c8d408a92ae88b962c49d4dc0e83e025@[2001:db8::1]:80";
let (pubkey, socket_address) = resolve_peer_info(ipv6).unwrap();
assert_eq!(pubkey.serialize().to_hex(), "033d8656219478701227199cbd6f670335c8d408a92ae88b962c49d4dc0e83e025");
assert_eq!(
pubkey.serialize().to_lower_hex_string(),
"033d8656219478701227199cbd6f670335c8d408a92ae88b962c49d4dc0e83e025"
);
assert_eq!(socket_address.to_string(), "[2001:db8::1]:80");

let localhost = "033d8656219478701227199cbd6f670335c8d408a92ae88b962c49d4dc0e83e025@localhost:9735";
let (pubkey, socket_address) = resolve_peer_info(localhost).unwrap();
assert_eq!(pubkey.serialize().to_hex(), "033d8656219478701227199cbd6f670335c8d408a92ae88b962c49d4dc0e83e025");
assert_eq!(
pubkey.serialize().to_lower_hex_string(),
"033d8656219478701227199cbd6f670335c8d408a92ae88b962c49d4dc0e83e025"
);
let socket_address = socket_address.to_string();
assert!(socket_address == "127.0.0.1:9735" || socket_address == "[::1]:9735");
}

#[test]
fn test_ln_peers() {
// Set the environment variable, including a repeated comma, leading space, and trailing comma.
std::env::set_var("LN_PEERS", "035e4ff418fc8b5554c5d9eea66396c227bd429a3251c8cbc711002ba215bfc226@170.75.163.209:9735,, 035e4ff418fc8b5554c5d9eea66396c227bd429a3251c8cbc711002ba215bfc227@170.75.163.210:9735,");
let peers = ln_peers();

// Assert output is as expected
assert_eq!(
peers,
vec![
(
PublicKey::from_str("035e4ff418fc8b5554c5d9eea66396c227bd429a3251c8cbc711002ba215bfc226").unwrap(),
SocketAddr::from_str("170.75.163.209:9735").unwrap()
),
(
PublicKey::from_str("035e4ff418fc8b5554c5d9eea66396c227bd429a3251c8cbc711002ba215bfc227").unwrap(),
SocketAddr::from_str("170.75.163.210:9735").unwrap()
)
]
);
}

#[test]
fn test_ln_peers() {
// Set the environment variable, including a repeated comma, leading space, and trailing comma.
std::env::set_var("LN_PEERS", "035e4ff418fc8b5554c5d9eea66396c227bd429a3251c8cbc711002ba215bfc226@170.75.163.209:9735,, 035e4ff418fc8b5554c5d9eea66396c227bd429a3251c8cbc711002ba215bfc227@170.75.163.210:9735,");
let peers = ln_peers();

// Assert output is as expected
assert_eq!(
peers,
vec![
(
PublicKey::from_str("035e4ff418fc8b5554c5d9eea66396c227bd429a3251c8cbc711002ba215bfc226").unwrap(),
SocketAddr::from_str("170.75.163.209:9735").unwrap()
),
(
PublicKey::from_str("035e4ff418fc8b5554c5d9eea66396c227bd429a3251c8cbc711002ba215bfc227").unwrap(),
SocketAddr::from_str("170.75.163.210:9735").unwrap()
)
]
);
}
}
2 changes: 1 addition & 1 deletion src/persistence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ impl<L: Deref> GossipPersister<L> where L::Target: Logger {
}
#[cfg(test)]
for task in tasks_spawned {
task.await;
task.await.unwrap();
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use bitcoin::Network;
use bitcoin::secp256k1::ecdsa::Signature;
use bitcoin::secp256k1::{Secp256k1, SecretKey};
use bitcoin::hashes::Hash;
use bitcoin::hashes::hex::ToHex;
use bitcoin::hashes::sha256d::Hash as Sha256dHash;
use hex_conservative::DisplayHex;
use lightning::ln::features::ChannelFeatures;
use lightning::ln::msgs::{ChannelAnnouncement, ChannelUpdate, UnsignedChannelAnnouncement, UnsignedChannelUpdate};
use lightning::routing::gossip::{NetworkGraph, NodeId};
Expand Down Expand Up @@ -121,9 +121,9 @@ impl SchemaSanitizer {
let thread_id = thread::current().id();
let preimage = format!("{:?}-{}", thread_id, timestamp_nanos);
println!("test schema preimage: {}", preimage);
let suffix = Sha256dHash::hash(preimage.as_bytes()).into_inner().to_hex();
let suffix = Sha256dHash::hash(preimage.as_bytes()).encode();
// the schema must start with a letter
let schema = format!("test_{}_{}", timestamp_seconds, suffix);
let schema = format!("test_{}_{}", timestamp_seconds, suffix.as_hex());
*suffix_option = Some(schema);
});

Expand Down
13 changes: 7 additions & 6 deletions src/tracking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use std::ops::Deref;
use std::sync::Arc;
use std::time::{Duration, Instant};

use bitcoin::hashes::hex::ToHex;
use bitcoin::secp256k1::PublicKey;
use hex_conservative::display::DisplayHex;
use lightning::ln::peer_handler::{
ErroringMessageHandler, IgnoringMessageHandler, MessageHandler, PeerManager,
};
Expand Down Expand Up @@ -167,29 +167,30 @@ async fn connect_peer<L: Deref + Clone + Send + Sync + 'static>(current_peer: (P
// we seek to find out if the first connection attempt was successful
let (sender, mut receiver) = mpsc::channel::<bool>(1);
tokio::spawn(async move {
log_info!(logger, "Connecting to peer {}@{}...", current_peer.0.to_hex(), current_peer.1.to_string());
let current_peer_pubkey_hex = current_peer.0.serialize().to_lower_hex_string();
log_info!(logger, "Connecting to peer {}@{}...", current_peer_pubkey_hex, current_peer.1);
let mut is_first_iteration = true;
loop {
if let Some(disconnection_future) = lightning_net_tokio::connect_outbound(
Arc::clone(&peer_manager),
current_peer.0,
current_peer.1,
).await {
log_info!(logger, "Connected to peer {}@{}!", current_peer.0.to_hex(), current_peer.1.to_string());
log_info!(logger, "Connected to peer {}@{}!", current_peer_pubkey_hex, current_peer.1);
if is_first_iteration {
sender.send(true).await.unwrap();
}
disconnection_future.await;
log_warn!(logger, "Disconnected from peer {}@{}", current_peer.0.to_hex(), current_peer.1.to_string());
log_warn!(logger, "Disconnected from peer {}@{}", current_peer_pubkey_hex, current_peer.1);
} else {
log_warn!(logger, "Failed to connect to peer {}@{}!", current_peer.0.to_hex(), current_peer.1.to_string());
log_warn!(logger, "Failed to connect to peer {}@{}!", current_peer_pubkey_hex, current_peer.1);
if is_first_iteration {
sender.send(false).await.unwrap();
}
}
is_first_iteration = false;
tokio::time::sleep(Duration::from_secs(10)).await;
log_warn!(logger, "Reconnecting to peer {}@{}...", current_peer.0.to_hex(), current_peer.1.to_string());
log_warn!(logger, "Reconnecting to peer {}@{}...", current_peer_pubkey_hex, current_peer.1);
}
});

Expand Down
4 changes: 2 additions & 2 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl RGSSLogger {
}

impl Logger for RGSSLogger {
fn log(&self, record: &Record) {
fn log(&self, record: Record) {
let threshold = config::log_level();
if record.level < threshold {
return;
Expand Down Expand Up @@ -84,7 +84,7 @@ pub mod tests {
}

impl Logger for TestLogger {
fn log(&self, record: &Record) {
fn log(&self, record: Record) {
*self.lines.lock().unwrap().entry((record.module_path.to_string(), format!("{}", record.args))).or_insert(0) += 1;
println!("{:<5} {} [{} : {}, {}] {}", record.level.to_string(), self.id, record.module_path, record.file, record.line, record.args);
}
Expand Down

0 comments on commit dc011b8

Please sign in to comment.