Skip to content

Commit f40e47c

Browse files
authored
Merge pull request #887 from valentinewallace/invoice-use-RL-routehint
invoice: swap RouteHop for RouteHint
2 parents e6c9228 + 11641fe commit f40e47c

File tree

7 files changed

+137
-111
lines changed

7 files changed

+137
-111
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
run: RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always
4848
- name: Build on Rust ${{ matrix.toolchain }}
4949
if: "! matrix.build-net-tokio"
50-
run: cargo build --verbose --color always -p lightning
50+
run: cargo build --verbose --color always -p lightning && cargo build --verbose --color always -p lightning-invoice
5151
- name: Build Block Sync Clients on Rust ${{ matrix.toolchain }} with features
5252
if: "matrix.build-net-tokio && !matrix.coverage"
5353
run: |
@@ -74,7 +74,7 @@ jobs:
7474
run: RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always
7575
- name: Test on Rust ${{ matrix.toolchain }}
7676
if: "! matrix.build-net-tokio"
77-
run: cargo test --verbose --color always -p lightning
77+
run: cargo test --verbose --color always -p lightning && cargo test --verbose --color always -p lightning-invoice
7878
- name: Test Block Sync Clients on Rust ${{ matrix.toolchain }} with features
7979
if: "matrix.build-net-tokio && !matrix.coverage"
8080
run: |

fuzz/src/router.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use lightning::chain;
1515
use lightning::ln::channelmanager::ChannelDetails;
1616
use lightning::ln::features::InitFeatures;
1717
use lightning::ln::msgs;
18-
use lightning::routing::router::{get_route, RouteHint};
18+
use lightning::routing::router::{get_route, RouteHintHop};
1919
use lightning::util::logger::Logger;
2020
use lightning::util::ser::Readable;
2121
use lightning::routing::network_graph::{NetworkGraph, RoutingFees};
@@ -224,7 +224,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
224224
for _ in 0..count {
225225
scid += 1;
226226
let rnid = node_pks.iter().skip(slice_to_be16(get_slice!(2))as usize % node_pks.len()).next().unwrap();
227-
last_hops_vec.push(RouteHint {
227+
last_hops_vec.push(RouteHintHop {
228228
src_node_id: *rnid,
229229
short_channel_id: scid,
230230
fees: RoutingFees {

lightning-invoice/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ readme = "README.md"
1010

1111
[dependencies]
1212
bech32 = "0.7"
13+
lightning = { version = "0.0.13", path = "../lightning" }
1314
secp256k1 = { version = "0.20", features = ["recovery"] }
1415
num-traits = "0.2.8"
1516
bitcoin_hashes = "0.9.4"

lightning-invoice/src/de.rs

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ use bech32::{u5, FromBase32};
1010

1111
use bitcoin_hashes::Hash;
1212
use bitcoin_hashes::sha256;
13+
use lightning::routing::network_graph::RoutingFees;
14+
use lightning::routing::router::RouteHintHop;
1315

1416
use num_traits::{CheckedAdd, CheckedMul};
1517

@@ -353,7 +355,7 @@ impl FromBase32 for Signature {
353355
}
354356
}
355357

356-
fn parse_int_be<T, U>(digits: &[U], base: T) -> Option<T>
358+
pub(crate) fn parse_int_be<T, U>(digits: &[U], base: T) -> Option<T>
357359
where T: CheckedAdd + CheckedMul + From<u8> + Default,
358360
U: Into<u8> + Copy
359361
{
@@ -428,7 +430,7 @@ impl FromBase32 for TaggedField {
428430
constants::TAG_FALLBACK =>
429431
Ok(TaggedField::Fallback(Fallback::from_base32(field_data)?)),
430432
constants::TAG_ROUTE =>
431-
Ok(TaggedField::Route(Route::from_base32(field_data)?)),
433+
Ok(TaggedField::Route(RouteHint::from_base32(field_data)?)),
432434
constants::TAG_PAYMENT_SECRET =>
433435
Ok(TaggedField::PaymentSecret(PaymentSecret::from_base32(field_data)?)),
434436
_ => {
@@ -565,17 +567,17 @@ impl FromBase32 for Fallback {
565567
}
566568
}
567569

568-
impl FromBase32 for Route {
570+
impl FromBase32 for RouteHint {
569571
type Err = ParseError;
570572

571-
fn from_base32(field_data: &[u5]) -> Result<Route, ParseError> {
573+
fn from_base32(field_data: &[u5]) -> Result<RouteHint, ParseError> {
572574
let bytes = Vec::<u8>::from_base32(field_data)?;
573575

574576
if bytes.len() % 51 != 0 {
575577
return Err(ParseError::UnexpectedEndOfTaggedFields);
576578
}
577579

578-
let mut route_hops = Vec::<RouteHop>::new();
580+
let mut route_hops = Vec::<RouteHintHop>::new();
579581

580582
let mut bytes = bytes.as_slice();
581583
while !bytes.is_empty() {
@@ -585,18 +587,22 @@ impl FromBase32 for Route {
585587
let mut channel_id: [u8; 8] = Default::default();
586588
channel_id.copy_from_slice(&hop_bytes[33..41]);
587589

588-
let hop = RouteHop {
589-
pubkey: PublicKey::from_slice(&hop_bytes[0..33])?,
590-
short_channel_id: channel_id,
591-
fee_base_msat: parse_int_be(&hop_bytes[41..45], 256).expect("slice too big?"),
592-
fee_proportional_millionths: parse_int_be(&hop_bytes[45..49], 256).expect("slice too big?"),
593-
cltv_expiry_delta: parse_int_be(&hop_bytes[49..51], 256).expect("slice too big?")
590+
let hop = RouteHintHop {
591+
src_node_id: PublicKey::from_slice(&hop_bytes[0..33])?,
592+
short_channel_id: parse_int_be(&channel_id, 256).expect("short chan ID slice too big?"),
593+
fees: RoutingFees {
594+
base_msat: parse_int_be(&hop_bytes[41..45], 256).expect("slice too big?"),
595+
proportional_millionths: parse_int_be(&hop_bytes[45..49], 256).expect("slice too big?"),
596+
},
597+
cltv_expiry_delta: parse_int_be(&hop_bytes[49..51], 256).expect("slice too big?"),
598+
htlc_minimum_msat: None,
599+
htlc_maximum_msat: None,
594600
};
595601

596602
route_hops.push(hop);
597603
}
598604

599-
Ok(Route(route_hops))
605+
Ok(RouteHint(route_hops))
600606
}
601607
}
602608

@@ -931,47 +937,57 @@ mod test {
931937

932938
#[test]
933939
fn test_parse_route() {
934-
use RouteHop;
935-
use ::Route;
940+
use lightning::routing::network_graph::RoutingFees;
941+
use lightning::routing::router::RouteHintHop;
942+
use ::RouteHint;
936943
use bech32::FromBase32;
944+
use de::parse_int_be;
937945

938946
let input = from_bech32(
939947
"q20q82gphp2nflc7jtzrcazrra7wwgzxqc8u7754cdlpfrmccae92qgzqvzq2ps8pqqqqqqpqqqqq9qqqvpeuqa\
940948
fqxu92d8lr6fvg0r5gv0heeeqgcrqlnm6jhphu9y00rrhy4grqszsvpcgpy9qqqqqqgqqqqq7qqzq".as_bytes()
941949
);
942950

943-
let mut expected = Vec::<RouteHop>::new();
944-
expected.push(RouteHop {
945-
pubkey: PublicKey::from_slice(
951+
let mut expected = Vec::<RouteHintHop>::new();
952+
expected.push(RouteHintHop {
953+
src_node_id: PublicKey::from_slice(
946954
&[
947955
0x02u8, 0x9e, 0x03, 0xa9, 0x01, 0xb8, 0x55, 0x34, 0xff, 0x1e, 0x92, 0xc4, 0x3c,
948956
0x74, 0x43, 0x1f, 0x7c, 0xe7, 0x20, 0x46, 0x06, 0x0f, 0xcf, 0x7a, 0x95, 0xc3,
949957
0x7e, 0x14, 0x8f, 0x78, 0xc7, 0x72, 0x55
950958
][..]
951959
).unwrap(),
952-
short_channel_id: [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08],
953-
fee_base_msat: 1,
954-
fee_proportional_millionths: 20,
955-
cltv_expiry_delta: 3
960+
short_channel_id: parse_int_be(&[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08], 256).expect("short chan ID slice too big?"),
961+
fees: RoutingFees {
962+
base_msat: 1,
963+
proportional_millionths: 20,
964+
},
965+
cltv_expiry_delta: 3,
966+
htlc_minimum_msat: None,
967+
htlc_maximum_msat: None
956968
});
957-
expected.push(RouteHop {
958-
pubkey: PublicKey::from_slice(
969+
expected.push(RouteHintHop {
970+
src_node_id: PublicKey::from_slice(
959971
&[
960972
0x03u8, 0x9e, 0x03, 0xa9, 0x01, 0xb8, 0x55, 0x34, 0xff, 0x1e, 0x92, 0xc4, 0x3c,
961973
0x74, 0x43, 0x1f, 0x7c, 0xe7, 0x20, 0x46, 0x06, 0x0f, 0xcf, 0x7a, 0x95, 0xc3,
962974
0x7e, 0x14, 0x8f, 0x78, 0xc7, 0x72, 0x55
963975
][..]
964976
).unwrap(),
965-
short_channel_id: [0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a],
966-
fee_base_msat: 2,
967-
fee_proportional_millionths: 30,
968-
cltv_expiry_delta: 4
977+
short_channel_id: parse_int_be(&[0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a], 256).expect("short chan ID slice too big?"),
978+
fees: RoutingFees {
979+
base_msat: 2,
980+
proportional_millionths: 30,
981+
},
982+
cltv_expiry_delta: 4,
983+
htlc_minimum_msat: None,
984+
htlc_maximum_msat: None
969985
});
970986

971-
assert_eq!(Route::from_base32(&input), Ok(Route(expected)));
987+
assert_eq!(RouteHint::from_base32(&input), Ok(RouteHint(expected)));
972988

973989
assert_eq!(
974-
Route::from_base32(&[u5::try_from_u8(0).unwrap(); 40][..]),
990+
RouteHint::from_base32(&[u5::try_from_u8(0).unwrap(); 40][..]),
975991
Err(ParseError::UnexpectedEndOfTaggedFields)
976992
);
977993
}

0 commit comments

Comments
 (0)