Skip to content

Commit

Permalink
fixup! fixup! Allow to configure the TX fee split when opening DLC ch…
Browse files Browse the repository at this point in the history
…annels
  • Loading branch information
luckysori committed May 15, 2024
1 parent 047686a commit 5cafc9e
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 33 deletions.
2 changes: 1 addition & 1 deletion dlc-manager/benches/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ fn create_transactions(payouts: &[Payout]) -> DlcTransactions {
input_amount: 300000000,
collateral: 100000000,
};
create_dlc_transactions(&offer_params, &accept_params, payouts, 1000, 2, 0, 1000, 3).unwrap()
create_dlc_transactions(&offer_params, &accept_params, payouts, 1000, 2, 0, 1000, 3, dlc::FeeConfig::EvenSplit).unwrap()
}

fn accept_seckey() -> SecretKey {
Expand Down
5 changes: 5 additions & 0 deletions dlc-manager/src/channel_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ where
offered_contract.cet_locktime,
offered_contract.fund_output_serial_id,
Sequence(offered_channel.cet_nsequence),
fee_config,
)?;
let accept_fund_sk = wallet.get_secret_key_for_pubkey(&accept_params.fund_pubkey)?;
let funding_output_value = txs.dlc_transactions.get_fund_output().value;
Expand Down Expand Up @@ -393,6 +394,7 @@ pub fn verify_and_sign_accepted_channel<S: Deref>(
cet_nsequence: u32,
signer: &S,
chain_monitor: &Mutex<ChainMonitor>,
fee_config: FeeConfig,
) -> Result<(SignedChannel, SignedContract, SignChannel), Error>
where
S::Target: Signer,
Expand All @@ -406,6 +408,7 @@ where
signer,
None,
chain_monitor,
fee_config,
)
}

Expand All @@ -418,6 +421,7 @@ pub(crate) fn verify_and_sign_accepted_channel_internal<S: Deref>(
signer: &S,
sub_channel_info: Option<SubChannelSignVerifyInfo>,
chain_monitor: &Mutex<ChainMonitor>,
fee_config: FeeConfig,
) -> Result<(SignedChannel, SignedContract, SignChannel), Error>
where
S::Target: Signer,
Expand Down Expand Up @@ -521,6 +525,7 @@ where
offered_contract.cet_locktime,
offered_contract.fund_output_serial_id,
Sequence(cet_nsequence),
fee_config,
)?;
let offer_fund_sk =
signer.get_secret_key_for_pubkey(&offered_contract.offer_params.fund_pubkey)?;
Expand Down
2 changes: 2 additions & 0 deletions dlc-manager/src/contract_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ where
0,
offered_contract.cet_locktime,
offered_contract.fund_output_serial_id,
FeeConfig::EvenSplit,
)?;

let fund_output_value = dlc_transactions.get_fund_output().value;
Expand Down Expand Up @@ -265,6 +266,7 @@ where
0,
offered_contract.cet_locktime,
offered_contract.fund_output_serial_id,
FeeConfig::EvenSplit,
)?;
let fund_output_value = dlc_transactions.get_fund_output().value;
let fund_privkey =
Expand Down
14 changes: 9 additions & 5 deletions dlc-manager/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use bitcoin::consensus::encode::serialize_hex;
use bitcoin::{Address, OutPoint, Txid};
use bitcoin::Transaction;
use bitcoin::hashes::hex::ToHex;
use dlc::FeeConfig;
use dlc_messages::channel::{
AcceptChannel, CollaborativeCloseOffer, OfferChannel, Reject, RenewAccept, RenewConfirm,
RenewFinalize, RenewOffer, RenewRevoke, SettleAccept, SettleConfirm, SettleFinalize,
Expand Down Expand Up @@ -237,6 +238,7 @@ where
&self,
msg: &DlcMessage,
counter_party: PublicKey,
fee_config: FeeConfig,
) -> Result<Option<DlcMessage>, Error> {
match msg {
DlcMessage::OnChain(on_chain) => match on_chain {
Expand All @@ -256,7 +258,7 @@ where
Ok(None)
}
ChannelMessage::Accept(a) => Ok(Some(DlcMessage::Channel(ChannelMessage::Sign(
self.on_accept_channel(a, &counter_party)?,
self.on_accept_channel(a, &counter_party, fee_config)?,
)))),
ChannelMessage::Sign(s) => {
self.on_sign_channel(s, &counter_party)?;
Expand Down Expand Up @@ -1438,6 +1440,7 @@ where
&self,
accept_channel: &AcceptChannel,
peer_id: &PublicKey,
fee_config: dlc::FeeConfig,
) -> Result<SignChannel, Error> {
let offered_channel = get_channel_in_state!(
self,
Expand All @@ -1462,6 +1465,7 @@ where
CET_NSEQUENCE,
&self.wallet,
&self.chain_monitor,
fee_config,
);

match res {
Expand Down Expand Up @@ -2938,11 +2942,11 @@ mod test {
let manager = get_manager();

manager
.on_dlc_message(&offer_message, pubkey())
.on_dlc_message(&offer_message, pubkey(), dlc::FeeConfig::EvenSplit)
.expect("To accept the first offer message");

manager
.on_dlc_message(&offer_message, pubkey())
.on_dlc_message(&offer_message, pubkey(), dlc::FeeConfig::EvenSplit)
.expect_err("To reject the second offer message");
}

Expand All @@ -2955,11 +2959,11 @@ mod test {
let manager = get_manager();

manager
.on_dlc_message(&offer_message, pubkey())
.on_dlc_message(&offer_message, pubkey(), dlc::FeeConfig::EvenSplit)
.expect("To accept the first offer message");

manager
.on_dlc_message(&offer_message, pubkey())
.on_dlc_message(&offer_message, pubkey(), dlc::FeeConfig::EvenSplit)
.expect_err("To reject the second offer message");
}
}
1 change: 1 addition & 0 deletions dlc-manager/src/sub_channel_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1920,6 +1920,7 @@ where
self.dlc_channel_manager.get_wallet(),
Some(sub_channel_info),
self.dlc_channel_manager.get_chain_monitor(),
FeeConfig::EvenSplit,
)?;

dlc::verify_tx_input_sig(
Expand Down
3 changes: 2 additions & 1 deletion dlc-manager/tests/channel_execution_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ mod test_utils;
use bitcoin::Amount;
use bitcoin_test_utils::rpc_helpers::init_clients;
use bitcoincore_rpc::RpcApi;
use dlc::FeeConfig;
use dlc_manager::contract::contract_input::ContractInput;
use dlc_manager::manager::{FeeConfig, Manager};
use dlc_manager::manager::Manager;
use dlc_manager::{channel::Channel, contract::Contract, Blockchain, Oracle, Storage, Wallet};
use dlc_manager::{ContractId, DlcChannelId};
use dlc_messages::{ChannelMessage, Message};
Expand Down
14 changes: 9 additions & 5 deletions dlc-manager/tests/ln_dlc_channel_execution_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2233,6 +2233,7 @@ fn settle(test_params: &LnDlcTestParams, channel_id: &DlcChannelId) {
.on_dlc_message(
&Message::Channel(ChannelMessage::SettleOffer(settle_offer)),
test_params.alice_node.channel_manager.get_our_node_id(),
dlc::FeeConfig::EvenSplit,
)
.unwrap();

Expand All @@ -2248,21 +2249,22 @@ fn settle(test_params: &LnDlcTestParams, channel_id: &DlcChannelId) {
.on_dlc_message(
&Message::Channel(ChannelMessage::SettleAccept(settle_accept)),
bob_key,
dlc::FeeConfig::EvenSplit,
)
.unwrap()
.unwrap();

let msg = test_params
.bob_node
.dlc_manager
.on_dlc_message(&msg, alice_key)
.on_dlc_message(&msg, alice_key, dlc::FeeConfig::EvenSplit)
.unwrap()
.unwrap();

test_params
.alice_node
.dlc_manager
.on_dlc_message(&msg, bob_key)
.on_dlc_message(&msg, bob_key, dlc::FeeConfig::EvenSplit)
.unwrap();
}

Expand All @@ -2284,6 +2286,7 @@ fn renew(test_params: &LnDlcTestParams, dlc_channel_id: &DlcChannelId) {
.on_dlc_message(
&Message::Channel(ChannelMessage::RenewOffer(renew_offer)),
test_params.alice_node.channel_manager.get_our_node_id(),
dlc::FeeConfig::EvenSplit,
)
.unwrap();

Expand All @@ -2299,28 +2302,29 @@ fn renew(test_params: &LnDlcTestParams, dlc_channel_id: &DlcChannelId) {
.on_dlc_message(
&Message::Channel(ChannelMessage::RenewAccept(accept)),
test_params.bob_node_id,
dlc::FeeConfig::EvenSplit,
)
.unwrap()
.unwrap();

let msg = test_params
.bob_node
.dlc_manager
.on_dlc_message(&msg, test_params.alice_node_id)
.on_dlc_message(&msg, test_params.alice_node_id, dlc::FeeConfig::EvenSplit)
.unwrap()
.unwrap();

let msg = test_params
.alice_node
.dlc_manager
.on_dlc_message(&msg, test_params.bob_node_id)
.on_dlc_message(&msg, test_params.bob_node_id, dlc::FeeConfig::EvenSplit)
.unwrap()
.unwrap();

test_params
.bob_node
.dlc_manager
.on_dlc_message(&msg, test_params.alice_node_id)
.on_dlc_message(&msg, test_params.alice_node_id, dlc::FeeConfig::EvenSplit)
.unwrap();
}

Expand Down
1 change: 1 addition & 0 deletions dlc-manager/tests/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ macro_rules! receive_loop {
"0218845781f631c48f1c9709e23092067d06837f30aa0cd0544ac887fe91ddd166"
.parse()
.unwrap(),
dlc::FeeConfig::EvenSplit,
);
$sync_send.send(()).expect("Error syncing");
match res {
Expand Down
4 changes: 3 additions & 1 deletion dlc/src/channel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use std::collections::HashMap;

use crate::{signatures_to_secret, util::get_sig_hash_msg, DlcTransactions, PartyParams, Payout};
use crate::{signatures_to_secret, util::get_sig_hash_msg, DlcTransactions, FeeConfig, PartyParams, Payout};

use super::Error;
use bitcoin::{
Expand Down Expand Up @@ -245,6 +245,7 @@ pub fn create_channel_transactions(
cet_lock_time: u32,
fund_output_serial_id: u64,
cet_nsequence: Sequence,
fee_config: FeeConfig,
) -> Result<DlcChannelTransactions, Error> {
let extra_fee = super::util::dlc_channel_extra_fee(fee_rate_per_vb)?;
let (fund, funding_script_pubkey) = super::create_fund_transaction_with_fees(
Expand All @@ -254,6 +255,7 @@ pub fn create_channel_transactions(
fund_lock_time,
fund_output_serial_id,
extra_fee,
fee_config
)?;

create_renewal_channel_transactions(
Expand Down
Loading

0 comments on commit 5cafc9e

Please sign in to comment.