Skip to content

Commit 2288fdb

Browse files
author
Antoine Riard
committed
Cache remote basepoint in new OnchainTxHandler::JusticeTxCache
Used in next commits to avoid passing script between ChannelMonitor and OnchainTxHandler. ChannelMonitor duplicata will be removed in future commits.
1 parent e8eb7d2 commit 2288fdb

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

lightning/src/ln/channelmonitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
11341134
onchain_events_waiting_threshold_conf: HashMap::new(),
11351135
outputs_to_watch: HashMap::new(),
11361136

1137-
onchain_tx_handler: OnchainTxHandler::new(destination_script.clone(), keys, funding_redeemscript, their_to_self_delay, logger.clone()),
1137+
onchain_tx_handler: OnchainTxHandler::new(destination_script.clone(), keys, funding_redeemscript, their_to_self_delay, their_delayed_payment_base_key.clone(), their_htlc_base_key.clone(), our_to_self_delay, logger.clone()),
11381138

11391139
last_block_hash: Default::default(),
11401140
secp_ctx: Secp256k1::new(),

lightning/src/ln/onchaintx.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use bitcoin::util::bip143;
1111
use bitcoin_hashes::sha256d::Hash as Sha256dHash;
1212

1313
use secp256k1::{Secp256k1, Signature};
14+
use secp256k1::key::PublicKey;
1415
use secp256k1;
1516

1617
use ln::msgs::DecodeError;
@@ -58,6 +59,12 @@ struct HTLCTxCache {
5859
per_htlc: HashMap<u32, (HTLCOutputInCommitment, Option<Signature>)>
5960
}
6061

62+
/// Cache remote basepoint to compute any justice tx.
63+
struct JusticeTxCache {
64+
remote_delayed_payment_base_key: PublicKey,
65+
remote_htlc_base_key: PublicKey
66+
}
67+
6168
/// Higher-level cache structure needed to re-generate bumped claim txn if needed
6269
#[derive(Clone, PartialEq)]
6370
pub struct ClaimTxBumpMaterial {
@@ -158,6 +165,8 @@ pub struct OnchainTxHandler<ChanSigner: ChannelKeys> {
158165
current_htlc_cache: Option<HTLCTxCache>,
159166
prev_htlc_cache: Option<HTLCTxCache>,
160167
local_csv: u16,
168+
justice_tx_cache: JusticeTxCache,
169+
remote_csv: u16,
161170

162171
key_storage: ChanSigner,
163172

@@ -233,6 +242,10 @@ impl<ChanSigner: ChannelKeys + Writeable> OnchainTxHandler<ChanSigner> {
233242
}
234243
self.local_csv.write(writer)?;
235244

245+
self.justice_tx_cache.remote_delayed_payment_base_key.write(writer)?;
246+
self.justice_tx_cache.remote_htlc_base_key.write(writer)?;
247+
self.remote_csv.write(writer)?;
248+
236249
self.key_storage.write(writer)?;
237250

238251
writer.write_all(&byte_utils::be64_to_array(self.pending_claim_requests.len() as u64))?;
@@ -319,6 +332,16 @@ impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for OnchainTx
319332
};
320333
let local_csv = Readable::read(reader)?;
321334

335+
let justice_tx_cache = {
336+
let remote_delayed_payment_base_key = Readable::read(reader)?;
337+
let remote_htlc_base_key = Readable::read(reader)?;
338+
JusticeTxCache {
339+
remote_delayed_payment_base_key,
340+
remote_htlc_base_key,
341+
}
342+
};
343+
let remote_csv = Readable::read(reader)?;
344+
322345
let key_storage = Readable::read(reader)?;
323346

324347
let pending_claim_requests_len: u64 = Readable::read(reader)?;
@@ -372,6 +395,8 @@ impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for OnchainTx
372395
current_htlc_cache,
373396
prev_htlc_cache,
374397
local_csv,
398+
justice_tx_cache,
399+
remote_csv,
375400
key_storage,
376401
claimable_outpoints,
377402
pending_claim_requests,
@@ -383,10 +408,15 @@ impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for OnchainTx
383408
}
384409

385410
impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
386-
pub(super) fn new(destination_script: Script, keys: ChanSigner, funding_redeemscript: Script, local_csv: u16, logger: Arc<Logger>) -> Self {
411+
pub(super) fn new(destination_script: Script, keys: ChanSigner, funding_redeemscript: Script, local_csv: u16, remote_delayed_payment_base_key: PublicKey, remote_htlc_base_key: PublicKey, remote_csv: u16, logger: Arc<Logger>) -> Self {
387412

388413
let key_storage = keys;
389414

415+
let justice_tx_cache = JusticeTxCache {
416+
remote_delayed_payment_base_key,
417+
remote_htlc_base_key,
418+
};
419+
390420
OnchainTxHandler {
391421
destination_script,
392422
funding_redeemscript,
@@ -395,6 +425,8 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
395425
current_htlc_cache: None,
396426
prev_htlc_cache: None,
397427
local_csv,
428+
justice_tx_cache,
429+
remote_csv,
398430
key_storage,
399431
pending_claim_requests: HashMap::new(),
400432
claimable_outpoints: HashMap::new(),

0 commit comments

Comments
 (0)