Skip to content

Commit 7893ddc

Browse files
Add counterparty_node_id to FundingGenerationReady
1 parent b5a6307 commit 7893ddc

File tree

8 files changed

+30
-21
lines changed

8 files changed

+30
-21
lines changed

fuzz/src/full_stack.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
408408
let mut should_forward = false;
409409
let mut payments_received: Vec<PaymentHash> = Vec::new();
410410
let mut payments_sent = 0;
411-
let mut pending_funding_generation: Vec<([u8; 32], u64, Script)> = Vec::new();
411+
let mut pending_funding_generation: Vec<([u8; 32], PublicKey, u64, Script)> = Vec::new();
412412
let mut pending_funding_signatures = HashMap::new();
413413

414414
loop {
@@ -556,7 +556,7 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
556556
10 => {
557557
'outer_loop: for funding_generation in pending_funding_generation.drain(..) {
558558
let mut tx = Transaction { version: 0, lock_time: 0, input: Vec::new(), output: vec![TxOut {
559-
value: funding_generation.1, script_pubkey: funding_generation.2,
559+
value: funding_generation.2, script_pubkey: funding_generation.3,
560560
}] };
561561
let funding_output = 'search_loop: loop {
562562
let funding_txid = tx.txid();
@@ -632,8 +632,8 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
632632
loss_detector.handler.process_events();
633633
for event in loss_detector.manager.get_and_clear_pending_events() {
634634
match event {
635-
Event::FundingGenerationReady { temporary_channel_id, channel_value_satoshis, output_script, .. } => {
636-
pending_funding_generation.push((temporary_channel_id, channel_value_satoshis, output_script));
635+
Event::FundingGenerationReady { temporary_channel_id, counterparty_node_id, channel_value_satoshis, output_script, .. } => {
636+
pending_funding_generation.push((temporary_channel_id, counterparty_node_id, channel_value_satoshis, output_script));
637637
},
638638
Event::PaymentReceived { payment_hash, .. } => {
639639
//TODO: enhance by fetching random amounts from fuzz input?

lightning-background-processor/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ mod tests {
540540
macro_rules! handle_funding_generation_ready {
541541
($event: expr, $channel_value: expr) => {{
542542
match $event {
543-
&Event::FundingGenerationReady { temporary_channel_id, channel_value_satoshis, ref output_script, user_channel_id } => {
543+
&Event::FundingGenerationReady { temporary_channel_id, channel_value_satoshis, ref output_script, user_channel_id, .. } => {
544544
assert_eq!(channel_value_satoshis, $channel_value);
545545
assert_eq!(user_channel_id, 42);
546546

lightning/src/ln/chanmon_update_fail_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1809,7 +1809,7 @@ fn do_during_funding_monitor_fail(confirm_a_first: bool, restore_b_before_conf:
18091809
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()));
18101810
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()));
18111811

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

18141814
nodes[0].node.funding_transaction_generated(&temporary_channel_id, funding_tx.clone()).unwrap();
18151815
check_added_monitors!(nodes[0], 0);

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4212,6 +4212,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
42124212
let mut pending_events = self.pending_events.lock().unwrap();
42134213
pending_events.push(events::Event::FundingGenerationReady {
42144214
temporary_channel_id: msg.temporary_channel_id,
4215+
counterparty_node_id: *counterparty_node_id,
42154216
channel_value_satoshis: value,
42164217
output_script,
42174218
user_channel_id: user_id,

lightning/src/ln/functional_test_utils.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -553,13 +553,14 @@ macro_rules! check_added_monitors {
553553
}
554554
}
555555

556-
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) {
556+
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) {
557557
let chan_id = *node.network_chan_count.borrow();
558558

559559
let events = node.node.get_and_clear_pending_events();
560560
assert_eq!(events.len(), 1);
561561
match events[0] {
562-
Event::FundingGenerationReady { ref temporary_channel_id, ref channel_value_satoshis, ref output_script, user_channel_id } => {
562+
Event::FundingGenerationReady { ref temporary_channel_id, ref counterparty_node_id, ref channel_value_satoshis, ref output_script, user_channel_id } => {
563+
assert_eq!(counterparty_node_id, expected_counterparty_node_id);
563564
assert_eq!(*channel_value_satoshis, expected_chan_value);
564565
assert_eq!(user_channel_id, expected_user_chan_id);
565566

@@ -573,7 +574,7 @@ pub fn create_funding_transaction<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, expected_
573574
}
574575
}
575576
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 {
576-
let (temporary_channel_id, tx, funding_output) = create_funding_transaction(node_a, channel_value, 42);
577+
let (temporary_channel_id, tx, funding_output) = create_funding_transaction(node_a, &node_b.node.get_our_node_id(), channel_value, 42);
577578
assert_eq!(temporary_channel_id, expected_temporary_channel_id);
578579

579580
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: &
722723
let accept_channel = get_event_msg!(nodes[b], MessageSendEvent::SendAcceptChannel, nodes[a].node.get_our_node_id());
723724
nodes[a].node.handle_accept_channel(&nodes[b].node.get_our_node_id(), b_flags, &accept_channel);
724725

725-
let (temporary_channel_id, tx, _) = create_funding_transaction(&nodes[a], channel_value, 42);
726+
let (temporary_channel_id, tx, _) = create_funding_transaction(&nodes[a], &nodes[b].node.get_our_node_id(), channel_value, 42);
726727
nodes[a].node.funding_transaction_generated(&temporary_channel_id, tx.clone()).unwrap();
727728
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()));
728729
check_added_monitors!(nodes[b], 1);

lightning/src/ln/functional_tests.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ fn do_test_sanity_on_in_flight_opens(steps: u8) {
515515
if steps & 0x0f == 2 { return; }
516516
nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), InitFeatures::known(), &accept_channel);
517517

518-
let (temporary_channel_id, tx, funding_output) = create_funding_transaction(&nodes[0], 100000, 42);
518+
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; }
521521
nodes[0].node.funding_transaction_generated(&temporary_channel_id, tx.clone()).unwrap();
@@ -3506,7 +3506,7 @@ fn test_peer_disconnected_before_funding_broadcasted() {
35063506
let accept_channel = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id());
35073507
nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), InitFeatures::known(), &accept_channel);
35083508

3509-
let (temporary_channel_id, tx, _funding_output) = create_funding_transaction(&nodes[0], 1_000_000, 42);
3509+
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

35123512
assert!(nodes[0].node.funding_transaction_generated(&temporary_channel_id, tx.clone()).is_ok());
@@ -4426,7 +4426,7 @@ fn test_manager_serialize_deserialize_events() {
44264426
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()));
44274427
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()));
44284428

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

44314431
node_a.node.funding_transaction_generated(&temporary_channel_id, tx.clone()).unwrap();
44324432
check_added_monitors!(node_a, 0);
@@ -8388,7 +8388,7 @@ fn test_reject_funding_before_inbound_channel_accepted() {
83888388
nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), InitFeatures::known(), &accept_chan_msg);
83898389
}
83908390

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

83938393
nodes[0].node.funding_transaction_generated(&temporary_channel_id, tx.clone()).unwrap();
83948394
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() {
88758875
nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), InitFeatures::known(), &accept_chan_msg);
88768876

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

88808880
nodes[0].node.funding_transaction_generated(&temporary_channel_id, tx.clone()).unwrap();
88818881
check_added_monitors!(nodes[0], 0);
@@ -9164,7 +9164,7 @@ fn test_duplicate_chan_id() {
91649164
}
91659165

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

91699169
nodes[0].node.funding_transaction_generated(&temporary_channel_id, tx.clone()).unwrap();
91709170
check_added_monitors!(nodes[0], 0);
@@ -9209,7 +9209,7 @@ fn test_duplicate_chan_id() {
92099209
let open_chan_2_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id());
92109210
nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), InitFeatures::known(), &open_chan_2_msg);
92119211
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()));
9212-
create_funding_transaction(&nodes[0], 100000, 42); // Get and check the FundingGenerationReady event
9212+
create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100000, 42); // Get and check the FundingGenerationReady event
92139213

92149214
let funding_created = {
92159215
let mut a_channel_lock = nodes[0].node.channel_state.lock().unwrap();
@@ -9342,7 +9342,7 @@ fn test_invalid_funding_tx() {
93429342
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()));
93439343
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()));
93449344

9345-
let (temporary_channel_id, mut tx, _) = create_funding_transaction(&nodes[0], 100_000, 42);
9345+
let (temporary_channel_id, mut tx, _) = create_funding_transaction(&nodes[0], &nodes[1].node.get_our_node_id(), 100_000, 42);
93469346
for output in tx.output.iter_mut() {
93479347
// Make the confirmed funding transaction have a bogus script_pubkey
93489348
output.script_pubkey = bitcoin::Script::new();
@@ -9878,7 +9878,7 @@ fn do_test_max_dust_htlc_exposure(dust_outbound_balance: bool, exposure_breach_e
98789878

98799879
let opt_anchors = false;
98809880

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

98839883
if on_holder_tx {
98849884
if let Some(mut chan) = nodes[0].node.channel_state.lock().unwrap().by_id.get_mut(&temporary_channel_id) {

lightning/src/ln/priv_short_conf_tests.rs

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

392-
let (temporary_channel_id, tx, _) = create_funding_transaction(&nodes[1], 100_000, 42);
392+
let (temporary_channel_id, tx, _) = create_funding_transaction(&nodes[1], &nodes[2].node.get_our_node_id(), 100_000, 42);
393393
nodes[1].node.funding_transaction_generated(&temporary_channel_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);

lightning/src/util/events.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,15 @@ pub enum Event {
162162
/// [`ChannelManager::funding_transaction_generated`]: crate::ln::channelmanager::ChannelManager::funding_transaction_generated
163163
FundingGenerationReady {
164164
/// The random channel_id we picked which you'll need to pass into
165-
/// ChannelManager::funding_transaction_generated.
165+
/// [`ChannelManager::funding_transaction_generated`].
166+
///
167+
/// [`ChannelManager::funding_transaction_generated`]: crate::ln::channelmanager::ChannelManager::funding_transaction_generated
166168
temporary_channel_id: [u8; 32],
169+
/// The counterparty's node_id, which you'll need to pass back into
170+
/// [`ChannelManager::funding_transaction_generated`].
171+
///
172+
/// [`ChannelManager::funding_transaction_generated`]: crate::ln::channelmanager::ChannelManager::funding_transaction_generated
173+
counterparty_node_id: PublicKey,
167174
/// The value, in satoshis, that the output should have.
168175
channel_value_satoshis: u64,
169176
/// The script which should be used in the transaction output.

0 commit comments

Comments
 (0)