@@ -114,9 +114,13 @@ impl LocalFeatures {
114
114
}
115
115
116
116
/// Tracks globalfeatures which are in init messages and routing announcements
117
- #[ derive( Clone , PartialEq ) ]
117
+ #[ derive( Clone , PartialEq , Debug ) ]
118
118
pub struct GlobalFeatures {
119
+ #[ cfg( not( test) ) ]
119
120
flags : Vec < u8 > ,
121
+ // Used to test encoding of diverse msgs
122
+ #[ cfg( test) ]
123
+ pub flags : Vec < u8 >
120
124
}
121
125
122
126
impl GlobalFeatures {
@@ -326,7 +330,7 @@ pub struct ChannelReestablish {
326
330
}
327
331
328
332
/// An announcement_signatures message to be sent or received from a peer
329
- #[ derive( Clone ) ]
333
+ #[ derive( PartialEq , Clone , Debug ) ]
330
334
pub struct AnnouncementSignatures {
331
335
pub ( crate ) channel_id : [ u8 ; 32 ] ,
332
336
pub ( crate ) short_channel_id : u64 ,
@@ -335,7 +339,7 @@ pub struct AnnouncementSignatures {
335
339
}
336
340
337
341
/// An address which can be used to connect to a remote peer
338
- #[ derive( PartialEq , Clone ) ]
342
+ #[ derive( Clone , PartialEq , Debug ) ]
339
343
pub enum NetAddress {
340
344
/// An IPv4 address/port on which the peer is listening.
341
345
IPv4 {
@@ -458,9 +462,9 @@ impl<R: ::std::io::Read> Readable<R> for Result<NetAddress, u8> {
458
462
}
459
463
}
460
464
461
- #[ derive( PartialEq , Clone ) ]
462
465
// Only exposed as broadcast of node_announcement should be filtered by node_id
463
466
/// The unsigned part of a node_announcement
467
+ #[ derive( PartialEq , Clone , Debug ) ]
464
468
pub struct UnsignedNodeAnnouncement {
465
469
pub ( crate ) features : GlobalFeatures ,
466
470
pub ( crate ) timestamp : u32 ,
@@ -484,7 +488,7 @@ pub struct NodeAnnouncement {
484
488
485
489
// Only exposed as broadcast of channel_announcement should be filtered by node_id
486
490
/// The unsigned part of a channel_announcement
487
- #[ derive( PartialEq , Clone ) ]
491
+ #[ derive( PartialEq , Clone , Debug ) ]
488
492
pub struct UnsignedChannelAnnouncement {
489
493
pub ( crate ) features : GlobalFeatures ,
490
494
pub ( crate ) chain_hash : Sha256dHash ,
@@ -498,7 +502,7 @@ pub struct UnsignedChannelAnnouncement {
498
502
pub ( crate ) excess_data : Vec < u8 > ,
499
503
}
500
504
/// A channel_announcement message to be sent or received from a peer
501
- #[ derive( PartialEq , Clone ) ]
505
+ #[ derive( PartialEq , Clone , Debug ) ]
502
506
pub struct ChannelAnnouncement {
503
507
pub ( crate ) node_signature_1 : Signature ,
504
508
pub ( crate ) node_signature_2 : Signature ,
@@ -507,7 +511,7 @@ pub struct ChannelAnnouncement {
507
511
pub ( crate ) contents : UnsignedChannelAnnouncement ,
508
512
}
509
513
510
- #[ derive( PartialEq , Clone ) ]
514
+ #[ derive( PartialEq , Clone , Debug ) ]
511
515
pub ( crate ) struct UnsignedChannelUpdate {
512
516
pub ( crate ) chain_hash : Sha256dHash ,
513
517
pub ( crate ) short_channel_id : u64 ,
@@ -520,7 +524,7 @@ pub(crate) struct UnsignedChannelUpdate {
520
524
pub ( crate ) excess_data : Vec < u8 > ,
521
525
}
522
526
/// A channel_update message to be sent or received from a peer
523
- #[ derive( PartialEq , Clone ) ]
527
+ #[ derive( PartialEq , Clone , Debug ) ]
524
528
pub struct ChannelUpdate {
525
529
pub ( crate ) signature : Signature ,
526
530
pub ( crate ) contents : UnsignedChannelUpdate ,
@@ -1388,10 +1392,13 @@ impl_writeable_len_match!(NodeAnnouncement, {
1388
1392
mod tests {
1389
1393
use hex;
1390
1394
use ln:: msgs;
1391
- use ln:: msgs:: OptionalField ;
1395
+ use ln:: msgs:: { GlobalFeatures , OptionalField } ;
1392
1396
use util:: ser:: Writeable ;
1397
+
1398
+ use bitcoin:: util:: hash:: Sha256dHash ;
1399
+
1393
1400
use secp256k1:: key:: { PublicKey , SecretKey } ;
1394
- use secp256k1:: Secp256k1 ;
1401
+ use secp256k1:: { Secp256k1 , Message } ;
1395
1402
1396
1403
#[ test]
1397
1404
fn encoding_channel_reestablish_no_secret ( ) {
@@ -1429,4 +1436,257 @@ mod tests {
1429
1436
vec![ 4 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 5 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 6 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 7 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 3 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 4 , 9 , 9 , 9 , 9 , 9 , 9 , 9 , 9 , 9 , 9 , 9 , 9 , 9 , 9 , 9 , 9 , 9 , 9 , 9 , 9 , 9 , 9 , 9 , 9 , 9 , 9 , 9 , 9 , 9 , 9 , 9 , 9 , 3 , 27 , 132 , 197 , 86 , 123 , 18 , 100 , 64 , 153 , 93 , 62 , 213 , 170 , 186 , 5 , 101 , 215 , 30 , 24 , 52 , 96 , 72 , 25 , 255 , 156 , 23 , 245 , 233 , 213 , 221 , 7 , 143 ]
1430
1437
) ;
1431
1438
}
1439
+
1440
+ macro_rules! get_keys_from {
1441
+ ( $slice: expr, $secp_ctx: expr) => {
1442
+ {
1443
+ let privkey = SecretKey :: from_slice( & hex:: decode( $slice) . unwrap( ) [ ..] ) . unwrap( ) ;
1444
+ let pubkey = PublicKey :: from_secret_key( & $secp_ctx, & privkey) ;
1445
+ ( privkey, pubkey)
1446
+ }
1447
+ }
1448
+ }
1449
+
1450
+ macro_rules! get_sig_on {
1451
+ ( $privkey: expr, $ctx: expr, $string: expr) => {
1452
+ {
1453
+ let sighash = Message :: from_slice( & $string. into_bytes( ) [ ..] ) . unwrap( ) ;
1454
+ $ctx. sign( & sighash, & $privkey)
1455
+ }
1456
+ }
1457
+ }
1458
+
1459
+ #[ test]
1460
+ fn encoding_announcement_signatures ( ) {
1461
+ let secp_ctx = Secp256k1 :: new ( ) ;
1462
+ let ( privkey, _) = get_keys_from ! ( "0101010101010101010101010101010101010101010101010101010101010101" , secp_ctx) ;
1463
+ let sig_1 = get_sig_on ! ( privkey, secp_ctx, String :: from( "01010101010101010101010101010101" ) ) ;
1464
+ let sig_2 = get_sig_on ! ( privkey, secp_ctx, String :: from( "02020202020202020202020202020202" ) ) ;
1465
+ let announcement_signatures = msgs:: AnnouncementSignatures {
1466
+ channel_id : [ 4 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 5 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 6 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 7 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ,
1467
+ short_channel_id : 2316138423780173 ,
1468
+ node_signature : sig_1,
1469
+ bitcoin_signature : sig_2,
1470
+ } ;
1471
+
1472
+ let encoded_value = announcement_signatures. encode ( ) ;
1473
+ assert_eq ! ( encoded_value, hex:: decode( "040000000000000005000000000000000600000000000000070000000000000000083a840000034dd977cb9b53d93a6ff64bb5f1e158b4094b66e798fb12911168a3ccdf80a83096340a6a95da0ae8d9f776528eecdbb747eb6b545495a4319ed5378e35b21e073acf9953cef4700860f5967838eba2bae89288ad188ebf8b20bf995c3ea53a26df1876d0a3a0e13172ba286a673140190c02ba9da60a2e43a745188c8a83c7f3ef" ) . unwrap( ) ) ;
1474
+ }
1475
+
1476
+ fn do_encoding_channel_announcement ( unknown_features_bits : bool , non_bitcoin_chain_hash : bool , excess_data : bool ) {
1477
+ let secp_ctx = Secp256k1 :: new ( ) ;
1478
+ let ( privkey_1, pubkey_1) = get_keys_from ! ( "0101010101010101010101010101010101010101010101010101010101010101" , secp_ctx) ;
1479
+ let ( privkey_2, pubkey_2) = get_keys_from ! ( "0202020202020202020202020202020202020202020202020202020202020202" , secp_ctx) ;
1480
+ let ( privkey_3, pubkey_3) = get_keys_from ! ( "0303030303030303030303030303030303030303030303030303030303030303" , secp_ctx) ;
1481
+ let ( privkey_4, pubkey_4) = get_keys_from ! ( "0404040404040404040404040404040404040404040404040404040404040404" , secp_ctx) ;
1482
+ let sig_1 = get_sig_on ! ( privkey_1, secp_ctx, String :: from( "01010101010101010101010101010101" ) ) ;
1483
+ let sig_2 = get_sig_on ! ( privkey_2, secp_ctx, String :: from( "01010101010101010101010101010101" ) ) ;
1484
+ let sig_3 = get_sig_on ! ( privkey_3, secp_ctx, String :: from( "01010101010101010101010101010101" ) ) ;
1485
+ let sig_4 = get_sig_on ! ( privkey_4, secp_ctx, String :: from( "01010101010101010101010101010101" ) ) ;
1486
+ let mut features = GlobalFeatures :: new ( ) ;
1487
+ if unknown_features_bits {
1488
+ features. flags = vec ! [ 0xFF , 0xFF ] ;
1489
+ }
1490
+ let unsigned_channel_announcement = msgs:: UnsignedChannelAnnouncement {
1491
+ features,
1492
+ chain_hash : if !non_bitcoin_chain_hash { Sha256dHash :: from_hex ( "6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000" ) . unwrap ( ) } else { Sha256dHash :: from_hex ( "000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943" ) . unwrap ( ) } ,
1493
+ short_channel_id : 2316138423780173 ,
1494
+ node_id_1 : pubkey_1,
1495
+ node_id_2 : pubkey_2,
1496
+ bitcoin_key_1 : pubkey_3,
1497
+ bitcoin_key_2 : pubkey_4,
1498
+ excess_data : if excess_data { vec ! [ 10 , 0 , 0 , 20 , 0 , 0 , 30 , 0 , 0 , 40 ] } else { Vec :: new ( ) } ,
1499
+ } ;
1500
+ let channel_announcement = msgs:: ChannelAnnouncement {
1501
+ node_signature_1 : sig_1,
1502
+ node_signature_2 : sig_2,
1503
+ bitcoin_signature_1 : sig_3,
1504
+ bitcoin_signature_2 : sig_4,
1505
+ contents : unsigned_channel_announcement,
1506
+ } ;
1507
+ let encoded_value = channel_announcement. encode ( ) ;
1508
+ let mut target_value = hex:: decode ( "d977cb9b53d93a6ff64bb5f1e158b4094b66e798fb12911168a3ccdf80a83096340a6a95da0ae8d9f776528eecdbb747eb6b545495a4319ed5378e35b21e073a1735b6a427e80d5fe7cd90a2f4ee08dc9c27cda7c35a4172e5d85b12c49d4232537e98f9b1f3c5e6989a8b9644e90e8918127680dbd0d4043510840fc0f1e11a216c280b5395a2546e7e4b2663e04f811622f15a4f91e83aa2e92ba2a573c139142c54ae63072a1ec1ee7dc0c04bde5c847806172aa05c92c22ae8e308d1d2692b12cc195ce0a2d1bda6a88befa19fa07f51caa75ce83837f28965600b8aacab0855ffb0e741ec5f7c41421e9829a9d48611c8c831f71be5ea73e66594977ffd" ) . unwrap ( ) ;
1509
+ if unknown_features_bits {
1510
+ target_value. append ( & mut hex:: decode ( "0002ffff" ) . unwrap ( ) ) ;
1511
+ } else {
1512
+ target_value. append ( & mut hex:: decode ( "0000" ) . unwrap ( ) ) ;
1513
+ }
1514
+ if non_bitcoin_chain_hash {
1515
+ target_value. append ( & mut hex:: decode ( "43497fd7f826957108f4a30fd9cec3aeba79972084e90ead01ea330900000000" ) . unwrap ( ) ) ;
1516
+ } else {
1517
+ target_value. append ( & mut hex:: decode ( "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f" ) . unwrap ( ) ) ;
1518
+ }
1519
+ target_value. append ( & mut hex:: decode ( "00083a840000034d031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f024d4b6cd1361032ca9bd2aeb9d900aa4d45d9ead80ac9423374c451a7254d076602531fe6068134503d2723133227c867ac8fa6c83c537e9a44c3c5bdbdcb1fe33703462779ad4aad39514614751a71085f2f10e1c7a593e4e030efb5b8721ce55b0b" ) . unwrap ( ) ) ;
1520
+ if excess_data {
1521
+ target_value. append ( & mut hex:: decode ( "0a00001400001e000028" ) . unwrap ( ) ) ;
1522
+ }
1523
+ assert_eq ! ( encoded_value, target_value) ;
1524
+ }
1525
+
1526
+ #[ test]
1527
+ fn encoding_channel_announcement ( ) {
1528
+ do_encoding_channel_announcement ( false , false , false ) ;
1529
+ do_encoding_channel_announcement ( true , false , false ) ;
1530
+ do_encoding_channel_announcement ( true , true , false ) ;
1531
+ do_encoding_channel_announcement ( true , true , true ) ;
1532
+ do_encoding_channel_announcement ( false , true , true ) ;
1533
+ do_encoding_channel_announcement ( false , false , true ) ;
1534
+ do_encoding_channel_announcement ( false , true , false ) ;
1535
+ do_encoding_channel_announcement ( true , false , true ) ;
1536
+ }
1537
+
1538
+ fn do_encoding_node_announcement ( unknown_features_bits : bool , ipv4 : bool , ipv6 : bool , onionv2 : bool , onionv3 : bool , excess_address_data : bool , excess_data : bool ) {
1539
+ let secp_ctx = Secp256k1 :: new ( ) ;
1540
+ let ( privkey_1, pubkey_1) = get_keys_from ! ( "0101010101010101010101010101010101010101010101010101010101010101" , secp_ctx) ;
1541
+ let sig_1 = get_sig_on ! ( privkey_1, secp_ctx, String :: from( "01010101010101010101010101010101" ) ) ;
1542
+ let mut features = GlobalFeatures :: new ( ) ;
1543
+ if unknown_features_bits {
1544
+ features. flags = vec ! [ 0xFF , 0xFF ] ;
1545
+ }
1546
+ let mut addresses = Vec :: new ( ) ;
1547
+ if ipv4 {
1548
+ addresses. push ( msgs:: NetAddress :: IPv4 {
1549
+ addr : [ 255 , 254 , 253 , 252 ] ,
1550
+ port : 9735
1551
+ } ) ;
1552
+ }
1553
+ if ipv6 {
1554
+ addresses. push ( msgs:: NetAddress :: IPv6 {
1555
+ addr : [ 255 , 254 , 253 , 252 , 251 , 250 , 249 , 248 , 247 , 246 , 245 , 244 , 243 , 242 , 241 , 240 ] ,
1556
+ port : 9735
1557
+ } ) ;
1558
+ }
1559
+ if onionv2 {
1560
+ addresses. push ( msgs:: NetAddress :: OnionV2 {
1561
+ addr : [ 255 , 254 , 253 , 252 , 251 , 250 , 249 , 248 , 247 , 246 ] ,
1562
+ port : 9735
1563
+ } ) ;
1564
+ }
1565
+ if onionv3 {
1566
+ addresses. push ( msgs:: NetAddress :: OnionV3 {
1567
+ ed25519_pubkey : [ 255 , 254 , 253 , 252 , 251 , 250 , 249 , 248 , 247 , 246 , 245 , 244 , 243 , 242 , 241 , 240 , 239 , 238 , 237 , 236 , 235 , 234 , 233 , 232 , 231 , 230 , 229 , 228 , 227 , 226 , 225 , 224 ] ,
1568
+ checksum : 32 ,
1569
+ version : 16 ,
1570
+ port : 9735
1571
+ } ) ;
1572
+ }
1573
+ let mut addr_len = 0 ;
1574
+ for addr in & addresses {
1575
+ addr_len += addr. len ( ) + 1 ;
1576
+ }
1577
+ let unsigned_node_announcement = msgs:: UnsignedNodeAnnouncement {
1578
+ features,
1579
+ timestamp : 20190119 ,
1580
+ node_id : pubkey_1,
1581
+ rgb : [ 32 ; 3 ] ,
1582
+ alias : [ 16 ; 32 ] ,
1583
+ addresses,
1584
+ excess_address_data : if excess_address_data { vec ! [ 33 , 108 , 40 , 11 , 83 , 149 , 162 , 84 , 110 , 126 , 75 , 38 , 99 , 224 , 79 , 129 , 22 , 34 , 241 , 90 , 79 , 146 , 232 , 58 , 162 , 233 , 43 , 162 , 165 , 115 , 193 , 57 , 20 , 44 , 84 , 174 , 99 , 7 , 42 , 30 , 193 , 238 , 125 , 192 , 192 , 75 , 222 , 92 , 132 , 120 , 6 , 23 , 42 , 160 , 92 , 146 , 194 , 42 , 232 , 227 , 8 , 209 , 210 , 105 ] } else { Vec :: new ( ) } ,
1585
+ excess_data : if excess_data { vec ! [ 59 , 18 , 204 , 25 , 92 , 224 , 162 , 209 , 189 , 166 , 168 , 139 , 239 , 161 , 159 , 160 , 127 , 81 , 202 , 167 , 92 , 232 , 56 , 55 , 242 , 137 , 101 , 96 , 11 , 138 , 172 , 171 , 8 , 85 , 255 , 176 , 231 , 65 , 236 , 95 , 124 , 65 , 66 , 30 , 152 , 41 , 169 , 212 , 134 , 17 , 200 , 200 , 49 , 247 , 27 , 229 , 234 , 115 , 230 , 101 , 148 , 151 , 127 , 253 ] } else { Vec :: new ( ) } ,
1586
+ } ;
1587
+ addr_len += unsigned_node_announcement. excess_address_data . len ( ) as u16 ;
1588
+ let node_announcement = msgs:: NodeAnnouncement {
1589
+ signature : sig_1,
1590
+ contents : unsigned_node_announcement,
1591
+ } ;
1592
+ let encoded_value = node_announcement. encode ( ) ;
1593
+ let mut target_value = hex:: decode ( "d977cb9b53d93a6ff64bb5f1e158b4094b66e798fb12911168a3ccdf80a83096340a6a95da0ae8d9f776528eecdbb747eb6b545495a4319ed5378e35b21e073a" ) . unwrap ( ) ;
1594
+ if unknown_features_bits {
1595
+ target_value. append ( & mut hex:: decode ( "0002ffff" ) . unwrap ( ) ) ;
1596
+ } else {
1597
+ target_value. append ( & mut hex:: decode ( "0000" ) . unwrap ( ) ) ;
1598
+ }
1599
+ target_value. append ( & mut hex:: decode ( "013413a7031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f2020201010101010101010101010101010101010101010101010101010101010101010" ) . unwrap ( ) ) ;
1600
+ target_value. append ( & mut vec ! [ ( addr_len >> 8 ) as u8 , addr_len as u8 ] ) ;
1601
+ if ipv4 {
1602
+ target_value. append ( & mut hex:: decode ( "01fffefdfc2607" ) . unwrap ( ) ) ;
1603
+ }
1604
+ if ipv6 {
1605
+ target_value. append ( & mut hex:: decode ( "02fffefdfcfbfaf9f8f7f6f5f4f3f2f1f02607" ) . unwrap ( ) ) ;
1606
+ }
1607
+ if onionv2 {
1608
+ target_value. append ( & mut hex:: decode ( "03fffefdfcfbfaf9f8f7f62607" ) . unwrap ( ) ) ;
1609
+ }
1610
+ if onionv3 {
1611
+ target_value. append ( & mut hex:: decode ( "04fffefdfcfbfaf9f8f7f6f5f4f3f2f1f0efeeedecebeae9e8e7e6e5e4e3e2e1e00020102607" ) . unwrap ( ) ) ;
1612
+ }
1613
+ if excess_address_data {
1614
+ target_value. append ( & mut hex:: decode ( "216c280b5395a2546e7e4b2663e04f811622f15a4f92e83aa2e92ba2a573c139142c54ae63072a1ec1ee7dc0c04bde5c847806172aa05c92c22ae8e308d1d269" ) . unwrap ( ) ) ;
1615
+ }
1616
+ if excess_data {
1617
+ target_value. append ( & mut hex:: decode ( "3b12cc195ce0a2d1bda6a88befa19fa07f51caa75ce83837f28965600b8aacab0855ffb0e741ec5f7c41421e9829a9d48611c8c831f71be5ea73e66594977ffd" ) . unwrap ( ) ) ;
1618
+ }
1619
+ assert_eq ! ( encoded_value, target_value) ;
1620
+ }
1621
+
1622
+ #[ test]
1623
+ fn encoding_node_announcement ( ) {
1624
+ do_encoding_node_announcement ( true , true , true , true , true , true , true ) ;
1625
+ do_encoding_node_announcement ( false , false , false , false , false , false , false ) ;
1626
+ do_encoding_node_announcement ( false , true , false , false , false , false , false ) ;
1627
+ do_encoding_node_announcement ( false , false , true , false , false , false , false ) ;
1628
+ do_encoding_node_announcement ( false , false , false , true , false , false , false ) ;
1629
+ do_encoding_node_announcement ( false , false , false , false , true , false , false ) ;
1630
+ do_encoding_node_announcement ( false , false , false , false , false , true , false ) ;
1631
+ do_encoding_node_announcement ( false , true , false , true , false , true , false ) ;
1632
+ do_encoding_node_announcement ( false , false , true , false , true , false , false ) ;
1633
+ }
1634
+
1635
+ fn do_encoding_channel_update ( non_bitcoin_chain_hash : bool , direction : bool , disable : bool , htlc_maximum_msat : bool ) {
1636
+ let secp_ctx = Secp256k1 :: new ( ) ;
1637
+ let ( privkey_1, _) = get_keys_from ! ( "0101010101010101010101010101010101010101010101010101010101010101" , secp_ctx) ;
1638
+ let sig_1 = get_sig_on ! ( privkey_1, secp_ctx, String :: from( "01010101010101010101010101010101" ) ) ;
1639
+ let unsigned_channel_update = msgs:: UnsignedChannelUpdate {
1640
+ chain_hash : if !non_bitcoin_chain_hash { Sha256dHash :: from_hex ( "6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000" ) . unwrap ( ) } else { Sha256dHash :: from_hex ( "000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943" ) . unwrap ( ) } ,
1641
+ short_channel_id : 2316138423780173 ,
1642
+ timestamp : 20190119 ,
1643
+ flags : if direction { 1 } else { 0 } | if disable { 1 << 1 } else { 0 } | if htlc_maximum_msat { 1 << 8 } else { 0 } ,
1644
+ cltv_expiry_delta : 144 ,
1645
+ htlc_minimum_msat : 1000000 ,
1646
+ fee_base_msat : 10000 ,
1647
+ fee_proportional_millionths : 20 ,
1648
+ excess_data : if htlc_maximum_msat { vec ! [ 0 , 0 , 0 , 0 , 59 , 154 , 202 , 0 ] } else { Vec :: new ( ) }
1649
+ } ;
1650
+ let channel_update = msgs:: ChannelUpdate {
1651
+ signature : sig_1,
1652
+ contents : unsigned_channel_update
1653
+ } ;
1654
+ let encoded_value = channel_update. encode ( ) ;
1655
+ let mut target_value = hex:: decode ( "d977cb9b53d93a6ff64bb5f1e158b4094b66e798fb12911168a3ccdf80a83096340a6a95da0ae8d9f776528eecdbb747eb6b545495a4319ed5378e35b21e073a" ) . unwrap ( ) ;
1656
+ if non_bitcoin_chain_hash {
1657
+ target_value. append ( & mut hex:: decode ( "43497fd7f826957108f4a30fd9cec3aeba79972084e90ead01ea330900000000" ) . unwrap ( ) ) ;
1658
+ } else {
1659
+ target_value. append ( & mut hex:: decode ( "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f" ) . unwrap ( ) ) ;
1660
+ }
1661
+ target_value. append ( & mut hex:: decode ( "00083a840000034d013413a7" ) . unwrap ( ) ) ;
1662
+ if htlc_maximum_msat {
1663
+ target_value. append ( & mut hex:: decode ( "01" ) . unwrap ( ) ) ;
1664
+ } else {
1665
+ target_value. append ( & mut hex:: decode ( "00" ) . unwrap ( ) ) ;
1666
+ }
1667
+ target_value. append ( & mut hex:: decode ( "00" ) . unwrap ( ) ) ;
1668
+ if direction {
1669
+ let flag = target_value. last_mut ( ) . unwrap ( ) ;
1670
+ * flag = 1 ;
1671
+ }
1672
+ if disable {
1673
+ let flag = target_value. last_mut ( ) . unwrap ( ) ;
1674
+ * flag = * flag | 1 << 1 ;
1675
+ }
1676
+ target_value. append ( & mut hex:: decode ( "009000000000000f42400000271000000014" ) . unwrap ( ) ) ;
1677
+ if htlc_maximum_msat {
1678
+ target_value. append ( & mut hex:: decode ( "000000003b9aca00" ) . unwrap ( ) ) ;
1679
+ }
1680
+ assert_eq ! ( encoded_value, target_value) ;
1681
+ }
1682
+
1683
+ #[ test]
1684
+ fn encoding_channel_update ( ) {
1685
+ do_encoding_channel_update ( false , false , false , false ) ;
1686
+ do_encoding_channel_update ( true , false , false , false ) ;
1687
+ do_encoding_channel_update ( false , true , false , false ) ;
1688
+ do_encoding_channel_update ( false , false , true , false ) ;
1689
+ do_encoding_channel_update ( false , false , false , true ) ;
1690
+ do_encoding_channel_update ( true , true , true , true ) ;
1691
+ }
1432
1692
}
0 commit comments