@@ -725,6 +725,36 @@ pub struct UpdateFulfillHTLC {
725725 pub payment_preimage : PaymentPreimage ,
726726}
727727
728+ /// A [`PeerStorage`] message that can be sent to or received from a peer.
729+ ///
730+ /// This message is used to distribute backup data to peers.
731+ /// If data is lost or corrupted, users can retrieve it through [`PeerStorageRetrievalMessage`]
732+ /// to recover critical information, such as channel states, for fund recovery.
733+ ///
734+ /// [`PeerStorageMessage`] is used to send our own encrypted backup data to a peer.
735+ ///
736+ /// [`PeerStorage`]: https://github.com/lightning/bolts/pull/1110
737+ #[ derive( Clone , Debug , Hash , PartialEq , Eq ) ]
738+ pub struct PeerStorageMessage {
739+ /// Our encrypted backup data included in the msg.
740+ pub data : Vec < u8 > ,
741+ }
742+
743+ /// A [`PeerStorageRetrievalMessage`] message that can be sent to or received from a peer.
744+ ///
745+ /// This message is sent to peers for whom we store backup data.
746+ /// If we receive this message, it indicates that the peer had stored our backup data.
747+ /// This data can be used for fund recovery in case of data loss.
748+ ///
749+ /// [`PeerStorageRetrievalMessage`] is used to send the most recent backup of the peer.
750+ ///
751+ /// [`PeerStorageRetrievalMessage`]: https://github.com/lightning/bolts/pull/1110
752+ #[ derive( Clone , Debug , Hash , PartialEq , Eq ) ]
753+ pub struct PeerStorageRetrievalMessage {
754+ /// Most recent peer's data included in the msg.
755+ pub data : Vec < u8 > ,
756+ }
757+
728758/// An [`update_fail_htlc`] message to be sent to or received from a peer.
729759///
730760/// [`update_fail_htlc`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#removing-an-htlc-update_fulfill_htlc-update_fail_htlc-and-update_fail_malformed_htlc
@@ -1507,6 +1537,12 @@ pub trait ChannelMessageHandler : MessageSendEventsProvider {
15071537 /// Handle an incoming `channel_ready` message from the given peer.
15081538 fn handle_channel_ready ( & self , their_node_id : PublicKey , msg : & ChannelReady ) ;
15091539
1540+ // Peer Storage
1541+ /// Handle an incoming `peer_storage` message from the given peer.
1542+ fn handle_peer_storage ( & self , their_node_id : PublicKey , msg : & PeerStorageMessage ) ;
1543+ /// Handle an incoming `peer_storage_retrieval` message from the given peer.
1544+ fn handle_peer_storage_retrieval ( & self , their_node_id : PublicKey , msg : & PeerStorageRetrievalMessage ) ;
1545+
15101546 // Channel close:
15111547 /// Handle an incoming `shutdown` message from the given peer.
15121548 fn handle_shutdown ( & self , their_node_id : PublicKey , msg : & Shutdown ) ;
@@ -2628,6 +2664,14 @@ impl_writeable_msg!(UpdateFulfillHTLC, {
26282664 payment_preimage
26292665} , { } ) ;
26302666
2667+ impl_writeable_msg ! ( PeerStorageMessage , {
2668+ data
2669+ } , { } ) ;
2670+
2671+ impl_writeable_msg ! ( PeerStorageRetrievalMessage , {
2672+ data
2673+ } , { } ) ;
2674+
26312675// Note that this is written as a part of ChannelManager objects, and thus cannot change its
26322676// serialization format in a way which assumes we know the total serialized length/message end
26332677// position.
@@ -4527,6 +4571,26 @@ mod tests {
45274571 assert_eq ! ( encoded_value, target_value) ;
45284572 }
45294573
4574+ #[ test]
4575+ fn encoding_peer_storage ( ) {
4576+ let peer_storage = msgs:: PeerStorageMessage {
4577+ data : <Vec < u8 > >:: from_hex ( "01020304050607080910" ) . unwrap ( )
4578+ } ;
4579+ let encoded_value = peer_storage. encode ( ) ;
4580+ let target_value = <Vec < u8 > >:: from_hex ( "000a01020304050607080910" ) . unwrap ( ) ;
4581+ assert_eq ! ( encoded_value, target_value) ;
4582+ }
4583+
4584+ #[ test]
4585+ fn encoding_peer_storage_retrieval ( ) {
4586+ let peer_storage_retrieval = msgs:: PeerStorageRetrievalMessage {
4587+ data : <Vec < u8 > >:: from_hex ( "01020304050607080910" ) . unwrap ( )
4588+ } ;
4589+ let encoded_value = peer_storage_retrieval. encode ( ) ;
4590+ let target_value = <Vec < u8 > >:: from_hex ( "000a01020304050607080910" ) . unwrap ( ) ;
4591+ assert_eq ! ( encoded_value, target_value) ;
4592+ }
4593+
45304594 #[ test]
45314595 fn encoding_pong ( ) {
45324596 let pong = msgs:: Pong {
0 commit comments