@@ -2041,8 +2041,12 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
2041
2041
// Prune HTLCs from the previous counterparty commitment tx so we don't generate failure/fulfill
2042
2042
// events for now-revoked/fulfilled HTLCs.
2043
2043
if let Some ( txid) = self . prev_counterparty_commitment_txid . take ( ) {
2044
- for & mut ( _, ref mut source) in self . counterparty_claimable_outpoints . get_mut ( & txid) . unwrap ( ) {
2045
- * source = None ;
2044
+ if self . current_counterparty_commitment_txid . unwrap ( ) != txid {
2045
+ for & mut ( _, ref mut source_opt) in self . counterparty_claimable_outpoints . get_mut ( & txid) . unwrap ( ) {
2046
+ * source_opt = None ;
2047
+ }
2048
+ } else {
2049
+ assert ! ( cfg!( fuzzing) , "Commitment txids are unique outside of fuzzing, where hashes can collide" ) ;
2046
2050
}
2047
2051
}
2048
2052
@@ -4168,10 +4172,10 @@ mod tests {
4168
4172
4169
4173
monitor. provide_latest_holder_commitment_tx ( HolderCommitmentTransaction :: dummy ( ) , preimages_to_holder_htlcs ! ( preimages[ 0 ..10 ] ) ) . unwrap ( ) ;
4170
4174
let dummy_txid = dummy_tx. txid ( ) ;
4171
- monitor. provide_latest_counterparty_commitment_tx ( dummy_txid , preimages_slice_to_htlc_outputs ! ( preimages [ 5 .. 15 ] ) , 281474976710655 , dummy_key , & logger ) ;
4172
- monitor . provide_latest_counterparty_commitment_tx ( dummy_txid , preimages_slice_to_htlc_outputs ! ( preimages[ 15 .. 20 ] ) , 281474976710654 , dummy_key, & logger) ;
4173
- monitor. provide_latest_counterparty_commitment_tx ( dummy_txid , preimages_slice_to_htlc_outputs ! ( preimages [ 17 .. 20 ] ) , 281474976710653 , dummy_key , & logger ) ;
4174
- monitor . provide_latest_counterparty_commitment_tx ( dummy_txid , preimages_slice_to_htlc_outputs ! ( preimages[ 18 ..20 ] ) , 281474976710652 , dummy_key, & logger) ;
4175
+ monitor. provide_latest_counterparty_commitment_tx ( Txid :: from_inner ( Sha256 :: hash ( b"1" ) . into_inner ( ) ) ,
4176
+ preimages_slice_to_htlc_outputs ! ( preimages[ 5 .. 15 ] ) , 281474976710655 , dummy_key, & logger) ;
4177
+ monitor. provide_latest_counterparty_commitment_tx ( Txid :: from_inner ( Sha256 :: hash ( b"2" ) . into_inner ( ) ) ,
4178
+ preimages_slice_to_htlc_outputs ! ( preimages[ 15 ..20 ] ) , 281474976710654 , dummy_key, & logger) ;
4175
4179
for & ( ref preimage, ref hash) in preimages. iter ( ) {
4176
4180
let bounded_fee_estimator = LowerBoundedFeeEstimator :: new ( & fee_estimator) ;
4177
4181
monitor. provide_payment_preimage ( hash, preimage, & broadcaster, & bounded_fee_estimator, & logger) ;
@@ -4185,13 +4189,19 @@ mod tests {
4185
4189
test_preimages_exist ! ( & preimages[ 0 ..10 ] , monitor) ;
4186
4190
test_preimages_exist ! ( & preimages[ 15 ..20 ] , monitor) ;
4187
4191
4192
+ monitor. provide_latest_counterparty_commitment_tx ( Txid :: from_inner ( Sha256 :: hash ( b"3" ) . into_inner ( ) ) ,
4193
+ preimages_slice_to_htlc_outputs ! ( preimages[ 17 ..20 ] ) , 281474976710653 , dummy_key, & logger) ;
4194
+
4188
4195
// Now provide a further secret, pruning preimages 15-17
4189
4196
secret[ 0 ..32 ] . clone_from_slice ( & hex:: decode ( "c7518c8ae4660ed02894df8976fa1a3659c1a8b4b5bec0c4b872abeba4cb8964" ) . unwrap ( ) ) ;
4190
4197
monitor. provide_secret ( 281474976710654 , secret. clone ( ) ) . unwrap ( ) ;
4191
4198
assert_eq ! ( monitor. inner. lock( ) . unwrap( ) . payment_preimages. len( ) , 13 ) ;
4192
4199
test_preimages_exist ! ( & preimages[ 0 ..10 ] , monitor) ;
4193
4200
test_preimages_exist ! ( & preimages[ 17 ..20 ] , monitor) ;
4194
4201
4202
+ monitor. provide_latest_counterparty_commitment_tx ( Txid :: from_inner ( Sha256 :: hash ( b"4" ) . into_inner ( ) ) ,
4203
+ preimages_slice_to_htlc_outputs ! ( preimages[ 18 ..20 ] ) , 281474976710652 , dummy_key, & logger) ;
4204
+
4195
4205
// Now update holder commitment tx info, pruning only element 18 as we still care about the
4196
4206
// previous commitment tx's preimages too
4197
4207
monitor. provide_latest_holder_commitment_tx ( HolderCommitmentTransaction :: dummy ( ) , preimages_to_holder_htlcs ! ( preimages[ 0 ..5 ] ) ) . unwrap ( ) ;
0 commit comments