Skip to content

Commit 5e871a7

Browse files
authored
Merge pull request #2617 from wpaulino/no-persist-same-channel-update
Avoid persisting on same counterparty's ChannelUpdate
2 parents a8fa5a1 + c8c5354 commit 5e871a7

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

lightning/src/ln/channel.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5537,14 +5537,20 @@ impl<SP: Deref> Channel<SP> where
55375537
}
55385538
}
55395539

5540-
pub fn channel_update(&mut self, msg: &msgs::ChannelUpdate) -> Result<(), ChannelError> {
5541-
self.context.counterparty_forwarding_info = Some(CounterpartyForwardingInfo {
5540+
/// Applies the `ChannelUpdate` and returns a boolean indicating whether a change actually
5541+
/// happened.
5542+
pub fn channel_update(&mut self, msg: &msgs::ChannelUpdate) -> Result<bool, ChannelError> {
5543+
let new_forwarding_info = Some(CounterpartyForwardingInfo {
55425544
fee_base_msat: msg.contents.fee_base_msat,
55435545
fee_proportional_millionths: msg.contents.fee_proportional_millionths,
55445546
cltv_expiry_delta: msg.contents.cltv_expiry_delta
55455547
});
5548+
let did_change = self.context.counterparty_forwarding_info != new_forwarding_info;
5549+
if did_change {
5550+
self.context.counterparty_forwarding_info = new_forwarding_info;
5551+
}
55465552

5547-
Ok(())
5553+
Ok(did_change)
55485554
}
55495555

55505556
/// Begins the shutdown process, getting a message for the remote peer and returning all
@@ -8140,7 +8146,7 @@ mod tests {
81408146
},
81418147
signature: Signature::from(unsafe { FFISignature::new() })
81428148
};
8143-
node_a_chan.channel_update(&update).unwrap();
8149+
assert!(node_a_chan.channel_update(&update).unwrap());
81448150

81458151
// The counterparty can send an update with a higher minimum HTLC, but that shouldn't
81468152
// change our official htlc_minimum_msat.
@@ -8153,6 +8159,8 @@ mod tests {
81538159
},
81548160
None => panic!("expected counterparty forwarding info to be Some")
81558161
}
8162+
8163+
assert!(!node_a_chan.channel_update(&update).unwrap());
81568164
}
81578165

81588166
#[cfg(feature = "_test_vectors")]

lightning/src/ln/channelmanager.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6756,7 +6756,12 @@ where
67566756
return Ok(NotifyOption::SkipPersistNoEvents);
67576757
} else {
67586758
log_debug!(self.logger, "Received channel_update {:?} for channel {}.", msg, chan_id);
6759-
try_chan_phase_entry!(self, chan.channel_update(&msg), chan_phase_entry);
6759+
let did_change = try_chan_phase_entry!(self, chan.channel_update(&msg), chan_phase_entry);
6760+
// If nothing changed after applying their update, we don't need to bother
6761+
// persisting.
6762+
if !did_change {
6763+
return Ok(NotifyOption::SkipPersistNoEvents);
6764+
}
67606765
}
67616766
} else {
67626767
return try_chan_phase_entry!(self, Err(ChannelError::Close(

0 commit comments

Comments
 (0)