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