@@ -1668,22 +1668,22 @@ 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 > {
1672
- //TODO: send back new outputs to guarantee pending_claim_request consistency
1671
+ fn check_spend_remote_htlc ( & mut self , tx : & Transaction , commitment_number : u64 , height : u32 ) -> ( Vec < ClaimRequest > , ( Sha256dHash , Vec < TxOut > ) ) {
1672
+ let htlc_txid = tx . txid ( ) ;
1673
1673
if tx. input . len ( ) != 1 || tx. output . len ( ) != 1 || tx. input [ 0 ] . witness . len ( ) != 5 {
1674
- return Vec :: new ( )
1674
+ return ( Vec :: new ( ) , ( htlc_txid , Vec :: new ( ) ) )
1675
1675
}
1676
1676
1677
1677
macro_rules! ignore_error {
1678
1678
( $thing : expr ) => {
1679
1679
match $thing {
1680
1680
Ok ( a) => a,
1681
- Err ( _) => return Vec :: new( )
1681
+ Err ( _) => return ( Vec :: new( ) , ( htlc_txid , Vec :: new ( ) ) )
1682
1682
}
1683
1683
} ;
1684
1684
}
1685
1685
1686
- let secret = if let Some ( secret) = self . get_secret ( commitment_number) { secret } else { return Vec :: new ( ) ; } ;
1686
+ let secret = if let Some ( secret) = self . get_secret ( commitment_number) { secret } else { return ( Vec :: new ( ) , ( htlc_txid , Vec :: new ( ) ) ) ; } ;
1687
1687
let per_commitment_key = ignore_error ! ( SecretKey :: from_slice( & secret) ) ;
1688
1688
let per_commitment_point = PublicKey :: from_secret_key ( & self . secp_ctx , & per_commitment_key) ;
1689
1689
let ( revocation_pubkey, revocation_key) = match self . key_storage {
@@ -1694,16 +1694,15 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1694
1694
Storage :: Watchtower { .. } => { unimplemented ! ( ) }
1695
1695
} ;
1696
1696
let delayed_key = match self . their_delayed_payment_base_key {
1697
- None => return Vec :: new ( ) ,
1697
+ None => return ( Vec :: new ( ) , ( htlc_txid , Vec :: new ( ) ) ) ,
1698
1698
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
1699
} ;
1700
1700
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
1701
1703
1702
log_trace ! ( self , "Remote HTLC broadcast {}:{}" , htlc_txid, 0 ) ;
1704
1703
let witness_data = InputMaterial :: Revoked { witness_script : redeemscript, pubkey : Some ( revocation_pubkey) , key : revocation_key, is_htlc : false , amount : tx. output [ 0 ] . value } ;
1705
1704
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
1705
+ ( claimable_outpoints, ( htlc_txid , tx . output . clone ( ) ) )
1707
1706
}
1708
1707
1709
1708
fn broadcast_by_local_state ( & self , local_tx : & LocalSignedTx , delayed_payment_base_key : & SecretKey ) -> ( Vec < Transaction > , Vec < SpendableOutputDescriptor > , Vec < TxOut > ) {
@@ -2019,8 +2018,9 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
2019
2018
}
2020
2019
} else {
2021
2020
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) ;
2021
+ let ( mut new_outpoints, new_outputs ) = self . check_spend_remote_htlc ( & tx, commitment_number, height) ;
2023
2022
claimable_outpoints. append ( & mut new_outpoints) ;
2023
+ watch_outputs. push ( new_outputs) ;
2024
2024
}
2025
2025
}
2026
2026
}
0 commit comments