@@ -544,6 +544,9 @@ pub(crate) enum ChannelMonitorUpdateStep {
544
544
ShutdownScript {
545
545
scriptpubkey : ScriptBuf ,
546
546
} ,
547
+ LatestPeerStorage {
548
+ data : Vec < u8 > ,
549
+ } ,
547
550
}
548
551
549
552
impl ChannelMonitorUpdateStep {
@@ -555,6 +558,7 @@ impl ChannelMonitorUpdateStep {
555
558
ChannelMonitorUpdateStep :: CommitmentSecret { .. } => "CommitmentSecret" ,
556
559
ChannelMonitorUpdateStep :: ChannelForceClosed { .. } => "ChannelForceClosed" ,
557
560
ChannelMonitorUpdateStep :: ShutdownScript { .. } => "ShutdownScript" ,
561
+ ChannelMonitorUpdateStep :: LatestPeerStorage { .. } => "LatestPeerStorage" ,
558
562
}
559
563
}
560
564
}
@@ -588,6 +592,9 @@ impl_writeable_tlv_based_enum_upgradable!(ChannelMonitorUpdateStep,
588
592
( 5 , ShutdownScript ) => {
589
593
( 0 , scriptpubkey, required) ,
590
594
} ,
595
+ ( 6 , LatestPeerStorage ) => {
596
+ ( 0 , data, required_vec) ,
597
+ } ,
591
598
) ;
592
599
593
600
/// Details about the balance(s) available for spending once the channel appears on chain.
@@ -835,6 +842,8 @@ pub(crate) struct ChannelMonitorImpl<Signer: WriteableEcdsaChannelSigner> {
835
842
/// revoked.
836
843
payment_preimages : HashMap < PaymentHash , PaymentPreimage > ,
837
844
845
+ peer_storage : Vec < u8 > ,
846
+
838
847
// Note that `MonitorEvent`s MUST NOT be generated during update processing, only generated
839
848
// during chain data processing. This prevents a race in `ChainMonitor::update_channel` (and
840
849
// presumably user implementations thereof as well) where we update the in-memory channel
@@ -1110,6 +1119,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Writeable for ChannelMonitorImpl<Signe
1110
1119
( 15 , self . counterparty_fulfilled_htlcs, required) ,
1111
1120
( 17 , self . initial_counterparty_commitment_info, option) ,
1112
1121
( 19 , self . channel_id, required) ,
1122
+ ( 21 , self . peer_storage, required_vec) ,
1113
1123
} ) ;
1114
1124
1115
1125
Ok ( ( ) )
@@ -1289,7 +1299,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
1289
1299
confirmed_commitment_tx_counterparty_output : None ,
1290
1300
htlcs_resolved_on_chain : Vec :: new ( ) ,
1291
1301
spendable_txids_confirmed : Vec :: new ( ) ,
1292
-
1302
+ peer_storage : Vec :: new ( ) ,
1293
1303
best_block,
1294
1304
counterparty_node_id : Some ( counterparty_node_id) ,
1295
1305
initial_counterparty_commitment_info : None ,
@@ -1406,6 +1416,11 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
1406
1416
self . inner . lock ( ) . unwrap ( ) . channel_id ( )
1407
1417
}
1408
1418
1419
+ /// Fets peer_storage of this peer.
1420
+ pub fn get_peer_storage ( & self ) -> Vec < u8 > {
1421
+ self . inner . lock ( ) . unwrap ( ) . peer_storage ( )
1422
+ }
1423
+
1409
1424
/// Gets a list of txids, with their output scripts (in the order they appear in the
1410
1425
/// transaction), which we must learn about spends of via block_connected().
1411
1426
pub fn get_outputs_to_watch ( & self ) -> Vec < ( Txid , Vec < ( u32 , ScriptBuf ) > ) > {
@@ -2700,6 +2715,10 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
2700
2715
}
2701
2716
}
2702
2717
2718
+ fn update_peer_storage ( & mut self , new_data : Vec < u8 > ) {
2719
+ self . peer_storage = new_data;
2720
+ }
2721
+
2703
2722
fn generate_claimable_outpoints_and_watch_outputs ( & mut self ) -> ( Vec < PackageTemplate > , Vec < TransactionOutputs > ) {
2704
2723
let funding_outp = HolderFundingOutput :: build (
2705
2724
self . funding_redeemscript . clone ( ) ,
@@ -2869,6 +2888,10 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
2869
2888
panic ! ( "Attempted to replace shutdown script {} with {}" , shutdown_script, scriptpubkey) ;
2870
2889
}
2871
2890
} ,
2891
+ ChannelMonitorUpdateStep :: LatestPeerStorage { data } => {
2892
+ log_trace ! ( logger, "Updating ChannelMonitor with latest recieved PeerStorage" ) ;
2893
+ self . update_peer_storage ( data. clone ( ) ) ;
2894
+ }
2872
2895
}
2873
2896
}
2874
2897
@@ -2900,6 +2923,10 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
2900
2923
& self . funding_info
2901
2924
}
2902
2925
2926
+ pub fn peer_storage ( & self ) -> Vec < u8 > {
2927
+ self . peer_storage . clone ( )
2928
+ }
2929
+
2903
2930
pub fn channel_id ( & self ) -> ChannelId {
2904
2931
self . channel_id
2905
2932
}
@@ -4601,6 +4628,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
4601
4628
let mut counterparty_fulfilled_htlcs = Some ( new_hash_map ( ) ) ;
4602
4629
let mut initial_counterparty_commitment_info = None ;
4603
4630
let mut channel_id = None ;
4631
+ let mut peer_storage = Some ( Vec :: new ( ) ) ;
4604
4632
read_tlv_fields ! ( reader, {
4605
4633
( 1 , funding_spend_confirmed, option) ,
4606
4634
( 3 , htlcs_resolved_on_chain, optional_vec) ,
@@ -4612,6 +4640,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
4612
4640
( 15 , counterparty_fulfilled_htlcs, option) ,
4613
4641
( 17 , initial_counterparty_commitment_info, option) ,
4614
4642
( 19 , channel_id, option) ,
4643
+ ( 21 , peer_storage, optional_vec) ,
4615
4644
} ) ;
4616
4645
4617
4646
// Monitors for anchor outputs channels opened in v0.0.116 suffered from a bug in which the
@@ -4676,7 +4705,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
4676
4705
confirmed_commitment_tx_counterparty_output,
4677
4706
htlcs_resolved_on_chain : htlcs_resolved_on_chain. unwrap ( ) ,
4678
4707
spendable_txids_confirmed : spendable_txids_confirmed. unwrap ( ) ,
4679
-
4708
+ peer_storage : peer_storage . unwrap ( ) ,
4680
4709
best_block,
4681
4710
counterparty_node_id,
4682
4711
initial_counterparty_commitment_info,
0 commit comments