@@ -726,6 +726,36 @@ pub struct UpdateFulfillHTLC {
726
726
pub payment_preimage : PaymentPreimage ,
727
727
}
728
728
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
+
729
759
/// An [`update_fail_htlc`] message to be sent to or received from a peer.
730
760
///
731
761
/// [`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 {
1508
1538
/// Handle an incoming `channel_ready` message from the given peer.
1509
1539
fn handle_channel_ready ( & self , their_node_id : PublicKey , msg : & ChannelReady ) ;
1510
1540
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
+
1511
1547
// Channel close:
1512
1548
/// Handle an incoming `shutdown` message from the given peer.
1513
1549
fn handle_shutdown ( & self , their_node_id : PublicKey , msg : & Shutdown ) ;
@@ -2634,6 +2670,14 @@ impl_writeable_msg!(UpdateFulfillHTLC, {
2634
2670
payment_preimage
2635
2671
} , { } ) ;
2636
2672
2673
+ impl_writeable_msg ! ( PeerStorage , {
2674
+ data
2675
+ } , { } ) ;
2676
+
2677
+ impl_writeable_msg ! ( PeerStorageRetrieval , {
2678
+ data
2679
+ } , { } ) ;
2680
+
2637
2681
// Note that this is written as a part of ChannelManager objects, and thus cannot change its
2638
2682
// serialization format in a way which assumes we know the total serialized length/message end
2639
2683
// position.
@@ -4536,6 +4580,26 @@ mod tests {
4536
4580
assert_eq ! ( encoded_value, target_value) ;
4537
4581
}
4538
4582
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
+
4539
4603
#[ test]
4540
4604
fn encoding_pong ( ) {
4541
4605
let pong = msgs:: Pong {
0 commit comments