Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a9e000a

Browse files
committedMay 15, 2024··
fixup! fixup! fixup! Allow to configure the TX fee split when opening DLC channels
1 parent 5cafc9e commit a9e000a

File tree

1 file changed

+29
-18
lines changed

1 file changed

+29
-18
lines changed
 

‎dlc/src/lib.rs

+29-18
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,14 @@ impl PartyParams {
302302
let this_party_fund_base_weight = (FUND_TX_BASE_WEIGHT as f32 * fee_multiplier) as usize;
303303

304304
let fund_weight_without_change = checked_add!(
305-
this_party_fund_base_weight,
306-
inputs_weight
305+
dbg!(this_party_fund_base_weight),
306+
dbg!(inputs_weight)
307307
)?;
308-
let fund_fee_without_change = util::tx_weight_to_fee(fund_weight_without_change, fee_rate_per_vb)?;
308+
let fund_fee_without_change = if inputs_weight > 0 {
309+
util::tx_weight_to_fee(fund_weight_without_change, fee_rate_per_vb)?
310+
} else {
311+
0
312+
};
309313

310314
// Base weight (nLocktime, nVersion, funding input ...) is distributed
311315
// among parties independently of output types
@@ -321,13 +325,11 @@ impl PartyParams {
321325
(FeeConfig::EvenSplit, _) => output_spk_fee,
322326
(FeeConfig::AllOffer, false) | (FeeConfig::AllAccept, true) => 0,
323327
};
324-
let cet_or_refund_base_fee = util::weight_to_fee(this_party_cet_base_weight, fee_rate_per_vb)?;
325-
let cet_or_refund_fee = checked_add!(cet_or_refund_base_fee, output_spk_fee)?;
326-
327-
let extra_fee = (extra_fee as f32 * fee_multiplier) as u64;
328+
let cet_or_refund_base_fee = util::weight_to_fee(dbg!(this_party_cet_base_weight), fee_rate_per_vb)?;
329+
let cet_or_refund_fee = checked_add!(dbg!(cet_or_refund_base_fee), dbg!(output_spk_fee))?;
328330

329331
let required_input_funds =
330-
checked_add!(self.collateral, fund_fee_without_change, cet_or_refund_fee, extra_fee)?;
332+
checked_add!(self.collateral, dbg!(fund_fee_without_change), dbg!(cet_or_refund_fee), dbg!(extra_fee))?;
331333

332334
if self.input_amount < required_input_funds {
333335
return Err(
@@ -375,14 +377,14 @@ impl PartyParams {
375377
}
376378
};
377379

378-
let fund_fee = fund_fee_without_change + change_fee;
380+
let fund_fee = dbg!(fund_fee_without_change) + dbg!(change_fee);
379381

380382
let change_output = TxOut {
381-
value: change_amount,
383+
value: dbg!(change_amount),
382384
script_pubkey: self.change_script_pubkey.clone(),
383385
};
384386

385-
Ok((change_output, fund_fee, cet_or_refund_fee))
387+
Ok((change_output, dbg!(fund_fee), dbg!(cet_or_refund_fee)))
386388
}
387389

388390
fn get_unsigned_tx_inputs_and_serial_ids(&self, sequence: Sequence) -> (Vec<TxIn>, Vec<u64>) {
@@ -460,13 +462,22 @@ pub(crate) fn create_fund_transaction_with_fees(
460462
) -> Result<(Transaction, Script), Error> {
461463
let total_collateral = checked_add!(offer_params.collateral, accept_params.collateral)?;
462464

463-
let (offer_extra_fee, accept_extra_fee) = {
464-
let half = extra_fee / 2;
465-
let remainder = extra_fee % 2;
465+
let (offer_extra_fee, accept_extra_fee) =
466+
match fee_config {
467+
FeeConfig::EvenSplit => {
468+
let half = extra_fee / 2;
469+
let remainder = extra_fee % 2;
466470

467-
// The offer party has to pay an extra sat if there is a remainder.
468-
(half + remainder, half)
469-
};
471+
// The offer party has to pay an extra sat if there is a remainder.
472+
(half + remainder, half)
473+
},
474+
FeeConfig::AllOffer => {
475+
(extra_fee, 0)
476+
},
477+
FeeConfig::AllAccept => {
478+
(0, extra_fee)
479+
},
480+
};
470481

471482
let (offer_change_output, offer_fund_fee, offer_cet_fee) =
472483
offer_params.get_change_output_and_fees(fee_rate_per_vb, offer_extra_fee, fee_config, true)?;
@@ -485,7 +496,7 @@ pub(crate) fn create_fund_transaction_with_fees(
485496
// transaction (for DLC channels) and a CET or refund transaction.
486497
assert_eq!(
487498
fund_output_value,
488-
total_collateral + offer_cet_fee + accept_cet_fee + offer_extra_fee + accept_extra_fee
499+
total_collateral + offer_cet_fee + dbg!(accept_cet_fee) + offer_extra_fee + dbg!(accept_extra_fee)
489500
);
490501

491502
// The sum of the inputs provided by both parties have to cover: the fund output; all the change

0 commit comments

Comments
 (0)
Please sign in to comment.