Skip to content

Commit 0982a96

Browse files
Remove OnionHopDataFormat::Legacy
1 parent ba522bf commit 0982a96

File tree

2 files changed

+32
-79
lines changed

2 files changed

+32
-79
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: 32 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use crate::io_extras::read_to_end;
4242

4343
use crate::util::events::{MessageSendEventsProvider, OnionMessageProvider};
4444
use crate::util::logger;
45-
use crate::util::ser::{BigSize, LengthReadable, Readable, ReadableArgs, Writeable, Writer, FixedLengthReader, HighZeroBytesDroppedBigSize, Hostname};
45+
use crate::util::ser::{LengthReadable, Readable, ReadableArgs, Writeable, Writer, FixedLengthReader, HighZeroBytesDroppedBigSize, Hostname};
4646

4747
use crate::ln::{PaymentPreimage, PaymentHash, PaymentSecret};
4848

@@ -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),
@@ -1488,58 +1477,44 @@ impl Writeable for OnionHopData {
14881477

14891478
impl Readable for OnionHopData {
14901479
fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
1491-
let b: BigSize = Readable::read(r)?;
1492-
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)
1480+
let mut amt = HighZeroBytesDroppedBigSize(0u64);
1481+
let mut cltv_value = HighZeroBytesDroppedBigSize(0u32);
1482+
let mut short_id: Option<u64> = None;
1483+
let mut payment_data: Option<FinalOnionHopData> = None;
1484+
let mut keysend_preimage: Option<PaymentPreimage> = None;
1485+
read_tlv_fields!(r, {
1486+
(2, amt, required),
1487+
(4, cltv_value, required),
1488+
(6, short_id, option),
1489+
(8, payment_data, option),
1490+
// See https://github.com/lightning/blips/blob/master/blip-0003.md
1491+
(5482373484, keysend_preimage, option)
1492+
});
1493+
1494+
let format = if let Some(short_channel_id) = short_id {
1495+
if payment_data.is_some() { return Err(DecodeError::InvalidValue); }
1496+
OnionHopDataFormat::NonFinalNode {
1497+
short_channel_id,
1498+
}
15261499
} 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)
1500+
if let &Some(ref data) = &payment_data {
1501+
if data.total_msat > MAX_VALUE_MSAT {
1502+
return Err(DecodeError::InvalidValue);
1503+
}
1504+
}
1505+
OnionHopDataFormat::FinalNode {
1506+
payment_data,
1507+
keysend_preimage,
1508+
}
15341509
};
15351510

1536-
if amt > MAX_VALUE_MSAT {
1511+
if amt.0 > MAX_VALUE_MSAT {
15371512
return Err(DecodeError::InvalidValue);
15381513
}
15391514
Ok(OnionHopData {
15401515
format,
1541-
amt_to_forward: amt,
1542-
outgoing_cltv_value: cltv_value,
1516+
amt_to_forward: amt.0,
1517+
outgoing_cltv_value: cltv_value.0,
15431518
})
15441519
}
15451520
}
@@ -2669,20 +2644,6 @@ mod tests {
26692644
assert_eq!(encoded_value, target_value);
26702645
}
26712646

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-
26862647
#[test]
26872648
fn encoding_nonfinal_onion_hop_data() {
26882649
let mut msg = msgs::OnionHopData {

0 commit comments

Comments
 (0)