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