@@ -726,6 +726,36 @@ pub struct UpdateFulfillHTLC {
726726 pub payment_preimage : PaymentPreimage ,
727727}
728728
729+ /// A [`peer_storage`] message that can be sent to or received from a peer.
730+ ///
731+ /// This message is used to distribute backup data to peers.
732+ /// If data is lost or corrupted, users can retrieve it through [`PeerStorageRetrieval`]
733+ /// to recover critical information, such as channel states, for fund recovery.
734+ ///
735+ /// [`peer_storage`] is used to send our own encrypted backup data to a peer.
736+ ///
737+ /// [`peer_storage`]: https://github.com/lightning/bolts/pull/1110
738+ #[ derive( Clone , Debug , Hash , PartialEq , Eq ) ]
739+ pub struct PeerStorage {
740+ /// Our encrypted backup data included in the msg.
741+ pub data : Vec < u8 > ,
742+ }
743+
744+ /// A [`peer_storage_retrieval`] message that can be sent to or received from a peer.
745+ ///
746+ /// This message is sent to peers for whom we store backup data.
747+ /// If we receive this message, it indicates that the peer had stored our backup data.
748+ /// This data can be used for fund recovery in case of data loss.
749+ ///
750+ /// [`peer_storage_retrieval`] is used to send the most recent backup of the peer.
751+ ///
752+ /// [`peer_storage_retrieval`]: https://github.com/lightning/bolts/pull/1110
753+ #[ derive( Clone , Debug , Hash , PartialEq , Eq ) ]
754+ pub struct PeerStorageRetrieval {
755+ /// Most recent peer's data included in the msg.
756+ pub data : Vec < u8 > ,
757+ }
758+
729759/// An [`update_fail_htlc`] message to be sent to or received from a peer.
730760///
731761/// [`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
@@ -1508,6 +1538,12 @@ pub trait ChannelMessageHandler : MessageSendEventsProvider {
15081538 /// Handle an incoming `channel_ready` message from the given peer.
15091539 fn handle_channel_ready ( & self , their_node_id : PublicKey , msg : & ChannelReady ) ;
15101540
1541+ // Peer Storage
1542+ /// Handle an incoming `peer_storage` message from the given peer.
1543+ fn handle_peer_storage ( & self , their_node_id : PublicKey , msg : PeerStorage ) ;
1544+ /// Handle an incoming `peer_storage_retrieval` message from the given peer.
1545+ fn handle_peer_storage_retrieval ( & self , their_node_id : PublicKey , msg : PeerStorageRetrieval ) ;
1546+
15111547 // Channel close:
15121548 /// Handle an incoming `shutdown` message from the given peer.
15131549 fn handle_shutdown ( & self , their_node_id : PublicKey , msg : & Shutdown ) ;
@@ -2634,6 +2670,14 @@ impl_writeable_msg!(UpdateFulfillHTLC, {
26342670 payment_preimage
26352671} , { } ) ;
26362672
2673+ impl_writeable_msg ! ( PeerStorage , {
2674+ data
2675+ } , { } ) ;
2676+
2677+ impl_writeable_msg ! ( PeerStorageRetrieval , {
2678+ data
2679+ } , { } ) ;
2680+
26372681// Note that this is written as a part of ChannelManager objects, and thus cannot change its
26382682// serialization format in a way which assumes we know the total serialized length/message end
26392683// position.
@@ -4536,6 +4580,26 @@ mod tests {
45364580 assert_eq ! ( encoded_value, target_value) ;
45374581 }
45384582
4583+ #[ test]
4584+ fn encoding_peer_storage ( ) {
4585+ let peer_storage = msgs:: PeerStorage {
4586+ data : <Vec < u8 > >:: from_hex ( "01020304050607080910" ) . unwrap ( )
4587+ } ;
4588+ let encoded_value = peer_storage. encode ( ) ;
4589+ let target_value = <Vec < u8 > >:: from_hex ( "000a01020304050607080910" ) . unwrap ( ) ;
4590+ assert_eq ! ( encoded_value, target_value) ;
4591+ }
4592+
4593+ #[ test]
4594+ fn encoding_peer_storage_retrieval ( ) {
4595+ let peer_storage_retrieval = msgs:: PeerStorageRetrieval {
4596+ data : <Vec < u8 > >:: from_hex ( "01020304050607080910" ) . unwrap ( )
4597+ } ;
4598+ let encoded_value = peer_storage_retrieval. encode ( ) ;
4599+ let target_value = <Vec < u8 > >:: from_hex ( "000a01020304050607080910" ) . unwrap ( ) ;
4600+ assert_eq ! ( encoded_value, target_value) ;
4601+ }
4602+
45394603 #[ test]
45404604 fn encoding_pong ( ) {
45414605 let pong = msgs:: Pong {
0 commit comments