Skip to content

Commit e404c12

Browse files
authored
Merge pull request #2400 from TheBlueMatt/2023-07-kill-vec_type
Fix backwards compat for blocked_monitor_updates and finally kill `vec_type`
2 parents 31a0456 + d83390c commit e404c12

File tree

12 files changed

+96
-90
lines changed

12 files changed

+96
-90
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ impl_writeable_tlv_based!(HolderSignedTx, {
262262
(8, delayed_payment_key, required),
263263
(10, per_commitment_point, required),
264264
(12, feerate_per_kw, required),
265-
(14, htlc_outputs, vec_type)
265+
(14, htlc_outputs, required_vec)
266266
});
267267

268268
impl HolderSignedTx {
@@ -538,15 +538,15 @@ impl ChannelMonitorUpdateStep {
538538
impl_writeable_tlv_based_enum_upgradable!(ChannelMonitorUpdateStep,
539539
(0, LatestHolderCommitmentTXInfo) => {
540540
(0, commitment_tx, required),
541-
(1, claimed_htlcs, vec_type),
542-
(2, htlc_outputs, vec_type),
541+
(1, claimed_htlcs, optional_vec),
542+
(2, htlc_outputs, required_vec),
543543
(4, nondust_htlc_sources, optional_vec),
544544
},
545545
(1, LatestCounterpartyCommitmentTXInfo) => {
546546
(0, commitment_txid, required),
547547
(2, commitment_number, required),
548548
(4, their_per_commitment_point, required),
549-
(6, htlc_outputs, vec_type),
549+
(6, htlc_outputs, required_vec),
550550
},
551551
(2, PaymentPreimage) => {
552552
(0, payment_preimage, required),
@@ -1071,12 +1071,12 @@ impl<Signer: WriteableEcdsaChannelSigner> Writeable for ChannelMonitorImpl<Signe
10711071

10721072
write_tlv_fields!(writer, {
10731073
(1, self.funding_spend_confirmed, option),
1074-
(3, self.htlcs_resolved_on_chain, vec_type),
1075-
(5, self.pending_monitor_events, vec_type),
1074+
(3, self.htlcs_resolved_on_chain, required_vec),
1075+
(5, self.pending_monitor_events, required_vec),
10761076
(7, self.funding_spend_seen, required),
10771077
(9, self.counterparty_node_id, option),
10781078
(11, self.confirmed_commitment_tx_counterparty_output, option),
1079-
(13, self.spendable_txids_confirmed, vec_type),
1079+
(13, self.spendable_txids_confirmed, required_vec),
10801080
(15, self.counterparty_fulfilled_htlcs, required),
10811081
});
10821082

@@ -4112,12 +4112,12 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
41124112
let mut counterparty_fulfilled_htlcs = Some(HashMap::new());
41134113
read_tlv_fields!(reader, {
41144114
(1, funding_spend_confirmed, option),
4115-
(3, htlcs_resolved_on_chain, vec_type),
4116-
(5, pending_monitor_events, vec_type),
4115+
(3, htlcs_resolved_on_chain, optional_vec),
4116+
(5, pending_monitor_events, optional_vec),
41174117
(7, funding_spend_seen, option),
41184118
(9, counterparty_node_id, option),
41194119
(11, confirmed_commitment_tx_counterparty_output, option),
4120-
(13, spendable_txids_confirmed, vec_type),
4120+
(13, spendable_txids_confirmed, optional_vec),
41214121
(15, counterparty_fulfilled_htlcs, option),
41224122
});
41234123

lightning/src/events/mod.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ impl Writeable for Event {
909909
(2, payment_failed_permanently, required),
910910
(3, false, required), // all_paths_failed in LDK versions prior to 0.0.114
911911
(4, path.blinded_tail, option),
912-
(5, path.hops, vec_type),
912+
(5, path.hops, required_vec),
913913
(7, short_channel_id, option),
914914
(9, None::<RouteParameters>, option), // retry in LDK versions prior to 0.0.115
915915
(11, payment_id, option),
@@ -977,7 +977,7 @@ impl Writeable for Event {
977977
write_tlv_fields!(writer, {
978978
(0, payment_id, required),
979979
(2, payment_hash, option),
980-
(4, path.hops, vec_type),
980+
(4, path.hops, required_vec),
981981
(6, path.blinded_tail, option),
982982
})
983983
},
@@ -1008,7 +1008,7 @@ impl Writeable for Event {
10081008
write_tlv_fields!(writer, {
10091009
(0, payment_id, required),
10101010
(2, payment_hash, required),
1011-
(4, path.hops, vec_type),
1011+
(4, path.hops, required_vec),
10121012
(6, path.blinded_tail, option),
10131013
})
10141014
},
@@ -1017,7 +1017,7 @@ impl Writeable for Event {
10171017
write_tlv_fields!(writer, {
10181018
(0, payment_id, required),
10191019
(2, payment_hash, required),
1020-
(4, path.hops, vec_type),
1020+
(4, path.hops, required_vec),
10211021
(6, short_channel_id, option),
10221022
(8, path.blinded_tail, option),
10231023
})
@@ -1162,7 +1162,9 @@ impl MaybeReadable for Event {
11621162
(1, network_update, upgradable_option),
11631163
(2, payment_failed_permanently, required),
11641164
(4, blinded_tail, option),
1165-
(5, path, vec_type),
1165+
// Added as a part of LDK 0.0.101 and always filled in since.
1166+
// Defaults to an empty Vec, though likely should have been `Option`al.
1167+
(5, path, optional_vec),
11661168
(7, short_channel_id, option),
11671169
(11, payment_id, option),
11681170
(13, failure_opt, upgradable_option),
@@ -1279,13 +1281,13 @@ impl MaybeReadable for Event {
12791281
_init_and_read_tlv_fields!(reader, {
12801282
(0, payment_id, required),
12811283
(2, payment_hash, option),
1282-
(4, path, vec_type),
1284+
(4, path, required_vec),
12831285
(6, blinded_tail, option),
12841286
});
12851287
Ok(Some(Event::PaymentPathSuccessful {
12861288
payment_id: payment_id.0.unwrap(),
12871289
payment_hash,
1288-
path: Path { hops: path.unwrap(), blinded_tail },
1290+
path: Path { hops: path, blinded_tail },
12891291
}))
12901292
};
12911293
f()
@@ -1338,13 +1340,13 @@ impl MaybeReadable for Event {
13381340
_init_and_read_tlv_fields!(reader, {
13391341
(0, payment_id, required),
13401342
(2, payment_hash, required),
1341-
(4, path, vec_type),
1343+
(4, path, required_vec),
13421344
(6, blinded_tail, option),
13431345
});
13441346
Ok(Some(Event::ProbeSuccessful {
13451347
payment_id: payment_id.0.unwrap(),
13461348
payment_hash: payment_hash.0.unwrap(),
1347-
path: Path { hops: path.unwrap(), blinded_tail },
1349+
path: Path { hops: path, blinded_tail },
13481350
}))
13491351
};
13501352
f()
@@ -1354,14 +1356,14 @@ impl MaybeReadable for Event {
13541356
_init_and_read_tlv_fields!(reader, {
13551357
(0, payment_id, required),
13561358
(2, payment_hash, required),
1357-
(4, path, vec_type),
1359+
(4, path, required_vec),
13581360
(6, short_channel_id, option),
13591361
(8, blinded_tail, option),
13601362
});
13611363
Ok(Some(Event::ProbeFailed {
13621364
payment_id: payment_id.0.unwrap(),
13631365
payment_hash: payment_hash.0.unwrap(),
1364-
path: Path { hops: path.unwrap(), blinded_tail },
1366+
path: Path { hops: path, blinded_tail },
13651367
short_channel_id,
13661368
}))
13671369
};

lightning/src/ln/chan_utils.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,7 @@ impl_writeable_tlv_based!(HolderCommitmentTransaction, {
10561056
(0, inner, required),
10571057
(2, counterparty_sig, required),
10581058
(4, holder_sig_first, required),
1059-
(6, counterparty_htlc_sigs, vec_type),
1059+
(6, counterparty_htlc_sigs, required_vec),
10601060
});
10611061

10621062
impl HolderCommitmentTransaction {
@@ -1346,7 +1346,7 @@ impl Writeable for CommitmentTransaction {
13461346
(6, self.feerate_per_kw, required),
13471347
(8, self.keys, required),
13481348
(10, self.built, required),
1349-
(12, self.htlcs, vec_type),
1349+
(12, self.htlcs, required_vec),
13501350
(14, legacy_deserialization_prevention_marker, option),
13511351
(15, self.channel_type_features, required),
13521352
});
@@ -1356,24 +1356,14 @@ impl Writeable for CommitmentTransaction {
13561356

13571357
impl Readable for CommitmentTransaction {
13581358
fn read<R: io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
1359-
let mut commitment_number = RequiredWrapper(None);
1360-
let mut to_broadcaster_value_sat = RequiredWrapper(None);
1361-
let mut to_countersignatory_value_sat = RequiredWrapper(None);
1362-
let mut feerate_per_kw = RequiredWrapper(None);
1363-
let mut keys = RequiredWrapper(None);
1364-
let mut built = RequiredWrapper(None);
1365-
_init_tlv_field_var!(htlcs, vec_type);
1366-
let mut _legacy_deserialization_prevention_marker: Option<()> = None;
1367-
let mut channel_type_features = None;
1368-
1369-
read_tlv_fields!(reader, {
1359+
_init_and_read_tlv_fields!(reader, {
13701360
(0, commitment_number, required),
13711361
(2, to_broadcaster_value_sat, required),
13721362
(4, to_countersignatory_value_sat, required),
13731363
(6, feerate_per_kw, required),
13741364
(8, keys, required),
13751365
(10, built, required),
1376-
(12, htlcs, vec_type),
1366+
(12, htlcs, required_vec),
13771367
(14, _legacy_deserialization_prevention_marker, option),
13781368
(15, channel_type_features, option),
13791369
});
@@ -1389,7 +1379,7 @@ impl Readable for CommitmentTransaction {
13891379
feerate_per_kw: feerate_per_kw.0.unwrap(),
13901380
keys: keys.0.unwrap(),
13911381
built: built.0.unwrap(),
1392-
htlcs: _init_tlv_based_struct_field!(htlcs, vec_type),
1382+
htlcs,
13931383
channel_type_features: channel_type_features.unwrap_or(ChannelTypeFeatures::only_static_remote_key())
13941384
})
13951385
}

lightning/src/ln/channel.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6856,11 +6856,11 @@ impl<Signer: WriteableEcdsaChannelSigner> Writeable for Channel<Signer> {
68566856
(5, self.context.config, required),
68576857
(6, serialized_holder_htlc_max_in_flight, option),
68586858
(7, self.context.shutdown_scriptpubkey, option),
6859-
(8, self.context.blocked_monitor_updates, vec_type),
6859+
(8, self.context.blocked_monitor_updates, optional_vec),
68606860
(9, self.context.target_closing_feerate_sats_per_kw, option),
6861-
(11, self.context.monitor_pending_finalized_fulfills, vec_type),
6861+
(11, self.context.monitor_pending_finalized_fulfills, required_vec),
68626862
(13, self.context.channel_creation_height, required),
6863-
(15, preimages, vec_type),
6863+
(15, preimages, required_vec),
68646864
(17, self.context.announcement_sigs_state, required),
68656865
(19, self.context.latest_inbound_scid_alias, option),
68666866
(21, self.context.outbound_scid_alias, required),
@@ -7164,11 +7164,11 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
71647164
(5, config, option), // Note that if none is provided we will *not* overwrite the existing one.
71657165
(6, holder_max_htlc_value_in_flight_msat, option),
71667166
(7, shutdown_scriptpubkey, option),
7167-
(8, blocked_monitor_updates, vec_type),
7167+
(8, blocked_monitor_updates, optional_vec),
71687168
(9, target_closing_feerate_sats_per_kw, option),
7169-
(11, monitor_pending_finalized_fulfills, vec_type),
7169+
(11, monitor_pending_finalized_fulfills, optional_vec),
71707170
(13, channel_creation_height, option),
7171-
(15, preimages_opt, vec_type),
7171+
(15, preimages_opt, optional_vec),
71727172
(17, announcement_sigs_state, option),
71737173
(19, latest_inbound_scid_alias, option),
71747174
(21, outbound_scid_alias, option),

lightning/src/ln/channelmanager.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ use crate::ln::features::{ChannelFeatures, ChannelTypeFeatures, InitFeatures, No
4545
#[cfg(any(feature = "_test_utils", test))]
4646
use crate::ln::features::InvoiceFeatures;
4747
use crate::routing::gossip::NetworkGraph;
48-
use crate::routing::router::{BlindedTail, DefaultRouter, InFlightHtlcs, Path, Payee, PaymentParameters, Route, RouteHop, RouteParameters, Router};
48+
use crate::routing::router::{BlindedTail, DefaultRouter, InFlightHtlcs, Path, Payee, PaymentParameters, Route, RouteParameters, Router};
4949
use crate::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringFeeParameters};
5050
use crate::ln::msgs;
5151
use crate::ln::onion_utils;
@@ -3198,6 +3198,7 @@ where
31983198
/// irrevocably committed to on our end. In such a case, do NOT retry the payment with a
31993199
/// different route unless you intend to pay twice!
32003200
///
3201+
/// [`RouteHop`]: crate::routing::router::RouteHop
32013202
/// [`Event::PaymentSent`]: events::Event::PaymentSent
32023203
/// [`Event::PaymentFailed`]: events::Event::PaymentFailed
32033204
/// [`UpdateHTLCs`]: events::MessageSendEvent::UpdateHTLCs
@@ -7515,7 +7516,7 @@ impl Readable for ChannelDetails {
75157516
}
75167517

75177518
impl_writeable_tlv_based!(PhantomRouteHints, {
7518-
(2, channels, vec_type),
7519+
(2, channels, required_vec),
75197520
(4, phantom_scid, required),
75207521
(6, real_node_pubkey, required),
75217522
});
@@ -7707,15 +7708,15 @@ impl Readable for HTLCSource {
77077708
0 => {
77087709
let mut session_priv: crate::util::ser::RequiredWrapper<SecretKey> = crate::util::ser::RequiredWrapper(None);
77097710
let mut first_hop_htlc_msat: u64 = 0;
7710-
let mut path_hops: Option<Vec<RouteHop>> = Some(Vec::new());
7711+
let mut path_hops = Vec::new();
77117712
let mut payment_id = None;
77127713
let mut payment_params: Option<PaymentParameters> = None;
77137714
let mut blinded_tail: Option<BlindedTail> = None;
77147715
read_tlv_fields!(reader, {
77157716
(0, session_priv, required),
77167717
(1, payment_id, option),
77177718
(2, first_hop_htlc_msat, required),
7718-
(4, path_hops, vec_type),
7719+
(4, path_hops, required_vec),
77197720
(5, payment_params, (option: ReadableArgs, 0)),
77207721
(6, blinded_tail, option),
77217722
});
@@ -7724,7 +7725,7 @@ impl Readable for HTLCSource {
77247725
// instead.
77257726
payment_id = Some(PaymentId(*session_priv.0.unwrap().as_ref()));
77267727
}
7727-
let path = Path { hops: path_hops.ok_or(DecodeError::InvalidValue)?, blinded_tail };
7728+
let path = Path { hops: path_hops, blinded_tail };
77287729
if path.hops.len() == 0 {
77297730
return Err(DecodeError::InvalidValue);
77307731
}
@@ -7759,7 +7760,7 @@ impl Writeable for HTLCSource {
77597760
(1, payment_id_opt, option),
77607761
(2, first_hop_htlc_msat, required),
77617762
// 3 was previously used to write a PaymentSecret for the payment.
7762-
(4, path.hops, vec_type),
7763+
(4, path.hops, required_vec),
77637764
(5, None::<PaymentParameters>, option), // payment_params in LDK versions prior to 0.0.115
77647765
(6, path.blinded_tail, option),
77657766
});
@@ -8009,7 +8010,7 @@ where
80098010
(6, monitor_update_blocked_actions_per_peer, option),
80108011
(7, self.fake_scid_rand_bytes, required),
80118012
(8, if events_not_backwards_compatible { Some(&*events) } else { None }, option),
8012-
(9, htlc_purposes, vec_type),
8013+
(9, htlc_purposes, required_vec),
80138014
(10, in_flight_monitor_updates, option),
80148015
(11, self.probing_cookie_secret, required),
80158016
(13, htlc_onion_fields, optional_vec),
@@ -8456,7 +8457,7 @@ where
84568457
(6, monitor_update_blocked_actions_per_peer, option),
84578458
(7, fake_scid_rand_bytes, option),
84588459
(8, events_override, option),
8459-
(9, claimable_htlc_purposes, vec_type),
8460+
(9, claimable_htlc_purposes, optional_vec),
84608461
(10, in_flight_monitor_updates, option),
84618462
(11, probing_cookie_secret, option),
84628463
(13, claimable_htlc_onion_fields, optional_vec),

lightning/src/ln/msgs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3760,7 +3760,7 @@ mod tests {
37603760
let test_bytes = vec![42u8; 1000];
37613761
if let OnionHopDataFormat::NonFinalNode { short_channel_id } = payload.format {
37623762
_encode_varint_length_prefixed_tlv!(&mut encoded_payload, {
3763-
(1, test_bytes, vec_type),
3763+
(1, test_bytes, required_vec),
37643764
(2, HighZeroBytesDroppedBigSize(payload.amt_to_forward), required),
37653765
(4, HighZeroBytesDroppedBigSize(payload.outgoing_cltv_value), required),
37663766
(6, short_channel_id, required)

lightning/src/ln/onion_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ impl_writeable_tlv_based_enum!(HTLCFailReasonRepr,
645645
},
646646
(1, Reason) => {
647647
(0, failure_code, required),
648-
(2, data, vec_type),
648+
(2, data, required_vec),
649649
},
650650
;);
651651

lightning/src/onion_message/packet.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,15 @@ impl<T: CustomOnionMessageContents> Writeable for (Payload<T>, [u8; 32]) {
169169
match &self.0 {
170170
Payload::Forward(ForwardControlTlvs::Blinded(encrypted_bytes)) => {
171171
_encode_varint_length_prefixed_tlv!(w, {
172-
(4, *encrypted_bytes, vec_type)
172+
(4, *encrypted_bytes, required_vec)
173173
})
174174
},
175175
Payload::Receive {
176176
control_tlvs: ReceiveControlTlvs::Blinded(encrypted_bytes), reply_path, message,
177177
} => {
178178
_encode_varint_length_prefixed_tlv!(w, {
179179
(2, reply_path, option),
180-
(4, *encrypted_bytes, vec_type),
180+
(4, *encrypted_bytes, required_vec),
181181
(message.tlv_type(), message, required)
182182
})
183183
},

0 commit comments

Comments
 (0)