@@ -4472,7 +4472,7 @@ fn get_v2_channel_reserve_satoshis(channel_value_satoshis: u64, dust_limit_satos
4472
4472
/// Estimate our part of the fee of the new funding transaction.
4473
4473
/// input_count: Number of contributed inputs.
4474
4474
/// witness_weight: The witness weight for contributed inputs.
4475
- #[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled .
4475
+ #[allow(dead_code)] // TODO(dual_funding): TODO(splicing): Remove allow once used .
4476
4476
fn estimate_v2_funding_transaction_fee(
4477
4477
is_initiator: bool, input_count: usize, witness_weight: Weight,
4478
4478
funding_feerate_sat_per_1000_weight: u32,
@@ -4498,33 +4498,6 @@ fn estimate_v2_funding_transaction_fee(
4498
4498
fee_for_weight(funding_feerate_sat_per_1000_weight, weight)
4499
4499
}
4500
4500
4501
- #[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
4502
- pub(super) fn calculate_our_funding_satoshis(
4503
- is_initiator: bool, funding_inputs: &[(TxIn, TransactionU16LenLimited)],
4504
- total_witness_weight: Weight, funding_feerate_sat_per_1000_weight: u32,
4505
- holder_dust_limit_satoshis: u64,
4506
- ) -> Result<u64, APIError> {
4507
- let estimated_fee = estimate_v2_funding_transaction_fee(is_initiator, funding_inputs.len(), total_witness_weight, funding_feerate_sat_per_1000_weight);
4508
-
4509
- let mut total_input_satoshis = 0u64;
4510
- for (idx, input) in funding_inputs.iter().enumerate() {
4511
- if let Some(output) = input.1.as_transaction().output.get(input.0.previous_output.vout as usize) {
4512
- total_input_satoshis = total_input_satoshis.saturating_add(output.value.to_sat());
4513
- } else {
4514
- return Err(APIError::APIMisuseError {
4515
- err: format!("Transaction with txid {} does not have an output with vout of {} corresponding to TxIn at funding_inputs[{}]",
4516
- input.1.as_transaction().compute_txid(), input.0.previous_output.vout, idx) });
4517
- }
4518
- }
4519
-
4520
- let funding_satoshis = total_input_satoshis.saturating_sub(estimated_fee);
4521
- if funding_satoshis < holder_dust_limit_satoshis {
4522
- Ok(0)
4523
- } else {
4524
- Ok(funding_satoshis)
4525
- }
4526
- }
4527
-
4528
4501
/// Context for dual-funded channels.
4529
4502
pub(super) struct DualFundingChannelContext {
4530
4503
/// The amount in satoshis we will be contributing to the channel.
@@ -9262,27 +9235,23 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
9262
9235
9263
9236
/// Creates a new dual-funded channel from a remote side's request for one.
9264
9237
/// Assumes chain_hash has already been checked and corresponds with what we expect!
9238
+ /// TODO(dual_funding): Allow contributions, pass intended amount and inputs
9265
9239
#[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
9266
9240
pub fn new_inbound<ES: Deref, F: Deref, L: Deref>(
9267
9241
fee_estimator: &LowerBoundedFeeEstimator<F>, entropy_source: &ES, signer_provider: &SP,
9268
9242
holder_node_id: PublicKey, counterparty_node_id: PublicKey, our_supported_features: &ChannelTypeFeatures,
9269
9243
their_features: &InitFeatures, msg: &msgs::OpenChannelV2,
9270
- funding_inputs: Vec<(TxIn, TransactionU16LenLimited)>, total_witness_weight: Weight,
9271
9244
user_id: u128, config: &UserConfig, current_chain_height: u32, logger: &L,
9272
9245
) -> Result<Self, ChannelError>
9273
9246
where ES::Target: EntropySource,
9274
9247
F::Target: FeeEstimator,
9275
9248
L::Target: Logger,
9276
9249
{
9277
- let funding_satoshis = calculate_our_funding_satoshis(
9278
- false, &funding_inputs, total_witness_weight, msg.funding_feerate_sat_per_1000_weight,
9279
- msg.common_fields.dust_limit_satoshis
9280
- ).map_err(|_| ChannelError::Close(
9281
- (
9282
- "Failed to accept channel".to_string(),
9283
- ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) },
9284
- )))?;
9285
- let channel_value_satoshis = funding_satoshis.saturating_add(msg.common_fields.funding_satoshis);
9250
+ // TODO(dual_funding): Take these as input once supported
9251
+ let our_funding_satoshis = 0u64;
9252
+ let our_funding_inputs = Vec::new();
9253
+
9254
+ let channel_value_satoshis = our_funding_satoshis.saturating_add(msg.common_fields.funding_satoshis);
9286
9255
let counterparty_selected_channel_reserve_satoshis = get_v2_channel_reserve_satoshis(
9287
9256
channel_value_satoshis, msg.common_fields.dust_limit_satoshis);
9288
9257
let holder_selected_channel_reserve_satoshis = get_v2_channel_reserve_satoshis(
@@ -9316,7 +9285,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
9316
9285
logger,
9317
9286
false,
9318
9287
9319
- funding_satoshis ,
9288
+ our_funding_satoshis ,
9320
9289
9321
9290
counterparty_pubkeys,
9322
9291
channel_type,
@@ -9331,10 +9300,10 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
9331
9300
context.channel_id = channel_id;
9332
9301
9333
9302
let dual_funding_context = DualFundingChannelContext {
9334
- our_funding_satoshis: funding_satoshis ,
9303
+ our_funding_satoshis: our_funding_satoshis ,
9335
9304
funding_tx_locktime: LockTime::from_consensus(msg.locktime),
9336
9305
funding_feerate_sat_per_1000_weight: msg.funding_feerate_sat_per_1000_weight,
9337
- our_funding_inputs: funding_inputs .clone(),
9306
+ our_funding_inputs: our_funding_inputs .clone(),
9338
9307
};
9339
9308
9340
9309
let interactive_tx_constructor = Some(InteractiveTxConstructor::new(
@@ -9346,7 +9315,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
9346
9315
feerate_sat_per_kw: dual_funding_context.funding_feerate_sat_per_1000_weight,
9347
9316
funding_tx_locktime: dual_funding_context.funding_tx_locktime,
9348
9317
is_initiator: false,
9349
- inputs_to_contribute: funding_inputs ,
9318
+ inputs_to_contribute: our_funding_inputs ,
9350
9319
outputs_to_contribute: Vec::new(),
9351
9320
expected_remote_shared_funding_output: Some((context.get_funding_redeemscript().to_p2wsh(), context.channel_value_satoshis)),
9352
9321
}
@@ -10479,7 +10448,7 @@ mod tests {
10479
10448
use bitcoin::amount::Amount;
10480
10449
use bitcoin::constants::ChainHash;
10481
10450
use bitcoin::script::{ScriptBuf, Builder};
10482
- use bitcoin::transaction::{Transaction, TxIn, TxOut, Version};
10451
+ use bitcoin::transaction::{Transaction, TxOut, Version};
10483
10452
use bitcoin::opcodes;
10484
10453
use bitcoin::network::Network;
10485
10454
use crate::ln::onion_utils::INVALID_ONION_BLINDING;
@@ -10501,7 +10470,7 @@ mod tests {
10501
10470
use crate::routing::router::{Path, RouteHop};
10502
10471
use crate::util::config::UserConfig;
10503
10472
use crate::util::errors::APIError;
10504
- use crate::util::ser::{ReadableArgs, TransactionU16LenLimited, Writeable};
10473
+ use crate::util::ser::{ReadableArgs, Writeable};
10505
10474
use crate::util::test_utils;
10506
10475
use crate::util::test_utils::{OnGetShutdownScriptpubkey, TestKeysInterface};
10507
10476
use bitcoin::secp256k1::{Secp256k1, ecdsa::Signature};
@@ -12253,7 +12222,7 @@ mod tests {
12253
12222
}
12254
12223
12255
12224
#[test]
12256
- fn test_estimate_v2_funding_transaction_fee () {
12225
+ fn test_estimate_v2_unding_transaction_fee () {
12257
12226
use crate::ln::channel::estimate_v2_funding_transaction_fee;
12258
12227
use bitcoin::Weight;
12259
12228
@@ -12287,50 +12256,4 @@ mod tests {
12287
12256
320
12288
12257
);
12289
12258
}
12290
-
12291
- fn funding_input_sats(input_value_sats: u64) -> (TxIn, TransactionU16LenLimited) {
12292
- let input_1_prev_out = TxOut { value: Amount::from_sat(input_value_sats), script_pubkey: ScriptBuf::default() };
12293
- let input_1_prev_tx = Transaction {
12294
- input: vec![], output: vec![input_1_prev_out],
12295
- version: Version::TWO, lock_time: bitcoin::absolute::LockTime::ZERO,
12296
- };
12297
- let input_1_txin = TxIn {
12298
- previous_output: bitcoin::OutPoint { txid: input_1_prev_tx.compute_txid(), vout: 0 },
12299
- ..Default::default()
12300
- };
12301
- (input_1_txin, TransactionU16LenLimited::new(input_1_prev_tx).unwrap())
12302
- }
12303
-
12304
- #[test]
12305
- fn test_calculate_our_funding_satoshis() {
12306
- use crate::ln::channel::calculate_our_funding_satoshis;
12307
- use bitcoin::Weight;
12308
-
12309
- // normal use case, output is less than the available inputs
12310
- assert_eq!(
12311
- calculate_our_funding_satoshis(
12312
- true,
12313
- &[
12314
- funding_input_sats(200_000),
12315
- funding_input_sats(100_000),
12316
- ],
12317
- Weight::from_wu(300),
12318
- 2000,
12319
- 1000,
12320
- ).unwrap(),
12321
- 298332
12322
- );
12323
-
12324
- // below dust limit
12325
- assert_eq!(
12326
- calculate_our_funding_satoshis(
12327
- true,
12328
- &[funding_input_sats(20_000)],
12329
- Weight::from_wu(300),
12330
- 2000,
12331
- 20_000,
12332
- ).unwrap(),
12333
- 0
12334
- );
12335
- }
12336
12259
}
0 commit comments