Skip to content

Commit

Permalink
fixup: Add weight field to counterparty sweeps in backwards compatibl…
Browse files Browse the repository at this point in the history
…e way
  • Loading branch information
tankyleo committed Jan 10, 2025
1 parent 64b528d commit c98fd36
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions lightning/src/chain/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ impl Readable for CounterpartyOfferedHTLCOutput {
let mut htlc = RequiredWrapper(None);
let mut _legacy_deserialization_prevention_marker: Option<()> = None;
let mut channel_type_features = None;
let mut weight = RequiredWrapper(None);
let mut weight = None;

read_tlv_fields!(reader, {
(0, per_commitment_point, required),
Expand All @@ -271,19 +271,22 @@ impl Readable for CounterpartyOfferedHTLCOutput {
(8, htlc, required),
(10, _legacy_deserialization_prevention_marker, option),
(11, channel_type_features, option),
(12, weight, required),
(12, weight, option),
});

verify_channel_type_features(&channel_type_features, None)?;

let channel_type_features = channel_type_features.unwrap_or(ChannelTypeFeatures::only_static_remote_key());
let weight = weight.unwrap_or(weight_offered_htlc(&channel_type_features));

Ok(Self {
per_commitment_point: per_commitment_point.0.unwrap(),
counterparty_delayed_payment_base_key,
counterparty_htlc_base_key,
preimage: preimage.0.unwrap(),
htlc: htlc.0.unwrap(),
channel_type_features: channel_type_features.unwrap_or(ChannelTypeFeatures::only_static_remote_key()),
weight: weight.0.unwrap(),
channel_type_features,
weight,
})
}
}
Expand Down Expand Up @@ -341,7 +344,7 @@ impl Readable for CounterpartyReceivedHTLCOutput {
let mut htlc = RequiredWrapper(None);
let mut _legacy_deserialization_prevention_marker: Option<()> = None;
let mut channel_type_features = None;
let mut weight = RequiredWrapper(None);
let mut weight = None;

read_tlv_fields!(reader, {
(0, per_commitment_point, required),
Expand All @@ -350,18 +353,21 @@ impl Readable for CounterpartyReceivedHTLCOutput {
(6, htlc, required),
(8, _legacy_deserialization_prevention_marker, option),
(9, channel_type_features, option),
(10, weight, required),
(10, weight, option),
});

verify_channel_type_features(&channel_type_features, None)?;

let channel_type_features = channel_type_features.unwrap_or(ChannelTypeFeatures::only_static_remote_key());
let weight = weight.unwrap_or(weight_received_htlc(&channel_type_features));

Ok(Self {
per_commitment_point: per_commitment_point.0.unwrap(),
counterparty_delayed_payment_base_key,
counterparty_htlc_base_key,
htlc: htlc.0.unwrap(),
channel_type_features: channel_type_features.unwrap_or(ChannelTypeFeatures::only_static_remote_key()),
weight: weight.0.unwrap(),
channel_type_features,
weight,
})
}
}
Expand Down

0 comments on commit c98fd36

Please sign in to comment.