@@ -3380,6 +3380,48 @@ mod tests {
3380
3380
}
3381
3381
}
3382
3382
3383
+ #[ test]
3384
+ fn test_htlc_ignore_latest_remote_commitment ( ) {
3385
+ // Test that HTLC transactions spending the latest remote commitment transaction are simply
3386
+ // ignored if we cannot claim them. This originally tickled an invalid unwrap().
3387
+ let nodes = create_network ( 2 ) ;
3388
+ create_announced_chan_between_nodes ( & nodes, 0 , 1 ) ;
3389
+
3390
+ route_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , 10000000 ) ;
3391
+ nodes[ 0 ] . node . force_close_channel ( & nodes[ 0 ] . node . list_channels ( ) [ 0 ] . channel_id ) ;
3392
+ {
3393
+ let events = nodes[ 0 ] . node . get_and_clear_pending_events ( ) ;
3394
+ assert_eq ! ( events. len( ) , 1 ) ;
3395
+ match events[ 0 ] {
3396
+ Event :: BroadcastChannelUpdate { msg : msgs:: ChannelUpdate { contents : msgs:: UnsignedChannelUpdate { flags, .. } , .. } } => {
3397
+ assert_eq ! ( flags & 0b10 , 0b10 ) ;
3398
+ } ,
3399
+ _ => panic ! ( "Unexpected event" ) ,
3400
+ }
3401
+ }
3402
+
3403
+ let node_txn = nodes[ 0 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
3404
+ assert_eq ! ( node_txn. len( ) , 2 ) ;
3405
+
3406
+ let mut header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
3407
+ nodes[ 1 ] . chain_monitor . block_connected_checked ( & header, 1 , & [ & node_txn[ 0 ] , & node_txn[ 1 ] ] , & [ 1 ; 2 ] ) ;
3408
+
3409
+ {
3410
+ let events = nodes[ 1 ] . node . get_and_clear_pending_events ( ) ;
3411
+ assert_eq ! ( events. len( ) , 1 ) ;
3412
+ match events[ 0 ] {
3413
+ Event :: BroadcastChannelUpdate { msg : msgs:: ChannelUpdate { contents : msgs:: UnsignedChannelUpdate { flags, .. } , .. } } => {
3414
+ assert_eq ! ( flags & 0b10 , 0b10 ) ;
3415
+ } ,
3416
+ _ => panic ! ( "Unexpected event" ) ,
3417
+ }
3418
+ }
3419
+
3420
+ // Duplicate the block_connected call since this may happen due to other listeners
3421
+ // registering new transactions
3422
+ nodes[ 1 ] . chain_monitor . block_connected_checked ( & header, 1 , & [ & node_txn[ 0 ] , & node_txn[ 1 ] ] , & [ 1 ; 2 ] ) ;
3423
+ }
3424
+
3383
3425
#[ test]
3384
3426
fn test_unconf_chan ( ) {
3385
3427
// After creating a chan between nodes, we disconnect all blocks previously seen to force a channel close on nodes[0] side
0 commit comments