@@ -17,7 +17,7 @@ use secp256k1;
17
17
use ln:: msgs:: DecodeError ;
18
18
use ln:: channelmonitor:: { ANTI_REORG_DELAY , CLTV_SHARED_CLAIM_BUFFER , InputMaterial , ClaimRequest } ;
19
19
use ln:: channelmanager:: PaymentPreimage ;
20
- use ln:: chan_utils:: { HTLCType , LocalCommitmentTransaction } ;
20
+ use ln:: chan_utils:: { HTLCType , LocalCommitmentTransaction , HTLCOutputInCommitment } ;
21
21
use chain:: chaininterface:: { FeeEstimator , BroadcasterInterface , ConfirmationTarget , MIN_RELAY_FEE_SAT_PER_1000_WEIGHT } ;
22
22
use chain:: keysinterface:: ChannelKeys ;
23
23
use util:: logger:: Logger ;
@@ -53,7 +53,8 @@ enum OnchainEvent {
53
53
/// remote outputs, either justice or preimage/timeout transactions.
54
54
struct RemoteTxCache {
55
55
remote_delayed_payment_base_key : PublicKey ,
56
- remote_htlc_base_key : PublicKey
56
+ remote_htlc_base_key : PublicKey ,
57
+ per_htlc : HashMap < Sha256dHash , Vec < ( HTLCOutputInCommitment ) > >
57
58
}
58
59
59
60
/// Higher-level cache structure needed to re-generate bumped claim txn if needed
@@ -253,6 +254,14 @@ impl<ChanSigner: ChannelKeys + Writeable> OnchainTxHandler<ChanSigner> {
253
254
254
255
self . remote_tx_cache . remote_delayed_payment_base_key . write ( writer) ?;
255
256
self . remote_tx_cache . remote_htlc_base_key . write ( writer) ?;
257
+ writer. write_all ( & byte_utils:: be64_to_array ( self . remote_tx_cache . per_htlc . len ( ) as u64 ) ) ?;
258
+ for ( ref txid, ref htlcs) in self . remote_tx_cache . per_htlc . iter ( ) {
259
+ writer. write_all ( & txid[ ..] ) ?;
260
+ writer. write_all ( & byte_utils:: be64_to_array ( htlcs. len ( ) as u64 ) ) ?;
261
+ for & ref htlc in htlcs. iter ( ) {
262
+ htlc. write ( writer) ?;
263
+ }
264
+ }
256
265
self . remote_csv . write ( writer) ?;
257
266
258
267
self . key_storage . write ( writer) ?;
@@ -306,9 +315,24 @@ impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for OnchainTx
306
315
let remote_tx_cache = {
307
316
let remote_delayed_payment_base_key = Readable :: read ( reader) ?;
308
317
let remote_htlc_base_key = Readable :: read ( reader) ?;
318
+ let per_htlc_len: u64 = Readable :: read ( reader) ?;
319
+ let mut per_htlc = HashMap :: with_capacity ( cmp:: min ( per_htlc_len as usize , MAX_ALLOC_SIZE / 64 ) ) ;
320
+ for _ in 0 ..per_htlc_len {
321
+ let txid: Sha256dHash = Readable :: read ( reader) ?;
322
+ let htlcs_count: u64 = Readable :: read ( reader) ?;
323
+ let mut htlcs = Vec :: with_capacity ( cmp:: min ( htlcs_count as usize , MAX_ALLOC_SIZE / 32 ) ) ;
324
+ for _ in 0 ..htlcs_count {
325
+ let htlc = Readable :: read ( reader) ?;
326
+ htlcs. push ( htlc) ;
327
+ }
328
+ if let Some ( _) = per_htlc. insert ( txid, htlcs) {
329
+ return Err ( DecodeError :: InvalidValue ) ;
330
+ }
331
+ }
309
332
RemoteTxCache {
310
333
remote_delayed_payment_base_key,
311
334
remote_htlc_base_key,
335
+ per_htlc,
312
336
}
313
337
} ;
314
338
let remote_csv = Readable :: read ( reader) ?;
@@ -385,6 +409,7 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
385
409
let remote_tx_cache = RemoteTxCache {
386
410
remote_delayed_payment_base_key,
387
411
remote_htlc_base_key,
412
+ per_htlc : HashMap :: new ( ) ,
388
413
} ;
389
414
390
415
OnchainTxHandler {
@@ -903,6 +928,10 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
903
928
}
904
929
}
905
930
931
+ pub ( super ) fn provide_latest_remote_tx ( & mut self , commitment_txid : Sha256dHash , htlcs : Vec < HTLCOutputInCommitment > ) {
932
+ self . remote_tx_cache . per_htlc . insert ( commitment_txid, htlcs) ;
933
+ }
934
+
906
935
#[ cfg( test) ]
907
936
pub ( super ) fn get_fully_signed_copy_local_tx ( & mut self , funding_redeemscript : & Script ) -> Option < Transaction > {
908
937
if let Some ( ref mut local_commitment) = self . local_commitment {
0 commit comments