]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Add `counterparty_node_id` to `FundingGenerationReady`
authorViktor Tigerström <11711198+ViktorTigerstrom@users.noreply.github.com>
Fri, 13 May 2022 21:43:25 +0000 (23:43 +0200)
committerViktor Tigerström <11711198+ViktorTigerstrom@users.noreply.github.com>
Sat, 14 May 2022 00:15:32 +0000 (02:15 +0200)
fuzz/src/full_stack.rs
lightning-background-processor/src/lib.rs
lightning/src/ln/chanmon_update_fail_tests.rs
lightning/src/ln/channelmanager.rs
lightning/src/ln/functional_test_utils.rs
lightning/src/ln/functional_tests.rs
lightning/src/ln/priv_short_conf_tests.rs
lightning/src/util/events.rs

index 330124f8a8942a23585517148096a80bc984dd4b..2da065151d311b8cd2683be1c8186d8f2f300cf8 100644 (file)
@@ -408,7 +408,7 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
        let mut should_forward = false;
        let mut payments_received: Vec<PaymentHash> = Vec::new();
        let mut payments_sent = 0;
-       let mut pending_funding_generation: Vec<([u8; 32], u64, Script)> = Vec::new();
+       let mut pending_funding_generation: Vec<([u8; 32], PublicKey, u64, Script)> = Vec::new();
        let mut pending_funding_signatures = HashMap::new();
 
        loop {
@@ -556,7 +556,7 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
                        10 => {
                                'outer_loop: for funding_generation in pending_funding_generation.drain(..) {
                                        let mut tx = Transaction { version: 0, lock_time: 0, input: Vec::new(), output: vec![TxOut {
-                                                       value: funding_generation.1, script_pubkey: funding_generation.2,
+                                                       value: funding_generation.2, script_pubkey: funding_generation.3,
                                                }] };
                                        let funding_output = 'search_loop: loop {
                                                let funding_txid = tx.txid();
@@ -632,8 +632,8 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
                loss_detector.handler.process_events();
                for event in loss_detector.manager.get_and_clear_pending_events() {
                        match event {
-                               Event::FundingGenerationReady { temporary_channel_id, channel_value_satoshis, output_script, .. } => {
-                                       pending_funding_generation.push((temporary_channel_id, channel_value_satoshis, output_script));
+                               Event::FundingGenerationReady { temporary_channel_id, counterparty_node_id, channel_value_satoshis, output_script, .. } => {
+                                       pending_funding_generation.push((temporary_channel_id, counterparty_node_id, channel_value_satoshis, output_script));
                                },
                                Event::PaymentReceived { payment_hash, .. } => {
                                        //TODO: enhance by fetching random amounts from fuzz input?
index 107f65f9b74f141cdb087eded0befe59d4c9dfac..a0ac265ea6b31778b780f3ff36481dae4e1874bf 100644 (file)
@@ -540,7 +540,7 @@ mod tests {
        macro_rules! handle_funding_generation_ready {
                ($event: expr, $channel_value: expr) => {{
                        match $event {
-                               &Event::FundingGenerationReady { temporary_channel_id, channel_value_satoshis, ref output_script, user_channel_id } => {
+                               &Event::FundingGenerationReady { temporary_channel_id, channel_value_satoshis, ref output_script, user_channel_id, .. } => {
                                        assert_eq!(channel_value_satoshis, $channel_value);
                                        assert_eq!(user_channel_id, 42);
 
index 58fe30ba2618026311066f347da4a99f2d5f4c3f..15ad15d5b542e8555c63bedcd763ef6838abe049 100644 (file)
@@ -1809,7 +1809,7 @@ fn do_during_funding_monitor_fail(confirm_a_first: bool, restore_b_before_conf:
        nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), InitFeatures::known(), &get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()));
        nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), InitFeatures::known(), &get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id()));
 
-       let (temporary_channel_id, funding_tx, funding_output) = create_funding_transaction(&nodes[0], 100000, 43);
+       let (temporary_channel_id, funding_tx, funding_output) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 43);
 
        nodes[0].node.funding_transaction_generated(&temporary_channel_id, funding_tx.clone()).unwrap();
        check_added_monitors!(nodes[0], 0);
index 2ce466c9ac6d4efe7c0cea8a2af324a7d4ecaf19..5cc3e71931bd1ae2035ed44eae56b54b66773df0 100644 (file)
@@ -4212,6 +4212,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
                let mut pending_events = self.pending_events.lock().unwrap();
                pending_events.push(events::Event::FundingGenerationReady {
                        temporary_channel_id: msg.temporary_channel_id,
+                       counterparty_node_id: *counterparty_node_id,
                        channel_value_satoshis: value,
                        output_script,
                        user_channel_id: user_id,
index b4807ea688629a5a1940a1bb37e9b9ba56aa9760..010a64f5668ec4a0fa82563dc702a1ceef9252cd 100644 (file)
@@ -553,13 +553,14 @@ macro_rules! check_added_monitors {
        }
 }
 
-pub fn create_funding_transaction<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, expected_chan_value: u64, expected_user_chan_id: u64) -> ([u8; 32], Transaction, OutPoint) {
+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: u64) -> ([u8; 32], Transaction, OutPoint) {
        let chan_id = *node.network_chan_count.borrow();
 
        let events = node.node.get_and_clear_pending_events();
        assert_eq!(events.len(), 1);
        match events[0] {
-               Event::FundingGenerationReady { ref temporary_channel_id, ref channel_value_satoshis, ref output_script, user_channel_id } => {
+               Event::FundingGenerationReady { ref temporary_channel_id, ref counterparty_node_id, ref channel_value_satoshis, ref output_script, user_channel_id } => {
+                       assert_eq!(counterparty_node_id, expected_counterparty_node_id);
                        assert_eq!(*channel_value_satoshis, expected_chan_value);
                        assert_eq!(user_channel_id, expected_user_chan_id);
 
@@ -573,7 +574,7 @@ pub fn create_funding_transaction<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, expected_
        }
 }
 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 {
-       let (temporary_channel_id, tx, funding_output) = create_funding_transaction(node_a, channel_value, 42);
+       let (temporary_channel_id, tx, funding_output) = create_funding_transaction(node_a, &node_b.node.get_our_node_id(), channel_value, 42);
        assert_eq!(temporary_channel_id, expected_temporary_channel_id);
 
        assert!(node_a.node.funding_transaction_generated(&temporary_channel_id, tx.clone()).is_ok());
@@ -722,7 +723,7 @@ pub fn create_unannounced_chan_between_nodes_with_value<'a, 'b, 'c, 'd>(nodes: &
        let accept_channel = get_event_msg!(nodes[b], MessageSendEvent::SendAcceptChannel, nodes[a].node.get_our_node_id());
        nodes[a].node.handle_accept_channel(&nodes[b].node.get_our_node_id(), b_flags, &accept_channel);
 
-       let (temporary_channel_id, tx, _) = create_funding_transaction(&nodes[a], channel_value, 42);
+       let (temporary_channel_id, tx, _) = create_funding_transaction(&nodes[a], &nodes[b].node.get_our_node_id(), channel_value, 42);
        nodes[a].node.funding_transaction_generated(&temporary_channel_id, tx.clone()).unwrap();
        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()));
        check_added_monitors!(nodes[b], 1);
index aa68454063a596e6f5895632fe9f1c0763453d66..49e06dab2d179acda19a5e07c164f186ba290d95 100644 (file)
@@ -515,7 +515,7 @@ fn do_test_sanity_on_in_flight_opens(steps: u8) {
        if steps & 0x0f == 2 { return; }
        nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), InitFeatures::known(), &accept_channel);
 
-       let (temporary_channel_id, tx, funding_output) = create_funding_transaction(&nodes[0], 100000, 42);
+       let (temporary_channel_id, tx, funding_output) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 42);
 
        if steps & 0x0f == 3 { return; }
        nodes[0].node.funding_transaction_generated(&temporary_channel_id, tx.clone()).unwrap();
@@ -3506,7 +3506,7 @@ fn test_peer_disconnected_before_funding_broadcasted() {
        let accept_channel = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id());
        nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), InitFeatures::known(), &accept_channel);
 
-       let (temporary_channel_id, tx, _funding_output) = create_funding_transaction(&nodes[0], 1_000_000, 42);
+       let (temporary_channel_id, tx, _funding_output) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 1_000_000, 42);
        assert_eq!(temporary_channel_id, expected_temporary_channel_id);
 
        assert!(nodes[0].node.funding_transaction_generated(&temporary_channel_id, tx.clone()).is_ok());
@@ -4426,7 +4426,7 @@ fn test_manager_serialize_deserialize_events() {
        node_b.node.handle_open_channel(&node_a.node.get_our_node_id(), a_flags, &get_event_msg!(node_a, MessageSendEvent::SendOpenChannel, node_b.node.get_our_node_id()));
        node_a.node.handle_accept_channel(&node_b.node.get_our_node_id(), b_flags, &get_event_msg!(node_b, MessageSendEvent::SendAcceptChannel, node_a.node.get_our_node_id()));
 
-       let (temporary_channel_id, tx, funding_output) = create_funding_transaction(&node_a, channel_value, 42);
+       let (temporary_channel_id, tx, funding_output) = create_funding_transaction(&node_a, &node_b.node.get_our_node_id(), channel_value, 42);
 
        node_a.node.funding_transaction_generated(&temporary_channel_id, tx.clone()).unwrap();
        check_added_monitors!(node_a, 0);
@@ -8388,7 +8388,7 @@ fn test_reject_funding_before_inbound_channel_accepted() {
                nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), InitFeatures::known(), &accept_chan_msg);
        }
 
-       let (temporary_channel_id, tx, _) = create_funding_transaction(&nodes[0], 100000, 42);
+       let (temporary_channel_id, tx, _) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 42);
 
        nodes[0].node.funding_transaction_generated(&temporary_channel_id, tx.clone()).unwrap();
        let funding_created_msg = get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, nodes[1].node.get_our_node_id());
@@ -8875,7 +8875,7 @@ fn test_pre_lockin_no_chan_closed_update() {
        nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), InitFeatures::known(), &accept_chan_msg);
 
        // Move the first channel through the funding flow...
-       let (temporary_channel_id, tx, _) = create_funding_transaction(&nodes[0], 100000, 42);
+       let (temporary_channel_id, tx, _) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 42);
 
        nodes[0].node.funding_transaction_generated(&temporary_channel_id, tx.clone()).unwrap();
        check_added_monitors!(nodes[0], 0);
@@ -9164,7 +9164,7 @@ fn test_duplicate_chan_id() {
        }
 
        // Move the first channel through the funding flow...
-       let (temporary_channel_id, tx, funding_output) = create_funding_transaction(&nodes[0], 100000, 42);
+       let (temporary_channel_id, tx, funding_output) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 42);
 
        nodes[0].node.funding_transaction_generated(&temporary_channel_id, tx.clone()).unwrap();
        check_added_monitors!(nodes[0], 0);
@@ -9209,7 +9209,7 @@ fn test_duplicate_chan_id() {
        let open_chan_2_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id());
        nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), InitFeatures::known(), &open_chan_2_msg);
        nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), InitFeatures::known(), &get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id()));
-       create_funding_transaction(&nodes[0], 100000, 42); // Get and check the FundingGenerationReady event
+       create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 42); // Get and check the FundingGenerationReady event
 
        let funding_created = {
                let mut a_channel_lock = nodes[0].node.channel_state.lock().unwrap();
@@ -9342,7 +9342,7 @@ fn test_invalid_funding_tx() {
        nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), InitFeatures::known(), &get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id()));
        nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), InitFeatures::known(), &get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id()));
 
-       let (temporary_channel_id, mut tx, _) = create_funding_transaction(&nodes[0], 100_000, 42);
+       let (temporary_channel_id, mut tx, _) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100_000, 42);
        for output in tx.output.iter_mut() {
                // Make the confirmed funding transaction have a bogus script_pubkey
                output.script_pubkey = bitcoin::Script::new();
@@ -9878,7 +9878,7 @@ fn do_test_max_dust_htlc_exposure(dust_outbound_balance: bool, exposure_breach_e
 
        let opt_anchors = false;
 
-       let (temporary_channel_id, tx, _) = create_funding_transaction(&nodes[0], 1_000_000, 42);
+       let (temporary_channel_id, tx, _) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 1_000_000, 42);
 
        if on_holder_tx {
                if let Some(mut chan) = nodes[0].node.channel_state.lock().unwrap().by_id.get_mut(&temporary_channel_id) {
index d7b940eb90e09dfce8e6557656327440fb987159..598262d90f9ddc8d031aca3a3a1478dbe2b5ac9f 100644 (file)
@@ -389,7 +389,7 @@ fn test_inbound_scid_privacy() {
        let accept_channel = get_event_msg!(nodes[2], MessageSendEvent::SendAcceptChannel, nodes[1].node.get_our_node_id());
        nodes[1].node.handle_accept_channel(&nodes[2].node.get_our_node_id(), InitFeatures::known(), &accept_channel);
 
-       let (temporary_channel_id, tx, _) = create_funding_transaction(&nodes[1], 100_000, 42);
+       let (temporary_channel_id, tx, _) = create_funding_transaction(&nodes[1], &nodes[2].node.get_our_node_id(), 100_000, 42);
        nodes[1].node.funding_transaction_generated(&temporary_channel_id, tx.clone()).unwrap();
        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()));
        check_added_monitors!(nodes[2], 1);
index b67c2ec77b3e3ed0bac42335e3bd9fb07209392e..bebc75baf9b774730d7149b9aee277930bc65013 100644 (file)
@@ -162,8 +162,15 @@ pub enum Event {
        /// [`ChannelManager::funding_transaction_generated`]: crate::ln::channelmanager::ChannelManager::funding_transaction_generated
        FundingGenerationReady {
                /// The random channel_id we picked which you'll need to pass into
-               /// ChannelManager::funding_transaction_generated.
+               /// [`ChannelManager::funding_transaction_generated`].
+               ///
+               /// [`ChannelManager::funding_transaction_generated`]: crate::ln::channelmanager::ChannelManager::funding_transaction_generated
                temporary_channel_id: [u8; 32],
+               /// The counterparty's node_id, which you'll need to pass back into
+               /// [`ChannelManager::funding_transaction_generated`].
+               ///
+               /// [`ChannelManager::funding_transaction_generated`]: crate::ln::channelmanager::ChannelManager::funding_transaction_generated
+               counterparty_node_id: PublicKey,
                /// The value, in satoshis, that the output should have.
                channel_value_satoshis: u64,
                /// The script which should be used in the transaction output.