Skip to content

Commit 6e2c800

Browse files
committed
Use owned UpdateFulfillHTLC msg to avoid attribution data clones
In the previous commit we switched to passing `UpdateFulfillHTLC` messages to handlers owned, rather than by reference. Here we update `ChanelManager`'s handling of fulfill attribution data to avoid unnecessary clones now that we own the object.
1 parent 52025d1 commit 6e2c800

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7898,7 +7898,7 @@ where
78987898
};
78997899

79007900
let attribution_data = process_fulfill_attribution_data(
7901-
attribution_data.as_ref(),
7901+
attribution_data,
79027902
&htlc.prev_hop.incoming_packet_shared_secret,
79037903
0,
79047904
);
@@ -8263,7 +8263,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
82638263
forwarded_htlc_value_msat: Option<u64>, skimmed_fee_msat: Option<u64>, from_onchain: bool,
82648264
startup_replay: bool, next_channel_counterparty_node_id: PublicKey,
82658265
next_channel_outpoint: OutPoint, next_channel_id: ChannelId,
8266-
next_user_channel_id: Option<u128>, attribution_data: Option<&AttributionData>,
8266+
next_user_channel_id: Option<u128>, attribution_data: Option<AttributionData>,
82678267
send_timestamp: Option<Duration>,
82688268
) {
82698269
match source {
@@ -9868,7 +9868,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
98689868
}
98699869

98709870
fn internal_update_fulfill_htlc(
9871-
&self, counterparty_node_id: &PublicKey, msg: &msgs::UpdateFulfillHTLC,
9871+
&self, counterparty_node_id: &PublicKey, msg: msgs::UpdateFulfillHTLC,
98729872
) -> Result<(), MsgHandleErrInternal> {
98739873
let funding_txo;
98749874
let next_user_channel_id;
@@ -9927,7 +9927,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
99279927
funding_txo,
99289928
msg.channel_id,
99299929
Some(next_user_channel_id),
9930-
msg.attribution_data.as_ref(),
9930+
msg.attribution_data,
99319931
send_timestamp,
99329932
);
99339933

@@ -13489,7 +13489,7 @@ where
1348913489
&self, counterparty_node_id: PublicKey, msg: msgs::UpdateFulfillHTLC,
1349013490
) {
1349113491
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
13492-
let res = self.internal_update_fulfill_htlc(&counterparty_node_id, &msg);
13492+
let res = self.internal_update_fulfill_htlc(&counterparty_node_id, msg);
1349313493
let _ = handle_error!(self, res, counterparty_node_id);
1349413494
}
1349513495

lightning/src/ln/onion_utils.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2871,12 +2871,10 @@ fn process_failure_packet(
28712871
/// attribution data is passed in, a new `AttributionData` field is instantiated. It is needless to say that in that
28722872
/// case the sender won't receive any hold times from nodes downstream of the current node.
28732873
pub(crate) fn process_fulfill_attribution_data(
2874-
attribution_data: Option<&AttributionData>, shared_secret: &[u8], hold_time: u32,
2874+
attribution_data: Option<AttributionData>, shared_secret: &[u8], hold_time: u32,
28752875
) -> AttributionData {
28762876
let mut attribution_data =
2877-
attribution_data.map_or(AttributionData::new(), |attribution_data| {
2878-
let mut attribution_data = attribution_data.clone();
2879-
2877+
attribution_data.map_or(AttributionData::new(), |mut attribution_data| {
28802878
// Shift the existing attribution data to the right to make space for the new hold time and HMACs.
28812879
attribution_data.shift_right();
28822880

0 commit comments

Comments
 (0)