@@ -3089,9 +3089,11 @@ mod tests {
3089
3089
3090
3090
#[ derive( PartialEq ) ]
3091
3091
enum HTLCType { NONE , TIMEOUT , SUCCESS }
3092
- fn test_txn_broadcast ( node : & Node , chan : & ( msgs:: ChannelUpdate , msgs:: ChannelUpdate , [ u8 ; 32 ] , Transaction ) , commitment_tx : Option < Transaction > , has_htlc_tx : HTLCType ) -> Vec < Transaction > {
3092
+ #[ derive( PartialEq ) ]
3093
+ enum PenaltyType { NONE , HTLC }
3094
+ fn test_txn_broadcast ( node : & Node , chan : & ( msgs:: ChannelUpdate , msgs:: ChannelUpdate , [ u8 ; 32 ] , Transaction ) , commitment_tx : Option < Transaction > , revoked_tx : Option < Transaction > , has_htlc_tx : HTLCType , has_penalty_tx : PenaltyType ) -> Vec < Transaction > {
3093
3095
let mut node_txn = node. tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
3094
- assert ! ( node_txn. len( ) >= if commitment_tx . is_some ( ) { 0 } else { 1 } + if has_htlc_tx == HTLCType :: NONE { 0 } else { 1 } ) ;
3096
+ assert ! ( node_txn. len( ) >= if has_htlc_tx == HTLCType :: NONE { 0 } else { 1 } + if has_penalty_tx == PenaltyType :: NONE { 0 } else { 1 } ) ;
3095
3097
3096
3098
let mut res = Vec :: with_capacity ( 2 ) ;
3097
3099
@@ -3107,7 +3109,9 @@ mod tests {
3107
3109
}
3108
3110
}
3109
3111
}
3110
- assert_eq ! ( res. len( ) , 1 ) ;
3112
+ if !revoked_tx. is_some ( ) && !( has_penalty_tx == PenaltyType :: HTLC ) {
3113
+ assert_eq ! ( res. len( ) , 1 ) ;
3114
+ }
3111
3115
3112
3116
if has_htlc_tx != HTLCType :: NONE {
3113
3117
for tx in node_txn. iter ( ) {
@@ -3126,6 +3130,20 @@ mod tests {
3126
3130
}
3127
3131
assert_eq ! ( res. len( ) , 2 ) ;
3128
3132
}
3133
+
3134
+ if has_penalty_tx == PenaltyType :: HTLC {
3135
+ let revoked_tx = revoked_tx. unwrap ( ) ;
3136
+ for tx in node_txn. iter ( ) {
3137
+ if tx. input . len ( ) == 1 && tx. input [ 0 ] . previous_output . txid == revoked_tx. txid ( ) {
3138
+ let mut funding_tx_map = HashMap :: new ( ) ;
3139
+ funding_tx_map. insert ( revoked_tx. txid ( ) , revoked_tx. clone ( ) ) ;
3140
+ tx. verify ( & funding_tx_map) . unwrap ( ) ;
3141
+ res. push ( tx. clone ( ) ) ;
3142
+ break ;
3143
+ }
3144
+ }
3145
+ assert_eq ! ( res. len( ) , 1 ) ;
3146
+ }
3129
3147
node_txn. clear ( ) ;
3130
3148
res
3131
3149
}
@@ -3203,10 +3221,10 @@ mod tests {
3203
3221
// Simple case with no pending HTLCs:
3204
3222
nodes[ 1 ] . node . peer_disconnected ( & nodes[ 0 ] . node . get_our_node_id ( ) , true ) ;
3205
3223
{
3206
- let mut node_txn = test_txn_broadcast ( & nodes[ 1 ] , & chan_1, None , HTLCType :: NONE ) ;
3224
+ let mut node_txn = test_txn_broadcast ( & nodes[ 1 ] , & chan_1, None , None , HTLCType :: NONE , PenaltyType :: NONE ) ;
3207
3225
let header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
3208
3226
nodes[ 0 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ node_txn. drain( ..) . next( ) . unwrap( ) ] } , 1 ) ;
3209
- test_txn_broadcast ( & nodes[ 0 ] , & chan_1, None , HTLCType :: NONE ) ;
3227
+ test_txn_broadcast ( & nodes[ 0 ] , & chan_1, None , None , HTLCType :: NONE , PenaltyType :: NONE ) ;
3210
3228
}
3211
3229
get_announce_close_broadcast_events ( & nodes, 0 , 1 ) ;
3212
3230
assert_eq ! ( nodes[ 0 ] . node. list_channels( ) . len( ) , 0 ) ;
@@ -3218,10 +3236,10 @@ mod tests {
3218
3236
// Simple case of one pending HTLC to HTLC-Timeout
3219
3237
nodes[ 1 ] . node . peer_disconnected ( & nodes[ 2 ] . node . get_our_node_id ( ) , true ) ;
3220
3238
{
3221
- let mut node_txn = test_txn_broadcast ( & nodes[ 1 ] , & chan_2, None , HTLCType :: TIMEOUT ) ;
3239
+ let mut node_txn = test_txn_broadcast ( & nodes[ 1 ] , & chan_2, None , None , HTLCType :: TIMEOUT , PenaltyType :: NONE ) ;
3222
3240
let header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
3223
3241
nodes[ 2 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ node_txn. drain( ..) . next( ) . unwrap( ) ] } , 1 ) ;
3224
- test_txn_broadcast ( & nodes[ 2 ] , & chan_2, None , HTLCType :: NONE ) ;
3242
+ test_txn_broadcast ( & nodes[ 2 ] , & chan_2, None , None , HTLCType :: NONE , PenaltyType :: NONE ) ;
3225
3243
}
3226
3244
get_announce_close_broadcast_events ( & nodes, 1 , 2 ) ;
3227
3245
assert_eq ! ( nodes[ 1 ] . node. list_channels( ) . len( ) , 0 ) ;
@@ -3255,7 +3273,7 @@ mod tests {
3255
3273
// HTLC-Timeout and a nodes[3] claim against it (+ its own announces)
3256
3274
nodes[ 2 ] . node . peer_disconnected ( & nodes[ 3 ] . node . get_our_node_id ( ) , true ) ;
3257
3275
{
3258
- let node_txn = test_txn_broadcast ( & nodes[ 2 ] , & chan_3, None , HTLCType :: TIMEOUT ) ;
3276
+ let node_txn = test_txn_broadcast ( & nodes[ 2 ] , & chan_3, None , None , HTLCType :: TIMEOUT , PenaltyType :: NONE ) ;
3259
3277
3260
3278
// Claim the payment on nodes[3], giving it knowledge of the preimage
3261
3279
claim_funds ! ( nodes[ 3 ] , nodes[ 2 ] , payment_preimage_1) ;
@@ -3280,9 +3298,9 @@ mod tests {
3280
3298
nodes[ 3 ] . chain_monitor . block_connected_checked ( & header, i, & Vec :: new ( ) [ ..] , & [ 0 ; 0 ] ) ;
3281
3299
}
3282
3300
3283
- let node_txn = test_txn_broadcast ( & nodes[ 3 ] , & chan_4, None , HTLCType :: TIMEOUT ) ;
3301
+ let node_txn = test_txn_broadcast ( & nodes[ 3 ] , & chan_4, None , None , HTLCType :: TIMEOUT , PenaltyType :: NONE ) ;
3284
3302
3285
- // Claim the payment on nodes[3 ], giving it knowledge of the preimage
3303
+ // Claim the payment on nodes[4 ], giving it knowledge of the preimage
3286
3304
claim_funds ! ( nodes[ 4 ] , nodes[ 3 ] , payment_preimage_2) ;
3287
3305
3288
3306
header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
@@ -3292,7 +3310,7 @@ mod tests {
3292
3310
nodes[ 4 ] . chain_monitor . block_connected_checked ( & header, i, & Vec :: new ( ) [ ..] , & [ 0 ; 0 ] ) ;
3293
3311
}
3294
3312
3295
- test_txn_broadcast ( & nodes[ 4 ] , & chan_4, None , HTLCType :: SUCCESS ) ;
3313
+ test_txn_broadcast ( & nodes[ 4 ] , & chan_4, None , None , HTLCType :: SUCCESS , PenaltyType :: NONE ) ;
3296
3314
3297
3315
header = BlockHeader { version : 0x20000000 , prev_blockhash : header. bitcoin_hash ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
3298
3316
nodes[ 4 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ node_txn[ 0 ] . clone( ) ] } , TEST_FINAL_CLTV - 5 ) ;
@@ -3327,15 +3345,13 @@ mod tests {
3327
3345
node_txn[ 0 ] . verify ( & funding_tx_map) . unwrap ( ) ;
3328
3346
node_txn. swap_remove ( 0 ) ;
3329
3347
}
3330
- test_txn_broadcast ( & nodes[ 1 ] , & chan_5, None , HTLCType :: NONE ) ;
3348
+ test_txn_broadcast ( & nodes[ 1 ] , & chan_5, None , None , HTLCType :: NONE , PenaltyType :: NONE ) ;
3331
3349
3332
3350
nodes[ 0 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ revoked_local_txn[ 0 ] . clone( ) ] } , 1 ) ;
3333
- let node_txn = test_txn_broadcast ( & nodes[ 0 ] , & chan_5, Some ( revoked_local_txn[ 0 ] . clone ( ) ) , HTLCType :: TIMEOUT ) ;
3351
+ let node_txn = test_txn_broadcast ( & nodes[ 0 ] , & chan_5, Some ( revoked_local_txn[ 0 ] . clone ( ) ) , None , HTLCType :: TIMEOUT , PenaltyType :: NONE ) ;
3334
3352
header = BlockHeader { version : 0x20000000 , prev_blockhash : header. bitcoin_hash ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
3335
3353
nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ node_txn[ 1 ] . clone( ) ] } , 1 ) ;
3336
-
3337
- //TODO: At this point nodes[1] should claim the revoked HTLC-Timeout output, but that's
3338
- //not yet implemented in ChannelMonitor
3354
+ test_txn_broadcast ( & nodes[ 1 ] , & chan_5, None , Some ( node_txn[ 1 ] . clone ( ) ) , HTLCType :: NONE , PenaltyType :: HTLC ) ;
3339
3355
}
3340
3356
get_announce_close_broadcast_events ( & nodes, 0 , 1 ) ;
3341
3357
assert_eq ! ( nodes[ 0 ] . node. list_channels( ) . len( ) , 0 ) ;
0 commit comments