From: Yuntai Kyong Date: Sun, 14 Oct 2018 13:32:58 +0000 (+0900) Subject: Add channel_update_timestamp to RouteHop X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=599d750c6a6e60766e2a3d27cb8ec4dc3e4c0963;p=rust-lightning Add channel_update_timestamp to RouteHop to compare it agains the timestamp of channel_update coming with onion failure message --- diff --git a/fuzz/fuzz_targets/router_target.rs b/fuzz/fuzz_targets/router_target.rs index f7b373cdb..975cfe1ec 100644 --- a/fuzz/fuzz_targets/router_target.rs +++ b/fuzz/fuzz_targets/router_target.rs @@ -223,6 +223,7 @@ pub fn do_test(data: &[u8]) { fee_proportional_millionths: slice_to_be32(get_slice!(4)), cltv_expiry_delta: slice_to_be16(get_slice!(2)), htlc_minimum_msat: slice_to_be64(get_slice!(8)), + last_update: 0, }); } &last_hops_vec[..] diff --git a/src/ln/channelmanager.rs b/src/ln/channelmanager.rs index 806d056dd..1bcf69b00 100644 --- a/src/ln/channelmanager.rs +++ b/src/ln/channelmanager.rs @@ -2416,23 +2416,23 @@ mod tests { hops: vec!( RouteHop { pubkey: PublicKey::from_slice(&secp_ctx, &hex::decode("02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619").unwrap()[..]).unwrap(), - short_channel_id: 0, fee_msat: 0, cltv_expiry_delta: 0 // Test vectors are garbage and not generateble from a RouteHop, we fill in payloads manually + short_channel_id: 0, fee_msat: 0, cltv_expiry_delta: 0, channel_update_timestamp: 0 // Test vectors are garbage and not generateble from a RouteHop, we fill in payloads manually }, RouteHop { pubkey: PublicKey::from_slice(&secp_ctx, &hex::decode("0324653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c").unwrap()[..]).unwrap(), - short_channel_id: 0, fee_msat: 0, cltv_expiry_delta: 0 // Test vectors are garbage and not generateble from a RouteHop, we fill in payloads manually + short_channel_id: 0, fee_msat: 0, cltv_expiry_delta: 0, channel_update_timestamp: 0 // Test vectors are garbage and not generateble from a RouteHop, we fill in payloads manually }, RouteHop { pubkey: PublicKey::from_slice(&secp_ctx, &hex::decode("027f31ebc5462c1fdce1b737ecff52d37d75dea43ce11c74d25aa297165faa2007").unwrap()[..]).unwrap(), - short_channel_id: 0, fee_msat: 0, cltv_expiry_delta: 0 // Test vectors are garbage and not generateble from a RouteHop, we fill in payloads manually + short_channel_id: 0, fee_msat: 0, cltv_expiry_delta: 0, channel_update_timestamp: 0 // Test vectors are garbage and not generateble from a RouteHop, we fill in payloads manually }, RouteHop { pubkey: PublicKey::from_slice(&secp_ctx, &hex::decode("032c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991").unwrap()[..]).unwrap(), - short_channel_id: 0, fee_msat: 0, cltv_expiry_delta: 0 // Test vectors are garbage and not generateble from a RouteHop, we fill in payloads manually + short_channel_id: 0, fee_msat: 0, cltv_expiry_delta: 0, channel_update_timestamp: 0 // Test vectors are garbage and not generateble from a RouteHop, we fill in payloads manually }, RouteHop { pubkey: PublicKey::from_slice(&secp_ctx, &hex::decode("02edabbd16b41c8371b92ef2f04c1185b4f03b6dcd52ba9b78d9d7c89c8f221145").unwrap()[..]).unwrap(), - short_channel_id: 0, fee_msat: 0, cltv_expiry_delta: 0 // Test vectors are garbage and not generateble from a RouteHop, we fill in payloads manually + short_channel_id: 0, fee_msat: 0, cltv_expiry_delta: 0, channel_update_timestamp: 0 // Test vectors are garbage and not generateble from a RouteHop, we fill in payloads manually }, ), }; @@ -3699,19 +3699,22 @@ mod tests { pubkey: nodes[2].node.get_our_node_id(), short_channel_id: chan_2.0.contents.short_channel_id, fee_msat: 0, - cltv_expiry_delta: chan_3.0.contents.cltv_expiry_delta as u32 + cltv_expiry_delta: chan_3.0.contents.cltv_expiry_delta as u32, + channel_update_timestamp: 0, }); hops.push(RouteHop { pubkey: nodes[3].node.get_our_node_id(), short_channel_id: chan_3.0.contents.short_channel_id, fee_msat: 0, - cltv_expiry_delta: chan_4.1.contents.cltv_expiry_delta as u32 + cltv_expiry_delta: chan_4.1.contents.cltv_expiry_delta as u32, + channel_update_timestamp: 0, }); hops.push(RouteHop { pubkey: nodes[1].node.get_our_node_id(), short_channel_id: chan_4.0.contents.short_channel_id, fee_msat: 1000000, cltv_expiry_delta: TEST_FINAL_CLTV, + channel_update_timestamp: 0, }); hops[1].fee_msat = chan_4.1.contents.fee_base_msat as u64 + chan_4.1.contents.fee_proportional_millionths as u64 * hops[2].fee_msat as u64 / 1000000; hops[0].fee_msat = chan_3.0.contents.fee_base_msat as u64 + chan_3.0.contents.fee_proportional_millionths as u64 * hops[1].fee_msat as u64 / 1000000; @@ -3722,19 +3725,22 @@ mod tests { pubkey: nodes[3].node.get_our_node_id(), short_channel_id: chan_4.0.contents.short_channel_id, fee_msat: 0, - cltv_expiry_delta: chan_3.1.contents.cltv_expiry_delta as u32 + cltv_expiry_delta: chan_3.1.contents.cltv_expiry_delta as u32, + channel_update_timestamp: 0, }); hops.push(RouteHop { pubkey: nodes[2].node.get_our_node_id(), short_channel_id: chan_3.0.contents.short_channel_id, fee_msat: 0, - cltv_expiry_delta: chan_2.1.contents.cltv_expiry_delta as u32 + cltv_expiry_delta: chan_2.1.contents.cltv_expiry_delta as u32, + channel_update_timestamp: 0, }); hops.push(RouteHop { pubkey: nodes[1].node.get_our_node_id(), short_channel_id: chan_2.0.contents.short_channel_id, fee_msat: 1000000, cltv_expiry_delta: TEST_FINAL_CLTV, + channel_update_timestamp: 0, }); hops[1].fee_msat = chan_2.1.contents.fee_base_msat as u64 + chan_2.1.contents.fee_proportional_millionths as u64 * hops[2].fee_msat as u64 / 1000000; hops[0].fee_msat = chan_3.1.contents.fee_base_msat as u64 + chan_3.1.contents.fee_proportional_millionths as u64 * hops[1].fee_msat as u64 / 1000000; diff --git a/src/ln/router.rs b/src/ln/router.rs index 33037c12a..4d256a12c 100644 --- a/src/ln/router.rs +++ b/src/ln/router.rs @@ -36,6 +36,9 @@ pub struct RouteHop { /// The CLTV delta added for this hop. For the last hop, this should be the full CLTV value /// expected at the destination, in excess of the current block height. pub cltv_expiry_delta: u32, + /// channel update timestamp of the outbound channel of each hop when this route is + /// calculated + pub channel_update_timestamp: u32, } /// A route from us through the network to a destination @@ -168,6 +171,8 @@ impl NetworkMap { pub struct RouteHint { /// The node_id of the non-target end of the route pub src_node_id: PublicKey, + /// last update + pub last_update: u32, /// The short_channel_id of this channel pub short_channel_id: u64, /// The static msat-denominated fee which must be paid to use this channel @@ -455,6 +460,7 @@ impl cmp::PartialOrd for RouteGraphNode { struct DummyDirectionalChannelInfo { src_node_id: PublicKey, + last_update: u32, cltv_expiry_delta: u32, htlc_minimum_msat: u64, fee_base_msat: u32, @@ -565,6 +571,7 @@ impl Router { let dummy_directional_info = DummyDirectionalChannelInfo { // used for first_hops routes src_node_id: network.our_node_id.clone(), + last_update: 0, cltv_expiry_delta: 0, htlc_minimum_msat: 0, fee_base_msat: 0, @@ -585,6 +592,7 @@ impl Router { short_channel_id, fee_msat: final_value_msat, cltv_expiry_delta: final_cltv, + channel_update_timestamp: 0, //TODO: related to local channel_update_handling? }], }); } @@ -618,6 +626,7 @@ impl Router { short_channel_id: 0, fee_msat: 0, cltv_expiry_delta: 0, + channel_update_timestamp: $directional_info.last_update, }) }); if $directional_info.src_node_id != network.our_node_id { @@ -644,6 +653,7 @@ impl Router { short_channel_id: $chan_id.clone(), fee_msat: new_fee, // This field is ignored on the last-hop anyway cltv_expiry_delta: $directional_info.cltv_expiry_delta as u32, + channel_update_timestamp: $directional_info.last_update, } } } @@ -1166,6 +1176,7 @@ mod tests { let mut last_hops = vec!(RouteHint { src_node_id: node4.clone(), short_channel_id: 8, + last_update: 0, fee_base_msat: 0, fee_proportional_millionths: 0, cltv_expiry_delta: (8 << 8) | 1, @@ -1173,6 +1184,7 @@ mod tests { }, RouteHint { src_node_id: node5.clone(), short_channel_id: 9, + last_update: 0, fee_base_msat: 1001, fee_proportional_millionths: 0, cltv_expiry_delta: (9 << 8) | 1, @@ -1180,6 +1192,7 @@ mod tests { }, RouteHint { src_node_id: node6.clone(), short_channel_id: 10, + last_update: 0, fee_base_msat: 0, fee_proportional_millionths: 0, cltv_expiry_delta: (10 << 8) | 1,