@@ -79,7 +79,7 @@ enum OnchainEvent {
7979 /// Outpoint under claim process by our own tx, once this one get enough confirmations, we remove it from
8080 /// bump-txn candidate buffer.
8181 Claim {
82- claim_request : Txid ,
82+ package_id : PackageID ,
8383 } ,
8484 /// Claim tx aggregate multiple claimable outpoints. One of the outpoint may be claimed by a counterparty party tx.
8585 /// In this case, we need to drop the outpoint and regenerate a new claim tx. By safety, we keep tracking
@@ -123,7 +123,7 @@ impl MaybeReadable for OnchainEventEntry {
123123
124124impl_writeable_tlv_based_enum_upgradable ! ( OnchainEvent ,
125125 ( 0 , Claim ) => {
126- ( 0 , claim_request , required) ,
126+ ( 0 , package_id , required) ,
127127 } ,
128128 ( 1 , ContentiousOutpoint ) => {
129129 ( 0 , package, required) ,
@@ -480,8 +480,8 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
480480 // We check for outpoint spends within claims individually rather than as a set
481481 // since requests can have outpoints split off.
482482 if !self . onchain_events_awaiting_threshold_conf . iter ( )
483- . any ( |event_entry| if let OnchainEvent :: Claim { claim_request } = event_entry. event {
484- first_claim_txid_height. 0 == claim_request . into_inner ( )
483+ . any ( |event_entry| if let OnchainEvent :: Claim { package_id } = event_entry. event {
484+ first_claim_txid_height. 0 == package_id
485485 } else {
486486 // The onchain event is not a claim, keep seeking until we find one.
487487 false
@@ -733,31 +733,13 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
733733 // outpoints to know if transaction is the original claim or a bumped one issued
734734 // by us.
735735 let mut are_sets_equal = true ;
736- if !request. requires_external_funding ( ) || !request. is_malleable ( ) {
737- // If the claim does not require external funds to be allocated through
738- // additional inputs we can simply check the inputs in order as they
739- // cannot change under us.
740- if request. outpoints ( ) . len ( ) != tx. input . len ( ) {
736+ let mut tx_inputs = tx. input . iter ( ) . map ( |input| & input. previous_output ) . collect :: < Vec < _ > > ( ) ;
737+ tx_inputs. sort_unstable ( ) ;
738+ for request_input in request. outpoints ( ) {
739+ if tx_inputs. binary_search ( & request_input) . is_err ( ) {
741740 are_sets_equal = false ;
742- } else {
743- for ( claim_inp, tx_inp) in request. outpoints ( ) . iter ( ) . zip ( tx. input . iter ( ) ) {
744- if * * claim_inp != tx_inp. previous_output {
745- are_sets_equal = false ;
746- }
747- }
748- }
749- } else {
750- // Otherwise, we'll do a linear search for each input (we don't expect
751- // large input sets to exist) to ensure the request's input set is fully
752- // spent to be resilient against the external claim reordering inputs.
753- let mut spends_all_inputs = true ;
754- for request_input in request. outpoints ( ) {
755- if tx. input . iter ( ) . find ( |input| input. previous_output == * request_input) . is_none ( ) {
756- spends_all_inputs = false ;
757- break ;
758- }
741+ break ;
759742 }
760- are_sets_equal = spends_all_inputs;
761743 }
762744
763745 macro_rules! clean_claim_request_after_safety_delay {
@@ -766,7 +748,7 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
766748 txid: tx. txid( ) ,
767749 height: conf_height,
768750 block_hash: Some ( conf_hash) ,
769- event: OnchainEvent :: Claim { claim_request : Txid :: from_inner ( first_claim_txid_height. 0 ) }
751+ event: OnchainEvent :: Claim { package_id : first_claim_txid_height. 0 }
770752 } ;
771753 if !self . onchain_events_awaiting_threshold_conf. contains( & entry) {
772754 self . onchain_events_awaiting_threshold_conf. push( entry) ;
@@ -821,13 +803,13 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
821803 for entry in onchain_events_awaiting_threshold_conf {
822804 if entry. has_reached_confirmation_threshold ( cur_height) {
823805 match entry. event {
824- OnchainEvent :: Claim { claim_request } => {
825- let package_id = claim_request. into_inner ( ) ;
806+ OnchainEvent :: Claim { package_id } => {
826807 // We may remove a whole set of claim outpoints here, as these one may have
827808 // been aggregated in a single tx and claimed so atomically
828809 if let Some ( request) = self . pending_claim_requests . remove ( & package_id) {
829810 for outpoint in request. outpoints ( ) {
830- log_debug ! ( logger, "Removing claim tracking for {} due to maturation of claim tx {}." , outpoint, claim_request) ;
811+ log_debug ! ( logger, "Removing claim tracking for {} due to maturation of claim package {}." ,
812+ outpoint, log_bytes!( package_id) ) ;
831813 self . claimable_outpoints . remove ( & outpoint) ;
832814 #[ cfg( anchors) ]
833815 self . pending_claim_events . remove ( & package_id) ;
@@ -1065,7 +1047,7 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
10651047
10661048 #[ cfg( anchors) ]
10671049 pub ( crate ) fn generate_external_htlc_claim (
1068- & mut self , outp : & :: bitcoin:: OutPoint , preimage : & Option < PaymentPreimage >
1050+ & self , outp : & :: bitcoin:: OutPoint , preimage : & Option < PaymentPreimage >
10691051 ) -> Option < ExternalHTLCClaim > {
10701052 let find_htlc = |holder_commitment : & HolderCommitmentTransaction | -> Option < ExternalHTLCClaim > {
10711053 let trusted_tx = holder_commitment. trust ( ) ;
0 commit comments