Skip to content

Commit abb53d1

Browse files
Remove now-unused NetworkUpdate::ChannelUpdateMessage.
See previous commit.
1 parent 85db25b commit abb53d1

File tree

3 files changed

+66
-48
lines changed

3 files changed

+66
-48
lines changed

lightning/src/ln/functional_test_utils.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2453,13 +2453,6 @@ pub fn expect_payment_failed_conditions_event<'a, 'b, 'c, 'd, 'e>(
24532453
if let Some(chan_closed) = conditions.expected_blamed_chan_closed {
24542454
if let PathFailure::OnPath { network_update: Some(upd) } = failure {
24552455
match upd {
2456-
NetworkUpdate::ChannelUpdateMessage { ref msg } if !chan_closed => {
2457-
if let Some(scid) = conditions.expected_blamed_scid {
2458-
assert_eq!(msg.contents.short_channel_id, scid);
2459-
}
2460-
const CHAN_DISABLED_FLAG: u8 = 2;
2461-
assert_eq!(msg.contents.flags & CHAN_DISABLED_FLAG, 0);
2462-
},
24632456
NetworkUpdate::ChannelFailure { short_channel_id, is_permanent } => {
24642457
if let Some(scid) = conditions.expected_blamed_scid {
24652458
assert_eq!(*short_channel_id, scid);

lightning/src/ln/onion_route_tests.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,6 @@ fn run_onion_failure_test_with_fail_intercept<F1,F2,F3>(
180180
if expected_channel_update.is_some() {
181181
match network_update {
182182
Some(update) => match update {
183-
&NetworkUpdate::ChannelUpdateMessage { .. } => {
184-
if let NetworkUpdate::ChannelUpdateMessage { .. } = expected_channel_update.unwrap() {} else {
185-
panic!("channel_update not found!");
186-
}
187-
},
188183
&NetworkUpdate::ChannelFailure { ref short_channel_id, ref is_permanent } => {
189184
if let NetworkUpdate::ChannelFailure { short_channel_id: ref expected_short_channel_id, is_permanent: ref expected_is_permanent } = expected_channel_update.unwrap() {
190185
assert!(*short_channel_id == *expected_short_channel_id);

lightning/src/routing/gossip.rs

Lines changed: 66 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use crate::routing::utxo::{self, UtxoLookup, UtxoResolver};
3131
use crate::util::indexed_map::{Entry as IndexedMapEntry, IndexedMap};
3232
use crate::util::logger::{Level, Logger};
3333
use crate::util::scid_utils::{block_from_scid, scid_from_parts, MAX_SCID_BLOCK};
34-
use crate::util::ser::{MaybeReadable, Readable, ReadableArgs, Writeable, Writer};
34+
use crate::util::ser::{MaybeReadable, Readable, ReadableArgs, RequiredWrapper, Writeable, Writer};
3535
use crate::util::string::PrintableString;
3636

3737
use crate::io;
@@ -218,12 +218,6 @@ pub struct ReadOnlyNetworkGraph<'a> {
218218
/// [BOLT #4]: https://github.com/lightning/bolts/blob/master/04-onion-routing.md
219219
#[derive(Clone, Debug, PartialEq, Eq)]
220220
pub enum NetworkUpdate {
221-
/// An error indicating a `channel_update` messages should be applied via
222-
/// [`NetworkGraph::update_channel`].
223-
ChannelUpdateMessage {
224-
/// The update to apply via [`NetworkGraph::update_channel`].
225-
msg: ChannelUpdate,
226-
},
227221
/// An error indicating that a channel failed to route a payment, which should be applied via
228222
/// [`NetworkGraph::channel_failed_permanent`] if permanent.
229223
ChannelFailure {
@@ -244,19 +238,69 @@ pub enum NetworkUpdate {
244238
}
245239
}
246240

247-
impl_writeable_tlv_based_enum_upgradable!(NetworkUpdate,
248-
(0, ChannelUpdateMessage) => {
249-
(0, msg, required),
250-
},
251-
(2, ChannelFailure) => {
252-
(0, short_channel_id, required),
253-
(2, is_permanent, required),
254-
},
255-
(4, NodeFailure) => {
256-
(0, node_id, required),
257-
(2, is_permanent, required),
258-
},
259-
);
241+
impl Writeable for NetworkUpdate {
242+
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
243+
match self {
244+
Self::ChannelFailure { short_channel_id, is_permanent } => {
245+
2u8.write(writer)?;
246+
write_tlv_fields!(writer, {
247+
(0, short_channel_id, required),
248+
(2, is_permanent, required),
249+
});
250+
},
251+
Self::NodeFailure { node_id, is_permanent } => {
252+
4u8.write(writer)?;
253+
write_tlv_fields!(writer, {
254+
(0, node_id, required),
255+
(2, is_permanent, required),
256+
});
257+
}
258+
}
259+
Ok(())
260+
}
261+
}
262+
263+
impl MaybeReadable for NetworkUpdate {
264+
fn read<R: io::Read>(reader: &mut R) -> Result<Option<Self>, DecodeError> {
265+
let id: u8 = Readable::read(reader)?;
266+
match id {
267+
0 => {
268+
// 0 was previously used for network updates containing a channel update, subsequently
269+
// removed in LDK version 0.0.124.
270+
let mut msg: RequiredWrapper<ChannelUpdate> = RequiredWrapper(None);
271+
read_tlv_fields!(reader, {
272+
(0, msg, required),
273+
});
274+
Ok(Some(Self::ChannelFailure {
275+
short_channel_id: msg.0.unwrap().contents.short_channel_id,
276+
is_permanent: false
277+
}))
278+
},
279+
2 => {
280+
_init_and_read_len_prefixed_tlv_fields!(reader, {
281+
(0, short_channel_id, required),
282+
(2, is_permanent, required),
283+
});
284+
Ok(Some(Self::ChannelFailure {
285+
short_channel_id: short_channel_id.0.unwrap(),
286+
is_permanent: is_permanent.0.unwrap(),
287+
}))
288+
},
289+
4 => {
290+
_init_and_read_len_prefixed_tlv_fields!(reader, {
291+
(0, node_id, required),
292+
(2, is_permanent, required),
293+
});
294+
Ok(Some(Self::NodeFailure {
295+
node_id: node_id.0.unwrap(),
296+
is_permanent: is_permanent.0.unwrap(),
297+
}))
298+
}
299+
t if t % 2 == 0 => Err(DecodeError::UnknownRequiredFeature),
300+
_ => Ok(None),
301+
}
302+
}
303+
}
260304

261305
/// Receives and validates network updates from peers,
262306
/// stores authentic and relevant data as a network graph.
@@ -353,19 +397,10 @@ where U::Target: UtxoLookup, L::Target: Logger
353397

354398
impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
355399
/// Handles any network updates originating from [`Event`]s.
356-
//
357-
/// Note that this will skip applying any [`NetworkUpdate::ChannelUpdateMessage`] to avoid
358-
/// leaking possibly identifying information of the sender to the public network.
359400
///
360401
/// [`Event`]: crate::events::Event
361402
pub fn handle_network_update(&self, network_update: &NetworkUpdate) {
362403
match *network_update {
363-
NetworkUpdate::ChannelUpdateMessage { ref msg } => {
364-
let short_channel_id = msg.contents.short_channel_id;
365-
let is_enabled = msg.contents.flags & (1 << 1) != (1 << 1);
366-
let status = if is_enabled { "enabled" } else { "disabled" };
367-
log_debug!(self.logger, "Skipping application of a channel update from a payment failure. Channel {} is {}.", short_channel_id, status);
368-
},
369404
NetworkUpdate::ChannelFailure { short_channel_id, is_permanent } => {
370405
if is_permanent {
371406
log_debug!(self.logger, "Removing channel graph entry for {} due to a payment failure.", short_channel_id);
@@ -2575,23 +2610,18 @@ pub(crate) mod tests {
25752610

25762611
let short_channel_id;
25772612
{
2578-
// Check we won't apply an update via `handle_network_update` for privacy reasons, but
2579-
// can continue fine if we manually apply it.
2613+
// Check that we can manually apply a channel update.
25802614
let valid_channel_announcement = get_signed_channel_announcement(|_| {}, node_1_privkey, node_2_privkey, &secp_ctx);
25812615
short_channel_id = valid_channel_announcement.contents.short_channel_id;
25822616
let chain_source: Option<&test_utils::TestChainSource> = None;
25832617
assert!(network_graph.update_channel_from_announcement(&valid_channel_announcement, &chain_source).is_ok());
25842618
assert!(network_graph.read_only().channels().get(&short_channel_id).is_some());
25852619

25862620
let valid_channel_update = get_signed_channel_update(|_| {}, node_1_privkey, &secp_ctx);
2587-
assert!(network_graph.read_only().channels().get(&short_channel_id).unwrap().one_to_two.is_none());
2588-
2589-
network_graph.handle_network_update(&NetworkUpdate::ChannelUpdateMessage {
2590-
msg: valid_channel_update.clone(),
2591-
});
25922621

25932622
assert!(network_graph.read_only().channels().get(&short_channel_id).unwrap().one_to_two.is_none());
25942623
network_graph.update_channel(&valid_channel_update).unwrap();
2624+
assert!(network_graph.read_only().channels().get(&short_channel_id).unwrap().one_to_two.is_some());
25952625
}
25962626

25972627
// Non-permanent failure doesn't touch the channel at all

0 commit comments

Comments
 (0)