@@ -62,7 +62,8 @@ struct HTLCTxCache {
62
62
/// Cache remote basepoint to compute any justice tx.
63
63
struct JusticeTxCache {
64
64
remote_delayed_payment_base_key : PublicKey ,
65
- remote_htlc_base_key : PublicKey
65
+ remote_htlc_base_key : PublicKey ,
66
+ per_htlc : HashMap < Sha256dHash , Vec < ( HTLCOutputInCommitment ) > >
66
67
}
67
68
68
69
/// Higher-level cache structure needed to re-generate bumped claim txn if needed
@@ -244,6 +245,14 @@ impl<ChanSigner: ChannelKeys + Writeable> OnchainTxHandler<ChanSigner> {
244
245
245
246
self . justice_tx_cache . remote_delayed_payment_base_key . write ( writer) ?;
246
247
self . justice_tx_cache . remote_htlc_base_key . write ( writer) ?;
248
+ writer. write_all ( & byte_utils:: be64_to_array ( self . justice_tx_cache . per_htlc . len ( ) as u64 ) ) ?;
249
+ for ( ref txid, ref htlcs) in self . justice_tx_cache . per_htlc . iter ( ) {
250
+ writer. write_all ( & txid[ ..] ) ?;
251
+ writer. write_all ( & byte_utils:: be64_to_array ( htlcs. len ( ) as u64 ) ) ?;
252
+ for & ref htlc in htlcs. iter ( ) {
253
+ htlc. write ( writer) ?;
254
+ }
255
+ }
247
256
self . remote_csv . write ( writer) ?;
248
257
249
258
self . key_storage . write ( writer) ?;
@@ -335,9 +344,24 @@ impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for OnchainTx
335
344
let justice_tx_cache = {
336
345
let remote_delayed_payment_base_key = Readable :: read ( reader) ?;
337
346
let remote_htlc_base_key = Readable :: read ( reader) ?;
347
+ let per_htlc_len: u64 = Readable :: read ( reader) ?;
348
+ let mut per_htlc = HashMap :: with_capacity ( cmp:: min ( per_htlc_len as usize , MAX_ALLOC_SIZE / 64 ) ) ;
349
+ for _ in 0 ..per_htlc_len {
350
+ let txid: Sha256dHash = Readable :: read ( reader) ?;
351
+ let htlcs_count: u64 = Readable :: read ( reader) ?;
352
+ let mut htlcs = Vec :: with_capacity ( cmp:: min ( htlcs_count as usize , MAX_ALLOC_SIZE / 32 ) ) ;
353
+ for _ in 0 ..htlcs_count {
354
+ let htlc = Readable :: read ( reader) ?;
355
+ htlcs. push ( htlc) ;
356
+ }
357
+ if let Some ( _) = per_htlc. insert ( txid, htlcs) {
358
+ return Err ( DecodeError :: InvalidValue ) ;
359
+ }
360
+ }
338
361
JusticeTxCache {
339
362
remote_delayed_payment_base_key,
340
363
remote_htlc_base_key,
364
+ per_htlc,
341
365
}
342
366
} ;
343
367
let remote_csv = Readable :: read ( reader) ?;
@@ -415,6 +439,7 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
415
439
let justice_tx_cache = JusticeTxCache {
416
440
remote_delayed_payment_base_key,
417
441
remote_htlc_base_key,
442
+ per_htlc : HashMap :: new ( ) ,
418
443
} ;
419
444
420
445
OnchainTxHandler {
@@ -916,6 +941,10 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
916
941
} ) ;
917
942
}
918
943
944
+ pub ( super ) fn provide_latest_remote_tx ( & mut self , commitment_txid : Sha256dHash , htlcs : Vec < HTLCOutputInCommitment > ) {
945
+ self . justice_tx_cache . per_htlc . insert ( commitment_txid, htlcs) ;
946
+ }
947
+
919
948
pub ( super ) fn get_fully_signed_local_tx ( & mut self , channel_value_satoshis : u64 ) -> Option < Transaction > {
920
949
if self . local_commitment . is_some ( ) {
921
950
let mut tx = self . local_commitment . clone ( ) . unwrap ( ) ;
0 commit comments