Skip to content

Commit 6424436

Browse files
committed
Add local balance field
1 parent 795887a commit 6424436

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

lightning/src/events/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,6 +1237,8 @@ pub enum Event {
12371237
/// status of the closing tx.
12381238
/// Note that for instances serialized in v0.0.119 or prior this will be missing (None).
12391239
channel_funding_txo: Option<transaction::OutPoint>,
1240+
/// Local balance in msats when a channel was force-closed.
1241+
last_local_balance_msats: Option<u64>,
12401242
},
12411243
/// Used to indicate to the user that they can abandon the funding transaction and recycle the
12421244
/// inputs for another purpose.
@@ -1516,7 +1518,8 @@ impl Writeable for Event {
15161518
});
15171519
},
15181520
&Event::ChannelClosed { ref channel_id, ref user_channel_id, ref reason,
1519-
ref counterparty_node_id, ref channel_capacity_sats, ref channel_funding_txo
1521+
ref counterparty_node_id, ref channel_capacity_sats, ref channel_funding_txo,
1522+
ref last_local_balance_msats
15201523
} => {
15211524
9u8.write(writer)?;
15221525
// `user_channel_id` used to be a single u64 value. In order to remain backwards
@@ -1532,6 +1535,7 @@ impl Writeable for Event {
15321535
(5, counterparty_node_id, option),
15331536
(7, channel_capacity_sats, option),
15341537
(9, channel_funding_txo, option),
1538+
(11, last_local_balance_msats, option)
15351539
});
15361540
},
15371541
&Event::DiscardFunding { ref channel_id, ref transaction } => {
@@ -1875,6 +1879,7 @@ impl MaybeReadable for Event {
18751879
let mut counterparty_node_id = None;
18761880
let mut channel_capacity_sats = None;
18771881
let mut channel_funding_txo = None;
1882+
let mut last_local_balance_msats = None;
18781883
read_tlv_fields!(reader, {
18791884
(0, channel_id, required),
18801885
(1, user_channel_id_low_opt, option),
@@ -1883,6 +1888,7 @@ impl MaybeReadable for Event {
18831888
(5, counterparty_node_id, option),
18841889
(7, channel_capacity_sats, option),
18851890
(9, channel_funding_txo, option),
1891+
(11, last_local_balance_msats, option)
18861892
});
18871893

18881894
// `user_channel_id` used to be a single u64 value. In order to remain
@@ -1892,7 +1898,7 @@ impl MaybeReadable for Event {
18921898
((user_channel_id_high_opt.unwrap_or(0) as u128) << 64);
18931899

18941900
Ok(Some(Event::ChannelClosed { channel_id, user_channel_id, reason: _init_tlv_based_struct_field!(reason, upgradable_required),
1895-
counterparty_node_id, channel_capacity_sats, channel_funding_txo }))
1901+
counterparty_node_id, channel_capacity_sats, channel_funding_txo, last_local_balance_msats}))
18961902
};
18971903
f()
18981904
},

lightning/src/ln/channel.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,7 @@ pub(crate) struct ShutdownResult {
939939
pub(crate) counterparty_node_id: PublicKey,
940940
pub(crate) unbroadcasted_funding_tx: Option<Transaction>,
941941
pub(crate) channel_funding_txo: Option<OutPoint>,
942+
pub(crate) last_local_balance_msats: u64,
942943
}
943944

944945
/// Tracks the transaction number, along with current and next commitment points.
@@ -2058,6 +2059,8 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
20582059
})
20592060
}
20602061

2062+
pub(crate) fn get_value_to_self_msat(&self) -> u64 {self.value_to_self_msat}
2063+
20612064
/// Allowed in any state (including after shutdown)
20622065
pub fn get_update_time_counter(&self) -> u32 {
20632066
self.update_time_counter
@@ -3528,6 +3531,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
35283531
counterparty_node_id: self.counterparty_node_id,
35293532
unbroadcasted_funding_tx,
35303533
channel_funding_txo: self.get_funding_txo(),
3534+
last_local_balance_msats: self.value_to_self_msat,
35313535
}
35323536
}
35333537

@@ -6218,6 +6222,7 @@ impl<SP: Deref> Channel<SP> where
62186222
counterparty_node_id: self.context.counterparty_node_id,
62196223
unbroadcasted_funding_tx: self.context.unbroadcasted_funding(),
62206224
channel_funding_txo: self.context.get_funding_txo(),
6225+
last_local_balance_msats: self.context.value_to_self_msat,
62216226
};
62226227
let tx = self.build_signed_closing_transaction(&mut closing_tx, &msg.signature, &sig);
62236228
self.context.channel_state = ChannelState::ShutdownComplete;
@@ -6253,6 +6258,7 @@ impl<SP: Deref> Channel<SP> where
62536258
counterparty_node_id: self.context.counterparty_node_id,
62546259
unbroadcasted_funding_tx: self.context.unbroadcasted_funding(),
62556260
channel_funding_txo: self.context.get_funding_txo(),
6261+
last_local_balance_msats: self.context.value_to_self_msat,
62566262
};
62576263
self.context.channel_state = ChannelState::ShutdownComplete;
62586264
self.context.update_time_counter += 1;

lightning/src/ln/channelmanager.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3518,6 +3518,7 @@ where
35183518
counterparty_node_id: Some(shutdown_res.counterparty_node_id),
35193519
channel_capacity_sats: Some(shutdown_res.channel_capacity_satoshis),
35203520
channel_funding_txo: shutdown_res.channel_funding_txo,
3521+
last_local_balance_msats: Some(shutdown_res.last_local_balance_msats),
35213522
}, None));
35223523

35233524
if let Some(transaction) = shutdown_res.unbroadcasted_funding_tx {
@@ -11879,6 +11880,7 @@ where
1187911880
counterparty_node_id: Some(channel.context.get_counterparty_node_id()),
1188011881
channel_capacity_sats: Some(channel.context.get_value_satoshis()),
1188111882
channel_funding_txo: channel.context.get_funding_txo(),
11883+
last_local_balance_msats: Some(channel.context.get_value_to_self_msat()),
1188211884
}, None));
1188311885
for (channel_htlc_source, payment_hash) in channel.inflight_htlc_sources() {
1188411886
let mut found_htlc = false;
@@ -11935,6 +11937,7 @@ where
1193511937
counterparty_node_id: Some(channel.context.get_counterparty_node_id()),
1193611938
channel_capacity_sats: Some(channel.context.get_value_satoshis()),
1193711939
channel_funding_txo: channel.context.get_funding_txo(),
11940+
last_local_balance_msats: Some(channel.context.get_value_to_self_msat()),
1193811941
}, None));
1193911942
} else {
1194011943
log_error!(logger, "Missing ChannelMonitor for channel {} needed by ChannelManager.", &channel.context.channel_id());

0 commit comments

Comments
 (0)