@@ -79,7 +79,7 @@ enum OnchainEvent {
79
79
/// Outpoint under claim process by our own tx, once this one get enough confirmations, we remove it from
80
80
/// bump-txn candidate buffer.
81
81
Claim {
82
- claim_request : Txid ,
82
+ package_id : PackageID ,
83
83
} ,
84
84
/// Claim tx aggregate multiple claimable outpoints. One of the outpoint may be claimed by a counterparty party tx.
85
85
/// 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 {
123
123
124
124
impl_writeable_tlv_based_enum_upgradable ! ( OnchainEvent ,
125
125
( 0 , Claim ) => {
126
- ( 0 , claim_request , required) ,
126
+ ( 0 , package_id , required) ,
127
127
} ,
128
128
( 1 , ContentiousOutpoint ) => {
129
129
( 0 , package, required) ,
@@ -480,8 +480,8 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
480
480
// We check for outpoint spends within claims individually rather than as a set
481
481
// since requests can have outpoints split off.
482
482
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
485
485
} else {
486
486
// The onchain event is not a claim, keep seeking until we find one.
487
487
false
@@ -733,31 +733,13 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
733
733
// outpoints to know if transaction is the original claim or a bumped one issued
734
734
// by us.
735
735
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 ( ) {
741
740
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 ;
759
742
}
760
- are_sets_equal = spends_all_inputs;
761
743
}
762
744
763
745
macro_rules! clean_claim_request_after_safety_delay {
@@ -766,7 +748,7 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
766
748
txid: tx. txid( ) ,
767
749
height: conf_height,
768
750
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 }
770
752
} ;
771
753
if !self . onchain_events_awaiting_threshold_conf. contains( & entry) {
772
754
self . onchain_events_awaiting_threshold_conf. push( entry) ;
@@ -821,13 +803,13 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
821
803
for entry in onchain_events_awaiting_threshold_conf {
822
804
if entry. has_reached_confirmation_threshold ( cur_height) {
823
805
match entry. event {
824
- OnchainEvent :: Claim { claim_request } => {
825
- let package_id = claim_request. into_inner ( ) ;
806
+ OnchainEvent :: Claim { package_id } => {
826
807
// We may remove a whole set of claim outpoints here, as these one may have
827
808
// been aggregated in a single tx and claimed so atomically
828
809
if let Some ( request) = self . pending_claim_requests . remove ( & package_id) {
829
810
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) ) ;
831
813
self . claimable_outpoints . remove ( & outpoint) ;
832
814
#[ cfg( anchors) ]
833
815
self . pending_claim_events . remove ( & package_id) ;
@@ -1065,7 +1047,7 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
1065
1047
1066
1048
#[ cfg( anchors) ]
1067
1049
pub ( crate ) fn generate_external_htlc_claim (
1068
- & mut self , outp : & :: bitcoin:: OutPoint , preimage : & Option < PaymentPreimage >
1050
+ & self , outp : & :: bitcoin:: OutPoint , preimage : & Option < PaymentPreimage >
1069
1051
) -> Option < ExternalHTLCClaim > {
1070
1052
let find_htlc = |holder_commitment : & HolderCommitmentTransaction | -> Option < ExternalHTLCClaim > {
1071
1053
let trusted_tx = holder_commitment. trust ( ) ;
0 commit comments