Skip to content

Commit

Permalink
use to_us_msat for pending_onchain_balance
Browse files Browse the repository at this point in the history
Previously `pending_onchain_balance` was defined by `min_to_us_msat`. However, it confused users, because it appears that the funds were gone while eventually they would resolve to the user. Theoretically the peer could steal the difference between `to_us_msat` and `min_to_us_msat`, but since this scenario is highly unlikely given we have a watchtower and/or the node will come online every week or so. So use `to_us_msat` instead, which should reflect the real balance the user is receiving in 99.99% of the scenarios.
  • Loading branch information
JssDWt committed Jun 24, 2024
1 parent 95c7d0b commit c5c4299
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions libs/sdk-core/src/greenlight/node_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ impl Greenlight {
) -> Result<u64> {
let pending_onchain_balance = peer_channels.iter().fold(0, |a, b| match b.state() {
ChanneldShuttingDown | ClosingdSigexchange | ClosingdComplete | AwaitingUnilateral
| FundingSpendSeen => a + b.min_to_us_msat.clone().unwrap_or_default().msat,
| FundingSpendSeen => a + b.to_us_msat.clone().unwrap_or_default().msat,

// When we unilaterally close the channel it will get status as `AwaitingUnilateral`
// first, but when the closing transaction is confirmed onchain the funds receive status
Expand All @@ -563,7 +563,7 @@ impl Greenlight {
.last()
.is_some_and(|status| status.contains("DELAYED_OUTPUT_TO_US"))
{
a + b.min_to_us_msat.clone().unwrap_or_default().msat
a + b.to_us_msat.clone().unwrap_or_default().msat
} else {
a
}
Expand Down

0 comments on commit c5c4299

Please sign in to comment.