@@ -725,6 +725,36 @@ pub struct UpdateFulfillHTLC {
725
725
pub payment_preimage : PaymentPreimage ,
726
726
}
727
727
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 [`PeerStorageRetrieval`]
732
+ /// to recover critical information, such as channel states, for fund recovery.
733
+ ///
734
+ /// [`PeerStorage`] 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 PeerStorage {
739
+ /// Our encrypted backup data included in the msg.
740
+ pub data : Vec < u8 > ,
741
+ }
742
+
743
+ /// A [`PeerStorageRetrieval`] 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
+ /// [`PeerStorageRetrieval`] is used to send the most recent backup of the peer.
750
+ ///
751
+ /// [`PeerStorageRetrieval`]: https://github.com/lightning/bolts/pull/1110
752
+ #[ derive( Clone , Debug , Hash , PartialEq , Eq ) ]
753
+ pub struct PeerStorageRetrieval {
754
+ /// Most recent peer's data included in the msg.
755
+ pub data : Vec < u8 > ,
756
+ }
757
+
728
758
/// An [`update_fail_htlc`] message to be sent to or received from a peer.
729
759
///
730
760
/// [`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 {
1507
1537
/// Handle an incoming `channel_ready` message from the given peer.
1508
1538
fn handle_channel_ready ( & self , their_node_id : PublicKey , msg : & ChannelReady ) ;
1509
1539
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 : & PeerStorage ) ;
1543
+ /// Handle an incoming `peer_storage_retrieval` message from the given peer.
1544
+ fn handle_peer_storage_retrieval ( & self , their_node_id : PublicKey , msg : & PeerStorageRetrieval ) ;
1545
+
1510
1546
// Channel close:
1511
1547
/// Handle an incoming `shutdown` message from the given peer.
1512
1548
fn handle_shutdown ( & self , their_node_id : PublicKey , msg : & Shutdown ) ;
@@ -2628,6 +2664,14 @@ impl_writeable_msg!(UpdateFulfillHTLC, {
2628
2664
payment_preimage
2629
2665
} , { } ) ;
2630
2666
2667
+ impl_writeable_msg ! ( PeerStorage , {
2668
+ data
2669
+ } , { } ) ;
2670
+
2671
+ impl_writeable_msg ! ( PeerStorageRetrieval , {
2672
+ data
2673
+ } , { } ) ;
2674
+
2631
2675
// Note that this is written as a part of ChannelManager objects, and thus cannot change its
2632
2676
// serialization format in a way which assumes we know the total serialized length/message end
2633
2677
// position.
@@ -4527,6 +4571,26 @@ mod tests {
4527
4571
assert_eq ! ( encoded_value, target_value) ;
4528
4572
}
4529
4573
4574
+ #[ test]
4575
+ fn encoding_peer_storage ( ) {
4576
+ let peer_storage = msgs:: PeerStorage {
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:: PeerStorageRetrieval {
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
+
4530
4594
#[ test]
4531
4595
fn encoding_pong ( ) {
4532
4596
let pong = msgs:: Pong {
0 commit comments