-
Notifications
You must be signed in to change notification settings - Fork 418
Update fee and dust handling for zero fee channels #3884
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6ecacc4
4f84f19
b497c73
4a8a50c
d8a3727
2a9b187
ccf3ef5
ea0341f
f12c191
54559b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,9 @@ use bitcoin::hashes::ripemd160::Hash as Ripemd160; | |
use bitcoin::hashes::sha256::Hash as Sha256; | ||
use bitcoin::hashes::{Hash, HashEngine}; | ||
|
||
use crate::chain::chaininterface::fee_for_weight; | ||
use crate::chain::chaininterface::{ | ||
fee_for_weight, ConfirmationTarget, FeeEstimator, LowerBoundedFeeEstimator, | ||
}; | ||
use crate::chain::package::WEIGHT_REVOKED_OUTPUT; | ||
use crate::ln::msgs::DecodeError; | ||
use crate::sign::EntropySource; | ||
|
@@ -233,15 +235,45 @@ pub(crate) fn commit_tx_fee_sat(feerate_per_kw: u32, num_htlcs: usize, channel_t | |
/ 1000 | ||
} | ||
|
||
/// Returns the fees for success and timeout second stage HTLC transactions. | ||
pub(super) fn second_stage_tx_fees_sat( | ||
channel_type: &ChannelTypeFeatures, feerate_sat_per_1000_weight: u32, | ||
) -> (u64, u64) { | ||
if channel_type.supports_anchors_zero_fee_htlc_tx() | ||
|| channel_type.supports_anchor_zero_fee_commitments() | ||
{ | ||
(0, 0) | ||
} else { | ||
( | ||
feerate_sat_per_1000_weight as u64 * htlc_success_tx_weight(channel_type) / 1000, | ||
feerate_sat_per_1000_weight as u64 * htlc_timeout_tx_weight(channel_type) / 1000, | ||
) | ||
} | ||
} | ||
|
||
#[rustfmt::skip] | ||
pub(crate) fn htlc_tx_fees_sat(feerate_per_kw: u32, num_accepted_htlcs: usize, num_offered_htlcs: usize, channel_type_features: &ChannelTypeFeatures) -> u64 { | ||
let htlc_tx_fees_sat = if !channel_type_features.supports_anchors_zero_fee_htlc_tx() { | ||
num_accepted_htlcs as u64 * htlc_success_tx_weight(channel_type_features) * feerate_per_kw as u64 / 1000 | ||
+ num_offered_htlcs as u64 * htlc_timeout_tx_weight(channel_type_features) * feerate_per_kw as u64 / 1000 | ||
} else { | ||
let (htlc_success_tx_fee_sat, htlc_timeout_tx_fee_sat) = second_stage_tx_fees_sat( | ||
channel_type_features, feerate_per_kw, | ||
); | ||
|
||
num_accepted_htlcs as u64 * htlc_success_tx_fee_sat + num_offered_htlcs as u64 * htlc_timeout_tx_fee_sat | ||
} | ||
|
||
/// Returns a fee estimate for the commitment transaction depending on channel type. | ||
pub(super) fn commitment_sat_per_1000_weight_for_type<F: Deref>( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a huge fan of the name because it hides which fee types we're using - we're using the "feerates that we'd want to assign to a channel" types, which are different from the "minimum/maximum we'd let our peer assign to a channel", but the name doesn't capture that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you think of anything less atrociously long than There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
fee_estimator: &LowerBoundedFeeEstimator<F>, channel_type: &ChannelTypeFeatures, | ||
) -> u32 | ||
where | ||
F::Target: FeeEstimator, | ||
{ | ||
if channel_type.supports_anchor_zero_fee_commitments() { | ||
0 | ||
}; | ||
htlc_tx_fees_sat | ||
} else if channel_type.supports_anchors_zero_fee_htlc_tx() { | ||
fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::AnchorChannelFee) | ||
} else { | ||
fee_estimator.bounded_sat_per_1000_weight(ConfirmationTarget::NonAnchorChannelFee) | ||
} | ||
} | ||
|
||
// Various functions for key derivation and transaction creation for use within channels. Primarily | ||
|
@@ -806,16 +838,17 @@ pub(crate) fn build_htlc_input(commitment_txid: &Txid, htlc: &HTLCOutputInCommit | |
pub(crate) fn build_htlc_output( | ||
feerate_per_kw: u32, contest_delay: u16, htlc: &HTLCOutputInCommitment, channel_type_features: &ChannelTypeFeatures, broadcaster_delayed_payment_key: &DelayedPaymentKey, revocation_key: &RevocationKey | ||
) -> TxOut { | ||
let weight = if htlc.offered { | ||
htlc_timeout_tx_weight(channel_type_features) | ||
} else { | ||
htlc_success_tx_weight(channel_type_features) | ||
}; | ||
let output_value = if channel_type_features.supports_anchors_zero_fee_htlc_tx() && !channel_type_features.supports_anchors_nonzero_fee_htlc_tx() { | ||
htlc.to_bitcoin_amount() | ||
} else { | ||
let total_fee = Amount::from_sat(feerate_per_kw as u64 * weight / 1000); | ||
htlc.to_bitcoin_amount() - total_fee | ||
let (htlc_success_tx_fee_sat, htlc_timeout_tx_fee_sat) = second_stage_tx_fees_sat( | ||
channel_type_features, feerate_per_kw, | ||
); | ||
|
||
let output_value = { | ||
let total_fee = if htlc.offered { | ||
htlc_timeout_tx_fee_sat | ||
} else { | ||
htlc_success_tx_fee_sat | ||
}; | ||
htlc.to_bitcoin_amount() - Amount::from_sat(total_fee) | ||
}; | ||
|
||
TxOut { | ||
|
Uh oh!
There was an error while loading. Please reload this page.