|
14 | 14 | use alloc::collections::BTreeMap;
|
15 | 15 | use core::ops::Deref;
|
16 | 16 |
|
17 |
| -use crate::chain::chaininterface::{BroadcasterInterface, compute_feerate_sat_per_1000_weight, fee_for_weight}; |
| 17 | +use crate::chain::chaininterface::{BroadcasterInterface, compute_feerate_sat_per_1000_weight, fee_for_weight, FEERATE_FLOOR_SATS_PER_KW}; |
18 | 18 | use crate::chain::ClaimId;
|
19 | 19 | use crate::io_extras::sink;
|
20 | 20 | use crate::ln::channel::ANCHOR_OUTPUT_VALUE_SATOSHI;
|
@@ -700,8 +700,21 @@ where
|
700 | 700 | &self, claim_id: ClaimId, package_target_feerate_sat_per_1000_weight: u32,
|
701 | 701 | commitment_tx: &Transaction, commitment_tx_fee_sat: u64, anchor_descriptor: &AnchorDescriptor,
|
702 | 702 | ) -> Result<(), ()> {
|
| 703 | + // Our commitment transaction already has fees allocated to it, so we should take them into |
| 704 | + // account. We compute its feerate and subtract it from the package target, using the result |
| 705 | + // as the target feerate for our anchor transaction. Unfortunately, this results in users |
| 706 | + // overpaying by a small margin since we don't yet know the anchor transaction size, and |
| 707 | + // avoiding the small overpayment only makes our API even more complex. |
| 708 | + let commitment_tx_sat_per_1000_weight: u32 = compute_feerate_sat_per_1000_weight( |
| 709 | + commitment_tx_fee_sat, commitment_tx.weight() as u64, |
| 710 | + ); |
| 711 | + let anchor_target_feerate_sat_per_1000_weight = core::cmp::max( |
| 712 | + package_target_feerate_sat_per_1000_weight - commitment_tx_sat_per_1000_weight, |
| 713 | + FEERATE_FLOOR_SATS_PER_KW, |
| 714 | + ); |
| 715 | + |
703 | 716 | let mut anchor_tx = self.build_anchor_tx(
|
704 |
| - claim_id, package_target_feerate_sat_per_1000_weight, commitment_tx, anchor_descriptor, |
| 717 | + claim_id, anchor_target_feerate_sat_per_1000_weight, commitment_tx, anchor_descriptor, |
705 | 718 | )?;
|
706 | 719 | debug_assert_eq!(anchor_tx.output.len(), 1);
|
707 | 720 |
|
|
0 commit comments