@@ -1210,35 +1210,32 @@ impl ChannelMonitor {
1210
1210
}
1211
1211
1212
1212
/// Attempst to claim a remote HTLC-Success/HTLC-Timeout s outputs using the revocation key
1213
- fn check_spend_remote_htlc ( & self , tx : & Transaction , commitment_number : u64 ) -> Vec < Transaction > {
1214
- let mut txn_to_broadcast = Vec :: new ( ) ;
1215
-
1213
+ fn check_spend_remote_htlc ( & self , tx : & Transaction , commitment_number : u64 ) -> Option < Transaction > {
1216
1214
let htlc_txid = tx. txid ( ) ; //TODO: This is gonna be a performance bottleneck for watchtowers!
1217
1215
1218
1216
macro_rules! ignore_error {
1219
1217
( $thing : expr ) => {
1220
1218
match $thing {
1221
1219
Ok ( a) => a,
1222
- Err ( _) => return txn_to_broadcast
1220
+ Err ( _) => return None
1223
1221
}
1224
1222
} ;
1225
1223
}
1226
1224
1227
1225
let secret = self . get_secret ( commitment_number) . unwrap ( ) ;
1228
1226
let per_commitment_key = ignore_error ! ( SecretKey :: from_slice( & self . secp_ctx, & secret) ) ;
1227
+ let per_commitment_point = PublicKey :: from_secret_key ( & self . secp_ctx , & per_commitment_key) ;
1229
1228
let revocation_pubkey = match self . key_storage {
1230
1229
KeyStorage :: PrivMode { ref revocation_base_key, .. } => {
1231
- let per_commitment_point = PublicKey :: from_secret_key ( & self . secp_ctx , & per_commitment_key) ;
1232
1230
ignore_error ! ( chan_utils:: derive_public_revocation_key( & self . secp_ctx, & per_commitment_point, & PublicKey :: from_secret_key( & self . secp_ctx, & revocation_base_key) ) )
1233
1231
} ,
1234
1232
KeyStorage :: SigsMode { ref revocation_base_key, .. } => {
1235
- let per_commitment_point = PublicKey :: from_secret_key ( & self . secp_ctx , & per_commitment_key) ;
1236
1233
ignore_error ! ( chan_utils:: derive_public_revocation_key( & self . secp_ctx, & per_commitment_point, & revocation_base_key) )
1237
1234
} ,
1238
1235
} ;
1239
1236
let delayed_key = match self . their_delayed_payment_base_key {
1240
- None => return txn_to_broadcast ,
1241
- Some ( their_delayed_payment_base_key) => ignore_error ! ( chan_utils:: derive_public_key( & self . secp_ctx, & PublicKey :: from_secret_key ( & self . secp_ctx , & per_commitment_key ) , & their_delayed_payment_base_key) ) ,
1237
+ None => return None ,
1238
+ Some ( their_delayed_payment_base_key) => ignore_error ! ( chan_utils:: derive_public_key( & self . secp_ctx, & per_commitment_point , & their_delayed_payment_base_key) ) ,
1242
1239
} ;
1243
1240
let redeemscript = chan_utils:: get_revokeable_redeemscript ( & revocation_pubkey, self . their_to_self_delay . unwrap ( ) , & delayed_key) ;
1244
1241
let revokeable_p2wsh = redeemscript. to_v0_p2wsh ( ) ;
@@ -1290,9 +1287,8 @@ impl ChannelMonitor {
1290
1287
spend_tx. input [ 0 ] . witness . push ( vec ! ( 1 ) ) ;
1291
1288
spend_tx. input [ 0 ] . witness . push ( redeemscript. into_bytes ( ) ) ;
1292
1289
1293
- txn_to_broadcast. push ( spend_tx) ;
1294
- }
1295
- txn_to_broadcast
1290
+ Some ( spend_tx)
1291
+ } else { None }
1296
1292
}
1297
1293
1298
1294
fn broadcast_by_local_state ( & self , local_tx : & LocalSignedTx ) -> Vec < Transaction > {
@@ -1369,8 +1365,10 @@ impl ChannelMonitor {
1369
1365
}
1370
1366
} else {
1371
1367
let remote_commitment_txn_on_chain = self . remote_commitment_txn_on_chain . lock ( ) . unwrap ( ) ;
1372
- for commitment_number in remote_commitment_txn_on_chain. get ( & txin. previous_output . txid ) {
1373
- txn = self . check_spend_remote_htlc ( tx, * commitment_number) ;
1368
+ if let Some ( commitment_number) = remote_commitment_txn_on_chain. get ( & prevout. txid ) {
1369
+ if let Some ( tx) = self . check_spend_remote_htlc ( tx, * commitment_number) {
1370
+ txn. push ( tx) ;
1371
+ }
1374
1372
}
1375
1373
}
1376
1374
for tx in txn. iter ( ) {
0 commit comments