Skip to content

Commit aa16a05

Browse files
committed
add timing logs
1 parent 927735f commit aa16a05

File tree

4 files changed

+73
-16
lines changed

4 files changed

+73
-16
lines changed

Cargo.toml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,18 @@ default = []
4141
# lightning-liquidity = { version = "0.2.0", features = ["std"] }
4242
# lightning-macros = { version = "0.2.0" }
4343

44-
# Branch: https://github.com/moneydevkit/rust-lightning/commits/lsp-0.2.0_accept-underpaying-htlcs
45-
lightning = { git = "https://github.com/moneydevkit/rust-lightning", rev = "edd82ba8dd7ed1c140a209eb1bafc30a2c38d80a", features = ["std"] }
46-
lightning-types = { git = "https://github.com/moneydevkit/rust-lightning", rev = "edd82ba8dd7ed1c140a209eb1bafc30a2c38d80a" }
47-
lightning-invoice = { git = "https://github.com/moneydevkit/rust-lightning", rev = "edd82ba8dd7ed1c140a209eb1bafc30a2c38d80a", features = ["std"] }
48-
lightning-net-tokio = { git = "https://github.com/moneydevkit/rust-lightning", rev = "edd82ba8dd7ed1c140a209eb1bafc30a2c38d80a" }
49-
lightning-persister = { git = "https://github.com/moneydevkit/rust-lightning", rev = "edd82ba8dd7ed1c140a209eb1bafc30a2c38d80a", features = ["tokio"] }
50-
lightning-background-processor = { git = "https://github.com/moneydevkit/rust-lightning", rev = "edd82ba8dd7ed1c140a209eb1bafc30a2c38d80a" }
51-
lightning-rapid-gossip-sync = { git = "https://github.com/moneydevkit/rust-lightning", rev = "edd82ba8dd7ed1c140a209eb1bafc30a2c38d80a" }
52-
lightning-block-sync = { git = "https://github.com/moneydevkit/rust-lightning", rev = "edd82ba8dd7ed1c140a209eb1bafc30a2c38d80a", features = ["rest-client", "rpc-client", "tokio"] }
53-
lightning-transaction-sync = { git = "https://github.com/moneydevkit/rust-lightning", rev = "edd82ba8dd7ed1c140a209eb1bafc30a2c38d80a", features = ["esplora-async-https", "time", "electrum-rustls-ring"] }
54-
lightning-liquidity = { git = "https://github.com/moneydevkit/rust-lightning", rev = "edd82ba8dd7ed1c140a209eb1bafc30a2c38d80a", features = ["std"] }
55-
lightning-macros = { git = "https://github.com/moneydevkit/rust-lightning", rev = "edd82ba8dd7ed1c140a209eb1bafc30a2c38d80a" }
44+
# Branch: https://github.com/moneydevkit/rust-lightning/tree/lsp-0.2.0_accept-underpaying-htlcs_with_timing_logs
45+
lightning = { git = "https://github.com/moneydevkit/rust-lightning", rev = "04116046a734275cceadae263c363ee0b4d2ea78", features = ["std"] }
46+
lightning-types = { git = "https://github.com/moneydevkit/rust-lightning", rev = "04116046a734275cceadae263c363ee0b4d2ea78" }
47+
lightning-invoice = { git = "https://github.com/moneydevkit/rust-lightning", rev = "04116046a734275cceadae263c363ee0b4d2ea78", features = ["std"] }
48+
lightning-net-tokio = { git = "https://github.com/moneydevkit/rust-lightning", rev = "04116046a734275cceadae263c363ee0b4d2ea78" }
49+
lightning-persister = { git = "https://github.com/moneydevkit/rust-lightning", rev = "04116046a734275cceadae263c363ee0b4d2ea78", features = ["tokio"] }
50+
lightning-background-processor = { git = "https://github.com/moneydevkit/rust-lightning", rev = "04116046a734275cceadae263c363ee0b4d2ea78" }
51+
lightning-rapid-gossip-sync = { git = "https://github.com/moneydevkit/rust-lightning", rev = "04116046a734275cceadae263c363ee0b4d2ea78" }
52+
lightning-block-sync = { git = "https://github.com/moneydevkit/rust-lightning", rev = "04116046a734275cceadae263c363ee0b4d2ea78", features = ["rest-client", "rpc-client", "tokio"] }
53+
lightning-transaction-sync = { git = "https://github.com/moneydevkit/rust-lightning", rev = "04116046a734275cceadae263c363ee0b4d2ea78", features = ["esplora-async-https", "time", "electrum-rustls-ring"] }
54+
lightning-liquidity = { git = "https://github.com/moneydevkit/rust-lightning", rev = "04116046a734275cceadae263c363ee0b4d2ea78", features = ["std"] }
55+
lightning-macros = { git = "https://github.com/moneydevkit/rust-lightning", rev = "04116046a734275cceadae263c363ee0b4d2ea78" }
5656

5757
#lightning = { path = "../rust-lightning/lightning", features = ["std"] }
5858
#lightning-types = { path = "../rust-lightning/lightning-types" }
@@ -99,7 +99,7 @@ winapi = { version = "0.3", features = ["winbase"] }
9999
[dev-dependencies]
100100
# lightning = { version = "0.2.0", features = ["std", "_test_utils"] }
101101
# Branch: https://github.com/moneydevkit/rust-lightning/commits/lsp-0.2.0_accept-underpaying-htlcs
102-
lightning = { git = "https://github.com/moneydevkit/rust-lightning", rev = "edd82ba8dd7ed1c140a209eb1bafc30a2c38d80a", features = ["std", "_test_utils"] }
102+
lightning = { git = "https://github.com/moneydevkit/rust-lightning", rev = "04116046a734275cceadae263c363ee0b4d2ea78", features = ["std", "_test_utils"] }
103103
#lightning = { path = "../rust-lightning/lightning", features = ["std", "_test_utils"] }
104104
proptest = "1.0.0"
105105
regex = "1.5.6"

src/lib.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ impl Node {
220220
/// After this returns, the [`Node`] instance can be controlled via the provided API methods in
221221
/// a thread-safe manner.
222222
pub fn start(&self) -> Result<(), Error> {
223+
let fn_start = Instant::now();
224+
223225
// Acquire a run lock and hold it until we're setup.
224226
let mut is_running_lock = self.is_running.write().unwrap();
225227
if *is_running_lock {
@@ -234,14 +236,18 @@ impl Node {
234236
);
235237

236238
// Start up any runtime-dependant chain sources (e.g. Electrum)
239+
let step_start = Instant::now();
237240
self.chain_source.start(Arc::clone(&self.runtime)).map_err(|e| {
238241
log_error!(self.logger, "Failed to start chain syncing: {}", e);
239242
e
240243
})?;
244+
log_info!(self.logger, "TIMING: chain_source.start() took {}ms", step_start.elapsed().as_millis());
241245

242246
// Block to ensure we update our fee rate cache once on startup
247+
let step_start = Instant::now();
243248
let chain_source = Arc::clone(&self.chain_source);
244249
self.runtime.block_on(async move { chain_source.update_fee_rate_estimates().await })?;
250+
log_info!(self.logger, "TIMING: update_fee_rate_estimates() took {}ms", step_start.elapsed().as_millis());
245251

246252
// Spawn background task continuously syncing onchain, lightning, and fee rate cache.
247253
let stop_sync_receiver = self.stop_sender.subscribe();
@@ -643,6 +649,7 @@ impl Node {
643649
});
644650
}
645651

652+
log_info!(self.logger, "TIMING: start() TOTAL took {}ms", fn_start.elapsed().as_millis());
646653
log_info!(self.logger, "Startup complete.");
647654
*is_running_lock = true;
648655
Ok(())
@@ -1437,6 +1444,9 @@ impl Node {
14371444
///
14381445
/// [`EsploraSyncConfig::background_sync_config`]: crate::config::EsploraSyncConfig::background_sync_config
14391446
pub fn sync_wallets(&self) -> Result<(), Error> {
1447+
let fn_start = Instant::now();
1448+
log_info!(self.logger, "TIMING: sync_wallets() START");
1449+
14401450
if !*self.is_running.read().unwrap() {
14411451
return Err(Error::NotRunning);
14421452
}
@@ -1446,15 +1456,28 @@ impl Node {
14461456
let sync_cman = Arc::clone(&self.channel_manager);
14471457
let sync_cmon = Arc::clone(&self.chain_monitor);
14481458
let sync_sweeper = Arc::clone(&self.output_sweeper);
1459+
let logger = Arc::clone(&self.logger);
14491460
self.runtime.block_on(async move {
14501461
if chain_source.is_transaction_based() {
1462+
let step_start = Instant::now();
14511463
chain_source.update_fee_rate_estimates().await?;
1464+
log_info!(logger, "TIMING: sync_wallets update_fee_rate_estimates() took {}ms", step_start.elapsed().as_millis());
1465+
1466+
let step_start = Instant::now();
14521467
chain_source
14531468
.sync_lightning_wallet(sync_cman, sync_cmon, Arc::clone(&sync_sweeper))
14541469
.await?;
1470+
log_info!(logger, "TIMING: sync_wallets sync_lightning_wallet() took {}ms", step_start.elapsed().as_millis());
1471+
1472+
let step_start = Instant::now();
14551473
chain_source.sync_onchain_wallet(sync_wallet).await?;
1474+
log_info!(logger, "TIMING: sync_wallets sync_onchain_wallet() took {}ms", step_start.elapsed().as_millis());
14561475
} else {
1476+
let step_start = Instant::now();
14571477
chain_source.update_fee_rate_estimates().await?;
1478+
log_info!(logger, "TIMING: sync_wallets update_fee_rate_estimates() took {}ms", step_start.elapsed().as_millis());
1479+
1480+
let step_start = Instant::now();
14581481
chain_source
14591482
.poll_and_update_listeners(
14601483
sync_wallet,
@@ -1463,8 +1486,12 @@ impl Node {
14631486
Arc::clone(&sync_sweeper),
14641487
)
14651488
.await?;
1489+
log_info!(logger, "TIMING: sync_wallets poll_and_update_listeners() took {}ms", step_start.elapsed().as_millis());
14661490
}
1491+
let step_start = Instant::now();
14671492
let _ = sync_sweeper.regenerate_and_broadcast_spend_if_necessary().await;
1493+
log_info!(logger, "TIMING: sync_wallets regenerate_and_broadcast_spend_if_necessary() took {}ms", step_start.elapsed().as_millis());
1494+
log_info!(logger, "TIMING: sync_wallets() TOTAL took {}ms", fn_start.elapsed().as_millis());
14681495
Ok(())
14691496
})
14701497
}

src/liquidity.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use std::collections::HashMap;
1111
use std::ops::Deref;
1212
use std::sync::{Arc, Mutex, RwLock};
13-
use std::time::{Duration, SystemTime, UNIX_EPOCH};
13+
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
1414

1515
use bitcoin::hashes::{sha256, Hash};
1616
use bitcoin::secp256k1::{PublicKey, Secp256k1};
@@ -1637,6 +1637,9 @@ where
16371637
}
16381638

16391639
async fn lsps4_register_node(&self) -> Result<LSPS4RegisterNodeResponse, Error> {
1640+
let fn_start = Instant::now();
1641+
log_info!(self.logger, "TIMING: lsps4_register_node() START");
1642+
16401643
let lsps4_client = self.lsps4_client.as_ref().ok_or(Error::LiquiditySourceUnavailable)?;
16411644

16421645
let client_handler = self.liquidity_manager.lsps4_client_handler().ok_or_else(|| {
@@ -1651,8 +1654,9 @@ where
16511654
let request_id = client_handler.register_node(lsps4_client.lsp_node_id).unwrap();
16521655
pending_register_node_requests_lock.insert(request_id, register_node_sender);
16531656
}
1657+
log_info!(self.logger, "TIMING: lsps4_register_node() sent request, waiting for response...");
16541658

1655-
tokio::time::timeout(
1659+
let result = tokio::time::timeout(
16561660
Duration::from_secs(LIQUIDITY_REQUEST_TIMEOUT_SECS),
16571661
register_node_receiver,
16581662
)
@@ -1664,22 +1668,33 @@ where
16641668
.map_err(|e| {
16651669
log_error!(self.logger, "Failed to handle response from liquidity service: {}", e);
16661670
Error::LiquidityRequestFailed
1667-
})
1671+
});
1672+
1673+
log_info!(self.logger, "TIMING: lsps4_register_node() TOTAL took {}ms", fn_start.elapsed().as_millis());
1674+
result
16681675
}
16691676

16701677
pub(crate) async fn lsps4_receive_to_jit_channel(
16711678
&self, amount_msat: Option<u64>, description: &Bolt11InvoiceDescription, expiry_secs: u32,
16721679
) -> Result<Bolt11Invoice, Error> {
1680+
let fn_start = Instant::now();
1681+
log_info!(self.logger, "TIMING: lsps4_receive_to_jit_channel() START amount_msat={:?}", amount_msat);
1682+
1683+
let step_start = Instant::now();
16731684
let register_node_response = self.lsps4_register_node().await?;
1685+
log_info!(self.logger, "TIMING: lsps4_receive_to_jit_channel() lsps4_register_node() took {}ms", step_start.elapsed().as_millis());
16741686

1687+
let step_start = Instant::now();
16751688
let invoice = self.lsps4_create_jit_invoice(
16761689
register_node_response.intercept_scid,
16771690
register_node_response.cltv_expiry_delta,
16781691
amount_msat,
16791692
description,
16801693
expiry_secs,
16811694
)?;
1695+
log_info!(self.logger, "TIMING: lsps4_receive_to_jit_channel() lsps4_create_jit_invoice() took {}ms", step_start.elapsed().as_millis());
16821696

1697+
log_info!(self.logger, "TIMING: lsps4_receive_to_jit_channel() TOTAL took {}ms", fn_start.elapsed().as_millis());
16831698
log_info!(self.logger, "LSPS4 JIT-channel invoice created: {}", invoice);
16841699
Ok(invoice)
16851700
}

src/payment/bolt11.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//! [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
1111
1212
use std::sync::{Arc, RwLock};
13+
use std::time::Instant;
1314

1415
use bitcoin::hashes::sha256::Hash as Sha256;
1516
use bitcoin::hashes::Hash;
@@ -93,6 +94,9 @@ impl Bolt11Payment {
9394
pub fn send(
9495
&self, invoice: &Bolt11Invoice, route_parameters: Option<RouteParametersConfig>,
9596
) -> Result<PaymentId, Error> {
97+
let fn_start = Instant::now();
98+
log_info!(self.logger, "TIMING: bolt11_payment.send() START");
99+
96100
if !*self.is_running.read().unwrap() {
97101
return Err(Error::NotRunning);
98102
}
@@ -114,6 +118,7 @@ impl Bolt11Payment {
114118
let retry_strategy = Retry::Timeout(LDK_PAYMENT_RETRY_TIMEOUT);
115119
let payment_secret = Some(*invoice.payment_secret());
116120

121+
let step_start = Instant::now();
117122
match self.channel_manager.pay_for_bolt11_invoice(
118123
invoice,
119124
payment_id,
@@ -122,6 +127,7 @@ impl Bolt11Payment {
122127
retry_strategy,
123128
) {
124129
Ok(()) => {
130+
log_info!(self.logger, "TIMING: bolt11_payment.send() channel_manager.pay_for_bolt11_invoice() took {}ms", step_start.elapsed().as_millis());
125131
let payee_pubkey = invoice.recover_payee_pub_key();
126132
let amt_msat = invoice.amount_milli_satoshis().unwrap();
127133
log_info!(self.logger, "Initiated sending {}msat to {}", amt_msat, payee_pubkey);
@@ -142,6 +148,7 @@ impl Bolt11Payment {
142148

143149
self.payment_store.insert(payment)?;
144150

151+
log_info!(self.logger, "TIMING: bolt11_payment.send() TOTAL took {}ms", fn_start.elapsed().as_millis());
145152
Ok(payment_id)
146153
},
147154
Err(Bolt11PaymentError::InvalidAmount) => {
@@ -752,6 +759,9 @@ impl Bolt11Payment {
752759
pub fn receive_via_lsps4_jit_channel(
753760
&self, amount_msat: Option<u64>, description: &Bolt11InvoiceDescription, expiry_secs: u32,
754761
) -> Result<Bolt11Invoice, Error> {
762+
let fn_start = Instant::now();
763+
log_info!(self.logger, "TIMING: receive_via_lsps4_jit_channel() START amount_msat={:?}", amount_msat);
764+
755765
let description = maybe_try_convert_enum(description)?;
756766

757767
let liquidity_source =
@@ -768,24 +778,29 @@ impl Bolt11Payment {
768778

769779
// We need to use our main runtime here as a local runtime might not be around to poll
770780
// connection futures going forward.
781+
let step_start = Instant::now();
771782
self.runtime.block_on(async move {
772783
con_cm.connect_peer_if_necessary(con_node_id, con_addr).await
773784
})?;
785+
log_info!(self.logger, "TIMING: receive_via_lsps4_jit_channel() connect_peer_if_necessary() took {}ms", step_start.elapsed().as_millis());
774786

775787
log_info!(self.logger, "Connected to LSP {}@{}. ", peer_info.node_id, peer_info.address);
776788

789+
let step_start = Instant::now();
777790
let liquidity_source = Arc::clone(&liquidity_source);
778791
let invoice = self.runtime.block_on(async move {
779792
liquidity_source
780793
.lsps4_receive_to_jit_channel(amount_msat, &description, expiry_secs)
781794
.await
782795
})?;
796+
log_info!(self.logger, "TIMING: receive_via_lsps4_jit_channel() lsps4_receive_to_jit_channel() took {}ms", step_start.elapsed().as_millis());
783797

784798
self.register_lsps4_payment(&invoice, amount_msat)?;
785799

786800
// Persist LSP peer to make sure we reconnect on restart.
787801
self.peer_store.add_peer(peer_info)?;
788802

803+
log_info!(self.logger, "TIMING: receive_via_lsps4_jit_channel() TOTAL took {}ms", fn_start.elapsed().as_millis());
789804
Ok(maybe_wrap(invoice))
790805
}
791806

0 commit comments

Comments
 (0)