@@ -20,7 +20,7 @@ use crate::chain::transaction::OutPoint;
2020use crate::sign::{ChannelSigner, EcdsaChannelSigner, EntropySource, SignerProvider};
2121use crate::events::{Event, MessageSendEvent, MessageSendEventsProvider, PathFailure, PaymentPurpose, ClosureReason, HTLCDestination, PaymentFailureReason};
2222use crate::ln::{ChannelId, PaymentPreimage, PaymentSecret, PaymentHash};
23- use crate::ln::channel::{commitment_tx_base_weight, COMMITMENT_TX_WEIGHT_PER_HTLC, CONCURRENT_INBOUND_HTLC_FEE_BUFFER, FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE, MIN_AFFORDABLE_HTLC_COUNT, get_holder_selected_channel_reserve_satoshis, OutboundV1Channel, InboundV1Channel};
23+ use crate::ln::channel::{commitment_tx_base_weight, COMMITMENT_TX_WEIGHT_PER_HTLC, CONCURRENT_INBOUND_HTLC_FEE_BUFFER, FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE, MIN_AFFORDABLE_HTLC_COUNT, get_holder_selected_channel_reserve_satoshis, OutboundV1Channel, InboundV1Channel, COINBASE_MATURITY };
2424use crate::ln::channelmanager::{self, PaymentId, RAACommitmentOrder, PaymentSendFailure, RecipientOnionFields, BREAKDOWN_TIMEOUT, ENABLE_GOSSIP_TICKS, DISABLE_GOSSIP_TICKS, MIN_CLTV_EXPIRY_DELTA};
2525use crate::ln::channel::{DISCONNECT_PEER_AWAITING_RESPONSE_TICKS, ChannelError};
2626use crate::ln::{chan_utils, onion_utils};
@@ -9133,6 +9133,71 @@ fn test_invalid_funding_tx() {
91339133 mine_transaction(&nodes[1], &spend_tx);
91349134}
91359135
9136+ #[test]
9137+ fn test_coinbase_funding_tx() {
9138+ // Miners are able to fund channels directly from coinbase transactions, however
9139+ // by consensus rules, outputs of a coinbase transaction are encumbered by a 100
9140+ // block maturity timelock. To ensure that a (non-0conf) channel like this is enforceable
9141+ // on-chain, the minimum depth is updated to 100 blocks for coinbase funding transactions.
9142+ //
9143+ // Note that 0conf channels with coinbase funding transactions are unaffected and are
9144+ // immediately operational after opening.
9145+ let chanmon_cfgs = create_chanmon_cfgs(2);
9146+ let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
9147+ let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
9148+ let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
9149+
9150+ nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100000, 10001, 42, None).unwrap();
9151+ let open_channel = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id());
9152+
9153+ nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), &open_channel);
9154+ let accept_channel = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id());
9155+
9156+ nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), &accept_channel);
9157+
9158+ // Create the coinbase funding transaction.
9159+ let (temporary_channel_id, tx, funding_output) = create_coinbase_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 42);
9160+
9161+ nodes[0].node.funding_transaction_generated(&temporary_channel_id, &nodes[1].node.get_our_node_id(), tx.clone()).unwrap();
9162+ check_added_monitors!(nodes[0], 0);
9163+ let funding_created = get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, nodes[1].node.get_our_node_id());
9164+
9165+ nodes[1].node.handle_funding_created(&nodes[0].node.get_our_node_id(), &funding_created);
9166+ {
9167+ let mut added_monitors = nodes[1].chain_monitor.added_monitors.lock().unwrap();
9168+ assert_eq!(added_monitors.len(), 1);
9169+ assert_eq!(added_monitors[0].0, funding_output);
9170+ added_monitors.clear();
9171+ }
9172+ expect_channel_pending_event(&nodes[1], &nodes[0].node.get_our_node_id());
9173+
9174+ let funding_signed = get_event_msg!(nodes[1], MessageSendEvent::SendFundingSigned, nodes[0].node.get_our_node_id());
9175+
9176+ nodes[0].node.handle_funding_signed(&nodes[1].node.get_our_node_id(), &funding_signed);
9177+ {
9178+ let mut added_monitors = nodes[0].chain_monitor.added_monitors.lock().unwrap();
9179+ assert_eq!(added_monitors.len(), 1);
9180+ assert_eq!(added_monitors[0].0, funding_output);
9181+ added_monitors.clear();
9182+ }
9183+
9184+ expect_channel_pending_event(&nodes[0], &nodes[1].node.get_our_node_id());
9185+ assert!(nodes[0].node.get_and_clear_pending_events().is_empty());
9186+
9187+ confirm_transaction_at(&nodes[0], &tx, 2);
9188+ connect_blocks(&nodes[0], COINBASE_MATURITY - 2);
9189+ assert!(nodes[0].node.get_and_clear_pending_events().is_empty());
9190+ connect_blocks(&nodes[0], 1);
9191+ let _ = &nodes[1].node.handle_channel_ready(&nodes[0].node.get_our_node_id(), &get_event_msg!(&nodes[0], MessageSendEvent::SendChannelReady, nodes[1].node.get_our_node_id()));
9192+
9193+ confirm_transaction_at(&nodes[1], &tx, 2);
9194+ connect_blocks(&nodes[1], COINBASE_MATURITY - 2);
9195+ assert!(nodes[1].node.get_and_clear_pending_events().is_empty());
9196+ connect_blocks(&nodes[1], 1);
9197+ expect_channel_ready_event(&nodes[1], &nodes[0].node.get_our_node_id());
9198+ create_chan_between_nodes_with_value_confirm_second(&nodes[0], &nodes[1]);
9199+ }
9200+
91369201fn do_test_tx_confirmed_skipping_blocks_immediate_broadcast(test_height_before_timelock: bool) {
91379202 // In the first version of the chain::Confirm interface, after a refactor was made to not
91389203 // broadcast CSV-locked transactions until their CSV lock is up, we wouldn't reliably broadcast
0 commit comments