@@ -544,6 +544,9 @@ pub(crate) enum ChannelMonitorUpdateStep {
544544 ShutdownScript {
545545 scriptpubkey : ScriptBuf ,
546546 } ,
547+ LatestPeerStorage {
548+ data : Vec < u8 > ,
549+ } ,
547550}
548551
549552impl ChannelMonitorUpdateStep {
@@ -555,6 +558,7 @@ impl ChannelMonitorUpdateStep {
555558 ChannelMonitorUpdateStep :: CommitmentSecret { .. } => "CommitmentSecret" ,
556559 ChannelMonitorUpdateStep :: ChannelForceClosed { .. } => "ChannelForceClosed" ,
557560 ChannelMonitorUpdateStep :: ShutdownScript { .. } => "ShutdownScript" ,
561+ ChannelMonitorUpdateStep :: LatestPeerStorage { .. } => "LatestPeerStorage" ,
558562 }
559563 }
560564}
@@ -588,6 +592,9 @@ impl_writeable_tlv_based_enum_upgradable!(ChannelMonitorUpdateStep,
588592 ( 5 , ShutdownScript ) => {
589593 ( 0 , scriptpubkey, required) ,
590594 } ,
595+ ( 6 , LatestPeerStorage ) => {
596+ ( 0 , data, required_vec) ,
597+ } ,
591598) ;
592599
593600/// Details about the balance(s) available for spending once the channel appears on chain.
@@ -835,6 +842,8 @@ pub(crate) struct ChannelMonitorImpl<Signer: WriteableEcdsaChannelSigner> {
835842 /// revoked.
836843 payment_preimages : HashMap < PaymentHash , PaymentPreimage > ,
837844
845+ peer_storage : Vec < u8 > ,
846+
838847 // Note that `MonitorEvent`s MUST NOT be generated during update processing, only generated
839848 // during chain data processing. This prevents a race in `ChainMonitor::update_channel` (and
840849 // presumably user implementations thereof as well) where we update the in-memory channel
@@ -1110,6 +1119,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Writeable for ChannelMonitorImpl<Signe
11101119 ( 15 , self . counterparty_fulfilled_htlcs, required) ,
11111120 ( 17 , self . initial_counterparty_commitment_info, option) ,
11121121 ( 19 , self . channel_id, required) ,
1122+ ( 21 , self . peer_storage, required_vec) ,
11131123 } ) ;
11141124
11151125 Ok ( ( ) )
@@ -1289,7 +1299,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
12891299 confirmed_commitment_tx_counterparty_output : None ,
12901300 htlcs_resolved_on_chain : Vec :: new ( ) ,
12911301 spendable_txids_confirmed : Vec :: new ( ) ,
1292-
1302+ peer_storage : Vec :: new ( ) ,
12931303 best_block,
12941304 counterparty_node_id : Some ( counterparty_node_id) ,
12951305 initial_counterparty_commitment_info : None ,
@@ -1406,6 +1416,11 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitor<Signer> {
14061416 self . inner . lock ( ) . unwrap ( ) . channel_id ( )
14071417 }
14081418
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+
14091424 /// Gets a list of txids, with their output scripts (in the order they appear in the
14101425 /// transaction), which we must learn about spends of via block_connected().
14111426 pub fn get_outputs_to_watch ( & self ) -> Vec < ( Txid , Vec < ( u32 , ScriptBuf ) > ) > {
@@ -2727,6 +2742,10 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
27272742 }
27282743 }
27292744
2745+ fn update_peer_storage ( & mut self , new_data : Vec < u8 > ) {
2746+ self . peer_storage = new_data;
2747+ }
2748+
27302749 fn generate_claimable_outpoints_and_watch_outputs ( & mut self ) -> ( Vec < PackageTemplate > , Vec < TransactionOutputs > ) {
27312750 let funding_outp = HolderFundingOutput :: build (
27322751 self . funding_redeemscript . clone ( ) ,
@@ -2896,6 +2915,10 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
28962915 panic ! ( "Attempted to replace shutdown script {} with {}" , shutdown_script, scriptpubkey) ;
28972916 }
28982917 } ,
2918+ ChannelMonitorUpdateStep :: LatestPeerStorage { data } => {
2919+ log_trace ! ( logger, "Updating ChannelMonitor with latest recieved PeerStorage" ) ;
2920+ self . update_peer_storage ( data. clone ( ) ) ;
2921+ }
28992922 }
29002923 }
29012924
@@ -2927,6 +2950,10 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
29272950 & self . funding_info
29282951 }
29292952
2953+ pub fn peer_storage ( & self ) -> Vec < u8 > {
2954+ self . peer_storage . clone ( )
2955+ }
2956+
29302957 pub fn channel_id ( & self ) -> ChannelId {
29312958 self . channel_id
29322959 }
@@ -4592,6 +4619,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
45924619 let mut counterparty_fulfilled_htlcs = Some ( new_hash_map ( ) ) ;
45934620 let mut initial_counterparty_commitment_info = None ;
45944621 let mut channel_id = None ;
4622+ let mut peer_storage = Some ( Vec :: new ( ) ) ;
45954623 read_tlv_fields ! ( reader, {
45964624 ( 1 , funding_spend_confirmed, option) ,
45974625 ( 3 , htlcs_resolved_on_chain, optional_vec) ,
@@ -4603,6 +4631,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
46034631 ( 15 , counterparty_fulfilled_htlcs, option) ,
46044632 ( 17 , initial_counterparty_commitment_info, option) ,
46054633 ( 19 , channel_id, option) ,
4634+ ( 21 , peer_storage, optional_vec) ,
46064635 } ) ;
46074636
46084637 // 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
46674696 confirmed_commitment_tx_counterparty_output,
46684697 htlcs_resolved_on_chain : htlcs_resolved_on_chain. unwrap ( ) ,
46694698 spendable_txids_confirmed : spendable_txids_confirmed. unwrap ( ) ,
4670-
4699+ peer_storage : peer_storage . unwrap ( ) ,
46714700 best_block,
46724701 counterparty_node_id,
46734702 initial_counterparty_commitment_info,
0 commit comments