Skip to content

Commit fad5dc9

Browse files
committed
Simplify new splice test; inputs also contain the weight
1 parent 0a997dd commit fad5dc9

File tree

5 files changed

+37
-200
lines changed

5 files changed

+37
-200
lines changed

lightning/src/ln/channel.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8380,7 +8380,7 @@ impl<SP: Deref> FundedChannel<SP> where
83808380
/// Initiate splicing
83818381
#[cfg(splicing)]
83828382
pub fn splice_channel(&mut self, our_funding_contribution_satoshis: i64,
8383-
our_funding_inputs: Vec<(TxIn, Transaction)>, funding_feerate_perkw: u32, locktime: u32,
8383+
our_funding_inputs: Vec<(TxIn, Transaction, Weight)>, funding_feerate_perkw: u32, locktime: u32,
83848384
) -> Result<msgs::SpliceInit, ChannelError> {
83858385
// Check if a splice has been initiated already.
83868386
// Note: this could be handled more nicely, and support multiple outstanding splice's, the incoming splice_ack matters anyways.
@@ -8415,7 +8415,7 @@ impl<SP: Deref> FundedChannel<SP> where
84158415

84168416
// Check that inputs are sufficient to cover our contribution
84178417
let sum_input: i64 = our_funding_inputs.into_iter().map(
8418-
|(txin, tx)| tx.output.get(txin.previous_output.vout as usize).map(|tx| tx.value.to_sat() as i64).unwrap_or(0)
8418+
|(txin, tx, _)| tx.output.get(txin.previous_output.vout as usize).map(|tx| tx.value.to_sat() as i64).unwrap_or(0)
84198419
).sum();
84208420
if sum_input < our_funding_contribution_satoshis {
84218421
return Err(ChannelError::Warn(format!(

lightning/src/ln/channelmanager.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ use bitcoin::hash_types::{BlockHash, Txid};
3131
use bitcoin::secp256k1::{SecretKey,PublicKey};
3232
use bitcoin::secp256k1::Secp256k1;
3333
use bitcoin::{secp256k1, Sequence, TxIn};
34+
#[cfg(splicing)]
35+
use bitcoin::Weight;
3436

3537
use crate::events::FundingInfo;
3638
use crate::blinded_path::message::{AsyncPaymentsContext, MessageContext, OffersContext};
@@ -4288,7 +4290,7 @@ where
42884290
#[cfg(splicing)]
42894291
pub fn splice_channel(
42904292
&self, channel_id: &ChannelId, counterparty_node_id: &PublicKey, our_funding_contribution_satoshis: i64,
4291-
our_funding_inputs: Vec<(TxIn, Transaction)>, funding_feerate_perkw: u32, locktime: u32,
4293+
our_funding_inputs: Vec<(TxIn, Transaction, Weight)>, funding_feerate_perkw: u32, locktime: u32,
42924294
) -> Result<(), APIError> {
42934295
let per_peer_state = self.per_peer_state.read().unwrap();
42944296

lightning/src/ln/dual_funding_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ fn do_test_v2_channel_establishment(session: V2ChannelEstablishmentTestSession)
4949
&[session.initiator_input_value_satoshis],
5050
)
5151
.into_iter()
52-
.map(|(txin, tx)| (txin, TransactionU16LenLimited::new(tx).unwrap()))
52+
.map(|(txin, tx, _)| (txin, TransactionU16LenLimited::new(tx).unwrap()))
5353
.collect();
5454

5555
// Alice creates a dual-funded channel as initiator.

lightning/src/ln/functional_test_utils.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use crate::util::test_utils;
3838
use crate::util::test_utils::{TestChainMonitor, TestScorer, TestKeysInterface};
3939
use crate::util::ser::{ReadableArgs, Writeable};
4040

41-
use bitcoin::WPubkeyHash;
41+
use bitcoin::{Weight, WPubkeyHash};
4242
use bitcoin::amount::Amount;
4343
use bitcoin::block::{Block, Header, Version as BlockVersion};
4444
use bitcoin::locktime::absolute::{LockTime, LOCK_TIME_THRESHOLD};
@@ -60,6 +60,7 @@ use core::mem;
6060
use core::ops::Deref;
6161
use crate::io;
6262
use crate::prelude::*;
63+
use crate::sign::P2WPKH_WITNESS_WEIGHT;
6364
use crate::sync::{Arc, Mutex, LockTestExt, RwLock};
6465

6566
pub const CHAN_CONFIRM_DEPTH: u32 = 10;
@@ -1236,9 +1237,11 @@ fn internal_create_funding_transaction<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>,
12361237
}
12371238
}
12381239

1240+
/// Create test inputs for a funding transaction.
1241+
/// Return the inputs (with prev tx), and the total witness weight for these inputs
12391242
pub fn create_dual_funding_utxos_with_prev_txs(
12401243
node: &Node<'_, '_, '_>, utxo_values_in_satoshis: &[u64],
1241-
) -> Vec<(TxIn, Transaction)> {
1244+
) -> Vec<(TxIn, Transaction, Weight)> {
12421245
// Ensure we have unique transactions per node by using the locktime.
12431246
let tx = Transaction {
12441247
version: TxVersion::TWO,
@@ -1251,9 +1254,9 @@ pub fn create_dual_funding_utxos_with_prev_txs(
12511254
}).collect()
12521255
};
12531256

1254-
let mut result = vec![];
1257+
let mut inputs = vec![];
12551258
for i in 0..utxo_values_in_satoshis.len() {
1256-
result.push(
1259+
inputs.push(
12571260
(TxIn {
12581261
previous_output: OutPoint {
12591262
txid: tx.compute_txid(),
@@ -1262,9 +1265,13 @@ pub fn create_dual_funding_utxos_with_prev_txs(
12621265
script_sig: ScriptBuf::new(),
12631266
sequence: Sequence::ZERO,
12641267
witness: Witness::new(),
1265-
}, tx.clone()));
1268+
},
1269+
tx.clone(),
1270+
Weight::from_wu(P2WPKH_WITNESS_WEIGHT),
1271+
));
12661272
}
1267-
result
1273+
1274+
inputs
12681275
}
12691276

12701277
pub fn sign_funding_transaction<'a, 'b, 'c>(node_a: &Node<'a, 'b, 'c>, node_b: &Node<'a, 'b, 'c>, channel_value: u64, expected_temporary_channel_id: ChannelId) -> Transaction {

lightning/src/ln/functional_tests_splice.rs

Lines changed: 18 additions & 190 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,17 @@
77
// You may not use this file except in accordance with one or both of these
88
// licenses.
99

10-
//! Tests that test standing up a network of ChannelManagers, creating channels, sending
11-
//! payments/messages between them, and often checking the resulting ChannelMonitors are able to
12-
//! claim outputs on-chain.
13-
14-
use crate::events::{Event, MessageSendEvent, MessageSendEventsProvider};
10+
use crate::events::{MessageSendEvent, MessageSendEventsProvider};
1511
use crate::ln::functional_test_utils::*;
1612
use crate::ln::msgs::ChannelMessageHandler;
17-
use crate::util::config::{ChannelHandshakeConfig, UserConfig};
1813

1914
/// Splicing test, simple splice-in flow. Starts with opening a V1 channel first.
2015
/// Builds on test_channel_open_simple()
2116
#[test]
2217
fn test_v1_splice_in() {
23-
// Set up a network of 2 nodes
24-
let cfg = UserConfig {
25-
channel_handshake_config: ChannelHandshakeConfig { ..Default::default() },
26-
..Default::default()
27-
};
2818
let chanmon_cfgs = create_chanmon_cfgs(2);
2919
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
30-
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[Some(cfg), None]);
20+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
3121
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
3222

3323
// Initiator and Acceptor nodes
@@ -41,193 +31,31 @@ fn test_v1_splice_in() {
4131
let push_msat = 0;
4232
let channel_reserve_amnt_sat = 1_000;
4333

34+
let (_, _, channel_id, _) = create_announced_chan_between_nodes_with_value(
35+
&nodes,
36+
initiator_node_index,
37+
acceptor_node_index,
38+
channel_value_sat,
39+
push_msat,
40+
);
41+
4442
let expected_funded_channel_id =
4543
"ae3367da2c13bc1ceb86bf56418f62828f7ce9d6bfb15a46af5ba1f1ed8b124f";
44+
assert_eq!(channel_id.to_string(), expected_funded_channel_id);
4645

47-
// Have initiator_node initiate a channel to acceptor_node with aforementioned parameters
48-
let channel_id_temp1 = initiator_node
49-
.node
50-
.create_channel(
51-
acceptor_node.node.get_our_node_id(),
52-
channel_value_sat,
53-
push_msat,
54-
42,
55-
None,
56-
None,
57-
)
58-
.unwrap();
59-
60-
// Extract the channel open message from initiator_node to acceptor_node
61-
let open_channel_message = get_event_msg!(
62-
initiator_node,
63-
MessageSendEvent::SendOpenChannel,
64-
acceptor_node.node.get_our_node_id()
65-
);
6646
let expected_initiator_funding_key =
6747
"03c21e841cbc0b48197d060c71e116c185fa0ac281b7d0aa5924f535154437ca3b";
68-
assert_eq!(
69-
open_channel_message.common_fields.funding_pubkey.to_string(),
70-
expected_initiator_funding_key
71-
);
72-
73-
let _res = acceptor_node
74-
.node
75-
.handle_open_channel(initiator_node.node.get_our_node_id(), &open_channel_message.clone());
76-
// Extract the accept channel message from acceptor_node to initiator_node
77-
let accept_channel_message = get_event_msg!(
78-
acceptor_node,
79-
MessageSendEvent::SendAcceptChannel,
80-
initiator_node.node.get_our_node_id()
81-
);
8248
let expected_acceptor_funding_key =
8349
"039481c28b904cbe12681e79937373fc76245c1b29871028ae60ba3152162c319b";
84-
assert_eq!(
85-
accept_channel_message.common_fields.funding_pubkey.to_string(),
86-
expected_acceptor_funding_key
87-
);
88-
89-
let _res = initiator_node.node.handle_accept_channel(
90-
acceptor_node.node.get_our_node_id(),
91-
&accept_channel_message.clone(),
92-
);
93-
// Note: FundingGenerationReady emitted, checked and used below
94-
let (_channel_id_temp2, funding_tx, _funding_output) = create_funding_transaction(
95-
&initiator_node,
96-
&acceptor_node.node.get_our_node_id(),
97-
channel_value_sat,
98-
42,
99-
);
100-
101-
// Funding transation created, provide it
102-
let _res = initiator_node
103-
.node
104-
.funding_transaction_generated(
105-
channel_id_temp1,
106-
acceptor_node.node.get_our_node_id(),
107-
funding_tx.clone(),
108-
)
109-
.unwrap();
110-
111-
let funding_created_message = get_event_msg!(
112-
initiator_node,
113-
MessageSendEvent::SendFundingCreated,
114-
acceptor_node.node.get_our_node_id()
115-
);
116-
117-
let _res = acceptor_node
118-
.node
119-
.handle_funding_created(initiator_node.node.get_our_node_id(), &funding_created_message);
120-
121-
assert_eq!(initiator_node.node.list_channels().len(), 1);
122-
{
123-
let channel = &initiator_node.node.list_channels()[0];
124-
assert!(!channel.is_channel_ready);
125-
}
126-
// do checks on the acceptor node as well (capacity, etc.)
127-
assert_eq!(acceptor_node.node.list_channels().len(), 1);
128-
{
129-
let channel = &acceptor_node.node.list_channels()[0];
130-
assert!(!channel.is_channel_ready);
131-
}
132-
133-
let funding_signed_message = get_event_msg!(
134-
acceptor_node,
135-
MessageSendEvent::SendFundingSigned,
136-
initiator_node.node.get_our_node_id()
137-
);
138-
let _res = initiator_node
139-
.node
140-
.handle_funding_signed(acceptor_node.node.get_our_node_id(), &funding_signed_message);
141-
// Take new channel ID
142-
let channel_id2 = funding_signed_message.channel_id;
143-
assert_eq!(channel_id2.to_string(), expected_funded_channel_id);
144-
145-
// Check that funding transaction has been broadcasted
146-
assert_eq!(
147-
chanmon_cfgs[initiator_node_index].tx_broadcaster.txn_broadcasted.lock().unwrap().len(),
148-
1
149-
);
150-
let broadcasted_funding_tx =
151-
chanmon_cfgs[initiator_node_index].tx_broadcaster.txn_broadcasted.lock().unwrap()[0]
152-
.clone();
153-
154-
check_added_monitors!(initiator_node, 1);
155-
let _ev = get_event!(initiator_node, Event::ChannelPending);
156-
check_added_monitors!(acceptor_node, 1);
157-
let _ev = get_event!(acceptor_node, Event::ChannelPending);
158-
159-
// Simulate confirmation of the funding tx
160-
confirm_transaction(&initiator_node, &broadcasted_funding_tx);
161-
let channel_ready_message = get_event_msg!(
162-
initiator_node,
163-
MessageSendEvent::SendChannelReady,
164-
acceptor_node.node.get_our_node_id()
165-
);
166-
167-
confirm_transaction(&acceptor_node, &broadcasted_funding_tx);
168-
let channel_ready_message2 = get_event_msg!(
169-
acceptor_node,
170-
MessageSendEvent::SendChannelReady,
171-
initiator_node.node.get_our_node_id()
172-
);
173-
174-
let _res = acceptor_node
175-
.node
176-
.handle_channel_ready(initiator_node.node.get_our_node_id(), &channel_ready_message);
177-
let _ev = get_event!(acceptor_node, Event::ChannelReady);
178-
let _channel_update = get_event_msg!(
179-
acceptor_node,
180-
MessageSendEvent::SendChannelUpdate,
181-
initiator_node.node.get_our_node_id()
182-
);
183-
184-
let _res = initiator_node
185-
.node
186-
.handle_channel_ready(acceptor_node.node.get_our_node_id(), &channel_ready_message2);
187-
let _ev = get_event!(initiator_node, Event::ChannelReady);
188-
let _channel_update = get_event_msg!(
189-
initiator_node,
190-
MessageSendEvent::SendChannelUpdate,
191-
acceptor_node.node.get_our_node_id()
192-
);
193-
194-
// check channel capacity and other parameters
195-
assert_eq!(initiator_node.node.list_channels().len(), 1);
196-
{
197-
let channel = &initiator_node.node.list_channels()[0];
198-
assert_eq!(channel.channel_id.to_string(), expected_funded_channel_id);
199-
assert!(channel.is_usable);
200-
assert!(channel.is_channel_ready);
201-
assert_eq!(channel.channel_value_satoshis, channel_value_sat);
202-
assert_eq!(
203-
channel.outbound_capacity_msat,
204-
1000 * (channel_value_sat - channel_reserve_amnt_sat)
205-
);
206-
assert_eq!(channel.funding_txo.unwrap().txid, funding_tx.compute_txid());
207-
assert_eq!(channel.confirmations.unwrap(), 10);
208-
}
209-
// do checks on the acceptor node as well (capacity, etc.)
210-
assert_eq!(acceptor_node.node.list_channels().len(), 1);
211-
{
212-
let channel = &acceptor_node.node.list_channels()[0];
213-
assert_eq!(channel.channel_id.to_string(), expected_funded_channel_id);
214-
assert!(channel.is_usable);
215-
assert!(channel.is_channel_ready);
216-
assert_eq!(channel.channel_value_satoshis, channel_value_sat);
217-
assert_eq!(channel.outbound_capacity_msat, 0);
218-
assert_eq!(channel.funding_txo.unwrap().txid, funding_tx.compute_txid());
219-
assert_eq!(channel.confirmations.unwrap(), 10);
220-
}
22150

22251
// ==== Channel is now ready for normal operation
22352

22453
// === Start of Splicing
225-
println!("Start of Splicing ..., channel_id {}", channel_id2);
54+
println!("Start of Splicing ..., channel_id {}", channel_id);
22655

22756
// Amount being added to the channel through the splice-in
22857
let splice_in_sats: u64 = 20000;
229-
let funding_feerate_perkw = 1024; // TODO
230-
let locktime = 0; // TODO
58+
let funding_feerate_per_kw = 1024; // TODO
23159

23260
// Create additional inputs
23361
let extra_splice_funding_input_sats = 35_000;
@@ -239,12 +67,12 @@ fn test_v1_splice_in() {
23967
let _res = initiator_node
24068
.node
24169
.splice_channel(
242-
&channel_id2,
70+
&channel_id,
24371
&acceptor_node.node.get_our_node_id(),
24472
splice_in_sats as i64,
24573
funding_inputs,
246-
funding_feerate_perkw,
247-
locktime,
74+
funding_feerate_per_kw,
75+
0, // locktime
24876
)
24977
.unwrap();
25078
// Extract the splice message from node0 to node1
@@ -254,7 +82,7 @@ fn test_v1_splice_in() {
25482
acceptor_node.node.get_our_node_id()
25583
);
25684
assert_eq!(splice_init_msg.funding_contribution_satoshis, splice_in_sats as i64);
257-
assert_eq!(splice_init_msg.funding_feerate_perkw, funding_feerate_perkw);
85+
assert_eq!(splice_init_msg.funding_feerate_perkw, funding_feerate_per_kw);
25886
assert_eq!(splice_init_msg.funding_pubkey.to_string(), expected_initiator_funding_key);
25987
assert!(splice_init_msg.require_confirmed_inputs.is_none());
26088

@@ -309,7 +137,7 @@ fn test_v1_splice_in() {
309137
// TODO(splicing): continue with splice transaction negotiation
310138

311139
// === Close channel, cooperatively
312-
initiator_node.node.close_channel(&channel_id2, &acceptor_node.node.get_our_node_id()).unwrap();
140+
initiator_node.node.close_channel(&channel_id, &acceptor_node.node.get_our_node_id()).unwrap();
313141
let node0_shutdown_message = get_event_msg!(
314142
initiator_node,
315143
MessageSendEvent::SendShutdown,

0 commit comments

Comments
 (0)