Skip to content

Commit 77e506b

Browse files
committed
f re-add constants, but not public ones
1 parent 5126488 commit 77e506b

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ pub struct ChannelMonitorUpdate {
102102
pub channel_id: Option<ChannelId>,
103103
}
104104

105+
/// LDK prior to 0.1 used this constant as the [`ChannelMonitorUpdate::update_id`] for any
106+
/// [`ChannelMonitorUpdate`]s which were generated after the channel was closed.
107+
const LEGACY_CLOSED_CHANNEL_UPDATE_ID: u64 = core::u64::MAX;
108+
105109
impl Writeable for ChannelMonitorUpdate {
106110
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
107111
write_ver_prefix!(w, SERIALIZATION_VERSION, MIN_SERIALIZATION_VERSION);
@@ -3106,10 +3110,10 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
31063110
F::Target: FeeEstimator,
31073111
L::Target: Logger,
31083112
{
3109-
if self.latest_update_id == u64::MAX && updates.update_id == u64::MAX {
3113+
if self.latest_update_id == LEGACY_CLOSED_CHANNEL_UPDATE_ID && updates.update_id == LEGACY_CLOSED_CHANNEL_UPDATE_ID {
31103114
log_info!(logger, "Applying pre-0.1 post-force-closed update to monitor {} with {} change(s).",
31113115
log_funding_info!(self), updates.updates.len());
3112-
} else if updates.update_id == u64::MAX {
3116+
} else if updates.update_id == LEGACY_CLOSED_CHANNEL_UPDATE_ID {
31133117
log_info!(logger, "Applying pre-0.1 force close update to monitor {} with {} change(s).",
31143118
log_funding_info!(self), updates.updates.len());
31153119
} else {
@@ -3133,7 +3137,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
31333137
// The `ChannelManager` may also queue redundant `ChannelForceClosed` updates if it still
31343138
// thinks the channel needs to have its commitment transaction broadcast, so we'll allow
31353139
// them as well.
3136-
if updates.update_id == u64::MAX || self.lockdown_from_offchain {
3140+
if updates.update_id == LEGACY_CLOSED_CHANNEL_UPDATE_ID || self.lockdown_from_offchain {
31373141
assert_eq!(updates.updates.len(), 1);
31383142
match updates.updates[0] {
31393143
ChannelMonitorUpdateStep::ChannelForceClosed { .. } => {},

lightning/src/util/persist.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -732,9 +732,11 @@ where
732732
&self, funding_txo: OutPoint, update: Option<&ChannelMonitorUpdate>,
733733
monitor: &ChannelMonitor<ChannelSigner>,
734734
) -> chain::ChannelMonitorUpdateStatus {
735+
const LEGACY_CLOSED_CHANNEL_UPDATE_ID: u64 = u64::MAX;
735736
if let Some(update) = update {
736-
if update.update_id != u64::MAX && update.update_id % self.maximum_pending_updates != 0
737-
{
737+
let persist_update = update.update_id != LEGACY_CLOSED_CHANNEL_UPDATE_ID
738+
&& update.update_id % self.maximum_pending_updates != 0;
739+
if persist_update {
738740
let monitor_name = MonitorName::from(funding_txo);
739741
let update_name = UpdateName::from(update.update_id);
740742
match self.kv_store.write(
@@ -761,22 +763,24 @@ where
761763
// In case of channel-close monitor update, we need to read old monitor before persisting
762764
// the new one in order to determine the cleanup range.
763765
let maybe_old_monitor = match monitor.get_latest_update_id() {
764-
u64::MAX => self.read_monitor(&monitor_name).ok(),
766+
LEGACY_CLOSED_CHANNEL_UPDATE_ID => self.read_monitor(&monitor_name).ok(),
765767
_ => None,
766768
};
767769

768770
// We could write this update, but it meets criteria of our design that calls for a full monitor write.
769771
let monitor_update_status = self.persist_new_channel(funding_txo, monitor);
770772

771773
if let chain::ChannelMonitorUpdateStatus::Completed = monitor_update_status {
772-
let cleanup_range = if monitor.get_latest_update_id() == u64::MAX {
774+
let channel_closed_legacy =
775+
monitor.get_latest_update_id() == LEGACY_CLOSED_CHANNEL_UPDATE_ID;
776+
let cleanup_range = if channel_closed_legacy {
773777
// If there is an error while reading old monitor, we skip clean up.
774778
maybe_old_monitor.map(|(_, ref old_monitor)| {
775779
let start = old_monitor.get_latest_update_id();
776-
// We never persist an update with update_id = u64::MAX
780+
// We never persist an update with the leagacy closed update_id
777781
let end = cmp::min(
778782
start.saturating_add(self.maximum_pending_updates),
779-
u64::MAX - 1,
783+
LEGACY_CLOSED_CHANNEL_UPDATE_ID - 1,
780784
);
781785
(start, end)
782786
})

0 commit comments

Comments
 (0)