Skip to content

Commit bc69711

Browse files
committed
Refactor: Take their_node_id by value across all handler interfaces
In order to maintain interface consistency, we refactor all message handler interfaces to take `PublicKey` rather than `&PublicKey`, as the difference in efficiency should be negigible and the former is easier to handle in binding languages. Over time, we also want to move (no pun intended) towards all messaging interfaces using move semantics, so dropping the reference for `PublicKey` is the first step in this direction.
1 parent dde402d commit bc69711

29 files changed

+1951
-1954
lines changed

fuzz/src/chanmon_consistency.rs

+32-32
Original file line numberDiff line numberDiff line change
@@ -806,13 +806,13 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
806806
networks: None,
807807
remote_network_address: None,
808808
};
809-
$source.peer_connected(&$dest.get_our_node_id(), &init_dest, true).unwrap();
809+
$source.peer_connected($dest.get_our_node_id(), &init_dest, true).unwrap();
810810
let init_src = Init {
811811
features: $source.init_features(),
812812
networks: None,
813813
remote_network_address: None,
814814
};
815-
$dest.peer_connected(&$source.get_our_node_id(), &init_src, false).unwrap();
815+
$dest.peer_connected($source.get_our_node_id(), &init_src, false).unwrap();
816816

817817
$source.create_channel($dest.get_our_node_id(), 100_000, 42, 0, None, None).unwrap();
818818
let open_channel = {
@@ -825,7 +825,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
825825
}
826826
};
827827

828-
$dest.handle_open_channel(&$source.get_our_node_id(), &open_channel);
828+
$dest.handle_open_channel($source.get_our_node_id(), &open_channel);
829829
let accept_channel = {
830830
if anchors {
831831
let events = $dest.get_and_clear_pending_events();
@@ -860,7 +860,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
860860
}
861861
};
862862

863-
$source.handle_accept_channel(&$dest.get_our_node_id(), &accept_channel);
863+
$source.handle_accept_channel($dest.get_our_node_id(), &accept_channel);
864864
let funding_output;
865865
{
866866
let mut events = $source.get_and_clear_pending_events();
@@ -904,7 +904,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
904904
panic!("Wrong event type");
905905
}
906906
};
907-
$dest.handle_funding_created(&$source.get_our_node_id(), &funding_created);
907+
$dest.handle_funding_created($source.get_our_node_id(), &funding_created);
908908

909909
let funding_signed = {
910910
let events = $dest.get_and_clear_pending_msg_events();
@@ -923,7 +923,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
923923
panic!("Wrong event type");
924924
}
925925

926-
$source.handle_funding_signed(&$dest.get_our_node_id(), &funding_signed);
926+
$source.handle_funding_signed($dest.get_our_node_id(), &funding_signed);
927927
let events = $source.get_and_clear_pending_events();
928928
assert_eq!(events.len(), 1);
929929
if let events::Event::ChannelPending { ref counterparty_node_id, .. } = events[0] {
@@ -963,7 +963,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
963963
{
964964
for node in $nodes.iter() {
965965
if node.get_our_node_id() == *node_id {
966-
node.handle_channel_ready(&$nodes[idx].get_our_node_id(), msg);
966+
node.handle_channel_ready($nodes[idx].get_our_node_id(), msg);
967967
}
968968
}
969969
} else {
@@ -1134,7 +1134,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
11341134
for update_add in update_add_htlcs.iter() {
11351135
out.locked_write(format!("Delivering update_add_htlc to node {}.\n", idx).as_bytes());
11361136
if !$corrupt_forward {
1137-
dest.handle_update_add_htlc(&nodes[$node].get_our_node_id(), update_add);
1137+
dest.handle_update_add_htlc(nodes[$node].get_our_node_id(), update_add);
11381138
} else {
11391139
// Corrupt the update_add_htlc message so that its HMAC
11401140
// check will fail and we generate a
@@ -1143,24 +1143,24 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
11431143
let mut msg_ser = update_add.encode();
11441144
msg_ser[1000] ^= 0xff;
11451145
let new_msg = UpdateAddHTLC::read(&mut Cursor::new(&msg_ser)).unwrap();
1146-
dest.handle_update_add_htlc(&nodes[$node].get_our_node_id(), &new_msg);
1146+
dest.handle_update_add_htlc(nodes[$node].get_our_node_id(), &new_msg);
11471147
}
11481148
}
11491149
for update_fulfill in update_fulfill_htlcs.iter() {
11501150
out.locked_write(format!("Delivering update_fulfill_htlc to node {}.\n", idx).as_bytes());
1151-
dest.handle_update_fulfill_htlc(&nodes[$node].get_our_node_id(), update_fulfill);
1151+
dest.handle_update_fulfill_htlc(nodes[$node].get_our_node_id(), update_fulfill);
11521152
}
11531153
for update_fail in update_fail_htlcs.iter() {
11541154
out.locked_write(format!("Delivering update_fail_htlc to node {}.\n", idx).as_bytes());
1155-
dest.handle_update_fail_htlc(&nodes[$node].get_our_node_id(), update_fail);
1155+
dest.handle_update_fail_htlc(nodes[$node].get_our_node_id(), update_fail);
11561156
}
11571157
for update_fail_malformed in update_fail_malformed_htlcs.iter() {
11581158
out.locked_write(format!("Delivering update_fail_malformed_htlc to node {}.\n", idx).as_bytes());
1159-
dest.handle_update_fail_malformed_htlc(&nodes[$node].get_our_node_id(), update_fail_malformed);
1159+
dest.handle_update_fail_malformed_htlc(nodes[$node].get_our_node_id(), update_fail_malformed);
11601160
}
11611161
if let Some(msg) = update_fee {
11621162
out.locked_write(format!("Delivering update_fee to node {}.\n", idx).as_bytes());
1163-
dest.handle_update_fee(&nodes[$node].get_our_node_id(), &msg);
1163+
dest.handle_update_fee(nodes[$node].get_our_node_id(), &msg);
11641164
}
11651165
let processed_change = !update_add_htlcs.is_empty() || !update_fulfill_htlcs.is_empty() ||
11661166
!update_fail_htlcs.is_empty() || !update_fail_malformed_htlcs.is_empty();
@@ -1177,7 +1177,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
11771177
break;
11781178
}
11791179
out.locked_write(format!("Delivering commitment_signed to node {}.\n", idx).as_bytes());
1180-
dest.handle_commitment_signed(&nodes[$node].get_our_node_id(), &commitment_signed);
1180+
dest.handle_commitment_signed(nodes[$node].get_our_node_id(), &commitment_signed);
11811181
break;
11821182
}
11831183
}
@@ -1186,15 +1186,15 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
11861186
for (idx, dest) in nodes.iter().enumerate() {
11871187
if dest.get_our_node_id() == *node_id {
11881188
out.locked_write(format!("Delivering revoke_and_ack to node {}.\n", idx).as_bytes());
1189-
dest.handle_revoke_and_ack(&nodes[$node].get_our_node_id(), msg);
1189+
dest.handle_revoke_and_ack(nodes[$node].get_our_node_id(), msg);
11901190
}
11911191
}
11921192
},
11931193
events::MessageSendEvent::SendChannelReestablish { ref node_id, ref msg } => {
11941194
for (idx, dest) in nodes.iter().enumerate() {
11951195
if dest.get_our_node_id() == *node_id {
11961196
out.locked_write(format!("Delivering channel_reestablish to node {}.\n", idx).as_bytes());
1197-
dest.handle_channel_reestablish(&nodes[$node].get_our_node_id(), msg);
1197+
dest.handle_channel_reestablish(nodes[$node].get_our_node_id(), msg);
11981198
}
11991199
}
12001200
},
@@ -1453,16 +1453,16 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
14531453

14541454
0x0c => {
14551455
if !chan_a_disconnected {
1456-
nodes[0].peer_disconnected(&nodes[1].get_our_node_id());
1457-
nodes[1].peer_disconnected(&nodes[0].get_our_node_id());
1456+
nodes[0].peer_disconnected(nodes[1].get_our_node_id());
1457+
nodes[1].peer_disconnected(nodes[0].get_our_node_id());
14581458
chan_a_disconnected = true;
14591459
drain_msg_events_on_disconnect!(0);
14601460
}
14611461
},
14621462
0x0d => {
14631463
if !chan_b_disconnected {
1464-
nodes[1].peer_disconnected(&nodes[2].get_our_node_id());
1465-
nodes[2].peer_disconnected(&nodes[1].get_our_node_id());
1464+
nodes[1].peer_disconnected(nodes[2].get_our_node_id());
1465+
nodes[2].peer_disconnected(nodes[1].get_our_node_id());
14661466
chan_b_disconnected = true;
14671467
drain_msg_events_on_disconnect!(2);
14681468
}
@@ -1474,13 +1474,13 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
14741474
networks: None,
14751475
remote_network_address: None,
14761476
};
1477-
nodes[0].peer_connected(&nodes[1].get_our_node_id(), &init_1, true).unwrap();
1477+
nodes[0].peer_connected(nodes[1].get_our_node_id(), &init_1, true).unwrap();
14781478
let init_0 = Init {
14791479
features: nodes[0].init_features(),
14801480
networks: None,
14811481
remote_network_address: None,
14821482
};
1483-
nodes[1].peer_connected(&nodes[0].get_our_node_id(), &init_0, false).unwrap();
1483+
nodes[1].peer_connected(nodes[0].get_our_node_id(), &init_0, false).unwrap();
14841484
chan_a_disconnected = false;
14851485
}
14861486
},
@@ -1491,13 +1491,13 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
14911491
networks: None,
14921492
remote_network_address: None,
14931493
};
1494-
nodes[1].peer_connected(&nodes[2].get_our_node_id(), &init_2, true).unwrap();
1494+
nodes[1].peer_connected(nodes[2].get_our_node_id(), &init_2, true).unwrap();
14951495
let init_1 = Init {
14961496
features: nodes[1].init_features(),
14971497
networks: None,
14981498
remote_network_address: None,
14991499
};
1500-
nodes[2].peer_connected(&nodes[1].get_our_node_id(), &init_1, false).unwrap();
1500+
nodes[2].peer_connected(nodes[1].get_our_node_id(), &init_1, false).unwrap();
15011501
chan_b_disconnected = false;
15021502
}
15031503
},
@@ -1534,7 +1534,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
15341534

15351535
0x2c => {
15361536
if !chan_a_disconnected {
1537-
nodes[1].peer_disconnected(&nodes[0].get_our_node_id());
1537+
nodes[1].peer_disconnected(nodes[0].get_our_node_id());
15381538
chan_a_disconnected = true;
15391539
push_excess_b_events!(
15401540
nodes[1].get_and_clear_pending_msg_events().drain(..),
@@ -1550,14 +1550,14 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
15501550
},
15511551
0x2d => {
15521552
if !chan_a_disconnected {
1553-
nodes[0].peer_disconnected(&nodes[1].get_our_node_id());
1553+
nodes[0].peer_disconnected(nodes[1].get_our_node_id());
15541554
chan_a_disconnected = true;
15551555
nodes[0].get_and_clear_pending_msg_events();
15561556
ab_events.clear();
15571557
ba_events.clear();
15581558
}
15591559
if !chan_b_disconnected {
1560-
nodes[2].peer_disconnected(&nodes[1].get_our_node_id());
1560+
nodes[2].peer_disconnected(nodes[1].get_our_node_id());
15611561
chan_b_disconnected = true;
15621562
nodes[2].get_and_clear_pending_msg_events();
15631563
bc_events.clear();
@@ -1570,7 +1570,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
15701570
},
15711571
0x2e => {
15721572
if !chan_b_disconnected {
1573-
nodes[1].peer_disconnected(&nodes[2].get_our_node_id());
1573+
nodes[1].peer_disconnected(nodes[2].get_our_node_id());
15741574
chan_b_disconnected = true;
15751575
push_excess_b_events!(
15761576
nodes[1].get_and_clear_pending_msg_events().drain(..),
@@ -1759,13 +1759,13 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
17591759
networks: None,
17601760
remote_network_address: None,
17611761
};
1762-
nodes[0].peer_connected(&nodes[1].get_our_node_id(), &init_1, true).unwrap();
1762+
nodes[0].peer_connected(nodes[1].get_our_node_id(), &init_1, true).unwrap();
17631763
let init_0 = Init {
17641764
features: nodes[0].init_features(),
17651765
networks: None,
17661766
remote_network_address: None,
17671767
};
1768-
nodes[1].peer_connected(&nodes[0].get_our_node_id(), &init_0, false).unwrap();
1768+
nodes[1].peer_connected(nodes[0].get_our_node_id(), &init_0, false).unwrap();
17691769
chan_a_disconnected = false;
17701770
}
17711771
if chan_b_disconnected {
@@ -1774,13 +1774,13 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
17741774
networks: None,
17751775
remote_network_address: None,
17761776
};
1777-
nodes[1].peer_connected(&nodes[2].get_our_node_id(), &init_2, true).unwrap();
1777+
nodes[1].peer_connected(nodes[2].get_our_node_id(), &init_2, true).unwrap();
17781778
let init_1 = Init {
17791779
features: nodes[1].init_features(),
17801780
networks: None,
17811781
remote_network_address: None,
17821782
};
1783-
nodes[2].peer_connected(&nodes[1].get_our_node_id(), &init_1, false).unwrap();
1783+
nodes[2].peer_connected(nodes[1].get_our_node_id(), &init_1, false).unwrap();
17841784
chan_b_disconnected = false;
17851785
}
17861786

fuzz/src/onion_message.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ pub fn do_test<L: Logger>(data: &[u8], logger: &L) {
6868
features.set_onion_messages_optional();
6969
let init = msgs::Init { features, networks: None, remote_network_address: None };
7070

71-
onion_messenger.peer_connected(&peer_node_id, &init, false).unwrap();
72-
onion_messenger.handle_onion_message(&peer_node_id, &msg);
71+
onion_messenger.peer_connected(peer_node_id, &init, false).unwrap();
72+
onion_messenger.handle_onion_message(peer_node_id, &msg);
7373
}
7474
}
7575

lightning-background-processor/src/lib.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -1648,7 +1648,7 @@ mod tests {
16481648
};
16491649
nodes[i]
16501650
.node
1651-
.peer_connected(&nodes[j].node.get_our_node_id(), &init_i, true)
1651+
.peer_connected(nodes[j].node.get_our_node_id(), &init_i, true)
16521652
.unwrap();
16531653
let init_j = Init {
16541654
features: nodes[i].node.init_features(),
@@ -1657,7 +1657,7 @@ mod tests {
16571657
};
16581658
nodes[j]
16591659
.node
1660-
.peer_connected(&nodes[i].node.get_our_node_id(), &init_j, false)
1660+
.peer_connected(nodes[i].node.get_our_node_id(), &init_j, false)
16611661
.unwrap();
16621662
}
16631663
}
@@ -1685,14 +1685,14 @@ mod tests {
16851685
MessageSendEvent::SendFundingCreated,
16861686
$node_b.node.get_our_node_id()
16871687
);
1688-
$node_b.node.handle_funding_created(&$node_a.node.get_our_node_id(), &msg_a);
1688+
$node_b.node.handle_funding_created($node_a.node.get_our_node_id(), &msg_a);
16891689
get_event!($node_b, Event::ChannelPending);
16901690
let msg_b = get_event_msg!(
16911691
$node_b,
16921692
MessageSendEvent::SendFundingSigned,
16931693
$node_a.node.get_our_node_id()
16941694
);
1695-
$node_a.node.handle_funding_signed(&$node_b.node.get_our_node_id(), &msg_b);
1695+
$node_a.node.handle_funding_signed($node_b.node.get_our_node_id(), &msg_b);
16961696
get_event!($node_a, Event::ChannelPending);
16971697
tx
16981698
}};
@@ -1709,13 +1709,13 @@ mod tests {
17091709
MessageSendEvent::SendOpenChannel,
17101710
$node_b.node.get_our_node_id()
17111711
);
1712-
$node_b.node.handle_open_channel(&$node_a.node.get_our_node_id(), &msg_a);
1712+
$node_b.node.handle_open_channel($node_a.node.get_our_node_id(), &msg_a);
17131713
let msg_b = get_event_msg!(
17141714
$node_b,
17151715
MessageSendEvent::SendAcceptChannel,
17161716
$node_a.node.get_our_node_id()
17171717
);
1718-
$node_a.node.handle_accept_channel(&$node_b.node.get_our_node_id(), &msg_b);
1718+
$node_a.node.handle_accept_channel($node_b.node.get_our_node_id(), &msg_b);
17191719
}};
17201720
}
17211721

@@ -2115,10 +2115,10 @@ mod tests {
21152115
.funding_transaction_generated(temporary_channel_id, node_1_id, funding_tx.clone())
21162116
.unwrap();
21172117
let msg_0 = get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, node_1_id);
2118-
nodes[1].node.handle_funding_created(&node_0_id, &msg_0);
2118+
nodes[1].node.handle_funding_created(node_0_id, &msg_0);
21192119
get_event!(nodes[1], Event::ChannelPending);
21202120
let msg_1 = get_event_msg!(nodes[1], MessageSendEvent::SendFundingSigned, node_0_id);
2121-
nodes[0].node.handle_funding_signed(&node_1_id, &msg_1);
2121+
nodes[0].node.handle_funding_signed(node_1_id, &msg_1);
21222122
let _ = channel_pending_recv
21232123
.recv_timeout(Duration::from_secs(EVENT_DEADLINE))
21242124
.expect("ChannelPending not handled within deadline");
@@ -2128,10 +2128,10 @@ mod tests {
21282128
let as_funding = get_event_msg!(nodes[0], MessageSendEvent::SendChannelReady, node_1_id);
21292129
confirm_transaction(&mut nodes[1], &funding_tx);
21302130
let bs_funding = get_event_msg!(nodes[1], MessageSendEvent::SendChannelReady, node_0_id);
2131-
nodes[0].node.handle_channel_ready(&node_1_id, &bs_funding);
2131+
nodes[0].node.handle_channel_ready(node_1_id, &bs_funding);
21322132
let _as_channel_update =
21332133
get_event_msg!(nodes[0], MessageSendEvent::SendChannelUpdate, node_1_id);
2134-
nodes[1].node.handle_channel_ready(&node_0_id, &as_funding);
2134+
nodes[1].node.handle_channel_ready(node_0_id, &as_funding);
21352135
let _bs_channel_update =
21362136
get_event_msg!(nodes[1], MessageSendEvent::SendChannelUpdate, node_0_id);
21372137
let broadcast_funding =

0 commit comments

Comments
 (0)