Flatten OnionHopData struct with the Realm0 struct.
[rust-lightning] / lightning / src / ln / onion_utils.rs
index c8d3bae5fde58c45ef5cd0b708aa1db52be5a48a..1c1105cfcae76dcc0634ad531d2aa73ffb012365 100644 (file)
@@ -121,12 +121,10 @@ pub(super) fn build_onion_payloads(route: &Route, starting_htlc_offset: u32) ->
                let value_msat = if cur_value_msat == 0 { hop.fee_msat } else { cur_value_msat };
                let cltv = if cur_cltv == starting_htlc_offset { hop.cltv_expiry_delta + starting_htlc_offset } else { cur_cltv };
                res.insert(0, msgs::OnionHopData {
-                       realm: 0,
-                       data: msgs::OnionRealm0HopData {
-                               short_channel_id: last_short_channel_id,
-                               amt_to_forward: value_msat,
-                               outgoing_cltv_value: cltv,
-                       },
+                       format: msgs::OnionHopDataFormat::Legacy,
+                       short_channel_id: last_short_channel_id,
+                       amt_to_forward: value_msat,
+                       outgoing_cltv_value: cltv,
                        hmac: [0; 32],
                });
                cur_value_msat += hop.fee_msat;
@@ -425,6 +423,7 @@ pub(super) fn process_onion_failure<T: secp256k1::Signing>(secp_ctx: &Secp256k1<
 #[cfg(test)]
 mod tests {
        use ln::channelmanager::PaymentHash;
+       use ln::features::{ChannelFeatures, NodeFeatures};
        use ln::router::{Route, RouteHop};
        use ln::msgs;
        use util::ser::Writeable;
@@ -444,22 +443,27 @@ mod tests {
                        hops: vec!(
                                        RouteHop {
                                                pubkey: PublicKey::from_slice(&hex::decode("02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619").unwrap()[..]).unwrap(),
+                                               channel_features: ChannelFeatures::empty(), node_features: NodeFeatures::empty(),
                                                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
                                        },
                                        RouteHop {
                                                pubkey: PublicKey::from_slice(&hex::decode("0324653eac434488002cc06bbfb7f10fe18991e35f9fe4302dbea6d2353dc0ab1c").unwrap()[..]).unwrap(),
+                                               channel_features: ChannelFeatures::empty(), node_features: NodeFeatures::empty(),
                                                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
                                        },
                                        RouteHop {
                                                pubkey: PublicKey::from_slice(&hex::decode("027f31ebc5462c1fdce1b737ecff52d37d75dea43ce11c74d25aa297165faa2007").unwrap()[..]).unwrap(),
+                                               channel_features: ChannelFeatures::empty(), node_features: NodeFeatures::empty(),
                                                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
                                        },
                                        RouteHop {
                                                pubkey: PublicKey::from_slice(&hex::decode("032c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991").unwrap()[..]).unwrap(),
+                                               channel_features: ChannelFeatures::empty(), node_features: NodeFeatures::empty(),
                                                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
                                        },
                                        RouteHop {
                                                pubkey: PublicKey::from_slice(&hex::decode("02edabbd16b41c8371b92ef2f04c1185b4f03b6dcd52ba9b78d9d7c89c8f221145").unwrap()[..]).unwrap(),
+                                               channel_features: ChannelFeatures::empty(), node_features: NodeFeatures::empty(),
                                                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
                                        },
                        ),
@@ -510,48 +514,38 @@ mod tests {
                // Test vectors below are flat-out wrong: they claim to set outgoing_cltv_value to non-0 :/
                let payloads = vec!(
                        msgs::OnionHopData {
-                               realm: 0,
-                               data: msgs::OnionRealm0HopData {
-                                       short_channel_id: 0,
-                                       amt_to_forward: 0,
-                                       outgoing_cltv_value: 0,
-                               },
+                               format: msgs::OnionHopDataFormat::Legacy,
+                               short_channel_id: 0,
+                               amt_to_forward: 0,
+                               outgoing_cltv_value: 0,
                                hmac: [0; 32],
                        },
                        msgs::OnionHopData {
-                               realm: 0,
-                               data: msgs::OnionRealm0HopData {
-                                       short_channel_id: 0x0101010101010101,
-                                       amt_to_forward: 0x0100000001,
-                                       outgoing_cltv_value: 0,
-                               },
+                               format: msgs::OnionHopDataFormat::Legacy,
+                               short_channel_id: 0x0101010101010101,
+                               amt_to_forward: 0x0100000001,
+                               outgoing_cltv_value: 0,
                                hmac: [0; 32],
                        },
                        msgs::OnionHopData {
-                               realm: 0,
-                               data: msgs::OnionRealm0HopData {
-                                       short_channel_id: 0x0202020202020202,
-                                       amt_to_forward: 0x0200000002,
-                                       outgoing_cltv_value: 0,
-                               },
+                               format: msgs::OnionHopDataFormat::Legacy,
+                               short_channel_id: 0x0202020202020202,
+                               amt_to_forward: 0x0200000002,
+                               outgoing_cltv_value: 0,
                                hmac: [0; 32],
                        },
                        msgs::OnionHopData {
-                               realm: 0,
-                               data: msgs::OnionRealm0HopData {
-                                       short_channel_id: 0x0303030303030303,
-                                       amt_to_forward: 0x0300000003,
-                                       outgoing_cltv_value: 0,
-                               },
+                               format: msgs::OnionHopDataFormat::Legacy,
+                               short_channel_id: 0x0303030303030303,
+                               amt_to_forward: 0x0300000003,
+                               outgoing_cltv_value: 0,
                                hmac: [0; 32],
                        },
                        msgs::OnionHopData {
-                               realm: 0,
-                               data: msgs::OnionRealm0HopData {
-                                       short_channel_id: 0x0404040404040404,
-                                       amt_to_forward: 0x0400000004,
-                                       outgoing_cltv_value: 0,
-                               },
+                               format: msgs::OnionHopDataFormat::Legacy,
+                               short_channel_id: 0x0404040404040404,
+                               amt_to_forward: 0x0400000004,
+                               outgoing_cltv_value: 0,
                                hmac: [0; 32],
                        },
                );