Skip to content

Commit 41f34a3

Browse files
committedOct 23, 2024··
Use correct input in settle claim transaction
Relying on the `is_offer` heuristic caused problems in production.
1 parent 8f65a0b commit 41f34a3

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed
 

‎dlc-manager/src/channel_updater.rs

-2
Original file line numberDiff line numberDiff line change
@@ -2855,7 +2855,6 @@ pub fn finalize_unilateral_close_settled_channel<S: Deref>(
28552855
destination_address: &Address,
28562856
fee_rate_per_vb: u64,
28572857
signer: &S,
2858-
is_offer: bool,
28592858
is_initiator: bool,
28602859
) -> Result<(Transaction, Channel), Error>
28612860
where
@@ -2892,7 +2891,6 @@ where
28922891
CET_NSEQUENCE,
28932892
0,
28942893
fee_rate_per_vb,
2895-
is_offer,
28962894
)?;
28972895

28982896
let closing_channel = SettledClosingChannel {

‎dlc-manager/src/manager.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -1298,11 +1298,10 @@ where
12981298
&self,
12991299
signed_channel: SignedChannel,
13001300
) -> Result<(), Error> {
1301-
let (settle_tx, &is_offer, &is_initiator) = get_signed_channel_state!(
1301+
let (settle_tx, &is_initiator) = get_signed_channel_state!(
13021302
signed_channel,
13031303
SettledClosing,
13041304
settle_transaction,
1305-
is_offer,
13061305
is_initiator
13071306
)?;
13081307

@@ -1312,11 +1311,9 @@ where
13121311
>= CET_NSEQUENCE
13131312
{
13141313
log::info!(
1315-
"Settle transaction {} for channel {} has enough confirmations to spend from it. is_offer={}, is_initiator={}",
1314+
"Settle transaction {} for channel {} has enough confirmations to spend from it",
13161315
settle_tx.txid(),
13171316
serialize_hex(&signed_channel.channel_id),
1318-
is_offer,
1319-
is_initiator
13201317
);
13211318

13221319
let fee_rate_per_vb: u64 = {
@@ -1338,7 +1335,6 @@ where
13381335
&self.wallet.get_new_address()?,
13391336
fee_rate_per_vb,
13401337
&self.wallet,
1341-
is_offer,
13421338
is_initiator,
13431339
)?;
13441340

‎dlc/src/channel/mod.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -415,27 +415,31 @@ pub fn create_and_sign_claim_settle_transaction<C: Signing>(
415415
csv_timelock: u32,
416416
lock_time: u32,
417417
fee_rate_per_vb: u64,
418-
is_offer: bool,
419418
) -> Result<Transaction, Error> {
420419
let own_descriptor = settle_descriptor(own_params, &counter_params.own_pk, csv_timelock);
421420

422-
let vout = if is_offer {
423-
0
424-
} else {
425-
1
421+
let output = settle_tx.output.iter().enumerate().find(|(_, output)| {
422+
output.script_pubkey == own_descriptor.script_pubkey()
423+
});
424+
425+
let (vout, output) = match output {
426+
Some((vout, output)) => (vout, output),
427+
None => {
428+
return Err(Error::InvalidArgument("No claimable output found on settle transaction".to_string()));
429+
},
426430
};
427431

428432
let tx_in = TxIn {
429433
previous_output: OutPoint {
430434
txid: settle_tx.txid(),
431-
vout,
435+
vout: vout as u32,
432436
},
433437
sequence: Sequence::from_height(csv_timelock as u16),
434438
script_sig: Script::default(),
435439
witness: Witness::default(),
436440
};
437441

438-
let input_value = settle_tx.output[vout as usize].value;
442+
let input_value = output.value;
439443

440444
let dest_script_pk_len = dest_address.script_pubkey().len();
441445
let var_int_prefix_len = crate::util::compute_var_int_prefix_size(dest_script_pk_len);

0 commit comments

Comments
 (0)
Please sign in to comment.