Skip to content

Commit c581bab

Browse files
Pass counterparty_node_id to funding_transaction_generated
1 parent 14e52cd commit c581bab

File tree

8 files changed

+24
-23
lines changed

8 files changed

+24
-23
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out) {
442442
value: *channel_value_satoshis, script_pubkey: output_script.clone(),
443443
}]};
444444
funding_output = OutPoint { txid: tx.txid(), index: 0 };
445-
$source.funding_transaction_generated(&temporary_channel_id, tx.clone()).unwrap();
445+
$source.funding_transaction_generated(&temporary_channel_id, &$dest.get_our_node_id(), tx.clone()).unwrap();
446446
channel_txn.push(tx);
447447
} else { panic!("Wrong event type"); }
448448
}

fuzz/src/full_stack.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
575575
continue 'outer_loop;
576576
}
577577
};
578-
if let Err(e) = channelmanager.funding_transaction_generated(&funding_generation.0, tx.clone()) {
578+
if let Err(e) = channelmanager.funding_transaction_generated(&funding_generation.0, &funding_generation.1, tx.clone()) {
579579
// It's possible the channel has been closed in the mean time, but any other
580580
// failure may be a bug.
581581
if let APIError::ChannelUnavailable { err } = e {

lightning-background-processor/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ mod tests {
556556

557557
macro_rules! end_open_channel {
558558
($node_a: expr, $node_b: expr, $temporary_channel_id: expr, $tx: expr) => {{
559-
$node_a.node.funding_transaction_generated(&$temporary_channel_id, $tx.clone()).unwrap();
559+
$node_a.node.funding_transaction_generated(&$temporary_channel_id, &$node_b.node.get_our_node_id(), $tx.clone()).unwrap();
560560
$node_b.node.handle_funding_created(&$node_a.node.get_our_node_id(), &get_event_msg!($node_a, MessageSendEvent::SendFundingCreated, $node_b.node.get_our_node_id()));
561561
$node_a.node.handle_funding_signed(&$node_b.node.get_our_node_id(), &get_event_msg!($node_b, MessageSendEvent::SendFundingSigned, $node_a.node.get_our_node_id()));
562562
}}

lightning/src/ln/chanmon_update_fail_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1811,7 +1811,7 @@ fn do_during_funding_monitor_fail(confirm_a_first: bool, restore_b_before_conf:
18111811

18121812
let (temporary_channel_id, funding_tx, funding_output) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 43);
18131813

1814-
nodes[0].node.funding_transaction_generated(&temporary_channel_id, funding_tx.clone()).unwrap();
1814+
nodes[0].node.funding_transaction_generated(&temporary_channel_id, &nodes[1].node.get_our_node_id(), funding_tx.clone()).unwrap();
18151815
check_added_monitors!(nodes[0], 0);
18161816

18171817
chanmon_cfgs[1].persister.set_update_ret(Err(ChannelMonitorUpdateErr::TemporaryFailure));

lightning/src/ln/channelmanager.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2686,8 +2686,9 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
26862686

26872687
/// Handles the generation of a funding transaction, optionally (for tests) with a function
26882688
/// which checks the correctness of the funding transaction given the associated channel.
2689-
fn funding_transaction_generated_intern<FundingOutput: Fn(&Channel<Signer>, &Transaction) -> Result<OutPoint, APIError>>
2690-
(&self, temporary_channel_id: &[u8; 32], funding_transaction: Transaction, find_funding_output: FundingOutput) -> Result<(), APIError> {
2689+
fn funding_transaction_generated_intern<FundingOutput: Fn(&Channel<Signer>, &Transaction) -> Result<OutPoint, APIError>>(
2690+
&self, temporary_channel_id: &[u8; 32], _counterparty_node_id: &PublicKey, funding_transaction: Transaction, find_funding_output: FundingOutput
2691+
) -> Result<(), APIError> {
26912692
let (chan, msg) = {
26922693
let (res, chan) = match self.channel_state.lock().unwrap().by_id.remove(temporary_channel_id) {
26932694
Some(mut chan) => {
@@ -2728,8 +2729,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
27282729
}
27292730

27302731
#[cfg(test)]
2731-
pub(crate) fn funding_transaction_generated_unchecked(&self, temporary_channel_id: &[u8; 32], funding_transaction: Transaction, output_index: u16) -> Result<(), APIError> {
2732-
self.funding_transaction_generated_intern(temporary_channel_id, funding_transaction, |_, tx| {
2732+
pub(crate) fn funding_transaction_generated_unchecked(&self, temporary_channel_id: &[u8; 32], counterparty_node_id: &PublicKey, funding_transaction: Transaction, output_index: u16) -> Result<(), APIError> {
2733+
self.funding_transaction_generated_intern(temporary_channel_id, counterparty_node_id, funding_transaction, |_, tx| {
27332734
Ok(OutPoint { txid: tx.txid(), index: output_index })
27342735
})
27352736
}
@@ -2756,7 +2757,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
27562757
///
27572758
/// [`Event::FundingGenerationReady`]: crate::util::events::Event::FundingGenerationReady
27582759
/// [`Event::ChannelClosed`]: crate::util::events::Event::ChannelClosed
2759-
pub fn funding_transaction_generated(&self, temporary_channel_id: &[u8; 32], funding_transaction: Transaction) -> Result<(), APIError> {
2760+
pub fn funding_transaction_generated(&self, temporary_channel_id: &[u8; 32], counterparty_node_id: &PublicKey, funding_transaction: Transaction) -> Result<(), APIError> {
27602761
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(&self.total_consistency_lock, &self.persistence_notifier);
27612762

27622763
for inp in funding_transaction.input.iter() {
@@ -2766,7 +2767,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
27662767
});
27672768
}
27682769
}
2769-
self.funding_transaction_generated_intern(temporary_channel_id, funding_transaction, |chan, tx| {
2770+
self.funding_transaction_generated_intern(temporary_channel_id, counterparty_node_id, funding_transaction, |chan, tx| {
27702771
let mut output_index = None;
27712772
let expected_spk = chan.get_funding_redeemscript().to_v0_p2wsh();
27722773
for (idx, outp) in tx.output.iter().enumerate() {
@@ -7424,7 +7425,7 @@ pub mod bench {
74247425
tx = Transaction { version: 2, lock_time: 0, input: Vec::new(), output: vec![TxOut {
74257426
value: 8_000_000, script_pubkey: output_script,
74267427
}]};
7427-
node_a.funding_transaction_generated(&temporary_channel_id, tx.clone()).unwrap();
7428+
node_a.funding_transaction_generated(&temporary_channel_id, &node_b.get_our_node_id(), tx.clone()).unwrap();
74287429
} else { panic!(); }
74297430

74307431
node_b.handle_funding_created(&node_a.get_our_node_id(), &get_event_msg!(node_a_holder, MessageSendEvent::SendFundingCreated, node_b.get_our_node_id()));

lightning/src/ln/functional_test_utils.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ pub fn sign_funding_transaction<'a, 'b, 'c>(node_a: &Node<'a, 'b, 'c>, node_b: &
577577
let (temporary_channel_id, tx, funding_output) = create_funding_transaction(node_a, &node_b.node.get_our_node_id(), channel_value, 42);
578578
assert_eq!(temporary_channel_id, expected_temporary_channel_id);
579579

580-
assert!(node_a.node.funding_transaction_generated(&temporary_channel_id, tx.clone()).is_ok());
580+
assert!(node_a.node.funding_transaction_generated(&temporary_channel_id, &node_b.node.get_our_node_id(), tx.clone()).is_ok());
581581
check_added_monitors!(node_a, 0);
582582

583583
let funding_created_msg = get_event_msg!(node_a, MessageSendEvent::SendFundingCreated, node_b.node.get_our_node_id());
@@ -606,7 +606,7 @@ pub fn sign_funding_transaction<'a, 'b, 'c>(node_a: &Node<'a, 'b, 'c>, node_b: &
606606
node_a.tx_broadcaster.txn_broadcasted.lock().unwrap().clear();
607607

608608
// Ensure that funding_transaction_generated is idempotent.
609-
assert!(node_a.node.funding_transaction_generated(&temporary_channel_id, tx.clone()).is_err());
609+
assert!(node_a.node.funding_transaction_generated(&temporary_channel_id, &node_b.node.get_our_node_id(), tx.clone()).is_err());
610610
assert!(node_a.node.get_and_clear_pending_msg_events().is_empty());
611611
check_added_monitors!(node_a, 0);
612612

@@ -724,7 +724,7 @@ pub fn create_unannounced_chan_between_nodes_with_value<'a, 'b, 'c, 'd>(nodes: &
724724
nodes[a].node.handle_accept_channel(&nodes[b].node.get_our_node_id(), b_flags, &accept_channel);
725725

726726
let (temporary_channel_id, tx, _) = create_funding_transaction(&nodes[a], &nodes[b].node.get_our_node_id(), channel_value, 42);
727-
nodes[a].node.funding_transaction_generated(&temporary_channel_id, tx.clone()).unwrap();
727+
nodes[a].node.funding_transaction_generated(&temporary_channel_id, &nodes[b].node.get_our_node_id(), tx.clone()).unwrap();
728728
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()));
729729
check_added_monitors!(nodes[b], 1);
730730

lightning/src/ln/functional_tests.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ fn do_test_sanity_on_in_flight_opens(steps: u8) {
518518
let (temporary_channel_id, tx, funding_output) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 42);
519519

520520
if steps & 0x0f == 3 { return; }
521-
nodes[0].node.funding_transaction_generated(&temporary_channel_id, tx.clone()).unwrap();
521+
nodes[0].node.funding_transaction_generated(&temporary_channel_id, &nodes[1].node.get_our_node_id(), tx.clone()).unwrap();
522522
check_added_monitors!(nodes[0], 0);
523523
let funding_created = get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, nodes[1].node.get_our_node_id());
524524

@@ -3509,7 +3509,7 @@ fn test_peer_disconnected_before_funding_broadcasted() {
35093509
let (temporary_channel_id, tx, _funding_output) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 1_000_000, 42);
35103510
assert_eq!(temporary_channel_id, expected_temporary_channel_id);
35113511

3512-
assert!(nodes[0].node.funding_transaction_generated(&temporary_channel_id, tx.clone()).is_ok());
3512+
assert!(nodes[0].node.funding_transaction_generated(&temporary_channel_id, &nodes[1].node.get_our_node_id(), tx.clone()).is_ok());
35133513

35143514
let funding_created_msg = get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, nodes[1].node.get_our_node_id());
35153515
assert_eq!(funding_created_msg.temporary_channel_id, expected_temporary_channel_id);
@@ -4428,7 +4428,7 @@ fn test_manager_serialize_deserialize_events() {
44284428

44294429
let (temporary_channel_id, tx, funding_output) = create_funding_transaction(&node_a, &node_b.node.get_our_node_id(), channel_value, 42);
44304430

4431-
node_a.node.funding_transaction_generated(&temporary_channel_id, tx.clone()).unwrap();
4431+
node_a.node.funding_transaction_generated(&temporary_channel_id, &node_b.node.get_our_node_id(), tx.clone()).unwrap();
44324432
check_added_monitors!(node_a, 0);
44334433

44344434
node_b.node.handle_funding_created(&node_a.node.get_our_node_id(), &get_event_msg!(node_a, MessageSendEvent::SendFundingCreated, node_b.node.get_our_node_id()));
@@ -8390,7 +8390,7 @@ fn test_reject_funding_before_inbound_channel_accepted() {
83908390

83918391
let (temporary_channel_id, tx, _) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 42);
83928392

8393-
nodes[0].node.funding_transaction_generated(&temporary_channel_id, tx.clone()).unwrap();
8393+
nodes[0].node.funding_transaction_generated(&temporary_channel_id, &nodes[1].node.get_our_node_id(), tx.clone()).unwrap();
83948394
let funding_created_msg = get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, nodes[1].node.get_our_node_id());
83958395

83968396
// The `funding_created_msg` should be rejected by `nodes[1]` as it hasn't accepted the channel
@@ -8877,7 +8877,7 @@ fn test_pre_lockin_no_chan_closed_update() {
88778877
// Move the first channel through the funding flow...
88788878
let (temporary_channel_id, tx, _) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 42);
88798879

8880-
nodes[0].node.funding_transaction_generated(&temporary_channel_id, tx.clone()).unwrap();
8880+
nodes[0].node.funding_transaction_generated(&temporary_channel_id, &nodes[1].node.get_our_node_id(), tx.clone()).unwrap();
88818881
check_added_monitors!(nodes[0], 0);
88828882

88838883
let funding_created_msg = get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, nodes[1].node.get_our_node_id());
@@ -9172,7 +9172,7 @@ fn test_duplicate_chan_id() {
91729172
// Move the first channel through the funding flow...
91739173
let (temporary_channel_id, tx, funding_output) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 42);
91749174

9175-
nodes[0].node.funding_transaction_generated(&temporary_channel_id, tx.clone()).unwrap();
9175+
nodes[0].node.funding_transaction_generated(&temporary_channel_id, &nodes[1].node.get_our_node_id(), tx.clone()).unwrap();
91769176
check_added_monitors!(nodes[0], 0);
91779177

91789178
let mut funding_created_msg = get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, nodes[1].node.get_our_node_id());
@@ -9354,7 +9354,7 @@ fn test_invalid_funding_tx() {
93549354
output.script_pubkey = bitcoin::Script::new();
93559355
}
93569356

9357-
nodes[0].node.funding_transaction_generated_unchecked(&temporary_channel_id, tx.clone(), 0).unwrap();
9357+
nodes[0].node.funding_transaction_generated_unchecked(&temporary_channel_id, &nodes[1].node.get_our_node_id(), tx.clone(), 0).unwrap();
93589358
nodes[1].node.handle_funding_created(&nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, nodes[1].node.get_our_node_id()));
93599359
check_added_monitors!(nodes[1], 1);
93609360

@@ -9892,7 +9892,7 @@ fn do_test_max_dust_htlc_exposure(dust_outbound_balance: bool, exposure_breach_e
98929892
}
98939893
}
98949894

9895-
nodes[0].node.funding_transaction_generated(&temporary_channel_id, tx.clone()).unwrap();
9895+
nodes[0].node.funding_transaction_generated(&temporary_channel_id, &nodes[1].node.get_our_node_id(), tx.clone()).unwrap();
98969896
nodes[1].node.handle_funding_created(&nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, nodes[1].node.get_our_node_id()));
98979897
check_added_monitors!(nodes[1], 1);
98989898

lightning/src/ln/priv_short_conf_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ fn test_inbound_scid_privacy() {
390390
nodes[1].node.handle_accept_channel(&nodes[2].node.get_our_node_id(), InitFeatures::known(), &accept_channel);
391391

392392
let (temporary_channel_id, tx, _) = create_funding_transaction(&nodes[1], &nodes[2].node.get_our_node_id(), 100_000, 42);
393-
nodes[1].node.funding_transaction_generated(&temporary_channel_id, tx.clone()).unwrap();
393+
nodes[1].node.funding_transaction_generated(&temporary_channel_id, &nodes[2].node.get_our_node_id(), tx.clone()).unwrap();
394394
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()));
395395
check_added_monitors!(nodes[2], 1);
396396

0 commit comments

Comments
 (0)