Skip to content

Commit 1060865

Browse files
authored
Merge pull request #4623 from jkczyz/2026-05-funding-tx-input
Remove `FundingTxInput` type alias in favor of `ConfirmedUtxo`
2 parents 00146df + 44ca076 commit 1060865

4 files changed

Lines changed: 50 additions & 58 deletions

File tree

lightning/src/ln/channel.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ use crate::ln::channelmanager::{
5656
PendingHTLCStatus, RAACommitmentOrder, SentHTLCId, TrustedChannelFeatures, BREAKDOWN_TIMEOUT,
5757
MAX_LOCAL_BREAKDOWN_TIMEOUT, MIN_CLTV_EXPIRY_DELTA,
5858
};
59-
use crate::ln::funding::{
60-
FeeRateAdjustmentError, FundingContribution, FundingTemplate, FundingTxInput,
61-
};
59+
use crate::ln::funding::{FeeRateAdjustmentError, FundingContribution, FundingTemplate};
6260
use crate::ln::interactivetxs::{
6361
AbortReason, HandleTxCompleteValue, InteractiveTxConstructor, InteractiveTxConstructorArgs,
6462
InteractiveTxMessageSend, InteractiveTxSigningSession, SharedOwnedInput, SharedOwnedOutput,
@@ -87,7 +85,7 @@ use crate::util::errors::APIError;
8785
use crate::util::logger::{Level as LoggerLevel, Logger, Record, WithContext};
8886
use crate::util::scid_utils::{block_from_scid, scid_from_parts};
8987
use crate::util::ser::{Readable, ReadableArgs, RequiredWrapper, Writeable, Writer};
90-
use crate::util::wallet_utils::Input;
88+
use crate::util::wallet_utils::{ConfirmedUtxo, Input};
9189
use crate::{impl_readable_for_vec, impl_writeable_for_vec};
9290

9391
use alloc::collections::{btree_map, BTreeMap};
@@ -3100,7 +3098,7 @@ impl FundingNegotiation {
31003098
funding: FundingScope, context: &ChannelContext<SP>, entropy_source: &ES,
31013099
holder_node_id: &PublicKey, our_funding_contribution: SignedAmount,
31023100
prev_funding_input: SharedOwnedInput, locktime: u32, feerate_sat_per_1000_weight: u32,
3103-
our_funding_inputs: Vec<FundingTxInput>, our_funding_outputs: Vec<TxOut>,
3101+
our_funding_inputs: Vec<ConfirmedUtxo>, our_funding_outputs: Vec<TxOut>,
31043102
) -> FundingNegotiation {
31053103
let funding_negotiation_context = FundingNegotiationContext {
31063104
is_initiator: false,
@@ -6933,7 +6931,7 @@ pub(super) struct FundingNegotiationContext {
69336931
pub shared_funding_input: Option<SharedOwnedInput>,
69346932
/// The funding inputs we will be contributing to the channel.
69356933
#[allow(dead_code)] // TODO(dual_funding): Remove once contribution to V2 channels is enabled.
6936-
pub our_funding_inputs: Vec<FundingTxInput>,
6934+
pub our_funding_inputs: Vec<ConfirmedUtxo>,
69376935
/// The funding outputs we will be contributing to the channel.
69386936
#[allow(dead_code)] // TODO(dual_funding): Remove once contribution to V2 channels is enabled.
69396937
pub our_funding_outputs: Vec<TxOut>,
@@ -15430,7 +15428,7 @@ impl<SP: SignerProvider> PendingV2Channel<SP> {
1543015428
pub fn new_outbound<ES: EntropySource, F: FeeEstimator, L: Logger>(
1543115429
fee_estimator: &LowerBoundedFeeEstimator<F>, entropy_source: &ES, signer_provider: &SP,
1543215430
counterparty_node_id: PublicKey, their_features: &InitFeatures, funding_satoshis: u64,
15433-
funding_inputs: Vec<FundingTxInput>, user_id: u128, config: &UserConfig,
15431+
funding_inputs: Vec<ConfirmedUtxo>, user_id: u128, config: &UserConfig,
1543415432
current_chain_height: u32, outbound_scid_alias: u64, funding_confirmation_target: ConfirmationTarget,
1543515433
logger: L, trusted_channel_features: Option<TrustedChannelFeatures>,
1543615434
) -> Result<Self, APIError> {

lightning/src/ln/functional_test_utils.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use crate::ln::channelmanager::{
2929
AChannelManager, ChainParameters, ChannelManager, ChannelManagerReadArgs, PaymentId,
3030
RAACommitmentOrder, TrustedChannelFeatures, MIN_CLTV_EXPIRY_DELTA,
3131
};
32-
use crate::ln::funding::{FundingContribution, FundingTxInput};
32+
use crate::ln::funding::FundingContribution;
3333
use crate::ln::msgs::{self, OpenChannel};
3434
use crate::ln::msgs::{
3535
BaseMessageHandler, ChannelMessageHandler, MessageSendEvent, RoutingMessageHandler,
@@ -55,7 +55,7 @@ use crate::util::test_channel_signer::SignerOp;
5555
use crate::util::test_channel_signer::TestChannelSigner;
5656
use crate::util::test_utils::{self, TestLogger};
5757
use crate::util::test_utils::{TestChainMonitor, TestKeysInterface, TestScorer};
58-
use crate::util::wallet_utils::{WalletSourceSync, WalletSync};
58+
use crate::util::wallet_utils::{ConfirmedUtxo, WalletSourceSync, WalletSync};
5959

6060
use bitcoin::amount::Amount;
6161
use bitcoin::block::{Block, Header, Version as BlockVersion};
@@ -1512,7 +1512,7 @@ fn internal_create_funding_transaction<'a, 'b, 'c>(
15121512
/// Return the inputs (with prev tx), and the total witness weight for these inputs
15131513
pub fn create_dual_funding_utxos_with_prev_txs(
15141514
node: &Node<'_, '_, '_>, utxo_values_in_satoshis: &[u64],
1515-
) -> Vec<FundingTxInput> {
1515+
) -> Vec<ConfirmedUtxo> {
15161516
// Ensure we have unique transactions per node by using the locktime.
15171517
let tx = Transaction {
15181518
version: TxVersion::TWO,
@@ -1536,7 +1536,7 @@ pub fn create_dual_funding_utxos_with_prev_txs(
15361536
.iter()
15371537
.enumerate()
15381538
.map(|(index, _)| index as u32)
1539-
.map(|vout| FundingTxInput::new_p2wpkh(tx.clone(), vout).unwrap())
1539+
.map(|vout| ConfirmedUtxo::new_p2wpkh(tx.clone(), vout).unwrap())
15401540
.collect()
15411541
}
15421542

lightning/src/ln/funding.rs

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::ln::LN_MAX_MSG_LEN;
2424
use crate::prelude::*;
2525
use crate::util::native_async::MaybeSend;
2626
use crate::util::wallet_utils::{
27-
CoinSelection, CoinSelectionSource, CoinSelectionSourceSync, Input,
27+
CoinSelection, CoinSelectionSource, CoinSelectionSourceSync, ConfirmedUtxo, Input,
2828
};
2929

3030
/// Error returned when a [`FundingContribution`] cannot be adjusted to a target feerate.
@@ -370,7 +370,7 @@ impl FundingTemplate {
370370
/// when that is set. `max_feerate` is the highest feerate we are willing to tolerate if we end
371371
/// up as the acceptor, and must be at least `min_feerate`.
372372
pub fn splice_in_inputs(
373-
self, inputs: Vec<FundingTxInput>, min_feerate: FeeRate, max_feerate: FeeRate,
373+
self, inputs: Vec<ConfirmedUtxo>, min_feerate: FeeRate, max_feerate: FeeRate,
374374
) -> Result<FundingContribution, FundingContributionError> {
375375
self.with_prior_contribution(min_feerate, max_feerate).add_inputs(inputs)?.build()
376376
}
@@ -466,8 +466,8 @@ impl FundingTemplate {
466466
}
467467

468468
fn estimate_transaction_fee(
469-
inputs: &[FundingTxInput], outputs: &[TxOut], change_output: Option<&TxOut>,
470-
is_initiator: bool, is_splice: bool, feerate: FeeRate,
469+
inputs: &[ConfirmedUtxo], outputs: &[TxOut], change_output: Option<&TxOut>, is_initiator: bool,
470+
is_splice: bool, feerate: FeeRate,
471471
) -> Amount {
472472
let input_weight: u64 = inputs
473473
.iter()
@@ -515,7 +515,7 @@ fn estimate_transaction_fee(
515515
Weight::from_wu(weight) * feerate
516516
}
517517

518-
fn validate_inputs(inputs: &[FundingTxInput]) -> Result<(), FundingContributionError> {
518+
fn validate_inputs(inputs: &[ConfirmedUtxo]) -> Result<(), FundingContributionError> {
519519
let mut total_value = Amount::ZERO;
520520
for (idx, input) in inputs.iter().enumerate() {
521521
if inputs[..idx]
@@ -559,7 +559,7 @@ enum FundingInputs {
559559
/// Replaces the contribution's inputs with the provided set and fully consumes them without a
560560
/// change output. The amount added to the channel is recomputed from the input total minus fees,
561561
/// while explicit withdrawal outputs still reduce the splice's net value.
562-
ManuallySelected { inputs: Vec<FundingTxInput> },
562+
ManuallySelected { inputs: Vec<ConfirmedUtxo> },
563563
}
564564

565565
impl FundingInputs {
@@ -584,7 +584,7 @@ impl FundingInputs {
584584
}
585585
}
586586

587-
fn manually_selected_inputs(&self) -> &[FundingTxInput] {
587+
fn manually_selected_inputs(&self) -> &[ConfirmedUtxo] {
588588
match self {
589589
FundingInputs::ManuallySelected { inputs } => inputs,
590590
FundingInputs::CoinSelected { .. } => &[],
@@ -613,7 +613,7 @@ pub struct FundingContribution {
613613
///
614614
/// For coin-selected contributions, excess value is returned via [`Self::change_output`]. For
615615
/// manually selected inputs, the full input value is consumed and no change output is created.
616-
inputs: Vec<FundingTxInput>,
616+
inputs: Vec<ConfirmedUtxo>,
617617

618618
/// The outputs to include in the funding transaction.
619619
///
@@ -691,7 +691,7 @@ impl FundingContribution {
691691
}
692692

693693
/// Returns the inputs included in this contribution.
694-
pub fn inputs(&self) -> &[FundingTxInput] {
694+
pub fn inputs(&self) -> &[ConfirmedUtxo] {
695695
&self.inputs
696696
}
697697

@@ -827,7 +827,7 @@ impl FundingContribution {
827827
Some(new_contribution_at_target_feerate)
828828
}
829829

830-
pub(super) fn into_tx_parts(self) -> (Vec<FundingTxInput>, Vec<TxOut>) {
830+
pub(super) fn into_tx_parts(self) -> (Vec<ConfirmedUtxo>, Vec<TxOut>) {
831831
let FundingContribution { inputs, mut outputs, change_output, .. } = self;
832832

833833
if let Some(change_output) = change_output {
@@ -1131,10 +1131,6 @@ impl FundingContribution {
11311131
}
11321132
}
11331133

1134-
/// An input to contribute to a channel's funding transaction either when using the v2 channel
1135-
/// establishment protocol or when splicing.
1136-
pub type FundingTxInput = crate::util::wallet_utils::ConfirmedUtxo;
1137-
11381134
#[derive(Debug, Clone, PartialEq, Eq)]
11391135
struct NoCoinSelectionSource;
11401136
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -1472,7 +1468,7 @@ impl FundingBuilder {
14721468
///
14731469
/// Returns [`FundingContributionError::InvalidSpliceValue`] if the builder already has a
14741470
/// coin-selected value request.
1475-
pub fn add_input(self, input: FundingTxInput) -> Result<Self, FundingContributionError> {
1471+
pub fn add_input(self, input: ConfirmedUtxo) -> Result<Self, FundingContributionError> {
14761472
self.0.add_input_inner(input).map(FundingBuilder)
14771473
}
14781474

@@ -1490,7 +1486,7 @@ impl FundingBuilder {
14901486
///
14911487
/// Returns [`FundingContributionError::InvalidSpliceValue`] if the builder already has a
14921488
/// coin-selected value request.
1493-
pub fn add_inputs(self, inputs: Vec<FundingTxInput>) -> Result<Self, FundingContributionError> {
1489+
pub fn add_inputs(self, inputs: Vec<ConfirmedUtxo>) -> Result<Self, FundingContributionError> {
14941490
self.0.add_inputs_inner(inputs).map(FundingBuilder)
14951491
}
14961492

@@ -1585,7 +1581,7 @@ impl<State> FundingBuilderInner<State> {
15851581
Ok(self)
15861582
}
15871583

1588-
fn add_input_inner(mut self, input: FundingTxInput) -> Result<Self, FundingContributionError> {
1584+
fn add_input_inner(mut self, input: ConfirmedUtxo) -> Result<Self, FundingContributionError> {
15891585
match &mut self.funding_inputs {
15901586
None => {
15911587
self.funding_inputs = Some(FundingInputs::ManuallySelected { inputs: vec![input] })
@@ -1599,7 +1595,7 @@ impl<State> FundingBuilderInner<State> {
15991595
}
16001596

16011597
fn add_inputs_inner(
1602-
mut self, inputs: Vec<FundingTxInput>,
1598+
mut self, inputs: Vec<ConfirmedUtxo>,
16031599
) -> Result<Self, FundingContributionError> {
16041600
match &mut self.funding_inputs {
16051601
None => self.funding_inputs = Some(FundingInputs::ManuallySelected { inputs }),
@@ -1875,11 +1871,11 @@ impl<W: CoinSelectionSourceSync> SyncFundingBuilder<W> {
18751871
mod tests {
18761872
use super::{
18771873
estimate_transaction_fee, FeeRateAdjustmentError, FundingBuilder, FundingContribution,
1878-
FundingContributionError, FundingInputMode, FundingTemplate, FundingTxInput,
1879-
SyncCoinSelectionSource, SyncFundingBuilder,
1874+
FundingContributionError, FundingInputMode, FundingTemplate, SyncCoinSelectionSource,
1875+
SyncFundingBuilder,
18801876
};
18811877
use crate::chain::ClaimId;
1882-
use crate::util::wallet_utils::{CoinSelection, CoinSelectionSourceSync, Input};
1878+
use crate::util::wallet_utils::{CoinSelection, CoinSelectionSourceSync, ConfirmedUtxo, Input};
18831879
use bitcoin::hashes::Hash;
18841880
use bitcoin::transaction::{Transaction, TxOut, Version};
18851881
use bitcoin::{Amount, FeeRate, Psbt, ScriptBuf, SignedAmount, WPubkeyHash, WScriptHash};
@@ -1960,7 +1956,7 @@ mod tests {
19601956
}
19611957

19621958
#[rustfmt::skip]
1963-
fn funding_input_sats(input_value_sats: u64) -> FundingTxInput {
1959+
fn funding_input_sats(input_value_sats: u64) -> ConfirmedUtxo {
19641960
let prevout = TxOut {
19651961
value: Amount::from_sat(input_value_sats),
19661962
script_pubkey: ScriptBuf::new_p2wpkh(&WPubkeyHash::all_zeros()),
@@ -1970,7 +1966,7 @@ mod tests {
19701966
version: Version::TWO, lock_time: bitcoin::absolute::LockTime::ZERO,
19711967
};
19721968

1973-
FundingTxInput::new_p2wpkh(prevtx, 0).unwrap()
1969+
ConfirmedUtxo::new_p2wpkh(prevtx, 0).unwrap()
19741970
}
19751971

19761972
fn funding_output_sats(output_value_sats: u64) -> TxOut {
@@ -1995,7 +1991,7 @@ mod tests {
19951991
}
19961992

19971993
struct MustPayToWallet {
1998-
utxo: FundingTxInput,
1994+
utxo: ConfirmedUtxo,
19991995
change_output: Option<TxOut>,
20001996
expected_must_pay_to_values: Vec<Amount>,
20011997
}
@@ -2805,7 +2801,7 @@ mod tests {
28052801
assert!(prevtx.serialized_length() > crate::ln::LN_MAX_MSG_LEN);
28062802

28072803
let wallet = SingleUtxoWallet {
2808-
utxo: FundingTxInput::new_p2wpkh(prevtx, 0).unwrap(),
2804+
utxo: ConfirmedUtxo::new_p2wpkh(prevtx, 0).unwrap(),
28092805
change_output: None,
28102806
};
28112807
assert!(matches!(
@@ -3713,7 +3709,7 @@ mod tests {
37133709

37143710
/// A mock wallet that returns a single UTXO for coin selection.
37153711
struct SingleUtxoWallet {
3716-
utxo: FundingTxInput,
3712+
utxo: ConfirmedUtxo,
37173713
change_output: Option<TxOut>,
37183714
}
37193715

0 commit comments

Comments
 (0)