mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-02-24 23:08:36 +01:00
Merge pull request #3235 from Mirebella/add-local-balance-msats
Add `last_local_balance_msats` field
This commit is contained in:
commit
f94bf98612
3 changed files with 28 additions and 3 deletions
|
@ -1293,6 +1293,17 @@ pub enum Event {
|
||||||
/// status of the closing tx.
|
/// status of the closing tx.
|
||||||
/// Note that for instances serialized in v0.0.119 or prior this will be missing (None).
|
/// Note that for instances serialized in v0.0.119 or prior this will be missing (None).
|
||||||
channel_funding_txo: Option<transaction::OutPoint>,
|
channel_funding_txo: Option<transaction::OutPoint>,
|
||||||
|
/// An upper bound on the our last local balance in msats before the channel was closed.
|
||||||
|
///
|
||||||
|
/// Will overstate our balance as it ignores pending outbound HTLCs and transaction fees.
|
||||||
|
///
|
||||||
|
/// For more accurate balances including fee information see
|
||||||
|
/// [`ChainMonitor::get_claimable_balances`].
|
||||||
|
///
|
||||||
|
/// This field will be `None` only for objects serialized prior to LDK 0.1.
|
||||||
|
///
|
||||||
|
/// [`ChainMonitor::get_claimable_balances`]: crate::chain::chainmonitor::ChainMonitor::get_claimable_balances
|
||||||
|
last_local_balance_msat: Option<u64>,
|
||||||
},
|
},
|
||||||
/// Used to indicate to the user that they can abandon the funding transaction and recycle the
|
/// Used to indicate to the user that they can abandon the funding transaction and recycle the
|
||||||
/// inputs for another purpose.
|
/// inputs for another purpose.
|
||||||
|
@ -1573,7 +1584,8 @@ impl Writeable for Event {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
&Event::ChannelClosed { ref channel_id, ref user_channel_id, ref reason,
|
&Event::ChannelClosed { ref channel_id, ref user_channel_id, ref reason,
|
||||||
ref counterparty_node_id, ref channel_capacity_sats, ref channel_funding_txo
|
ref counterparty_node_id, ref channel_capacity_sats, ref channel_funding_txo,
|
||||||
|
ref last_local_balance_msat,
|
||||||
} => {
|
} => {
|
||||||
9u8.write(writer)?;
|
9u8.write(writer)?;
|
||||||
// `user_channel_id` used to be a single u64 value. In order to remain backwards
|
// `user_channel_id` used to be a single u64 value. In order to remain backwards
|
||||||
|
@ -1589,6 +1601,7 @@ impl Writeable for Event {
|
||||||
(5, counterparty_node_id, option),
|
(5, counterparty_node_id, option),
|
||||||
(7, channel_capacity_sats, option),
|
(7, channel_capacity_sats, option),
|
||||||
(9, channel_funding_txo, option),
|
(9, channel_funding_txo, option),
|
||||||
|
(11, last_local_balance_msat, option)
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
&Event::DiscardFunding { ref channel_id, ref funding_info } => {
|
&Event::DiscardFunding { ref channel_id, ref funding_info } => {
|
||||||
|
@ -1964,6 +1977,7 @@ impl MaybeReadable for Event {
|
||||||
let mut counterparty_node_id = None;
|
let mut counterparty_node_id = None;
|
||||||
let mut channel_capacity_sats = None;
|
let mut channel_capacity_sats = None;
|
||||||
let mut channel_funding_txo = None;
|
let mut channel_funding_txo = None;
|
||||||
|
let mut last_local_balance_msat = None;
|
||||||
read_tlv_fields!(reader, {
|
read_tlv_fields!(reader, {
|
||||||
(0, channel_id, required),
|
(0, channel_id, required),
|
||||||
(1, user_channel_id_low_opt, option),
|
(1, user_channel_id_low_opt, option),
|
||||||
|
@ -1972,6 +1986,7 @@ impl MaybeReadable for Event {
|
||||||
(5, counterparty_node_id, option),
|
(5, counterparty_node_id, option),
|
||||||
(7, channel_capacity_sats, option),
|
(7, channel_capacity_sats, option),
|
||||||
(9, channel_funding_txo, option),
|
(9, channel_funding_txo, option),
|
||||||
|
(11, last_local_balance_msat, option)
|
||||||
});
|
});
|
||||||
|
|
||||||
// `user_channel_id` used to be a single u64 value. In order to remain
|
// `user_channel_id` used to be a single u64 value. In order to remain
|
||||||
|
@ -1980,8 +1995,10 @@ impl MaybeReadable for Event {
|
||||||
let user_channel_id = (user_channel_id_low_opt.unwrap_or(0) as u128) +
|
let user_channel_id = (user_channel_id_low_opt.unwrap_or(0) as u128) +
|
||||||
((user_channel_id_high_opt.unwrap_or(0) as u128) << 64);
|
((user_channel_id_high_opt.unwrap_or(0) as u128) << 64);
|
||||||
|
|
||||||
Ok(Some(Event::ChannelClosed { channel_id, user_channel_id, reason: _init_tlv_based_struct_field!(reason, upgradable_required),
|
Ok(Some(Event::ChannelClosed {
|
||||||
counterparty_node_id, channel_capacity_sats, channel_funding_txo }))
|
channel_id, user_channel_id, reason: _init_tlv_based_struct_field!(reason, upgradable_required),
|
||||||
|
counterparty_node_id, channel_capacity_sats, channel_funding_txo, last_local_balance_msat,
|
||||||
|
}))
|
||||||
};
|
};
|
||||||
f()
|
f()
|
||||||
},
|
},
|
||||||
|
|
|
@ -937,6 +937,7 @@ pub(crate) struct ShutdownResult {
|
||||||
pub(crate) is_manual_broadcast: bool,
|
pub(crate) is_manual_broadcast: bool,
|
||||||
pub(crate) unbroadcasted_funding_tx: Option<Transaction>,
|
pub(crate) unbroadcasted_funding_tx: Option<Transaction>,
|
||||||
pub(crate) channel_funding_txo: Option<OutPoint>,
|
pub(crate) channel_funding_txo: Option<OutPoint>,
|
||||||
|
pub(crate) last_local_balance_msat: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Tracks the transaction number, along with current and next commitment points.
|
/// Tracks the transaction number, along with current and next commitment points.
|
||||||
|
@ -2066,6 +2067,8 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn get_value_to_self_msat(&self) -> u64 {self.value_to_self_msat}
|
||||||
|
|
||||||
/// Allowed in any state (including after shutdown)
|
/// Allowed in any state (including after shutdown)
|
||||||
pub fn get_update_time_counter(&self) -> u32 {
|
pub fn get_update_time_counter(&self) -> u32 {
|
||||||
self.update_time_counter
|
self.update_time_counter
|
||||||
|
@ -3532,6 +3535,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
|
||||||
unbroadcasted_funding_tx,
|
unbroadcasted_funding_tx,
|
||||||
is_manual_broadcast: self.is_manual_broadcast,
|
is_manual_broadcast: self.is_manual_broadcast,
|
||||||
channel_funding_txo: self.get_funding_txo(),
|
channel_funding_txo: self.get_funding_txo(),
|
||||||
|
last_local_balance_msat: self.value_to_self_msat,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6180,6 +6184,7 @@ impl<SP: Deref> Channel<SP> where
|
||||||
unbroadcasted_funding_tx: self.context.unbroadcasted_funding(),
|
unbroadcasted_funding_tx: self.context.unbroadcasted_funding(),
|
||||||
is_manual_broadcast: self.context.is_manual_broadcast,
|
is_manual_broadcast: self.context.is_manual_broadcast,
|
||||||
channel_funding_txo: self.context.get_funding_txo(),
|
channel_funding_txo: self.context.get_funding_txo(),
|
||||||
|
last_local_balance_msat: self.context.value_to_self_msat,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3684,6 +3684,7 @@ where
|
||||||
counterparty_node_id: Some(shutdown_res.counterparty_node_id),
|
counterparty_node_id: Some(shutdown_res.counterparty_node_id),
|
||||||
channel_capacity_sats: Some(shutdown_res.channel_capacity_satoshis),
|
channel_capacity_sats: Some(shutdown_res.channel_capacity_satoshis),
|
||||||
channel_funding_txo: shutdown_res.channel_funding_txo,
|
channel_funding_txo: shutdown_res.channel_funding_txo,
|
||||||
|
last_local_balance_msat: Some(shutdown_res.last_local_balance_msat),
|
||||||
}, None));
|
}, None));
|
||||||
|
|
||||||
if let Some(transaction) = shutdown_res.unbroadcasted_funding_tx {
|
if let Some(transaction) = shutdown_res.unbroadcasted_funding_tx {
|
||||||
|
@ -12294,6 +12295,7 @@ where
|
||||||
counterparty_node_id: Some(channel.context.get_counterparty_node_id()),
|
counterparty_node_id: Some(channel.context.get_counterparty_node_id()),
|
||||||
channel_capacity_sats: Some(channel.context.get_value_satoshis()),
|
channel_capacity_sats: Some(channel.context.get_value_satoshis()),
|
||||||
channel_funding_txo: channel.context.get_funding_txo(),
|
channel_funding_txo: channel.context.get_funding_txo(),
|
||||||
|
last_local_balance_msat: Some(channel.context.get_value_to_self_msat()),
|
||||||
}, None));
|
}, None));
|
||||||
for (channel_htlc_source, payment_hash) in channel.inflight_htlc_sources() {
|
for (channel_htlc_source, payment_hash) in channel.inflight_htlc_sources() {
|
||||||
let mut found_htlc = false;
|
let mut found_htlc = false;
|
||||||
|
@ -12350,6 +12352,7 @@ where
|
||||||
counterparty_node_id: Some(channel.context.get_counterparty_node_id()),
|
counterparty_node_id: Some(channel.context.get_counterparty_node_id()),
|
||||||
channel_capacity_sats: Some(channel.context.get_value_satoshis()),
|
channel_capacity_sats: Some(channel.context.get_value_satoshis()),
|
||||||
channel_funding_txo: channel.context.get_funding_txo(),
|
channel_funding_txo: channel.context.get_funding_txo(),
|
||||||
|
last_local_balance_msat: Some(channel.context.get_value_to_self_msat()),
|
||||||
}, None));
|
}, None));
|
||||||
} else {
|
} else {
|
||||||
log_error!(logger, "Missing ChannelMonitor for channel {} needed by ChannelManager.", &channel.context.channel_id());
|
log_error!(logger, "Missing ChannelMonitor for channel {} needed by ChannelManager.", &channel.context.channel_id());
|
||||||
|
|
Loading…
Add table
Reference in a new issue