Skip to content

Commit d282bbf

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

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-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: 34 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,13 @@ struct HTLCTxCache {
5859
per_htlc: HashMap<u32, (HTLCOutputInCommitment, Option<Signature>)>
5960
}
6061

62+
/// Cache remote basepoint to compute any transaction on
63+
/// remote outputs, either justice or preimage/timeout transactions.
64+
struct RemoteTxCache {
65+
remote_delayed_payment_base_key: PublicKey,
66+
remote_htlc_base_key: PublicKey
67+
}
68+
6169
/// Higher-level cache structure needed to re-generate bumped claim txn if needed
6270
#[derive(Clone, PartialEq)]
6371
pub struct ClaimTxBumpMaterial {
@@ -158,6 +166,8 @@ pub struct OnchainTxHandler<ChanSigner: ChannelKeys> {
158166
current_htlc_cache: Option<HTLCTxCache>,
159167
prev_htlc_cache: Option<HTLCTxCache>,
160168
local_csv: u16,
169+
remote_tx_cache: RemoteTxCache,
170+
remote_csv: u16,
161171

162172
key_storage: ChanSigner,
163173

@@ -233,6 +243,10 @@ impl<ChanSigner: ChannelKeys + Writeable> OnchainTxHandler<ChanSigner> {
233243
}
234244
self.local_csv.write(writer)?;
235245

246+
self.remote_tx_cache.remote_delayed_payment_base_key.write(writer)?;
247+
self.remote_tx_cache.remote_htlc_base_key.write(writer)?;
248+
self.remote_csv.write(writer)?;
249+
236250
self.key_storage.write(writer)?;
237251

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

336+
let remote_tx_cache = {
337+
let remote_delayed_payment_base_key = Readable::read(reader)?;
338+
let remote_htlc_base_key = Readable::read(reader)?;
339+
RemoteTxCache {
340+
remote_delayed_payment_base_key,
341+
remote_htlc_base_key,
342+
}
343+
};
344+
let remote_csv = Readable::read(reader)?;
345+
322346
let key_storage = Readable::read(reader)?;
323347

324348
let pending_claim_requests_len: u64 = Readable::read(reader)?;
@@ -372,6 +396,8 @@ impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for OnchainTx
372396
current_htlc_cache,
373397
prev_htlc_cache,
374398
local_csv,
399+
remote_tx_cache,
400+
remote_csv,
375401
key_storage,
376402
claimable_outpoints,
377403
pending_claim_requests,
@@ -383,10 +409,15 @@ impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for OnchainTx
383409
}
384410

385411
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 {
412+
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 {
387413

388414
let key_storage = keys;
389415

416+
let remote_tx_cache = RemoteTxCache {
417+
remote_delayed_payment_base_key,
418+
remote_htlc_base_key,
419+
};
420+
390421
OnchainTxHandler {
391422
destination_script,
392423
funding_redeemscript,
@@ -395,6 +426,8 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
395426
current_htlc_cache: None,
396427
prev_htlc_cache: None,
397428
local_csv,
429+
remote_tx_cache,
430+
remote_csv,
398431
key_storage,
399432
pending_claim_requests: HashMap::new(),
400433
claimable_outpoints: HashMap::new(),

0 commit comments

Comments
 (0)