@@ -1291,4 +1291,108 @@ mod tests {
12911291 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
12921292 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
12931293 }
1294+
1295+ #[ test]
1296+ fn test_gossip_exchange_breakage ( ) {
1297+ // To avoid accidentally causing all existing fuzz test cases to be useless by making minor
1298+ // changes (such as requesting feerate info in a new place), we exchange some gossip
1299+ // messages. Obviously this is pretty finicky, so this should be updated pretty liberally,
1300+ // but at least we'll know when changes occur.
1301+ // This test serves as a pretty good full_stack_target seed.
1302+
1303+ // What each byte represents is broken down below, and then everything is concatenated into
1304+ // one large test at the end (you want %s/ -.*//g %s/\n\| \|\t\|\///g).
1305+
1306+ // Following BOLT 8, lightning message on the wire are: 2-byte encrypted message length +
1307+ // 16-byte MAC of the encrypted message length + encrypted Lightning message + 16-byte MAC
1308+ // of the Lightning message
1309+ // I.e 2nd inbound read, len 18 : 0006 (encrypted message length) + 03000000000000000000000000000000 (MAC of the encrypted message length)
1310+ // Len 22 : 0010 00000000 (encrypted lightning message) + 03000000000000000000000000000000 (MAC of the Lightning message)
1311+
1312+ // Writing new code generating transactions and see a new failure ? Don't forget to add input for the FuzzEstimator !
1313+
1314+ let mut test = Vec :: new ( ) ;
1315+
1316+ // our network key
1317+ ext_from_hex ( "0100000000000000000000000000000000000000000000000000000000000000" , & mut test) ;
1318+ // config
1319+ ext_from_hex ( "0000000000900000000000000000640001000000000001ffff0000000000000000ffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff000000ffffffff00ffff1a000400010000020400000000040200000a08ffffffffffffffff0001000000" , & mut test) ;
1320+
1321+ // new outbound connection with id 0
1322+ ext_from_hex ( "00" , & mut test) ;
1323+ // peer's pubkey
1324+ ext_from_hex ( "030000000000000000000000000000000000000000000000000000000000000002" , & mut test) ;
1325+ // inbound read from peer id 0 of len 50
1326+ ext_from_hex ( "030032" , & mut test) ;
1327+ // noise act two (0||pubkey||mac)
1328+ ext_from_hex ( "00 030000000000000000000000000000000000000000000000000000000000000002 03000000000000000000000000000000" , & mut test) ;
1329+
1330+ // inbound read from peer id 0 of len 18
1331+ ext_from_hex ( "030012" , & mut test) ;
1332+ // message header indicating message length 16
1333+ ext_from_hex ( "0010 03000000000000000000000000000000" , & mut test) ;
1334+ // inbound read from peer id 0 of len 32
1335+ ext_from_hex ( "030020" , & mut test) ;
1336+ // init message (type 16) with static_remotekey required, no channel_type/anchors/taproot, and other bits optional and mac
1337+ ext_from_hex ( "0010 00021aaa 0008aaa20aaa2a0a9aaa 03000000000000000000000000000000" , & mut test) ;
1338+
1339+ // new inbound connection with id 1
1340+ ext_from_hex ( "01" , & mut test) ;
1341+ // inbound read from peer id 1 of len 50
1342+ ext_from_hex ( "030132" , & mut test) ;
1343+ // inbound noise act 1
1344+ ext_from_hex ( "0003000000000000000000000000000000000000000000000000000000000000000703000000000000000000000000000000" , & mut test) ;
1345+ // inbound read from peer id 1 of len 66
1346+ ext_from_hex ( "030142" , & mut test) ;
1347+ // inbound noise act 3
1348+ ext_from_hex ( "000302000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000003000000000000000000000000000000" , & mut test) ;
1349+
1350+ // inbound read from peer id 1 of len 18
1351+ ext_from_hex ( "030112" , & mut test) ;
1352+ // message header indicating message length 16
1353+ ext_from_hex ( "0010 01000000000000000000000000000000" , & mut test) ;
1354+ // inbound read from peer id 1 of len 32
1355+ ext_from_hex ( "030120" , & mut test) ;
1356+ // init message (type 16) with static_remotekey required, no channel_type/anchors/taproot, and other bits optional and mac
1357+ ext_from_hex ( "0010 00021aaa 0008aaa20aaa2a0a9aaa 01000000000000000000000000000000" , & mut test) ;
1358+
1359+ // inbound read from peer id 0 of len 18
1360+ ext_from_hex ( "030012" , & mut test) ;
1361+ // message header indicating message length 432
1362+ ext_from_hex ( "01b0 03000000000000000000000000000000" , & mut test) ;
1363+ // inbound read from peer id 0 of len 255
1364+ ext_from_hex ( "0300ff" , & mut test) ;
1365+ // First part of channel_announcement (type 256)
1366+ ext_from_hex ( "0100 00000000000000000000000000000000000000000000000000000000000000b20303030303030303030303030303030303030303030303030303030303030303 00000000000000000000000000000000000000000000000000000000000000b20202020202020202020202020202020202020202020202020202020202020202 00000000000000000000000000000000000000000000000000000000000000b20303030303030303030303030303030303030303030303030303030303030303 00000000000000000000000000000000000000000000000000000000000000b20202020202020202020202020202020202020202020202020202020202" , & mut test) ;
1367+ // inbound read from peer id 0 of len 193
1368+ ext_from_hex ( "0300c1" , & mut test) ;
1369+ // Last part of channel_announcement and mac
1370+ ext_from_hex ( "020202 00006fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000000000000000002a030303030303030303030303030303030303030303030303030303030303030303020202020202020202020202020202020202020202020202020202020202020202030303030303030303030303030303030303030303030303030303030303030303020202020202020202020202020202020202020202020202020202020202020202 03000000000000000000000000000000" , & mut test) ;
1371+
1372+ // inbound read from peer id 0 of len 18
1373+ ext_from_hex ( "030012" , & mut test) ;
1374+ // message header indicating message length 138
1375+ ext_from_hex ( "008a 03000000000000000000000000000000" , & mut test) ;
1376+ // inbound read from peer id 0 of len 154
1377+ ext_from_hex ( "03009a" , & mut test) ;
1378+ // channel_update (type 258) and mac
1379+ ext_from_hex ( "0102 00000000000000000000000000000000000000000000000000000000000000a60303030303030303030303030303030303030303030303030303030303030303 6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000 000000000000002a0000002c01000028000000000000000000000000000000000000000005f5e100 03000000000000000000000000000000" , & mut test) ;
1380+
1381+ // inbound read from peer id 0 of len 18
1382+ ext_from_hex ( "030012" , & mut test) ;
1383+ // message header indicating message length 142
1384+ ext_from_hex ( "008e 03000000000000000000000000000000" , & mut test) ;
1385+ // inbound read from peer id 0 of len 158
1386+ ext_from_hex ( "03009e" , & mut test) ;
1387+ // node_announcement (type 257) and mac
1388+ ext_from_hex ( "0101 00000000000000000000000000000000000000000000000000000000000000280303030303030303030303030303030303030303030303030303030303030303 00000000002b03030303030303030303030303030303030303030303030303030303030303030300000000000000000000000000000000000000000000000000000000000000000000000000 03000000000000000000000000000000" , & mut test) ;
1389+
1390+ let logger = Arc :: new ( TrackingLogger { lines : Mutex :: new ( HashMap :: new ( ) ) } ) ;
1391+ super :: do_test ( & test, & ( Arc :: clone ( & logger) as Arc < dyn Logger > ) ) ;
1392+
1393+ let log_entries = logger. lines . lock ( ) . unwrap ( ) ;
1394+ 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 ) ) ;
1395+ 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 ) ) ;
1396+ 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 ) ) ;
1397+ }
12941398}
0 commit comments