Skip to content

Commit

Permalink
chore: rustfmt [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
fiksn committed Aug 30, 2023
1 parent bfe483b commit 6bf88af
Show file tree
Hide file tree
Showing 6 changed files with 275 additions and 175 deletions.
6 changes: 2 additions & 4 deletions src/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,12 @@ impl FromStr for LightningNodeAddrVec {
let result: Result<Vec<LightningNodeAddr>, LightningNodeAddrError> = s
.split(',')
.map(str::trim)
.map(|part| {
LightningNodeAddr::from_str(part)
})
.map(|part| LightningNodeAddr::from_str(part))
.collect();

if let Ok(ret) = result {
return Ok(LightningNodeAddrVec(ret));
} else if let Err(err) = result{
} else if let Err(err) = result {
return Err(err);
}

Expand Down
8 changes: 4 additions & 4 deletions src/dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ use lightning::ln::msgs::{self, RoutingMessageHandler};
use lightning::ln::peer_handler::{
ErroringMessageHandler, IgnoringMessageHandler, PeerManager, SimpleArcPeerManager,
};
use lightning::routing::gossip::ChannelInfo;
use lightning::routing::gossip::NodeId;
use lightning::routing::utxo::{UtxoLookup, UtxoLookupError, UtxoResult};
use lightning::sign::{EntropySource, InMemorySigner, KeysManager, SpendableOutputDescriptor};
use lightning::util::logger::{Logger, Level, Record};
use lightning::util::logger::{Level, Logger, Record};
use lightning_net_tokio::{setup_outbound, SocketDescriptor};
use lightning_persister::FilesystemPersister;
use rand::RngCore;
Expand All @@ -40,11 +41,10 @@ use tokio::main;
use tokio::net::TcpStream;
use tokio::net::ToSocketAddrs;
use tokio::time::timeout;
use lightning::routing::gossip::ChannelInfo;

/// Dummy implementations

pub struct DummyLogger{
pub struct DummyLogger {
level: Level,
}

Expand Down Expand Up @@ -87,4 +87,4 @@ impl FeeEstimator for DummyBitcoin {
fn get_est_sat_per_1000_weight(&self, confirmation_target: ConfirmationTarget) -> u32 {
0
}
}
}
49 changes: 37 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#![allow(unused_imports)]
//#![allow(unreachable_code)]

mod mutex;
mod addr;
mod dummy;
mod mutex;
mod resolve;
mod voter;

Expand All @@ -21,7 +21,6 @@ use bitcoin::Block;
use chrono::Utc;
use clap::Parser;
use dummy::*;
use voter::*;
use futures::future::join;
use futures::future::join_all;
use futures::future::ready;
Expand All @@ -36,10 +35,11 @@ use lightning::ln::msgs::{self, RoutingMessageHandler};
use lightning::ln::peer_handler::{
ErroringMessageHandler, IgnoringMessageHandler, PeerManager, SimpleArcPeerManager,
};
use lightning::log_info;
use lightning::routing::gossip::NodeId;
use lightning::routing::utxo::{UtxoLookup, UtxoLookupError, UtxoResult};
use lightning::sign::{EntropySource, InMemorySigner, KeysManager, SpendableOutputDescriptor};
use lightning::util::logger::{Logger, Level, Record};
use lightning::util::logger::{Level, Logger, Record};
use lightning_net_tokio::{setup_outbound, SocketDescriptor};
use lightning_persister::FilesystemPersister;
use rand::RngCore;
Expand All @@ -59,7 +59,7 @@ use tokio::main;
use tokio::net::TcpStream;
use tokio::net::ToSocketAddrs;
use tokio::time::timeout;
use lightning::log_info;
use voter::*;

struct ChannelInfo {
node1: NodeId,
Expand All @@ -74,9 +74,9 @@ struct Args {
default_value = "03864ef025fde8fb587d989186ce6a4a186895ee44a926bfc370e2c366597a3f8f@3.33.236.230:9735",
)]
nodes: Vec<LightningNodeAddr>,

/// Threshold
#[arg(short, long, num_args=1, default_value_t = 3)]
#[arg(short, long, num_args = 1, default_value_t = 3)]
threshold: u8,
}

Expand Down Expand Up @@ -106,7 +106,8 @@ async fn main() {
//let persister = Arc::new(FilesystemPersister::new(".".to_string()));
//let bitcoin = Arc::new(DummyBitcoin());

let resolver: Arc<CachingChannelResolving<Arc<DummyLogger>>> = Arc::new(CachingChannelResolving::new(logger.clone()));
let resolver: Arc<CachingChannelResolving<Arc<DummyLogger>>> =
Arc::new(CachingChannelResolving::new(logger.clone()));

let peer_manager: Arc<ResolvePeerManager> = Arc::new(PeerManager::new_routing_only(
resolver.clone(),
Expand All @@ -122,24 +123,48 @@ async fn main() {
let voter = Arc::new(Voter::new(args.threshold, logger.clone()));
voter.register_resolver(resolver.clone());
resolver.register_voter(voter.clone());

let mut futures: Vec<Box<dyn std::future::Future<Output = ()> + Unpin>> = Vec::new();

for node in args.nodes.clone() {
if let Some(future) = connect(node, peer_manager.clone()).await {
futures.push(Box::new(Box::pin(future)));
}
}

if DEBUG {
let query = async {
thread::sleep(Duration::from_secs(7));

log_info!(logger, "Invoking query");

let nodeid1 = (*resolver).get_node((*resolver).get_endpoints_async(869059488412139521u64).await.expect("channel data").nodes[0]).unwrap().node_id;
let nodeid2 = (*resolver).get_node((*resolver).get_endpoints_async(869059488412139521u64).await.expect("channel data").nodes[1]).unwrap().node_id;
log_info!(logger, "{} --{}--> {}", nodeid1, 869059488412139521u64, nodeid2);
let nodeid1 = (*resolver)
.get_node(
(*resolver)
.get_endpoints_async(869059488412139521u64)
.await
.expect("channel data")
.nodes[0],
)
.unwrap()
.node_id;
let nodeid2 = (*resolver)
.get_node(
(*resolver)
.get_endpoints_async(869059488412139521u64)
.await
.expect("channel data")
.nodes[1],
)
.unwrap()
.node_id;
log_info!(
logger,
"{} --{}--> {}",
nodeid1,
869059488412139521u64,
nodeid2
);
};

futures.push(Box::new(Box::pin(query)));
Expand Down
14 changes: 7 additions & 7 deletions src/mutex.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use parking_lot::lock_api::{RawMutex, GuardSend};
use chrono::{DateTime, TimeZone, Utc};
use parking_lot::lock_api::{GuardSend, RawMutex};
use parking_lot::RawMutex as RMutex;
use chrono::{Utc, DateTime, TimeZone};
use std::time::Duration;
use std::sync::Mutex;
use std::time::Duration;

/// RMutexMax is a mutex with maximum lifetime (you can probably solve this in a more elegant way)

pub struct RMutexMax {
mutex: RMutex,
time: Mutex<DateTime::<Utc>>,
time: Mutex<DateTime<Utc>>,
}

pub unsafe trait RawMutexMax: RawMutex {
Expand All @@ -27,8 +27,8 @@ unsafe impl RawMutexMax for RMutexMax {
unsafe {
self.mutex.unlock();
*self.time.lock().unwrap() = now + chrono::Duration::from_std(timeout).unwrap();
return self.mutex.try_lock()

return self.mutex.try_lock();
}
}

Expand Down Expand Up @@ -60,4 +60,4 @@ unsafe impl RawMutex for RMutexMax {
unsafe fn unlock(&self) {
self.mutex.unlock()
}
}
}
Loading

0 comments on commit 6bf88af

Please sign in to comment.