@@ -1668,22 +1668,23 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1668
1668
}
1669
1669
1670
1670
/// Attempts to claim a remote HTLC-Success/HTLC-Timeout's outputs using the revocation key
1671
- fn check_spend_remote_htlc ( & mut self , tx : & Transaction , commitment_number : u64 , height : u32 ) -> Vec < ClaimRequest > {
1671
+ fn check_spend_remote_htlc ( & mut self , tx : & Transaction , commitment_number : u64 , height : u32 ) -> ( Vec < ClaimRequest > , ( Sha256dHash , Vec < TxOut > ) ) {
1672
1672
//TODO: send back new outputs to guarantee pending_claim_request consistency
1673
+ let htlc_txid = tx. txid ( ) ; //TODO: This is gonna be a performance bottleneck for watchtowers!
1673
1674
if tx. input . len ( ) != 1 || tx. output . len ( ) != 1 || tx. input [ 0 ] . witness . len ( ) != 5 {
1674
- return Vec :: new ( )
1675
+ return ( Vec :: new ( ) , ( htlc_txid , Vec :: new ( ) ) )
1675
1676
}
1676
1677
1677
1678
macro_rules! ignore_error {
1678
1679
( $thing : expr ) => {
1679
1680
match $thing {
1680
1681
Ok ( a) => a,
1681
- Err ( _) => return Vec :: new( )
1682
+ Err ( _) => return ( Vec :: new( ) , ( htlc_txid , Vec :: new ( ) ) )
1682
1683
}
1683
1684
} ;
1684
1685
}
1685
1686
1686
- let secret = if let Some ( secret) = self . get_secret ( commitment_number) { secret } else { return Vec :: new ( ) ; } ;
1687
+ let secret = if let Some ( secret) = self . get_secret ( commitment_number) { secret } else { return ( Vec :: new ( ) , ( htlc_txid , Vec :: new ( ) ) ) ; } ;
1687
1688
let per_commitment_key = ignore_error ! ( SecretKey :: from_slice( & secret) ) ;
1688
1689
let per_commitment_point = PublicKey :: from_secret_key ( & self . secp_ctx , & per_commitment_key) ;
1689
1690
let ( revocation_pubkey, revocation_key) = match self . key_storage {
@@ -1694,16 +1695,15 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1694
1695
Storage :: Watchtower { .. } => { unimplemented ! ( ) }
1695
1696
} ;
1696
1697
let delayed_key = match self . their_delayed_payment_base_key {
1697
- None => return Vec :: new ( ) ,
1698
+ None => return ( Vec :: new ( ) , ( htlc_txid , Vec :: new ( ) ) ) ,
1698
1699
Some ( their_delayed_payment_base_key) => ignore_error ! ( chan_utils:: derive_public_key( & self . secp_ctx, & per_commitment_point, & their_delayed_payment_base_key) ) ,
1699
1700
} ;
1700
1701
let redeemscript = chan_utils:: get_revokeable_redeemscript ( & revocation_pubkey, self . our_to_self_delay , & delayed_key) ;
1701
- let htlc_txid = tx. txid ( ) ; //TODO: This is gonna be a performance bottleneck for watchtowers!
1702
1702
1703
1703
log_trace ! ( self , "Remote HTLC broadcast {}:{}" , htlc_txid, 0 ) ;
1704
1704
let witness_data = InputMaterial :: Revoked { witness_script : redeemscript, pubkey : Some ( revocation_pubkey) , key : revocation_key, is_htlc : false , amount : tx. output [ 0 ] . value } ;
1705
1705
let claimable_outpoints = vec ! ( ClaimRequest { absolute_timelock: height + self . our_to_self_delay as u32 , aggregable: true , outpoint: BitcoinOutPoint { txid: htlc_txid, vout: 0 } , witness_data } ) ;
1706
- claimable_outpoints
1706
+ ( claimable_outpoints, ( htlc_txid , tx . output . clone ( ) ) )
1707
1707
}
1708
1708
1709
1709
fn broadcast_by_local_state ( & self , local_tx : & LocalSignedTx , delayed_payment_base_key : & SecretKey ) -> ( Vec < Transaction > , Vec < SpendableOutputDescriptor > , Vec < TxOut > ) {
@@ -2019,8 +2019,9 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
2019
2019
}
2020
2020
} else {
2021
2021
if let Some ( & ( commitment_number, _) ) = self . remote_commitment_txn_on_chain . get ( & prevout. txid ) {
2022
- let mut new_outpoints = self . check_spend_remote_htlc ( & tx, commitment_number, height) ;
2022
+ let ( mut new_outpoints, new_outputs ) = self . check_spend_remote_htlc ( & tx, commitment_number, height) ;
2023
2023
claimable_outpoints. append ( & mut new_outpoints) ;
2024
+ watch_outputs. push ( new_outputs) ;
2024
2025
}
2025
2026
}
2026
2027
}
0 commit comments