Skip to content

Commit 32ee4e2

Browse files
committed
wip
1 parent e174f61 commit 32ee4e2

2 files changed

Lines changed: 72 additions & 3 deletions

File tree

src/liquidity.rs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,12 @@ where
893893
Err(Error::WalletOperationFailed)
894894
})
895895
.unwrap_or(0);
896+
log_info!(
897+
self.logger,
898+
"LSPS4 OpenChannel wallet check returned spendable_amount_sats={} for peer {}",
899+
spendable_amount_sats,
900+
their_network_key,
901+
);
896902
let required_funds_sats = channel_amount_sats
897903
+ self.config.anchor_channels_config.as_ref().map_or(0, |c| {
898904
if init_features.requires_anchors_zero_fee_htlc_tx()
@@ -1196,6 +1202,13 @@ where
11961202
amt_to_forward_msat,
11971203
channel_count
11981204
}) => {
1205+
log_info!(
1206+
self.logger,
1207+
"Handling LSPS4 OpenChannel for peer {} (amt_to_forward_msat={}, channel_count={})",
1208+
their_network_key,
1209+
amt_to_forward_msat,
1210+
channel_count,
1211+
);
11991212
if self.liquidity_manager.lsps4_service_handler().is_none() {
12001213
log_error!(self.logger, "Failed to handle LSPS4ServiceEvent as LSPS4 liquidity service was not configured.",);
12011214
return;
@@ -1232,6 +1245,11 @@ where
12321245
log_error!(self.logger, "Failed to handle LSPS4ServiceEvent as peer manager isn't available. This should never happen.",);
12331246
return;
12341247
};
1248+
log_info!(
1249+
self.logger,
1250+
"LSPS4 OpenChannel peer {} is connected; computing channel size",
1251+
their_network_key,
1252+
);
12351253

12361254
// Fail if we have insufficient onchain funds available.
12371255
let over_provisioning_msat = (amt_to_forward_msat
@@ -1284,6 +1302,14 @@ where
12841302
// succeed.
12851303
return;
12861304
}
1305+
log_info!(
1306+
self.logger,
1307+
"LSPS4 OpenChannel peer {} passed funding checks (channel_amount_sats={}, required_funds_sats={}, spendable_amount_sats={})",
1308+
their_network_key,
1309+
channel_amount_sats,
1310+
required_funds_sats,
1311+
spendable_amount_sats,
1312+
);
12871313

12881314
let mut config = self.channel_manager.get_current_config().clone();
12891315

@@ -1307,6 +1333,13 @@ where
13071333

13081334
// TODO: does LSPS4 service need to track this? seems like no?
13091335
let user_channel_id = 0;
1336+
log_info!(
1337+
self.logger,
1338+
"Calling create_channel for LSPS4 peer {} (channel_amount_sats={}, user_channel_id={})",
1339+
their_network_key,
1340+
channel_amount_sats,
1341+
user_channel_id,
1342+
);
13101343

13111344
match self.channel_manager.create_channel(
13121345
their_network_key,
@@ -1316,7 +1349,14 @@ where
13161349
None,
13171350
Some(config),
13181351
) {
1319-
Ok(_) => {},
1352+
Ok(_) => {
1353+
log_info!(
1354+
self.logger,
1355+
"LSPS4 create_channel accepted for peer {} (channel_amount_sats={})",
1356+
their_network_key,
1357+
channel_amount_sats,
1358+
);
1359+
},
13201360
Err(e) => {
13211361
// TODO: We just silently fail here. Eventually we will need to remember
13221362
// the pending requests and regularly retry opening the channel until we

src/wallet/mod.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use std::ops::Deref;
1010
use std::pin::Pin;
1111
use std::str::FromStr;
1212
use std::sync::{Arc, Mutex};
13+
use std::time::Instant;
1314

1415
use bdk_chain::spk_client::{FullScanRequest, SyncRequest};
1516
use bdk_wallet::descriptor::ExtendedDescriptor;
@@ -320,7 +321,28 @@ impl Wallet {
320321
pub(crate) fn get_balances(
321322
&self, total_anchor_channels_reserve_sats: u64,
322323
) -> Result<(u64, u64), Error> {
323-
let balance = self.inner.lock().unwrap().balance();
324+
let lock_wait_start = Instant::now();
325+
log_info!(
326+
self.logger,
327+
"Wallet get_balances starting (reserve_sats={})",
328+
total_anchor_channels_reserve_sats,
329+
);
330+
let locked_wallet = self.inner.lock().unwrap();
331+
let lock_wait_ms = lock_wait_start.elapsed().as_millis();
332+
log_info!(
333+
self.logger,
334+
"Wallet get_balances acquired wallet lock in {}ms",
335+
lock_wait_ms,
336+
);
337+
let balance_start = Instant::now();
338+
let balance = locked_wallet.balance();
339+
let balance_ms = balance_start.elapsed().as_millis();
340+
log_info!(
341+
self.logger,
342+
"Wallet get_balances fetched BDK balance in {}ms",
343+
balance_ms,
344+
);
345+
drop(locked_wallet);
324346

325347
// Make sure `list_confirmed_utxos` returns at least one `Utxo` we could use to spend/bump
326348
// Anchors if we have any confirmed amounts.
@@ -332,7 +354,14 @@ impl Wallet {
332354
);
333355
}
334356

335-
self.get_balances_inner(balance, total_anchor_channels_reserve_sats)
357+
let balances = self.get_balances_inner(balance, total_anchor_channels_reserve_sats)?;
358+
log_info!(
359+
self.logger,
360+
"Wallet get_balances computed balances total_sats={} spendable_sats={}",
361+
balances.0,
362+
balances.1,
363+
);
364+
Ok(balances)
336365
}
337366

338367
fn get_balances_inner(

0 commit comments

Comments
 (0)