Skip to content

Commit 5b18ee4

Browse files
committed
Remove OnionHopDataFormat::Legacy
1 parent 550a989 commit 5b18ee4

File tree

2 files changed

+38
-76
lines changed

2 files changed

+38
-76
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2103,13 +2103,6 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
21032103
}
21042104

21052105
let routing = match hop_data.format {
2106-
msgs::OnionHopDataFormat::Legacy { .. } => {
2107-
return Err(ReceiveError {
2108-
err_code: 0x4000|0x2000|3,
2109-
err_data: Vec::new(),
2110-
msg: "We require payment_secrets",
2111-
});
2112-
},
21132106
msgs::OnionHopDataFormat::NonFinalNode { .. } => {
21142107
return Err(ReceiveError {
21152108
err_code: 0x4000|22,
@@ -2244,7 +2237,6 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
22442237
};
22452238

22462239
let short_channel_id = match next_hop_data.format {
2247-
msgs::OnionHopDataFormat::Legacy { short_channel_id } => short_channel_id,
22482240
msgs::OnionHopDataFormat::NonFinalNode { short_channel_id } => short_channel_id,
22492241
msgs::OnionHopDataFormat::FinalNode { .. } => {
22502242
return_err!("Final Node OnionHopData provided for us as an intermediary node", 0x4000 | 22, &[0;0]);

lightning/src/ln/msgs.rs

Lines changed: 38 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,9 +1028,6 @@ mod fuzzy_internal_msgs {
10281028
}
10291029

10301030
pub(crate) enum OnionHopDataFormat {
1031-
Legacy { // aka Realm-0
1032-
short_channel_id: u64,
1033-
},
10341031
NonFinalNode {
10351032
short_channel_id: u64,
10361033
},
@@ -1046,7 +1043,6 @@ mod fuzzy_internal_msgs {
10461043
/// Message serialization may panic if this value is more than 21 million Bitcoin.
10471044
pub(crate) amt_to_forward: u64,
10481045
pub(crate) outgoing_cltv_value: u32,
1049-
// 12 bytes of 0-padding for Legacy format
10501046
}
10511047

10521048
pub struct DecodedOnionErrorPacket {
@@ -1459,13 +1455,6 @@ impl Readable for FinalOnionHopData {
14591455
impl Writeable for OnionHopData {
14601456
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
14611457
match self.format {
1462-
OnionHopDataFormat::Legacy { short_channel_id } => {
1463-
0u8.write(w)?;
1464-
short_channel_id.write(w)?;
1465-
self.amt_to_forward.write(w)?;
1466-
self.outgoing_cltv_value.write(w)?;
1467-
w.write_all(&[0;12])?;
1468-
},
14691458
OnionHopDataFormat::NonFinalNode { short_channel_id } => {
14701459
encode_varint_length_prefixed_tlv!(w, {
14711460
(2, HighZeroBytesDroppedBigSize(self.amt_to_forward), required),
@@ -1490,56 +1479,51 @@ impl Readable for OnionHopData {
14901479
fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
14911480
let b: BigSize = Readable::read(r)?;
14921481
const LEGACY_ONION_HOP_FLAG: u64 = 0;
1493-
let (format, amt, cltv_value) = if b.0 != LEGACY_ONION_HOP_FLAG {
1494-
let mut rd = FixedLengthReader::new(r, b.0);
1495-
let mut amt = HighZeroBytesDroppedBigSize(0u64);
1496-
let mut cltv_value = HighZeroBytesDroppedBigSize(0u32);
1497-
let mut short_id: Option<u64> = None;
1498-
let mut payment_data: Option<FinalOnionHopData> = None;
1499-
let mut keysend_preimage: Option<PaymentPreimage> = None;
1500-
decode_tlv_stream!(&mut rd, {
1501-
(2, amt, required),
1502-
(4, cltv_value, required),
1503-
(6, short_id, option),
1504-
(8, payment_data, option),
1505-
// See https://github.com/lightning/blips/blob/master/blip-0003.md
1506-
(5482373484, keysend_preimage, option)
1507-
});
1508-
rd.eat_remaining().map_err(|_| DecodeError::ShortRead)?;
1509-
let format = if let Some(short_channel_id) = short_id {
1510-
if payment_data.is_some() { return Err(DecodeError::InvalidValue); }
1511-
OnionHopDataFormat::NonFinalNode {
1512-
short_channel_id,
1513-
}
1514-
} else {
1515-
if let &Some(ref data) = &payment_data {
1516-
if data.total_msat > MAX_VALUE_MSAT {
1517-
return Err(DecodeError::InvalidValue);
1518-
}
1519-
}
1520-
OnionHopDataFormat::FinalNode {
1521-
payment_data,
1522-
keysend_preimage,
1523-
}
1524-
};
1525-
(format, amt.0, cltv_value.0)
1482+
if b.0 == LEGACY_ONION_HOP_FLAG {
1483+
// Support for Legacy onion payload format has been removed as of LDK 0.XX,
1484+
// due to being deprecated in BOLT4.
1485+
return Err(DecodeError::InvalidValue);
1486+
}
1487+
1488+
let mut rd = FixedLengthReader::new(r, b.0);
1489+
let mut amt = HighZeroBytesDroppedBigSize(0u64);
1490+
let mut cltv_value = HighZeroBytesDroppedBigSize(0u32);
1491+
let mut short_id: Option<u64> = None;
1492+
let mut payment_data: Option<FinalOnionHopData> = None;
1493+
let mut keysend_preimage: Option<PaymentPreimage> = None;
1494+
decode_tlv_stream!(&mut rd, {
1495+
(2, amt, required),
1496+
(4, cltv_value, required),
1497+
(6, short_id, option),
1498+
(8, payment_data, option),
1499+
// See https://github.com/lightning/blips/blob/master/blip-0003.md
1500+
(5482373484, keysend_preimage, option)
1501+
});
1502+
rd.eat_remaining().map_err(|_| DecodeError::ShortRead)?;
1503+
let format = if let Some(short_channel_id) = short_id {
1504+
if payment_data.is_some() { return Err(DecodeError::InvalidValue); }
1505+
OnionHopDataFormat::NonFinalNode {
1506+
short_channel_id,
1507+
}
15261508
} else {
1527-
let format = OnionHopDataFormat::Legacy {
1528-
short_channel_id: Readable::read(r)?,
1529-
};
1530-
let amt: u64 = Readable::read(r)?;
1531-
let cltv_value: u32 = Readable::read(r)?;
1532-
r.read_exact(&mut [0; 12])?;
1533-
(format, amt, cltv_value)
1509+
if let &Some(ref data) = &payment_data {
1510+
if data.total_msat > MAX_VALUE_MSAT {
1511+
return Err(DecodeError::InvalidValue);
1512+
}
1513+
}
1514+
OnionHopDataFormat::FinalNode {
1515+
payment_data,
1516+
keysend_preimage,
1517+
}
15341518
};
15351519

1536-
if amt > MAX_VALUE_MSAT {
1520+
if amt.0 > MAX_VALUE_MSAT {
15371521
return Err(DecodeError::InvalidValue);
15381522
}
15391523
Ok(OnionHopData {
15401524
format,
1541-
amt_to_forward: amt,
1542-
outgoing_cltv_value: cltv_value,
1525+
amt_to_forward: amt.0,
1526+
outgoing_cltv_value: cltv_value.0,
15431527
})
15441528
}
15451529
}
@@ -2669,20 +2653,6 @@ mod tests {
26692653
assert_eq!(encoded_value, target_value);
26702654
}
26712655

2672-
#[test]
2673-
fn encoding_legacy_onion_hop_data() {
2674-
let msg = msgs::OnionHopData {
2675-
format: OnionHopDataFormat::Legacy {
2676-
short_channel_id: 0xdeadbeef1bad1dea,
2677-
},
2678-
amt_to_forward: 0x0badf00d01020304,
2679-
outgoing_cltv_value: 0xffffffff,
2680-
};
2681-
let encoded_value = msg.encode();
2682-
let target_value = hex::decode("00deadbeef1bad1dea0badf00d01020304ffffffff000000000000000000000000").unwrap();
2683-
assert_eq!(encoded_value, target_value);
2684-
}
2685-
26862656
#[test]
26872657
fn encoding_nonfinal_onion_hop_data() {
26882658
let mut msg = msgs::OnionHopData {

0 commit comments

Comments
 (0)