Skip to content

ln: reduce size_of Event from 1680 B -> 576 B #3723

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lightning/src/chain/channelmonitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3544,7 +3544,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
package_target_feerate_sat_per_1000_weight,
commitment_tx,
commitment_tx_fee_satoshis,
anchor_descriptor: AnchorDescriptor {
anchor_descriptor: Box::new(AnchorDescriptor {
channel_derivation_parameters: ChannelDerivationParameters {
keys_id: self.channel_keys_id,
value_satoshis: channel_parameters.channel_value_satoshis,
Expand All @@ -3554,7 +3554,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
txid: commitment_txid,
vout: anchor_output_idx,
},
},
}),
pending_htlcs: pending_nondust_htlcs,
}));
},
Expand Down
6 changes: 3 additions & 3 deletions lightning/src/events/bump_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ pub enum BumpTransactionEvent {
commitment_tx_fee_satoshis: u64,
/// The descriptor to sign the anchor input of the anchor transaction constructed as a
/// result of consuming this event.
anchor_descriptor: AnchorDescriptor,
anchor_descriptor: Box<AnchorDescriptor>,
/// The set of pending HTLCs on the commitment transaction that need to be resolved once the
/// commitment transaction confirms.
pending_htlcs: Vec<HTLCOutputInCommitment>,
Expand Down Expand Up @@ -955,14 +955,14 @@ mod tests {
package_target_feerate_sat_per_1000_weight: 868,
commitment_tx_fee_satoshis: 930,
commitment_tx,
anchor_descriptor: AnchorDescriptor {
anchor_descriptor: Box::new(AnchorDescriptor {
channel_derivation_parameters: ChannelDerivationParameters {
value_satoshis: 42_000_000,
keys_id: [42; 32],
transaction_parameters,
},
outpoint: OutPoint { txid: Txid::from_byte_array([42; 32]), vout: 0 },
},
}),
pending_htlcs: Vec::new(),
});
}
Expand Down
42 changes: 21 additions & 21 deletions lightning/src/offers/invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ pub const SIGNATURE_TAG: &'static str = concat!("lightning", "invoice", "signatu
/// [module-level documentation]: self
pub struct InvoiceBuilder<'a, S: SigningPubkeyStrategy> {
invreq_bytes: &'a Vec<u8>,
invoice: InvoiceContents,
invoice: Box<InvoiceContents>,
signing_pubkey_strategy: S,
}

Expand All @@ -200,7 +200,7 @@ pub struct InvoiceBuilder<'a, S: SigningPubkeyStrategy> {
#[cfg(c_bindings)]
pub struct InvoiceWithExplicitSigningPubkeyBuilder<'a> {
invreq_bytes: &'a Vec<u8>,
invoice: InvoiceContents,
invoice: Box<InvoiceContents>,
signing_pubkey_strategy: ExplicitSigningPubkey,
}

Expand All @@ -216,7 +216,7 @@ pub struct InvoiceWithExplicitSigningPubkeyBuilder<'a> {
#[cfg(c_bindings)]
pub struct InvoiceWithDerivedSigningPubkeyBuilder<'a> {
invreq_bytes: &'a Vec<u8>,
invoice: InvoiceContents,
invoice: Box<InvoiceContents>,
signing_pubkey_strategy: DerivedSigningPubkey,
}

Expand Down Expand Up @@ -246,7 +246,7 @@ macro_rules! invoice_explicit_signing_pubkey_builder_methods {
created_at: Duration, payment_hash: PaymentHash, signing_pubkey: PublicKey,
) -> Result<Self, Bolt12SemanticError> {
let amount_msats = Self::amount_msats(invoice_request)?;
let contents = InvoiceContents::ForOffer {
let contents = Box::new(InvoiceContents::ForOffer {
invoice_request: invoice_request.contents.clone(),
fields: Self::fields(
payment_paths,
Expand All @@ -255,7 +255,7 @@ macro_rules! invoice_explicit_signing_pubkey_builder_methods {
amount_msats,
signing_pubkey,
),
};
});

Self::new(&invoice_request.bytes, contents, ExplicitSigningPubkey {})
}
Expand All @@ -266,7 +266,7 @@ macro_rules! invoice_explicit_signing_pubkey_builder_methods {
payment_hash: PaymentHash, signing_pubkey: PublicKey,
) -> Result<Self, Bolt12SemanticError> {
let amount_msats = refund.amount_msats();
let contents = InvoiceContents::ForRefund {
let contents = Box::new(InvoiceContents::ForRefund {
refund: refund.contents.clone(),
fields: Self::fields(
payment_paths,
Expand All @@ -275,7 +275,7 @@ macro_rules! invoice_explicit_signing_pubkey_builder_methods {
amount_msats,
signing_pubkey,
),
};
});

Self::new(&refund.bytes, contents, ExplicitSigningPubkey {})
}
Expand Down Expand Up @@ -319,7 +319,7 @@ macro_rules! invoice_derived_signing_pubkey_builder_methods {
) -> Result<Self, Bolt12SemanticError> {
let amount_msats = Self::amount_msats(invoice_request)?;
let signing_pubkey = keys.public_key();
let contents = InvoiceContents::ForOffer {
let contents = Box::new(InvoiceContents::ForOffer {
invoice_request: invoice_request.contents.clone(),
fields: Self::fields(
payment_paths,
Expand All @@ -328,7 +328,7 @@ macro_rules! invoice_derived_signing_pubkey_builder_methods {
amount_msats,
signing_pubkey,
),
};
});

Self::new(&invoice_request.bytes, contents, DerivedSigningPubkey(keys))
}
Expand All @@ -340,7 +340,7 @@ macro_rules! invoice_derived_signing_pubkey_builder_methods {
) -> Result<Self, Bolt12SemanticError> {
let amount_msats = refund.amount_msats();
let signing_pubkey = keys.public_key();
let contents = InvoiceContents::ForRefund {
let contents = Box::new(InvoiceContents::ForRefund {
refund: refund.contents.clone(),
fields: Self::fields(
payment_paths,
Expand All @@ -349,7 +349,7 @@ macro_rules! invoice_derived_signing_pubkey_builder_methods {
amount_msats,
signing_pubkey,
),
};
});

Self::new(&refund.bytes, contents, DerivedSigningPubkey(keys))
}
Expand Down Expand Up @@ -429,7 +429,7 @@ macro_rules! invoice_builder_methods {

#[cfg_attr(c_bindings, allow(dead_code))]
fn new(
invreq_bytes: &'a Vec<u8>, contents: InvoiceContents,
invreq_bytes: &'a Vec<u8>, contents: Box<InvoiceContents>,
signing_pubkey_strategy: $type_param,
) -> Result<Self, Bolt12SemanticError> {
if contents.fields().payment_paths.is_empty() {
Expand Down Expand Up @@ -593,7 +593,7 @@ impl<'a> From<InvoiceWithDerivedSigningPubkeyBuilder<'a>>
pub struct UnsignedBolt12Invoice {
bytes: Vec<u8>,
experimental_bytes: Vec<u8>,
contents: InvoiceContents,
contents: Box<InvoiceContents>,
tagged_hash: TaggedHash,
}

Expand Down Expand Up @@ -622,7 +622,7 @@ where
}

impl UnsignedBolt12Invoice {
fn new(invreq_bytes: &[u8], contents: InvoiceContents) -> Self {
fn new(invreq_bytes: &[u8], contents: Box<InvoiceContents>) -> Self {
// TLV record ranges applicable to invreq_bytes.
const NON_EXPERIMENTAL_TYPES: core::ops::Range<u64> = 0..INVOICE_REQUEST_TYPES.end;
const EXPERIMENTAL_TYPES: core::ops::Range<u64> =
Expand Down Expand Up @@ -731,7 +731,7 @@ impl AsRef<TaggedHash> for UnsignedBolt12Invoice {
#[derive(Clone, Debug)]
pub struct Bolt12Invoice {
bytes: Vec<u8>,
contents: InvoiceContents,
contents: Box<InvoiceContents>,
signature: Signature,
tagged_hash: TaggedHash,
}
Expand Down Expand Up @@ -974,7 +974,7 @@ impl Bolt12Invoice {
pub fn verify_using_metadata<T: secp256k1::Signing>(
&self, key: &ExpandedKey, secp_ctx: &Secp256k1<T>,
) -> Result<PaymentId, ()> {
let (metadata, iv_bytes) = match &self.contents {
let (metadata, iv_bytes) = match &*self.contents {
InvoiceContents::ForOffer { invoice_request, .. } => {
(&invoice_request.inner.payer.0, INVOICE_REQUEST_IV_BYTES)
},
Expand All @@ -992,7 +992,7 @@ impl Bolt12Invoice {
&self, payment_id: PaymentId, nonce: Nonce, key: &ExpandedKey, secp_ctx: &Secp256k1<T>,
) -> Result<PaymentId, ()> {
let metadata = Metadata::payer_data(payment_id, nonce, key);
let iv_bytes = match &self.contents {
let iv_bytes = match &*self.contents {
InvoiceContents::ForOffer { .. } => INVOICE_REQUEST_IV_BYTES,
InvoiceContents::ForRefund { .. } => REFUND_IV_BYTES_WITHOUT_METADATA,
};
Expand Down Expand Up @@ -1027,7 +1027,7 @@ impl Bolt12Invoice {
}

pub(crate) fn is_for_refund_without_paths(&self) -> bool {
match self.contents {
match &*self.contents {
InvoiceContents::ForOffer { .. } => false,
InvoiceContents::ForRefund { .. } => self.message_paths().is_empty(),
}
Expand Down Expand Up @@ -1422,7 +1422,7 @@ impl TryFrom<Vec<u8>> for UnsignedBolt12Invoice {
fn try_from(bytes: Vec<u8>) -> Result<Self, Self::Error> {
let invoice = ParsedMessage::<PartialInvoiceTlvStream>::try_from(bytes)?;
let ParsedMessage { mut bytes, tlv_stream } = invoice;
let contents = InvoiceContents::try_from(tlv_stream)?;
let contents = Box::new(InvoiceContents::try_from(tlv_stream)?);

let tagged_hash = TaggedHash::from_valid_tlv_stream_bytes(SIGNATURE_TAG, &bytes);

Expand Down Expand Up @@ -1606,15 +1606,15 @@ impl TryFrom<ParsedMessage<FullInvoiceTlvStream>> for Bolt12Invoice {
experimental_invoice_request_tlv_stream,
experimental_invoice_tlv_stream,
) = tlv_stream;
let contents = InvoiceContents::try_from((
let contents = Box::new(InvoiceContents::try_from((
payer_tlv_stream,
offer_tlv_stream,
invoice_request_tlv_stream,
invoice_tlv_stream,
experimental_offer_tlv_stream,
experimental_invoice_request_tlv_stream,
experimental_invoice_tlv_stream,
))?;
))?);

let signature = signature
.ok_or(Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingSignature))?;
Expand Down
14 changes: 7 additions & 7 deletions lightning/src/offers/static_invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub const SIGNATURE_TAG: &'static str = concat!("lightning", "static_invoice", "
#[derive(Clone, Debug)]
pub struct StaticInvoice {
bytes: Vec<u8>,
contents: InvoiceContents,
contents: Box<InvoiceContents>,
signature: Signature,
}

Expand Down Expand Up @@ -104,7 +104,7 @@ struct InvoiceContents {
// TODO: add module-level docs and link here
pub struct StaticInvoiceBuilder<'a> {
offer_bytes: &'a Vec<u8>,
invoice: InvoiceContents,
invoice: Box<InvoiceContents>,
keys: Keypair,
}

Expand Down Expand Up @@ -141,7 +141,7 @@ impl<'a> StaticInvoiceBuilder<'a> {
}

let invoice =
InvoiceContents::new(offer, payment_paths, message_paths, created_at, signing_pubkey);
Box::new(InvoiceContents::new(offer, payment_paths, message_paths, created_at, signing_pubkey));

Ok(Self { offer_bytes: &offer.bytes, invoice, keys })
}
Expand Down Expand Up @@ -190,7 +190,7 @@ impl<'a> StaticInvoiceBuilder<'a> {
pub struct UnsignedStaticInvoice {
bytes: Vec<u8>,
experimental_bytes: Vec<u8>,
contents: InvoiceContents,
contents: Box<InvoiceContents>,
tagged_hash: TaggedHash,
}

Expand Down Expand Up @@ -294,7 +294,7 @@ macro_rules! invoice_accessors_signing_pubkey {
} }

impl UnsignedStaticInvoice {
fn new(offer_bytes: &Vec<u8>, contents: InvoiceContents) -> Self {
fn new(offer_bytes: &Vec<u8>, contents: Box<InvoiceContents>) -> Self {
let (_, invoice_tlv_stream, _, experimental_invoice_tlv_stream) = contents.as_tlv_stream();

const INVOICE_ALLOCATION_SIZE: usize = 1024;
Expand Down Expand Up @@ -602,12 +602,12 @@ impl TryFrom<ParsedMessage<FullInvoiceTlvStream>> for StaticInvoice {
experimental_offer_tlv_stream,
experimental_invoice_tlv_stream,
) = tlv_stream;
let contents = InvoiceContents::try_from((
let contents = Box::new(InvoiceContents::try_from((
offer_tlv_stream,
invoice_tlv_stream,
experimental_offer_tlv_stream,
experimental_invoice_tlv_stream,
))?;
))?);

let signature = match signature {
None => {
Expand Down
Loading