Skip to content

Commit b7a11a9

Browse files
authored
Merge pull request #4642 from joostjager/ser-tlv-length-fastpath
Speed up TLV serialization length accounting
2 parents c2587b0 + eb47742 commit b7a11a9

39 files changed

Lines changed: 280 additions & 222 deletions

lightning-liquidity/src/lsps1/msgs.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::lsps0::ser::{
2121
use bitcoin::{Address, FeeRate, OutPoint};
2222
use lightning::offers::offer::Offer;
2323
use lightning::util::ser::{Readable, Writeable};
24-
use lightning::{impl_writeable_tlv_based, impl_writeable_tlv_based_enum};
24+
use lightning::{impl_ser_tlv_based, impl_ser_tlv_based_enum};
2525
use lightning_invoice::Bolt11Invoice;
2626

2727
use serde::{Deserialize, Serialize};
@@ -145,7 +145,7 @@ pub struct LSPS1OrderParams {
145145
pub announce_channel: bool,
146146
}
147147

148-
impl_writeable_tlv_based!(LSPS1OrderParams, {
148+
impl_ser_tlv_based!(LSPS1OrderParams, {
149149
(0, lsp_balance_sat, required),
150150
(2, client_balance_sat, required),
151151
(4, required_channel_confirmations, required),
@@ -185,7 +185,7 @@ pub enum LSPS1OrderState {
185185
Failed,
186186
}
187187

188-
impl_writeable_tlv_based_enum!(LSPS1OrderState,
188+
impl_ser_tlv_based_enum!(LSPS1OrderState,
189189
(0, Created) => {},
190190
(2, Completed) => {},
191191
(4, Failed) => {}
@@ -202,7 +202,7 @@ pub struct LSPS1PaymentInfo {
202202
pub onchain: Option<LSPS1OnchainPaymentInfo>,
203203
}
204204

205-
impl_writeable_tlv_based!(LSPS1PaymentInfo, {
205+
impl_ser_tlv_based!(LSPS1PaymentInfo, {
206206
(0, bolt11, option),
207207
(2, bolt12, option),
208208
(4, onchain, option),
@@ -225,7 +225,7 @@ pub struct LSPS1Bolt11PaymentInfo {
225225
pub invoice: Bolt11Invoice,
226226
}
227227

228-
impl_writeable_tlv_based!(LSPS1Bolt11PaymentInfo, {
228+
impl_ser_tlv_based!(LSPS1Bolt11PaymentInfo, {
229229
(0, state, required),
230230
(2, expires_at, required),
231231
(4, fee_total_sat, required),
@@ -251,7 +251,7 @@ pub struct LSPS1Bolt12PaymentInfo {
251251
pub offer: Offer,
252252
}
253253

254-
impl_writeable_tlv_based!(LSPS1Bolt12PaymentInfo, {
254+
impl_ser_tlv_based!(LSPS1Bolt12PaymentInfo, {
255255
(0, state, required),
256256
(2, expires_at, required),
257257
(4, fee_total_sat, required),
@@ -290,7 +290,7 @@ pub struct LSPS1OnchainPaymentInfo {
290290
pub refund_onchain_address: Option<Address>,
291291
}
292292

293-
impl_writeable_tlv_based!(LSPS1OnchainPaymentInfo, {
293+
impl_ser_tlv_based!(LSPS1OnchainPaymentInfo, {
294294
(0, state, required),
295295
(2, expires_at, required),
296296
(4, fee_total_sat, required),
@@ -322,7 +322,7 @@ pub enum LSPS1PaymentState {
322322
Refunded,
323323
}
324324

325-
impl_writeable_tlv_based_enum!(LSPS1PaymentState,
325+
impl_ser_tlv_based_enum!(LSPS1PaymentState,
326326
(0, ExpectPayment) => {},
327327
(2, Hold) => {},
328328
(4, Paid) => {},
@@ -340,7 +340,7 @@ pub struct LSPS1ChannelInfo {
340340
pub expires_at: LSPSDateTime,
341341
}
342342

343-
impl_writeable_tlv_based!(LSPS1ChannelInfo, {
343+
impl_ser_tlv_based!(LSPS1ChannelInfo, {
344344
(0, funded_at, required),
345345
(2, funding_outpoint, required),
346346
(4, expires_at, required),

lightning-liquidity/src/lsps1/peer_state.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::lsps0::ser::{LSPSDateTime, LSPSRequestId};
1818
use crate::prelude::HashMap;
1919

2020
use lightning::util::hash_tables::new_hash_map;
21-
use lightning::{impl_writeable_tlv_based, impl_writeable_tlv_based_enum};
21+
use lightning::{impl_ser_tlv_based, impl_ser_tlv_based_enum};
2222

2323
use core::fmt;
2424

@@ -251,7 +251,7 @@ impl ChannelOrderState {
251251
}
252252
}
253253

254-
impl_writeable_tlv_based_enum!(ChannelOrderState,
254+
impl_ser_tlv_based_enum!(ChannelOrderState,
255255
(0, ExpectingPayment) => {
256256
(0, payment_details, required),
257257
},
@@ -415,7 +415,7 @@ impl PeerState {
415415
}
416416
}
417417

418-
impl_writeable_tlv_based!(PeerState, {
418+
impl_ser_tlv_based!(PeerState, {
419419
(0, outbound_channels_by_order_id, required),
420420
(_unused, pending_requests, (static_value, new_hash_map())),
421421
(_unused, needs_persist, (static_value, false)),
@@ -491,7 +491,7 @@ impl ChannelOrder {
491491
}
492492
}
493493

494-
impl_writeable_tlv_based!(ChannelOrder, {
494+
impl_ser_tlv_based!(ChannelOrder, {
495495
(0, order_params, required),
496496
(2, state, required),
497497
(4, created_at, required),

lightning-liquidity/src/lsps2/event.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use alloc::vec::Vec;
1616

1717
use bitcoin::secp256k1::PublicKey;
1818

19-
use lightning::impl_writeable_tlv_based_enum;
19+
use lightning::impl_ser_tlv_based_enum;
2020

2121
/// An event which an LSPS2 client should take some action in response to.
2222
#[derive(Clone, Debug, PartialEq, Eq)]
@@ -181,7 +181,7 @@ pub enum LSPS2ServiceEvent {
181181
},
182182
}
183183

184-
impl_writeable_tlv_based_enum!(LSPS2ServiceEvent,
184+
impl_ser_tlv_based_enum!(LSPS2ServiceEvent,
185185
(0, GetInfo) => {
186186
(0, request_id, required),
187187
(2, counterparty_node_id, required),

lightning-liquidity/src/lsps2/msgs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use bitcoin::secp256k1::PublicKey;
2121

2222
use serde::{Deserialize, Serialize};
2323

24-
use lightning::impl_writeable_tlv_based;
24+
use lightning::impl_ser_tlv_based;
2525
use lightning::util::scid_utils;
2626

2727
use crate::lsps0::ser::{
@@ -123,7 +123,7 @@ pub struct LSPS2OpeningFeeParams {
123123
pub promise: String,
124124
}
125125

126-
impl_writeable_tlv_based!(LSPS2OpeningFeeParams, {
126+
impl_ser_tlv_based!(LSPS2OpeningFeeParams, {
127127
(0, min_fee_msat, required),
128128
(2, proportional, required),
129129
(4, valid_until, required),

lightning-liquidity/src/lsps2/payment_queue.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
use alloc::vec::Vec;
1111

12-
use lightning::impl_writeable_tlv_based;
12+
use lightning::impl_ser_tlv_based;
1313
use lightning::ln::channelmanager::InterceptId;
1414
use lightning_types::payment::PaymentHash;
1515

@@ -63,7 +63,7 @@ impl PaymentQueue {
6363
}
6464
}
6565

66-
impl_writeable_tlv_based!(PaymentQueue, {
66+
impl_ser_tlv_based!(PaymentQueue, {
6767
(0, payments, optional_vec),
6868
});
6969

@@ -73,7 +73,7 @@ pub(crate) struct PaymentQueueEntry {
7373
pub(crate) htlcs: Vec<InterceptedHTLC>,
7474
}
7575

76-
impl_writeable_tlv_based!(PaymentQueueEntry, {
76+
impl_ser_tlv_based!(PaymentQueueEntry, {
7777
(0, payment_hash, required),
7878
(2, htlcs, optional_vec),
7979
});
@@ -85,7 +85,7 @@ pub(crate) struct InterceptedHTLC {
8585
pub(crate) payment_hash: PaymentHash,
8686
}
8787

88-
impl_writeable_tlv_based!(InterceptedHTLC, {
88+
impl_ser_tlv_based!(InterceptedHTLC, {
8989
(0, intercept_id, required),
9090
(2, expected_outbound_amount_msat, required),
9191
(4, payment_hash, required),

lightning-liquidity/src/lsps2/service.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ use lightning::ln::types::ChannelId;
4848
use lightning::util::errors::APIError;
4949
use lightning::util::logger::Level;
5050
use lightning::util::ser::Writeable;
51-
use lightning::{impl_writeable_tlv_based, impl_writeable_tlv_based_enum};
51+
use lightning::{impl_ser_tlv_based, impl_ser_tlv_based_enum};
5252

5353
use lightning_types::payment::PaymentHash;
5454

@@ -181,7 +181,7 @@ impl TrustModel {
181181
}
182182
}
183183

184-
impl_writeable_tlv_based_enum!(TrustModel,
184+
impl_ser_tlv_based_enum!(TrustModel,
185185
(0, ClientTrustsLsp) => {
186186
(0, funding_tx_broadcast_safe, required),
187187
(2, funding_tx, option),
@@ -468,7 +468,7 @@ impl OutboundJITChannelState {
468468
}
469469
}
470470

471-
impl_writeable_tlv_based_enum!(OutboundJITChannelState,
471+
impl_ser_tlv_based_enum!(OutboundJITChannelState,
472472
(0, PendingInitialPayment) => {
473473
(0, payment_queue, required),
474474
},
@@ -499,7 +499,7 @@ struct OutboundJITChannel {
499499
trust_model: TrustModel,
500500
}
501501

502-
impl_writeable_tlv_based!(OutboundJITChannel, {
502+
impl_ser_tlv_based!(OutboundJITChannel, {
503503
(0, state, required),
504504
(2, user_channel_id, required),
505505
(4, opening_fee_params, required),
@@ -660,7 +660,7 @@ impl PeerState {
660660
}
661661
}
662662

663-
impl_writeable_tlv_based!(PeerState, {
663+
impl_ser_tlv_based!(PeerState, {
664664
(0, outbound_channels_by_intercept_scid, required),
665665
(2, intercept_scid_by_user_channel_id, required),
666666
(4, intercept_scid_by_channel_id, required),

lightning-liquidity/src/lsps5/event.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use alloc::string::String;
1414
use alloc::vec::Vec;
1515
use bitcoin::secp256k1::PublicKey;
1616

17-
use lightning::impl_writeable_tlv_based_enum;
17+
use lightning::impl_ser_tlv_based_enum;
1818

1919
use super::msgs::LSPS5AppName;
2020
use super::msgs::LSPS5Error;
@@ -76,7 +76,7 @@ pub enum LSPS5ServiceEvent {
7676
},
7777
}
7878

79-
impl_writeable_tlv_based_enum!(LSPS5ServiceEvent,
79+
impl_ser_tlv_based_enum!(LSPS5ServiceEvent,
8080
(0, SendWebhookNotification) => {
8181
(0, counterparty_node_id, required),
8282
(2, app_name, required),

lightning-liquidity/src/lsps5/msgs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use super::url_utils::LSPSUrl;
1818

1919
use lightning::ln::msgs::DecodeError;
2020
use lightning::util::ser::{Readable, Writeable};
21-
use lightning::{impl_writeable_tlv_based, impl_writeable_tlv_based_enum};
21+
use lightning::{impl_ser_tlv_based, impl_ser_tlv_based_enum};
2222
use lightning_types::string::UntrustedString;
2323

2424
use serde::de::{self, Deserializer, MapAccess, Visitor};
@@ -527,7 +527,7 @@ pub enum WebhookNotificationMethod {
527527
LSPS5OnionMessageIncoming,
528528
}
529529

530-
impl_writeable_tlv_based_enum!(WebhookNotificationMethod,
530+
impl_ser_tlv_based_enum!(WebhookNotificationMethod,
531531
(0, LSPS5WebhookRegistered) => {},
532532
(2, LSPS5PaymentIncoming) => {},
533533
(4, LSPS5ExpirySoon) => {
@@ -688,7 +688,7 @@ impl<'de> Deserialize<'de> for WebhookNotification {
688688
}
689689
}
690690

691-
impl_writeable_tlv_based!(WebhookNotification, {
691+
impl_ser_tlv_based!(WebhookNotification, {
692692
(0, method, required),
693693
});
694694

lightning-liquidity/src/lsps5/service.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use crate::utils::time::TimeProvider;
2727

2828
use bitcoin::secp256k1::PublicKey;
2929

30-
use lightning::impl_writeable_tlv_based;
30+
use lightning::impl_ser_tlv_based;
3131
use lightning::ln::channelmanager::AChannelManager;
3232
use lightning::ln::msgs::{ErrorAction, LightningError};
3333
use lightning::sign::NodeSigner;
@@ -66,7 +66,7 @@ struct Webhook {
6666
last_notification_sent: Option<LSPSDateTime>,
6767
}
6868

69-
impl_writeable_tlv_based!(Webhook, {
69+
impl_ser_tlv_based!(Webhook, {
7070
(0, _app_name, required),
7171
(2, url, required),
7272
(4, _counterparty_node_id, required),
@@ -834,7 +834,7 @@ impl Default for PeerState {
834834
}
835835
}
836836

837-
impl_writeable_tlv_based!(PeerState, {
837+
impl_ser_tlv_based!(PeerState, {
838838
(0, webhooks, required_vec),
839839
(_unused, needs_persist, (static_value, false)),
840840
});

lightning/src/blinded_path/message.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ pub enum AsyncPaymentsContext {
660660
},
661661
}
662662

663-
impl_writeable_tlv_based_enum!(MessageContext,
663+
impl_ser_tlv_based_enum!(MessageContext,
664664
{0, Offers} => (),
665665
{1, Custom} => (),
666666
{2, AsyncPayments} => (),
@@ -671,7 +671,7 @@ impl_writeable_tlv_based_enum!(MessageContext,
671671
// introduction of `ReceiveAuthKey`-based authentication for inbound `BlindedMessagePath`s. Because
672672
// we do not support receiving to those contexts anymore (they will fail the `ReceiveAuthKey`-based
673673
// authentication checks), we can reuse those fields here.
674-
impl_writeable_tlv_based_enum!(OffersContext,
674+
impl_ser_tlv_based_enum!(OffersContext,
675675
(0, InvoiceRequest) => {
676676
(0, nonce, required),
677677
(1, payment_metadata, (option, encoding: (BTreeMap<u64, Vec<u8>>, BigSizeKeyedMap))),
@@ -694,7 +694,7 @@ impl_writeable_tlv_based_enum!(OffersContext,
694694
},
695695
);
696696

697-
impl_writeable_tlv_based_enum!(AsyncPaymentsContext,
697+
impl_ser_tlv_based_enum!(AsyncPaymentsContext,
698698
(0, OutboundPayment) => {
699699
(0, payment_id, required),
700700
},
@@ -737,7 +737,7 @@ pub struct DNSResolverContext {
737737
pub nonce: [u8; 16],
738738
}
739739

740-
impl_writeable_tlv_based!(DNSResolverContext, {
740+
impl_ser_tlv_based!(DNSResolverContext, {
741741
(0, nonce, required),
742742
});
743743

0 commit comments

Comments
 (0)