@@ -1286,4 +1286,108 @@ mod tests {
12861286 assert_eq ! ( log_entries. get( & ( "lightning::ln::peer_handler" . to_string( ) , "Handling UpdateHTLCs event in peer_handler for node 030000000000000000000000000000000000000000000000000000000000000002 with 0 adds, 0 fulfills, 1 fails for channel 3d00000000000000000000000000000000000000000000000000000000000000" . to_string( ) ) ) , Some ( & 2 ) ) ; // 9
12871287 assert_eq ! ( log_entries. get( & ( "lightning::chain::channelmonitor" . to_string( ) , "Input spending counterparty commitment tx (0000000000000000000000000000000000000000000000000000000000000073:0) in 0000000000000000000000000000000000000000000000000000000000000067 resolves outbound HTLC with payment hash ff00000000000000000000000000000000000000000000000000000000000000 with timeout" . to_string( ) ) ) , Some ( & 1 ) ) ; // 10
12881288 }
1289+
1290+ #[ test]
1291+ fn test_gossip_exchange_breakage ( ) {
1292+ // To avoid accidentally causing all existing fuzz test cases to be useless by making minor
1293+ // changes (such as requesting feerate info in a new place), we exchange some gossip
1294+ // messages. Obviously this is pretty finicky, so this should be updated pretty liberally,
1295+ // but at least we'll know when changes occur.
1296+ // This test serves as a pretty good full_stack_target seed.
1297+
1298+ // What each byte represents is broken down below, and then everything is concatenated into
1299+ // one large test at the end (you want %s/ -.*//g %s/\n\| \|\t\|\///g).
1300+
1301+ // Following BOLT 8, lightning message on the wire are: 2-byte encrypted message length +
1302+ // 16-byte MAC of the encrypted message length + encrypted Lightning message + 16-byte MAC
1303+ // of the Lightning message
1304+ // I.e 2nd inbound read, len 18 : 0006 (encrypted message length) + 03000000000000000000000000000000 (MAC of the encrypted message length)
1305+ // Len 22 : 0010 00000000 (encrypted lightning message) + 03000000000000000000000000000000 (MAC of the Lightning message)
1306+
1307+ // Writing new code generating transactions and see a new failure ? Don't forget to add input for the FuzzEstimator !
1308+
1309+ let mut test = Vec :: new ( ) ;
1310+
1311+ // our network key
1312+ ext_from_hex ( "0100000000000000000000000000000000000000000000000000000000000000" , & mut test) ;
1313+ // config
1314+ ext_from_hex ( "0000000000900000000000000000640001000000000001ffff0000000000000000ffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff000000ffffffff00ffff1a000400010000020400000000040200000a08ffffffffffffffff0001000000" , & mut test) ;
1315+
1316+ // new outbound connection with id 0
1317+ ext_from_hex ( "00" , & mut test) ;
1318+ // peer's pubkey
1319+ ext_from_hex ( "030000000000000000000000000000000000000000000000000000000000000002" , & mut test) ;
1320+ // inbound read from peer id 0 of len 50
1321+ ext_from_hex ( "030032" , & mut test) ;
1322+ // noise act two (0||pubkey||mac)
1323+ ext_from_hex ( "00 030000000000000000000000000000000000000000000000000000000000000002 03000000000000000000000000000000" , & mut test) ;
1324+
1325+ // inbound read from peer id 0 of len 18
1326+ ext_from_hex ( "030012" , & mut test) ;
1327+ // message header indicating message length 16
1328+ ext_from_hex ( "0010 03000000000000000000000000000000" , & mut test) ;
1329+ // inbound read from peer id 0 of len 32
1330+ ext_from_hex ( "030020" , & mut test) ;
1331+ // init message (type 16) with static_remotekey required, no channel_type/anchors/taproot, and other bits optional and mac
1332+ ext_from_hex ( "0010 00021aaa 0008aaa20aaa2a0a9aaa 03000000000000000000000000000000" , & mut test) ;
1333+
1334+ // new inbound connection with id 1
1335+ ext_from_hex ( "01" , & mut test) ;
1336+ // inbound read from peer id 1 of len 50
1337+ ext_from_hex ( "030132" , & mut test) ;
1338+ // inbound noise act 1
1339+ ext_from_hex ( "0003000000000000000000000000000000000000000000000000000000000000000703000000000000000000000000000000" , & mut test) ;
1340+ // inbound read from peer id 1 of len 66
1341+ ext_from_hex ( "030142" , & mut test) ;
1342+ // inbound noise act 3
1343+ ext_from_hex ( "000302000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000003000000000000000000000000000000" , & mut test) ;
1344+
1345+ // inbound read from peer id 1 of len 18
1346+ ext_from_hex ( "030112" , & mut test) ;
1347+ // message header indicating message length 16
1348+ ext_from_hex ( "0010 01000000000000000000000000000000" , & mut test) ;
1349+ // inbound read from peer id 1 of len 32
1350+ ext_from_hex ( "030120" , & mut test) ;
1351+ // init message (type 16) with static_remotekey required, no channel_type/anchors/taproot, and other bits optional and mac
1352+ ext_from_hex ( "0010 00021aaa 0008aaa20aaa2a0a9aaa 01000000000000000000000000000000" , & mut test) ;
1353+
1354+ // inbound read from peer id 0 of len 18
1355+ ext_from_hex ( "030012" , & mut test) ;
1356+ // message header indicating message length 432
1357+ ext_from_hex ( "01b0 03000000000000000000000000000000" , & mut test) ;
1358+ // inbound read from peer id 0 of len 255
1359+ ext_from_hex ( "0300ff" , & mut test) ;
1360+ // First part of channel_announcement (type 256)
1361+ ext_from_hex ( "0100 00000000000000000000000000000000000000000000000000000000000000b20303030303030303030303030303030303030303030303030303030303030303 00000000000000000000000000000000000000000000000000000000000000b20202020202020202020202020202020202020202020202020202020202020202 00000000000000000000000000000000000000000000000000000000000000b20303030303030303030303030303030303030303030303030303030303030303 00000000000000000000000000000000000000000000000000000000000000b20202020202020202020202020202020202020202020202020202020202" , & mut test) ;
1362+ // inbound read from peer id 0 of len 193
1363+ ext_from_hex ( "0300c1" , & mut test) ;
1364+ // Last part of channel_announcement and mac
1365+ ext_from_hex ( "020202 00006fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000000000000000002a030303030303030303030303030303030303030303030303030303030303030303020202020202020202020202020202020202020202020202020202020202020202030303030303030303030303030303030303030303030303030303030303030303020202020202020202020202020202020202020202020202020202020202020202 03000000000000000000000000000000" , & mut test) ;
1366+
1367+ // inbound read from peer id 0 of len 18
1368+ ext_from_hex ( "030012" , & mut test) ;
1369+ // message header indicating message length 138
1370+ ext_from_hex ( "008a 03000000000000000000000000000000" , & mut test) ;
1371+ // inbound read from peer id 0 of len 154
1372+ ext_from_hex ( "03009a" , & mut test) ;
1373+ // channel_update (type 258) and mac
1374+ ext_from_hex ( "0102 00000000000000000000000000000000000000000000000000000000000000a60303030303030303030303030303030303030303030303030303030303030303 6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000 000000000000002a0000002c01000028000000000000000000000000000000000000000005f5e100 03000000000000000000000000000000" , & mut test) ;
1375+
1376+ // inbound read from peer id 0 of len 18
1377+ ext_from_hex ( "030012" , & mut test) ;
1378+ // message header indicating message length 142
1379+ ext_from_hex ( "008e 03000000000000000000000000000000" , & mut test) ;
1380+ // inbound read from peer id 0 of len 158
1381+ ext_from_hex ( "03009e" , & mut test) ;
1382+ // node_announcement (type 257) and mac
1383+ ext_from_hex ( "0101 00000000000000000000000000000000000000000000000000000000000000280303030303030303030303030303030303030303030303030303030303030303 00000000002b03030303030303030303030303030303030303030303030303030303030303030300000000000000000000000000000000000000000000000000000000000000000000000000 03000000000000000000000000000000" , & mut test) ;
1384+
1385+ let logger = Arc :: new ( TrackingLogger { lines : Mutex :: new ( HashMap :: new ( ) ) } ) ;
1386+ super :: do_test ( & test, & ( Arc :: clone ( & logger) as Arc < dyn Logger > ) ) ;
1387+
1388+ let log_entries = logger. lines . lock ( ) . unwrap ( ) ;
1389+ assert_eq ! ( log_entries. get( & ( "lightning::ln::peer_handler" . to_string( ) , "Sending message to all peers except Some(PublicKey(0000000000000000000000000000000000000000000000000000000000000002ff00000000000000000000000000000000000000000000000000000000000002)) or the announced channel's counterparties: ChannelAnnouncement { node_signature_1: 3026020200b202200303030303030303030303030303030303030303030303030303030303030303, node_signature_2: 3026020200b202200202020202020202020202020202020202020202020202020202020202020202, bitcoin_signature_1: 3026020200b202200303030303030303030303030303030303030303030303030303030303030303, bitcoin_signature_2: 3026020200b202200202020202020202020202020202020202020202020202020202020202020202, contents: UnsignedChannelAnnouncement { features: [], chain_hash: 6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000, short_channel_id: 42, node_id_1: NodeId(030303030303030303030303030303030303030303030303030303030303030303), node_id_2: NodeId(020202020202020202020202020202020202020202020202020202020202020202), bitcoin_key_1: NodeId(030303030303030303030303030303030303030303030303030303030303030303), bitcoin_key_2: NodeId(020202020202020202020202020202020202020202020202020202020202020202), excess_data: [] } }" . to_string( ) ) ) , Some ( & 1 ) ) ;
1390+ assert_eq ! ( log_entries. get( & ( "lightning::ln::peer_handler" . to_string( ) , "Sending message to all peers except Some(PublicKey(0000000000000000000000000000000000000000000000000000000000000002ff00000000000000000000000000000000000000000000000000000000000002)): ChannelUpdate { signature: 3026020200a602200303030303030303030303030303030303030303030303030303030303030303, contents: UnsignedChannelUpdate { chain_hash: 6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000, short_channel_id: 42, timestamp: 44, flags: 0, cltv_expiry_delta: 40, htlc_minimum_msat: 0, htlc_maximum_msat: 100000000, fee_base_msat: 0, fee_proportional_millionths: 0, excess_data: [] } }" . to_string( ) ) ) , Some ( & 1 ) ) ;
1391+ assert_eq ! ( log_entries. get( & ( "lightning::ln::peer_handler" . to_string( ) , "Sending message to all peers except Some(PublicKey(0000000000000000000000000000000000000000000000000000000000000002ff00000000000000000000000000000000000000000000000000000000000002)) or the announced node: NodeAnnouncement { signature: 302502012802200303030303030303030303030303030303030303030303030303030303030303, contents: UnsignedNodeAnnouncement { features: [], timestamp: 43, node_id: NodeId(030303030303030303030303030303030303030303030303030303030303030303), rgb: [0, 0, 0], alias: NodeAlias([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), addresses: [], excess_address_data: [], excess_data: [] } }" . to_string( ) ) ) , Some ( & 1 ) ) ;
1392+ }
12891393}
0 commit comments