@@ -3108,9 +3108,11 @@ mod tests {
3108
3108
3109
3109
#[ derive( PartialEq ) ]
3110
3110
enum HTLCType { NONE , TIMEOUT , SUCCESS }
3111
- fn test_txn_broadcast ( node : & Node , chan : & ( msgs:: ChannelUpdate , msgs:: ChannelUpdate , [ u8 ; 32 ] , Transaction ) , commitment_tx : Option < Transaction > , has_htlc_tx : HTLCType ) -> Vec < Transaction > {
3111
+ #[ derive( PartialEq ) ]
3112
+ enum PenaltyType { NONE , COMMIT , HTLC }
3113
+ 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 > {
3112
3114
let mut node_txn = node. tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) ;
3113
- assert ! ( node_txn. len( ) >= if commitment_tx . is_some ( ) { 0 } else { 1 } + if has_htlc_tx == HTLCType :: NONE { 0 } else { 1 } ) ;
3115
+ assert ! ( node_txn. len( ) >= if has_htlc_tx == HTLCType :: NONE { 0 } else { 1 } + if has_penalty_tx == PenaltyType :: NONE { 0 } else { 1 } ) ;
3114
3116
3115
3117
let mut res = Vec :: with_capacity ( 2 ) ;
3116
3118
@@ -3126,7 +3128,9 @@ mod tests {
3126
3128
}
3127
3129
}
3128
3130
}
3129
- assert_eq ! ( res. len( ) , 1 ) ;
3131
+ if revoked_tx. is_none ( ) {
3132
+ assert_eq ! ( res. len( ) , 1 ) ;
3133
+ }
3130
3134
3131
3135
if has_htlc_tx != HTLCType :: NONE {
3132
3136
for tx in node_txn. iter ( ) {
@@ -3145,6 +3149,21 @@ mod tests {
3145
3149
}
3146
3150
assert_eq ! ( res. len( ) , 2 ) ;
3147
3151
}
3152
+
3153
+ if has_penalty_tx == PenaltyType :: HTLC {
3154
+ if let Some ( revoked_tx) = revoked_tx {
3155
+ for tx in node_txn. iter ( ) {
3156
+ if tx. input . len ( ) == 1 && tx. input [ 0 ] . previous_output . txid == revoked_tx. txid ( ) {
3157
+ let mut funding_tx_map = HashMap :: new ( ) ;
3158
+ funding_tx_map. insert ( revoked_tx. txid ( ) , revoked_tx. clone ( ) ) ;
3159
+ tx. verify ( & funding_tx_map) . unwrap ( ) ;
3160
+ res. push ( tx. clone ( ) ) ;
3161
+ break ;
3162
+ }
3163
+ }
3164
+ assert_eq ! ( res. len( ) , 1 ) ;
3165
+ }
3166
+ }
3148
3167
node_txn. clear ( ) ;
3149
3168
res
3150
3169
}
@@ -3222,10 +3241,10 @@ mod tests {
3222
3241
// Simple case with no pending HTLCs:
3223
3242
nodes[ 1 ] . node . peer_disconnected ( & nodes[ 0 ] . node . get_our_node_id ( ) , true ) ;
3224
3243
{
3225
- let mut node_txn = test_txn_broadcast ( & nodes[ 1 ] , & chan_1, None , HTLCType :: NONE ) ;
3244
+ let mut node_txn = test_txn_broadcast ( & nodes[ 1 ] , & chan_1, None , None , HTLCType :: NONE , PenaltyType :: NONE ) ;
3226
3245
let header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
3227
3246
nodes[ 0 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ node_txn. drain( ..) . next( ) . unwrap( ) ] } , 1 ) ;
3228
- test_txn_broadcast ( & nodes[ 0 ] , & chan_1, None , HTLCType :: NONE ) ;
3247
+ test_txn_broadcast ( & nodes[ 0 ] , & chan_1, None , None , HTLCType :: NONE , PenaltyType :: NONE ) ;
3229
3248
}
3230
3249
get_announce_close_broadcast_events ( & nodes, 0 , 1 ) ;
3231
3250
assert_eq ! ( nodes[ 0 ] . node. list_channels( ) . len( ) , 0 ) ;
@@ -3237,10 +3256,10 @@ mod tests {
3237
3256
// Simple case of one pending HTLC to HTLC-Timeout
3238
3257
nodes[ 1 ] . node . peer_disconnected ( & nodes[ 2 ] . node . get_our_node_id ( ) , true ) ;
3239
3258
{
3240
- let mut node_txn = test_txn_broadcast ( & nodes[ 1 ] , & chan_2, None , HTLCType :: TIMEOUT ) ;
3259
+ let mut node_txn = test_txn_broadcast ( & nodes[ 1 ] , & chan_2, None , None , HTLCType :: TIMEOUT , PenaltyType :: NONE ) ;
3241
3260
let header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
3242
3261
nodes[ 2 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ node_txn. drain( ..) . next( ) . unwrap( ) ] } , 1 ) ;
3243
- test_txn_broadcast ( & nodes[ 2 ] , & chan_2, None , HTLCType :: NONE ) ;
3262
+ test_txn_broadcast ( & nodes[ 2 ] , & chan_2, None , None , HTLCType :: NONE , PenaltyType :: NONE ) ;
3244
3263
}
3245
3264
get_announce_close_broadcast_events ( & nodes, 1 , 2 ) ;
3246
3265
assert_eq ! ( nodes[ 1 ] . node. list_channels( ) . len( ) , 0 ) ;
@@ -3274,7 +3293,7 @@ mod tests {
3274
3293
// HTLC-Timeout and a nodes[3] claim against it (+ its own announces)
3275
3294
nodes[ 2 ] . node . peer_disconnected ( & nodes[ 3 ] . node . get_our_node_id ( ) , true ) ;
3276
3295
{
3277
- let node_txn = test_txn_broadcast ( & nodes[ 2 ] , & chan_3, None , HTLCType :: TIMEOUT ) ;
3296
+ let node_txn = test_txn_broadcast ( & nodes[ 2 ] , & chan_3, None , None , HTLCType :: TIMEOUT , PenaltyType :: NONE ) ;
3278
3297
3279
3298
// Claim the payment on nodes[3], giving it knowledge of the preimage
3280
3299
claim_funds ! ( nodes[ 3 ] , nodes[ 2 ] , payment_preimage_1) ;
@@ -3299,9 +3318,9 @@ mod tests {
3299
3318
nodes[ 3 ] . chain_monitor . block_connected_checked ( & header, i, & Vec :: new ( ) [ ..] , & [ 0 ; 0 ] ) ;
3300
3319
}
3301
3320
3302
- let node_txn = test_txn_broadcast ( & nodes[ 3 ] , & chan_4, None , HTLCType :: TIMEOUT ) ;
3321
+ let node_txn = test_txn_broadcast ( & nodes[ 3 ] , & chan_4, None , None , HTLCType :: TIMEOUT , PenaltyType :: NONE ) ;
3303
3322
3304
- // Claim the payment on nodes[3 ], giving it knowledge of the preimage
3323
+ // Claim the payment on nodes[4 ], giving it knowledge of the preimage
3305
3324
claim_funds ! ( nodes[ 4 ] , nodes[ 3 ] , payment_preimage_2) ;
3306
3325
3307
3326
header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
@@ -3311,7 +3330,7 @@ mod tests {
3311
3330
nodes[ 4 ] . chain_monitor . block_connected_checked ( & header, i, & Vec :: new ( ) [ ..] , & [ 0 ; 0 ] ) ;
3312
3331
}
3313
3332
3314
- test_txn_broadcast ( & nodes[ 4 ] , & chan_4, None , HTLCType :: SUCCESS ) ;
3333
+ test_txn_broadcast ( & nodes[ 4 ] , & chan_4, None , None , HTLCType :: SUCCESS , PenaltyType :: NONE ) ;
3315
3334
3316
3335
header = BlockHeader { version : 0x20000000 , prev_blockhash : header. bitcoin_hash ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
3317
3336
nodes[ 4 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ node_txn[ 0 ] . clone( ) ] } , TEST_FINAL_CLTV - 5 ) ;
@@ -3346,15 +3365,13 @@ mod tests {
3346
3365
node_txn[ 0 ] . verify ( & funding_tx_map) . unwrap ( ) ;
3347
3366
node_txn. swap_remove ( 0 ) ;
3348
3367
}
3349
- test_txn_broadcast ( & nodes[ 1 ] , & chan_5, None , HTLCType :: NONE ) ;
3368
+ test_txn_broadcast ( & nodes[ 1 ] , & chan_5, None , None , HTLCType :: NONE , PenaltyType :: NONE ) ;
3350
3369
3351
3370
nodes[ 0 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ revoked_local_txn[ 0 ] . clone( ) ] } , 1 ) ;
3352
- let node_txn = test_txn_broadcast ( & nodes[ 0 ] , & chan_5, Some ( revoked_local_txn[ 0 ] . clone ( ) ) , HTLCType :: TIMEOUT ) ;
3371
+ let node_txn = test_txn_broadcast ( & nodes[ 0 ] , & chan_5, Some ( revoked_local_txn[ 0 ] . clone ( ) ) , None , HTLCType :: TIMEOUT , PenaltyType :: NONE ) ;
3353
3372
header = BlockHeader { version : 0x20000000 , prev_blockhash : header. bitcoin_hash ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
3354
3373
nodes[ 1 ] . chain_monitor . block_connected_with_filtering ( & Block { header, txdata : vec ! [ node_txn[ 1 ] . clone( ) ] } , 1 ) ;
3355
-
3356
- //TODO: At this point nodes[1] should claim the revoked HTLC-Timeout output, but that's
3357
- //not yet implemented in ChannelMonitor
3374
+ test_txn_broadcast ( & nodes[ 1 ] , & chan_5, None , Some ( node_txn[ 1 ] . clone ( ) ) , HTLCType :: NONE , PenaltyType :: HTLC ) ;
3358
3375
}
3359
3376
get_announce_close_broadcast_events ( & nodes, 0 , 1 ) ;
3360
3377
assert_eq ! ( nodes[ 0 ] . node. list_channels( ) . len( ) , 0 ) ;
0 commit comments