Skip to content

Commit 588e8d5

Browse files
committed
Process events with BackgroundProcessor
1 parent 3f92528 commit 588e8d5

File tree

4 files changed

+169
-225
lines changed

4 files changed

+169
-225
lines changed

Cargo.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ edition = "2018"
88
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
99

1010
[dependencies]
11-
lightning = { version = "0.0.14", git = "https://github.com/rust-bitcoin/rust-lightning" }
12-
lightning-block-sync = { version = "0.0.14", git = "https://github.com/rust-bitcoin/rust-lightning", features = [ "rpc-client" ] }
13-
lightning-invoice = { version = "0.5", git = "https://github.com/rust-bitcoin/rust-lightning" }
14-
lightning-net-tokio = { version = "0.0.14", git = "https://github.com/rust-bitcoin/rust-lightning" }
15-
lightning-persister = { version = "0.0.14", git = "https://github.com/rust-bitcoin/rust-lightning" }
16-
lightning-background-processor = { version = "0.0.14", git = "https://github.com/rust-bitcoin/rust-lightning" }
11+
lightning = { version = "0.0.14", git = "https://github.com/rust-bitcoin/rust-lightning", branch = "main" }
12+
lightning-block-sync = { version = "0.0.14", git = "https://github.com/rust-bitcoin/rust-lightning", branch = "main", features = [ "rpc-client" ] }
13+
lightning-invoice = { version = "0.5", git = "https://github.com/rust-bitcoin/rust-lightning", branch = "main" }
14+
lightning-net-tokio = { version = "0.0.14", git = "https://github.com/rust-bitcoin/rust-lightning", branch = "main" }
15+
lightning-persister = { version = "0.0.14", git = "https://github.com/rust-bitcoin/rust-lightning", branch = "main" }
16+
lightning-background-processor = { version = "0.0.14", git = "https://github.com/rust-bitcoin/rust-lightning", branch = "main" }
1717

1818
base64 = "0.13.0"
1919
bitcoin = "0.26"
@@ -25,7 +25,7 @@ futures = "0.3"
2525
time = "0.2"
2626
rand = "0.4"
2727
serde_json = { version = "1.0" }
28-
tokio = { version = "1.0", features = [ "io-util", "macros", "rt", "rt-multi-thread", "sync", "net", "time" ] }
28+
tokio = { version = "1.5", features = [ "io-util", "macros", "rt", "rt-multi-thread", "sync", "net", "time" ] }
2929

3030
[profile.release]
3131
panic = "abort"

src/cli.rs

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use std::path::Path;
2525
use std::str::FromStr;
2626
use std::sync::Arc;
2727
use std::time::Duration;
28-
use tokio::sync::mpsc;
2928

3029
pub(crate) struct LdkUserInfo {
3130
pub(crate) bitcoind_rpc_username: String,
@@ -131,8 +130,7 @@ pub(crate) async fn poll_for_user_input(
131130
keys_manager: Arc<KeysManager>,
132131
router: Arc<NetGraphMsgHandler<Arc<dyn chain::Access + Send + Sync>, Arc<FilesystemLogger>>>,
133132
inbound_payments: PaymentInfoStorage, outbound_payments: PaymentInfoStorage,
134-
event_notifier: mpsc::Sender<()>, ldk_data_dir: String, logger: Arc<FilesystemLogger>,
135-
network: Network,
133+
ldk_data_dir: String, logger: Arc<FilesystemLogger>, network: Network,
136134
) {
137135
println!("LDK startup successful. To view available commands: \"help\".");
138136
println!("LDK logs are available at <your-supplied-ldk-data-dir-path>/.ldk/logs");
@@ -141,7 +139,6 @@ pub(crate) async fn poll_for_user_input(
141139
print!("> ");
142140
io::stdout().flush().unwrap(); // Without flushing, the `>` doesn't print
143141
for line in stdin.lock().lines() {
144-
let _ = event_notifier.try_send(());
145142
let line = line.unwrap();
146143
let mut words = line.split_whitespace();
147144
if let Some(word) = words.next() {
@@ -176,14 +173,9 @@ pub(crate) async fn poll_for_user_input(
176173
continue;
177174
}
178175

179-
if connect_peer_if_necessary(
180-
pubkey,
181-
peer_addr,
182-
peer_manager.clone(),
183-
event_notifier.clone(),
184-
)
185-
.await
186-
.is_err()
176+
if connect_peer_if_necessary(pubkey, peer_addr, peer_manager.clone())
177+
.await
178+
.is_err()
187179
{
188180
print!("> ");
189181
io::stdout().flush().unwrap();
@@ -326,14 +318,9 @@ pub(crate) async fn poll_for_user_input(
326318
continue;
327319
}
328320
};
329-
if connect_peer_if_necessary(
330-
pubkey,
331-
peer_addr,
332-
peer_manager.clone(),
333-
event_notifier.clone(),
334-
)
335-
.await
336-
.is_ok()
321+
if connect_peer_if_necessary(pubkey, peer_addr, peer_manager.clone())
322+
.await
323+
.is_ok()
337324
{
338325
println!("SUCCESS: connected to peer {}", pubkey);
339326
}
@@ -490,20 +477,13 @@ fn list_payments(inbound_payments: PaymentInfoStorage, outbound_payments: Paymen
490477

491478
pub(crate) async fn connect_peer_if_necessary(
492479
pubkey: PublicKey, peer_addr: SocketAddr, peer_manager: Arc<PeerManager>,
493-
event_notifier: mpsc::Sender<()>,
494480
) -> Result<(), ()> {
495481
for node_pubkey in peer_manager.get_peer_node_ids() {
496482
if node_pubkey == pubkey {
497483
return Ok(());
498484
}
499485
}
500-
match lightning_net_tokio::connect_outbound(
501-
Arc::clone(&peer_manager),
502-
event_notifier,
503-
pubkey,
504-
peer_addr,
505-
)
506-
.await
486+
match lightning_net_tokio::connect_outbound(Arc::clone(&peer_manager), pubkey, peer_addr).await
507487
{
508488
Some(conn_closed_fut) => {
509489
let mut closed_fut_box = Box::pin(conn_closed_fut);

0 commit comments

Comments
 (0)