@@ -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 ) > ) > {
@@ -2727,6 +2742,10 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
2727
2742
}
2728
2743
}
2729
2744
2745
+ fn update_peer_storage ( & mut self , new_data : Vec < u8 > ) {
2746
+ self . peer_storage = new_data;
2747
+ }
2748
+
2730
2749
fn generate_claimable_outpoints_and_watch_outputs ( & mut self ) -> ( Vec < PackageTemplate > , Vec < TransactionOutputs > ) {
2731
2750
let funding_outp = HolderFundingOutput :: build (
2732
2751
self . funding_redeemscript . clone ( ) ,
@@ -2896,6 +2915,10 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
2896
2915
panic ! ( "Attempted to replace shutdown script {} with {}" , shutdown_script, scriptpubkey) ;
2897
2916
}
2898
2917
} ,
2918
+ ChannelMonitorUpdateStep :: LatestPeerStorage { data } => {
2919
+ log_trace ! ( logger, "Updating ChannelMonitor with latest recieved PeerStorage" ) ;
2920
+ self . update_peer_storage ( data. clone ( ) ) ;
2921
+ }
2899
2922
}
2900
2923
}
2901
2924
@@ -2927,6 +2950,10 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
2927
2950
& self . funding_info
2928
2951
}
2929
2952
2953
+ pub fn peer_storage ( & self ) -> Vec < u8 > {
2954
+ self . peer_storage . clone ( )
2955
+ }
2956
+
2930
2957
pub fn channel_id ( & self ) -> ChannelId {
2931
2958
self . channel_id
2932
2959
}
@@ -4592,6 +4619,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
4592
4619
let mut counterparty_fulfilled_htlcs = Some ( new_hash_map ( ) ) ;
4593
4620
let mut initial_counterparty_commitment_info = None ;
4594
4621
let mut channel_id = None ;
4622
+ let mut peer_storage = Some ( Vec :: new ( ) ) ;
4595
4623
read_tlv_fields ! ( reader, {
4596
4624
( 1 , funding_spend_confirmed, option) ,
4597
4625
( 3 , htlcs_resolved_on_chain, optional_vec) ,
@@ -4603,6 +4631,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
4603
4631
( 15 , counterparty_fulfilled_htlcs, option) ,
4604
4632
( 17 , initial_counterparty_commitment_info, option) ,
4605
4633
( 19 , channel_id, option) ,
4634
+ ( 21 , peer_storage, optional_vec) ,
4606
4635
} ) ;
4607
4636
4608
4637
// Monitors for anchor outputs channels opened in v0.0.116 suffered from a bug in which the
@@ -4667,7 +4696,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
4667
4696
confirmed_commitment_tx_counterparty_output,
4668
4697
htlcs_resolved_on_chain : htlcs_resolved_on_chain. unwrap ( ) ,
4669
4698
spendable_txids_confirmed : spendable_txids_confirmed. unwrap ( ) ,
4670
-
4699
+ peer_storage : peer_storage . unwrap ( ) ,
4671
4700
best_block,
4672
4701
counterparty_node_id,
4673
4702
initial_counterparty_commitment_info,
0 commit comments