Skip to content

Commit a72cf4d

Browse files
committed
Migrate packages sub-fields to TLV serialization
1 parent 00ad43c commit a72cf4d

File tree

2 files changed

+60
-49
lines changed

2 files changed

+60
-49
lines changed

lightning/src/chain/package.rs

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use bitcoin::hash_types::Txid;
2121
use bitcoin::secp256k1::key::{SecretKey,PublicKey};
2222

2323
use ln::PaymentPreimage;
24-
use ln::chan_utils::{TxCreationKeys, HTLCOutputInCommitment, HTLC_OUTPUT_IN_COMMITMENT_SIZE};
24+
use ln::chan_utils::{TxCreationKeys, HTLCOutputInCommitment};
2525
use ln::chan_utils;
2626
use ln::msgs::DecodeError;
2727
use chain::chaininterface::{FeeEstimator, ConfirmationTarget, MIN_RELAY_FEE_SAT_PER_1000_WEIGHT};
@@ -86,15 +86,15 @@ impl RevokedOutput {
8686
}
8787
}
8888

89-
impl_writeable!(RevokedOutput, 33*3 + 32 + 8 + 8 + 2, {
90-
per_commitment_point,
91-
counterparty_delayed_payment_base_key,
92-
counterparty_htlc_base_key,
93-
per_commitment_key,
94-
weight,
95-
amount,
96-
on_counterparty_tx_csv
97-
});
89+
impl_writeable_tlv_based!(RevokedOutput, {
90+
(0, per_commitment_point),
91+
(2, counterparty_delayed_payment_base_key),
92+
(4, counterparty_htlc_base_key),
93+
(6, per_commitment_key),
94+
(8, weight),
95+
(10, amount),
96+
(12, on_counterparty_tx_csv),
97+
}, {}, {});
9898

9999
/// A struct to describe a revoked offered output and corresponding information to generate a
100100
/// solving witness.
@@ -130,15 +130,15 @@ impl RevokedHTLCOutput {
130130
}
131131
}
132132

133-
impl_writeable!(RevokedHTLCOutput, 33*3 + 32 + 8 + 8 + HTLC_OUTPUT_IN_COMMITMENT_SIZE, {
134-
per_commitment_point,
135-
counterparty_delayed_payment_base_key,
136-
counterparty_htlc_base_key,
137-
per_commitment_key,
138-
weight,
139-
amount,
140-
htlc
141-
});
133+
impl_writeable_tlv_based!(RevokedHTLCOutput, {
134+
(0, per_commitment_point),
135+
(2, counterparty_delayed_payment_base_key),
136+
(4, counterparty_htlc_base_key),
137+
(6, per_commitment_key),
138+
(8, weight),
139+
(10, amount),
140+
(12, htlc),
141+
}, {}, {});
142142

143143
/// A struct to describe a HTLC output on a counterparty commitment transaction.
144144
///
@@ -167,13 +167,13 @@ impl CounterpartyOfferedHTLCOutput {
167167
}
168168
}
169169

170-
impl_writeable!(CounterpartyOfferedHTLCOutput, 33*3 + 32 + HTLC_OUTPUT_IN_COMMITMENT_SIZE, {
171-
per_commitment_point,
172-
counterparty_delayed_payment_base_key,
173-
counterparty_htlc_base_key,
174-
preimage,
175-
htlc
176-
});
170+
impl_writeable_tlv_based!(CounterpartyOfferedHTLCOutput, {
171+
(0, per_commitment_point),
172+
(2, counterparty_delayed_payment_base_key),
173+
(4, counterparty_htlc_base_key),
174+
(6, preimage),
175+
(8, htlc),
176+
}, {}, {});
177177

178178
/// A struct to describe a HTLC output on a counterparty commitment transaction.
179179
///
@@ -198,12 +198,12 @@ impl CounterpartyReceivedHTLCOutput {
198198
}
199199
}
200200

201-
impl_writeable!(CounterpartyReceivedHTLCOutput, 33*3 + HTLC_OUTPUT_IN_COMMITMENT_SIZE, {
202-
per_commitment_point,
203-
counterparty_delayed_payment_base_key,
204-
counterparty_htlc_base_key,
205-
htlc
206-
});
201+
impl_writeable_tlv_based!(CounterpartyReceivedHTLCOutput, {
202+
(0, per_commitment_point),
203+
(2, counterparty_delayed_payment_base_key),
204+
(4, counterparty_htlc_base_key),
205+
(6, htlc),
206+
}, {}, {});
207207

208208
/// A struct to describe a HTLC output on holder commitment transaction.
209209
///
@@ -224,10 +224,11 @@ impl HolderHTLCOutput {
224224
}
225225
}
226226

227-
impl_writeable!(HolderHTLCOutput, 0, {
228-
preimage,
229-
amount
230-
});
227+
impl_writeable_tlv_based!(HolderHTLCOutput, {
228+
(0, amount, 0),
229+
}, {
230+
(2, preimage),
231+
}, {});
231232

232233
/// A struct to describe the channel output on the funding transaction.
233234
///
@@ -245,9 +246,9 @@ impl HolderFundingOutput {
245246
}
246247
}
247248

248-
impl_writeable!(HolderFundingOutput, 0, {
249-
funding_redeemscript
250-
});
249+
impl_writeable_tlv_based!(HolderFundingOutput, {
250+
(0, funding_redeemscript),
251+
}, {}, {});
251252

252253
/// A wrapper encapsulating all in-protocol differing outputs types.
253254
///

lightning/src/ln/chan_utils.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -429,16 +429,26 @@ pub struct HTLCOutputInCommitment {
429429
pub transaction_output_index: Option<u32>,
430430
}
431431

432-
impl_writeable_len_match!(HTLCOutputInCommitment, {
433-
{ HTLCOutputInCommitment { transaction_output_index: None, .. }, HTLC_OUTPUT_IN_COMMITMENT_SIZE - 4 },
434-
{ _, HTLC_OUTPUT_IN_COMMITMENT_SIZE }
435-
}, {
436-
offered,
437-
amount_msat,
438-
cltv_expiry,
439-
payment_hash,
440-
transaction_output_index
441-
});
432+
impl HTLCOutputInCommitment {
433+
pub(crate) fn deserialization_dummy() -> Self {
434+
Self {
435+
offered: false,
436+
amount_msat: 0,
437+
cltv_expiry: 0,
438+
payment_hash: PaymentHash([0; 32]),
439+
transaction_output_index: None,
440+
}
441+
}
442+
}
443+
444+
impl_writeable_tlv_based!(HTLCOutputInCommitment, {
445+
(0, offered, false),
446+
(2, amount_msat, 0),
447+
(4, cltv_expiry, 0),
448+
(6, payment_hash, PaymentHash([0; 32])),
449+
}, {
450+
(8, transaction_output_index)
451+
}, {});
442452

443453
#[inline]
444454
pub(crate) fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommitment, broadcaster_htlc_key: &PublicKey, countersignatory_htlc_key: &PublicKey, revocation_key: &PublicKey) -> Script {

0 commit comments

Comments
 (0)