Skip to content

Commit 5e99ad4

Browse files
committed
f - move FundingTxInput
1 parent 9986d2e commit 5e99ad4

File tree

7 files changed

+125
-109
lines changed

7 files changed

+125
-109
lines changed

lightning/src/ln/channel.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,11 @@ use crate::ln::channel_state::{
5353
OutboundHTLCDetails, OutboundHTLCStateDetails,
5454
};
5555
use crate::ln::channelmanager::{
56-
self, FundingConfirmedMessage, FundingTxInput, HTLCFailureMsg, HTLCSource, OpenChannelMessage,
56+
self, FundingConfirmedMessage, HTLCFailureMsg, HTLCSource, OpenChannelMessage,
5757
PaymentClaimDetails, PendingHTLCInfo, PendingHTLCStatus, RAACommitmentOrder, SentHTLCId,
5858
BREAKDOWN_TIMEOUT, MAX_LOCAL_BREAKDOWN_TIMEOUT, MIN_CLTV_EXPIRY_DELTA,
5959
};
60+
use crate::ln::funding::FundingTxInput;
6061
#[cfg(splicing)]
6162
use crate::ln::interactivetxs::{
6263
calculate_change_output_value, AbortReason, InteractiveTxMessageSend,
@@ -14122,9 +14123,9 @@ mod tests {
1412214123
TOTAL_BITCOIN_SUPPLY_SATOSHIS,
1412314124
};
1412414125
use crate::ln::channel_keys::{RevocationBasepoint, RevocationKey};
14125-
#[cfg(splicing)]
14126-
use crate::ln::channelmanager::FundingTxInput;
1412714126
use crate::ln::channelmanager::{self, HTLCSource, PaymentId};
14127+
#[cfg(splicing)]
14128+
use crate::ln::funding::FundingTxInput;
1412814129
use crate::ln::msgs;
1412914130
use crate::ln::msgs::{ChannelUpdate, UnsignedChannelUpdate, MAX_VALUE_MSAT};
1413014131
use crate::ln::onion_utils::{AttributionData, LocalHTLCFailureReason};

lightning/src/ln/channelmanager.rs

Lines changed: 4 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use bitcoin::secp256k1::Secp256k1;
3232
use bitcoin::secp256k1::{PublicKey, SecretKey};
3333
#[cfg(splicing)]
3434
use bitcoin::ScriptBuf;
35-
use bitcoin::{secp256k1, Sequence, SignedAmount, Weight};
35+
use bitcoin::{secp256k1, Sequence, SignedAmount};
3636

3737
use crate::blinded_path::message::MessageForwardNode;
3838
use crate::blinded_path::message::{AsyncPaymentsContext, OffersContext};
@@ -51,7 +51,6 @@ use crate::chain::channelmonitor::{
5151
};
5252
use crate::chain::transaction::{OutPoint, TransactionData};
5353
use crate::chain::{BestBlock, ChannelMonitorUpdateStatus, Confirm, Watch};
54-
use crate::events::bump_transaction::{Utxo, EMPTY_SCRIPT_SIG_WEIGHT};
5554
use crate::events::{
5655
self, ClosureReason, Event, EventHandler, EventsProvider, HTLCHandlingFailureType,
5756
InboundChannelFunds, PaymentFailureReason, ReplayEvent,
@@ -66,6 +65,8 @@ use crate::ln::channel::{
6665
UpdateFulfillCommitFetch, WithChannelContext,
6766
};
6867
use crate::ln::channel_state::ChannelDetails;
68+
#[cfg(splicing)]
69+
use crate::ln::funding::FundingTxInput;
6970
use crate::ln::inbound_payment;
7071
use crate::ln::interactivetxs::{HandleTxCompleteResult, InteractiveTxMessageSendResult};
7172
use crate::ln::msgs;
@@ -117,10 +118,7 @@ use crate::routing::router::{
117118
RouteParameters, RouteParametersConfig, Router,
118119
};
119120
use crate::sign::ecdsa::EcdsaChannelSigner;
120-
use crate::sign::{
121-
EntropySource, NodeSigner, Recipient, SignerProvider, P2TR_KEY_PATH_WITNESS_WEIGHT,
122-
P2WPKH_WITNESS_WEIGHT,
123-
};
121+
use crate::sign::{EntropySource, NodeSigner, Recipient, SignerProvider};
124122
#[cfg(any(feature = "_test_utils", test))]
125123
use crate::types::features::Bolt11InvoiceFeatures;
126124
use crate::types::features::{
@@ -204,101 +202,6 @@ pub use crate::ln::outbound_payment::{
204202
};
205203
use crate::ln::script::ShutdownScript;
206204

207-
/// An input to contribute to a channel's funding transaction either when using the v2 channel
208-
/// establishment protocol or when splicing.
209-
#[derive(Clone)]
210-
pub struct FundingTxInput {
211-
/// The unspent [`TxOut`] that the input spends.
212-
///
213-
/// [`TxOut`]: bitcoin::TxOut
214-
pub(super) utxo: Utxo,
215-
216-
/// The sequence number to use in the [`TxIn`].
217-
///
218-
/// [`TxIn`]: bitcoin::TxIn
219-
pub(super) sequence: Sequence,
220-
221-
/// The transaction containing the unspent [`TxOut`] referenced by [`utxo`].
222-
///
223-
/// [`TxOut`]: bitcoin::TxOut
224-
/// [`utxo`]: Self::utxo
225-
pub(super) prevtx: Transaction,
226-
}
227-
228-
impl FundingTxInput {
229-
fn new<F: FnOnce(&bitcoin::Script) -> bool>(
230-
prevtx: Transaction, vout: u32, sequence: Sequence, witness_weight: Weight,
231-
script_filter: F,
232-
) -> Result<Self, ()> {
233-
Ok(FundingTxInput {
234-
utxo: Utxo {
235-
outpoint: bitcoin::OutPoint { txid: prevtx.compute_txid(), vout },
236-
output: prevtx
237-
.output
238-
.get(vout as usize)
239-
.filter(|output| script_filter(&output.script_pubkey))
240-
.ok_or(())?
241-
.clone(),
242-
satisfaction_weight: EMPTY_SCRIPT_SIG_WEIGHT + witness_weight.to_wu(),
243-
},
244-
sequence,
245-
prevtx,
246-
})
247-
}
248-
249-
/// Creates an input spending a P2WPKH output from the given `prevtx` at index `vout` using the
250-
/// provided `sequence` number.
251-
///
252-
/// Returns `Err` if no such output exists in `prevtx` at index `vout`.
253-
pub fn new_p2wpkh(prevtx: Transaction, vout: u32, sequence: Sequence) -> Result<Self, ()> {
254-
let witness_weight = Weight::from_wu(P2WPKH_WITNESS_WEIGHT);
255-
FundingTxInput::new(prevtx, vout, sequence, witness_weight, bitcoin::Script::is_p2wpkh)
256-
}
257-
258-
/// Creates an input spending a P2WSH output from the given `prevtx` at index `vout` using the
259-
/// provided `sequence` number.
260-
///
261-
/// Requires passing the weight of witness needed to satisfy the output's script.
262-
///
263-
/// Returns `Err` if no such output exists in `prevtx` at index `vout`.
264-
pub fn new_p2wsh(
265-
prevtx: Transaction, vout: u32, sequence: Sequence, witness_weight: Weight,
266-
) -> Result<Self, ()> {
267-
FundingTxInput::new(prevtx, vout, sequence, witness_weight, bitcoin::Script::is_p2wsh)
268-
}
269-
270-
/// Creates an input spending a P2TR output from the given `prevtx` at index `vout` using the
271-
/// provided `sequence` number.
272-
///
273-
/// This is meant for inputs spending a taproot output using the key path. See
274-
/// [`new_p2tr_script_spend`] for when spending using a script path.
275-
///
276-
/// Returns `Err` if no such output exists in `prevtx` at index `vout`.
277-
///
278-
/// [`new_p2tr_script_spend`]: Self::new_p2tr_script_spend
279-
pub fn new_p2tr_key_spend(
280-
prevtx: Transaction, vout: u32, sequence: Sequence,
281-
) -> Result<Self, ()> {
282-
let witness_weight = Weight::from_wu(P2TR_KEY_PATH_WITNESS_WEIGHT);
283-
FundingTxInput::new(prevtx, vout, sequence, witness_weight, bitcoin::Script::is_p2tr)
284-
}
285-
286-
/// Creates an input spending a P2TR output from the given `prevtx` at index `vout` using the
287-
/// provided `sequence` number.
288-
///
289-
/// Requires passing the weight of witness needed to satisfy a script path of the taproot
290-
/// output. See [`new_p2tr_key_spend`] for when spending using the key path.
291-
///
292-
/// Returns `Err` if no such output exists in `prevtx` at index `vout`.
293-
///
294-
/// [`new_p2tr_key_spend`]: Self::new_p2tr_key_spend
295-
pub fn new_p2tr_script_spend(
296-
prevtx: Transaction, vout: u32, sequence: Sequence, witness_weight: Weight,
297-
) -> Result<Self, ()> {
298-
FundingTxInput::new(prevtx, vout, sequence, witness_weight, bitcoin::Script::is_p2tr)
299-
}
300-
}
301-
302205
// We hold various information about HTLC relay in the HTLC objects in Channel itself:
303206
//
304207
// Upon receipt of an HTLC from a peer, we'll give it a PendingHTLCStatus indicating if it should

lightning/src/ln/dual_funding_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ use {
1818
},
1919
crate::ln::channel::PendingV2Channel,
2020
crate::ln::channel_keys::{DelayedPaymentBasepoint, HtlcBasepoint, RevocationBasepoint},
21-
crate::ln::channelmanager::FundingTxInput,
2221
crate::ln::functional_test_utils::*,
22+
crate::ln::funding::FundingTxInput,
2323
crate::ln::msgs::{BaseMessageHandler, ChannelMessageHandler, MessageSendEvent},
2424
crate::ln::msgs::{CommitmentSigned, TxAddInput, TxAddOutput, TxComplete, TxSignatures},
2525
crate::ln::types::ChannelId,

lightning/src/ln/functional_test_utils.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ use crate::events::{
2323
};
2424
use crate::ln::chan_utils::{commitment_tx_base_weight, COMMITMENT_TX_WEIGHT_PER_HTLC};
2525
use crate::ln::channelmanager::{
26-
AChannelManager, ChainParameters, ChannelManager, ChannelManagerReadArgs, FundingTxInput,
27-
PaymentId, RAACommitmentOrder, RecipientOnionFields, MIN_CLTV_EXPIRY_DELTA,
26+
AChannelManager, ChainParameters, ChannelManager, ChannelManagerReadArgs, PaymentId,
27+
RAACommitmentOrder, RecipientOnionFields, MIN_CLTV_EXPIRY_DELTA,
2828
};
29+
use crate::ln::funding::FundingTxInput;
2930
use crate::ln::msgs;
3031
use crate::ln::msgs::{
3132
BaseMessageHandler, ChannelMessageHandler, MessageSendEvent, RoutingMessageHandler,

lightning/src/ln/funding.rs

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// This file is Copyright its original authors, visible in version control
2+
// history.
3+
//
4+
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
5+
// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
7+
// You may not use this file except in accordance with one or both of these
8+
// licenses.
9+
10+
//! Types pertaining to funding channels.
11+
12+
use bitcoin::{Script, Sequence, Transaction, Weight};
13+
14+
use crate::events::bump_transaction::{Utxo, EMPTY_SCRIPT_SIG_WEIGHT};
15+
use crate::sign::{P2TR_KEY_PATH_WITNESS_WEIGHT, P2WPKH_WITNESS_WEIGHT};
16+
17+
/// An input to contribute to a channel's funding transaction either when using the v2 channel
18+
/// establishment protocol or when splicing.
19+
#[derive(Clone)]
20+
pub struct FundingTxInput {
21+
/// The unspent [`TxOut`] that the input spends.
22+
///
23+
/// [`TxOut`]: bitcoin::TxOut
24+
pub(super) utxo: Utxo,
25+
26+
/// The sequence number to use in the [`TxIn`].
27+
///
28+
/// [`TxIn`]: bitcoin::TxIn
29+
pub(super) sequence: Sequence,
30+
31+
/// The transaction containing the unspent [`TxOut`] referenced by [`utxo`].
32+
///
33+
/// [`TxOut`]: bitcoin::TxOut
34+
/// [`utxo`]: Self::utxo
35+
pub(super) prevtx: Transaction,
36+
}
37+
38+
impl FundingTxInput {
39+
fn new<F: FnOnce(&bitcoin::Script) -> bool>(
40+
prevtx: Transaction, vout: u32, sequence: Sequence, witness_weight: Weight,
41+
script_filter: F,
42+
) -> Result<Self, ()> {
43+
Ok(FundingTxInput {
44+
utxo: Utxo {
45+
outpoint: bitcoin::OutPoint { txid: prevtx.compute_txid(), vout },
46+
output: prevtx
47+
.output
48+
.get(vout as usize)
49+
.filter(|output| script_filter(&output.script_pubkey))
50+
.ok_or(())?
51+
.clone(),
52+
satisfaction_weight: EMPTY_SCRIPT_SIG_WEIGHT + witness_weight.to_wu(),
53+
},
54+
sequence,
55+
prevtx,
56+
})
57+
}
58+
59+
/// Creates an input spending a P2WPKH output from the given `prevtx` at index `vout` using the
60+
/// provided `sequence` number.
61+
///
62+
/// Returns `Err` if no such output exists in `prevtx` at index `vout`.
63+
pub fn new_p2wpkh(prevtx: Transaction, vout: u32, sequence: Sequence) -> Result<Self, ()> {
64+
let witness_weight = Weight::from_wu(P2WPKH_WITNESS_WEIGHT);
65+
FundingTxInput::new(prevtx, vout, sequence, witness_weight, Script::is_p2wpkh)
66+
}
67+
68+
/// Creates an input spending a P2WSH output from the given `prevtx` at index `vout` using the
69+
/// provided `sequence` number.
70+
///
71+
/// Requires passing the weight of witness needed to satisfy the output's script.
72+
///
73+
/// Returns `Err` if no such output exists in `prevtx` at index `vout`.
74+
pub fn new_p2wsh(
75+
prevtx: Transaction, vout: u32, sequence: Sequence, witness_weight: Weight,
76+
) -> Result<Self, ()> {
77+
FundingTxInput::new(prevtx, vout, sequence, witness_weight, Script::is_p2wsh)
78+
}
79+
80+
/// Creates an input spending a P2TR output from the given `prevtx` at index `vout` using the
81+
/// provided `sequence` number.
82+
///
83+
/// This is meant for inputs spending a taproot output using the key path. See
84+
/// [`new_p2tr_script_spend`] for when spending using a script path.
85+
///
86+
/// Returns `Err` if no such output exists in `prevtx` at index `vout`.
87+
///
88+
/// [`new_p2tr_script_spend`]: Self::new_p2tr_script_spend
89+
pub fn new_p2tr_key_spend(
90+
prevtx: Transaction, vout: u32, sequence: Sequence,
91+
) -> Result<Self, ()> {
92+
let witness_weight = Weight::from_wu(P2TR_KEY_PATH_WITNESS_WEIGHT);
93+
FundingTxInput::new(prevtx, vout, sequence, witness_weight, Script::is_p2tr)
94+
}
95+
96+
/// Creates an input spending a P2TR output from the given `prevtx` at index `vout` using the
97+
/// provided `sequence` number.
98+
///
99+
/// Requires passing the weight of witness needed to satisfy a script path of the taproot
100+
/// output. See [`new_p2tr_key_spend`] for when spending using the key path.
101+
///
102+
/// Returns `Err` if no such output exists in `prevtx` at index `vout`.
103+
///
104+
/// [`new_p2tr_key_spend`]: Self::new_p2tr_key_spend
105+
pub fn new_p2tr_script_spend(
106+
prevtx: Transaction, vout: u32, sequence: Sequence, witness_weight: Weight,
107+
) -> Result<Self, ()> {
108+
FundingTxInput::new(prevtx, vout, sequence, witness_weight, Script::is_p2tr)
109+
}
110+
}

lightning/src/ln/interactivetxs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use crate::chain::chaininterface::fee_for_weight;
2828
use crate::events::bump_transaction::{BASE_INPUT_WEIGHT, EMPTY_SCRIPT_SIG_WEIGHT};
2929
use crate::ln::chan_utils::FUNDING_TRANSACTION_WITNESS_WEIGHT;
3030
use crate::ln::channel::{FundingNegotiationContext, TOTAL_BITCOIN_SUPPLY_SATOSHIS};
31-
use crate::ln::channelmanager::FundingTxInput;
31+
use crate::ln::funding::FundingTxInput;
3232
use crate::ln::msgs;
3333
use crate::ln::msgs::{MessageSendEvent, SerialId, TxSignatures};
3434
use crate::ln::types::ChannelId;
@@ -2122,7 +2122,7 @@ pub(super) fn calculate_change_output_value(
21222122
mod tests {
21232123
use crate::chain::chaininterface::{fee_for_weight, FEERATE_FLOOR_SATS_PER_KW};
21242124
use crate::ln::channel::{FundingNegotiationContext, TOTAL_BITCOIN_SUPPLY_SATOSHIS};
2125-
use crate::ln::channelmanager::FundingTxInput;
2125+
use crate::ln::funding::FundingTxInput;
21262126
use crate::ln::interactivetxs::{
21272127
calculate_change_output_value, generate_holder_serial_id, AbortReason,
21282128
HandleTxCompleteValue, InteractiveTxConstructor, InteractiveTxConstructorArgs,

lightning/src/ln/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub mod channel_keys;
1818
pub mod channel_state;
1919
pub mod channelmanager;
2020
mod features;
21+
pub mod funding;
2122
pub mod inbound_payment;
2223
pub mod msgs;
2324
pub mod onion_payment;

0 commit comments

Comments
 (0)