Skip to content

Commit 0f01921

Browse files
committed
Support creating coinbase funding transactions in tests
1 parent 035b8e4 commit 0f01921

File tree

7 files changed

+39
-30
lines changed

7 files changed

+39
-30
lines changed

lightning/src/ln/chanmon_update_fail_tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1870,7 +1870,7 @@ fn do_during_funding_monitor_fail(confirm_a_first: bool, restore_b_before_conf:
18701870
nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()));
18711871
nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id()));
18721872

1873-
let (temporary_channel_id, funding_tx, funding_output) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 43);
1873+
let (temporary_channel_id, funding_tx, funding_output) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 43, false);
18741874

18751875
nodes[0].node.funding_transaction_generated(&temporary_channel_id, &nodes[1].node.get_our_node_id(), funding_tx.clone()).unwrap();
18761876
check_added_monitors!(nodes[0], 0);
@@ -2836,7 +2836,7 @@ fn do_test_outbound_reload_without_init_mon(use_0conf: bool) {
28362836

28372837
nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id()));
28382838

2839-
let (temporary_channel_id, funding_tx, ..) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 43);
2839+
let (temporary_channel_id, funding_tx, ..) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 43, false);
28402840

28412841
nodes[0].node.funding_transaction_generated(&temporary_channel_id, &nodes[1].node.get_our_node_id(), funding_tx.clone()).unwrap();
28422842
check_added_monitors!(nodes[0], 0);
@@ -2926,7 +2926,7 @@ fn do_test_inbound_reload_without_init_mon(use_0conf: bool, lock_commitment: boo
29262926

29272927
nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id()));
29282928

2929-
let (temporary_channel_id, funding_tx, ..) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 43);
2929+
let (temporary_channel_id, funding_tx, ..) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 43, false);
29302930

29312931
nodes[0].node.funding_transaction_generated(&temporary_channel_id, &nodes[1].node.get_our_node_id(), funding_tx.clone()).unwrap();
29322932
check_added_monitors!(nodes[0], 0);

lightning/src/ln/channel.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5237,16 +5237,16 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
52375237
Err(_) => panic!("Block was bogus - either height was > 16 million, had > 16 million transactions, or had > 65k outputs"),
52385238
}
52395239
}
5240-
}
52415240

5242-
// if this is a coinbase transaction and not a 0-conf channel
5243-
// we should update our min_depth to 100 to handle coinbase maturity
5244-
if tx.is_coin_base() &&
5245-
self.minimum_depth.unwrap_or(0) > 0 &&
5246-
self.minimum_depth.unwrap_or(0) < COINBASE_MATURITY {
5247-
self.minimum_depth = Some(COINBASE_MATURITY);
5248-
}
5241+
// if this is a coinbase transaction and not a 0-conf channel
5242+
// we should update our min_depth to 100 to handle coinbase maturity
5243+
if tx.is_coin_base() &&
5244+
self.minimum_depth.unwrap_or(0) > 0 &&
5245+
self.minimum_depth.unwrap_or(0) < COINBASE_MATURITY {
5246+
self.minimum_depth = Some(COINBASE_MATURITY);
5247+
}
52495248

5249+
}
52505250
// If we allow 1-conf funding, we may need to check for channel_ready here and
52515251
// send it immediately instead of waiting for a best_block_updated call (which
52525252
// may have already happened for this block).

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8862,7 +8862,7 @@ mod tests {
88628862
let accept_channel = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id());
88638863
nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &accept_channel);
88648864

8865-
let (temporary_channel_id, tx, _funding_output) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 1_000_000, 42);
8865+
let (temporary_channel_id, tx, _funding_output) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 1_000_000, 42, false);
88668866
let channel_id = &tx.txid().into_inner();
88678867
{
88688868
// Ensure that the `id_to_peer` map is empty until either party has received the
@@ -9039,7 +9039,7 @@ mod tests {
90399039

90409040
if idx == 0 {
90419041
nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &accept_channel);
9042-
let (temporary_channel_id, tx, _) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100_000, 42);
9042+
let (temporary_channel_id, tx, _) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100_000, 42, false);
90439043
funding_tx = Some(tx.clone());
90449044
nodes[0].node.funding_transaction_generated(&temporary_channel_id, &nodes[1].node.get_our_node_id(), tx).unwrap();
90459045
let funding_created_msg = get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, nodes[1].node.get_our_node_id());

lightning/src/ln/functional_test_utils.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use alloc::rc::Rc;
4747
use crate::sync::{Arc, Mutex, LockTestExt};
4848
use core::mem;
4949
use core::iter::repeat;
50-
use bitcoin::{PackedLockTime, TxMerkleNode};
50+
use bitcoin::{PackedLockTime, TxIn, TxMerkleNode};
5151

5252
pub const CHAN_CONFIRM_DEPTH: u32 = 10;
5353

@@ -933,7 +933,7 @@ macro_rules! reload_node {
933933
};
934934
}
935935

936-
pub fn create_funding_transaction<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, expected_counterparty_node_id: &PublicKey, expected_chan_value: u64, expected_user_chan_id: u128) -> ([u8; 32], Transaction, OutPoint) {
936+
pub fn create_funding_transaction<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, expected_counterparty_node_id: &PublicKey, expected_chan_value: u64, expected_user_chan_id: u128, coinbase: bool) -> ([u8; 32], Transaction, OutPoint) {
937937
let chan_id = *node.network_chan_count.borrow();
938938

939939
let events = node.node.get_and_clear_pending_events();
@@ -944,7 +944,16 @@ pub fn create_funding_transaction<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, expected_
944944
assert_eq!(*channel_value_satoshis, expected_chan_value);
945945
assert_eq!(user_channel_id, expected_user_chan_id);
946946

947-
let tx = Transaction { version: chan_id as i32, lock_time: PackedLockTime::ZERO, input: Vec::new(), output: vec![TxOut {
947+
let input = if coinbase {
948+
vec![TxIn {
949+
previous_output: bitcoin::OutPoint::null(),
950+
..Default::default()
951+
}]
952+
} else {
953+
Vec::new()
954+
};
955+
956+
let tx = Transaction { version: chan_id as i32, lock_time: PackedLockTime::ZERO, input, output: vec![TxOut {
948957
value: *channel_value_satoshis, script_pubkey: output_script.clone(),
949958
}]};
950959
let funding_outpoint = OutPoint { txid: tx.txid(), index: 0 };
@@ -954,7 +963,7 @@ pub fn create_funding_transaction<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, expected_
954963
}
955964
}
956965
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: [u8; 32]) -> Transaction {
957-
let (temporary_channel_id, tx, funding_output) = create_funding_transaction(node_a, &node_b.node.get_our_node_id(), channel_value, 42);
966+
let (temporary_channel_id, tx, funding_output) = create_funding_transaction(node_a, &node_b.node.get_our_node_id(), channel_value, 42, false);
958967
assert_eq!(temporary_channel_id, expected_temporary_channel_id);
959968

960969
assert!(node_a.node.funding_transaction_generated(&temporary_channel_id, &node_b.node.get_our_node_id(), tx.clone()).is_ok());
@@ -1017,7 +1026,7 @@ pub fn open_zero_conf_channel<'a, 'b, 'c, 'd>(initiator: &'a Node<'b, 'c, 'd>, r
10171026
assert_eq!(accept_channel.minimum_depth, 0);
10181027
initiator.node.handle_accept_channel(&receiver.node.get_our_node_id(), &accept_channel);
10191028

1020-
let (temporary_channel_id, tx, _) = create_funding_transaction(&initiator, &receiver.node.get_our_node_id(), 100_000, 42);
1029+
let (temporary_channel_id, tx, _) = create_funding_transaction(&initiator, &receiver.node.get_our_node_id(), 100_000, 42, false);
10211030
initiator.node.funding_transaction_generated(&temporary_channel_id, &receiver.node.get_our_node_id(), tx.clone()).unwrap();
10221031
let funding_created = get_event_msg!(initiator, MessageSendEvent::SendFundingCreated, receiver.node.get_our_node_id());
10231032

@@ -1180,7 +1189,7 @@ pub fn create_unannounced_chan_between_nodes_with_value<'a, 'b, 'c, 'd>(nodes: &
11801189
let accept_channel = get_event_msg!(nodes[b], MessageSendEvent::SendAcceptChannel, nodes[a].node.get_our_node_id());
11811190
nodes[a].node.handle_accept_channel(&nodes[b].node.get_our_node_id(), &accept_channel);
11821191

1183-
let (temporary_channel_id, tx, _) = create_funding_transaction(&nodes[a], &nodes[b].node.get_our_node_id(), channel_value, 42);
1192+
let (temporary_channel_id, tx, _) = create_funding_transaction(&nodes[a], &nodes[b].node.get_our_node_id(), channel_value, 42, false);
11841193
nodes[a].node.funding_transaction_generated(&temporary_channel_id, &nodes[b].node.get_our_node_id(), tx.clone()).unwrap();
11851194
nodes[b].node.handle_funding_created(&nodes[a].node.get_our_node_id(), &get_event_msg!(nodes[a], MessageSendEvent::SendFundingCreated, nodes[b].node.get_our_node_id()));
11861195
check_added_monitors!(nodes[b], 1);

lightning/src/ln/functional_tests.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ fn do_test_sanity_on_in_flight_opens(steps: u8) {
528528
if steps & 0x0f == 2 { return; }
529529
nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &accept_channel);
530530

531-
let (temporary_channel_id, tx, funding_output) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 42);
531+
let (temporary_channel_id, tx, funding_output) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 42, false);
532532

533533
if steps & 0x0f == 3 { return; }
534534
nodes[0].node.funding_transaction_generated(&temporary_channel_id, &nodes[1].node.get_our_node_id(), tx.clone()).unwrap();
@@ -3598,7 +3598,7 @@ fn test_peer_disconnected_before_funding_broadcasted() {
35983598
let accept_channel = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id());
35993599
nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &accept_channel);
36003600

3601-
let (temporary_channel_id, tx, _funding_output) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 1_000_000, 42);
3601+
let (temporary_channel_id, tx, _funding_output) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 1_000_000, 42, false);
36023602
assert_eq!(temporary_channel_id, expected_temporary_channel_id);
36033603

36043604
assert!(nodes[0].node.funding_transaction_generated(&temporary_channel_id, &nodes[1].node.get_our_node_id(), tx.clone()).is_ok());
@@ -7931,7 +7931,7 @@ fn test_reject_funding_before_inbound_channel_accepted() {
79317931
};
79327932
nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &accept_chan_msg);
79337933

7934-
let (temporary_channel_id, tx, _) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 42);
7934+
let (temporary_channel_id, tx, _) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 42, false);
79357935

79367936
nodes[0].node.funding_transaction_generated(&temporary_channel_id, &nodes[1].node.get_our_node_id(), tx.clone()).unwrap();
79377937
let funding_created_msg = get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, nodes[1].node.get_our_node_id());
@@ -8615,7 +8615,7 @@ fn test_pre_lockin_no_chan_closed_update() {
86158615
nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &accept_chan_msg);
86168616

86178617
// Move the first channel through the funding flow...
8618-
let (temporary_channel_id, tx, _) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 42);
8618+
let (temporary_channel_id, tx, _) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 42, false);
86198619

86208620
nodes[0].node.funding_transaction_generated(&temporary_channel_id, &nodes[1].node.get_our_node_id(), tx.clone()).unwrap();
86218621
check_added_monitors!(nodes[0], 0);
@@ -8952,7 +8952,7 @@ fn test_duplicate_chan_id() {
89528952
}
89538953

89548954
// Move the first channel through the funding flow...
8955-
let (temporary_channel_id, tx, funding_output) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 42);
8955+
let (temporary_channel_id, tx, funding_output) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 42, false);
89568956

89578957
nodes[0].node.funding_transaction_generated(&temporary_channel_id, &nodes[1].node.get_our_node_id(), tx.clone()).unwrap();
89588958
check_added_monitors!(nodes[0], 0);
@@ -8999,7 +8999,7 @@ fn test_duplicate_chan_id() {
89998999
let open_chan_2_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id());
90009000
nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_chan_2_msg);
90019001
nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id()));
9002-
create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 42); // Get and check the FundingGenerationReady event
9002+
create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 42, false); // Get and check the FundingGenerationReady event
90039003

90049004
let funding_created = {
90059005
let per_peer_state = nodes[0].node.per_peer_state.read().unwrap();
@@ -9141,7 +9141,7 @@ fn test_invalid_funding_tx() {
91419141
nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()));
91429142
nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id()));
91439143

9144-
let (temporary_channel_id, mut tx, _) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100_000, 42);
9144+
let (temporary_channel_id, mut tx, _) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100_000, 42, false);
91459145

91469146
// Create a witness program which can be spent by a 4-empty-stack-elements witness and which is
91479147
// 136 bytes long. This matches our "accepted HTLC preimage spend" matching, previously causing
@@ -9671,7 +9671,7 @@ fn do_test_max_dust_htlc_exposure(dust_outbound_balance: bool, exposure_breach_e
96719671

96729672
let opt_anchors = false;
96739673

9674-
let (temporary_channel_id, tx, _) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 1_000_000, 42);
9674+
let (temporary_channel_id, tx, _) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 1_000_000, 42, false);
96759675

96769676
if on_holder_tx {
96779677
let mut node_0_per_peer_lock;

lightning/src/ln/priv_short_conf_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ fn test_inbound_scid_privacy() {
359359
let accept_channel = get_event_msg!(nodes[2], MessageSendEvent::SendAcceptChannel, nodes[1].node.get_our_node_id());
360360
nodes[1].node.handle_accept_channel(&nodes[2].node.get_our_node_id(), &accept_channel);
361361

362-
let (temporary_channel_id, tx, _) = create_funding_transaction(&nodes[1], &nodes[2].node.get_our_node_id(), 100_000, 42);
362+
let (temporary_channel_id, tx, _) = create_funding_transaction(&nodes[1], &nodes[2].node.get_our_node_id(), 100_000, 42, false);
363363
nodes[1].node.funding_transaction_generated(&temporary_channel_id, &nodes[2].node.get_our_node_id(), tx.clone()).unwrap();
364364
nodes[2].node.handle_funding_created(&nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendFundingCreated, nodes[2].node.get_our_node_id()));
365365
check_added_monitors!(nodes[2], 1);
@@ -598,7 +598,7 @@ fn test_0conf_channel_with_async_monitor() {
598598
assert_eq!(accept_channel.minimum_depth, 0);
599599
nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &accept_channel);
600600

601-
let (temporary_channel_id, tx, funding_output) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 42);
601+
let (temporary_channel_id, tx, funding_output) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 42, false);
602602
nodes[0].node.funding_transaction_generated(&temporary_channel_id, &nodes[1].node.get_our_node_id(), tx.clone()).unwrap();
603603
let funding_created = get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, nodes[1].node.get_our_node_id());
604604

lightning/src/ln/reload_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ fn test_manager_serialize_deserialize_events() {
238238
node_b.node.handle_open_channel(&node_a.node.get_our_node_id(), &get_event_msg!(node_a, MessageSendEvent::SendOpenChannel, node_b.node.get_our_node_id()));
239239
node_a.node.handle_accept_channel(&node_b.node.get_our_node_id(), &get_event_msg!(node_b, MessageSendEvent::SendAcceptChannel, node_a.node.get_our_node_id()));
240240

241-
let (temporary_channel_id, tx, funding_output) = create_funding_transaction(&node_a, &node_b.node.get_our_node_id(), channel_value, 42);
241+
let (temporary_channel_id, tx, funding_output) = create_funding_transaction(&node_a, &node_b.node.get_our_node_id(), channel_value, 42, false);
242242

243243
node_a.node.funding_transaction_generated(&temporary_channel_id, &node_b.node.get_our_node_id(), tx.clone()).unwrap();
244244
check_added_monitors!(node_a, 0);

0 commit comments

Comments
 (0)