Skip to content

Commit 4e4c4ae

Browse files
committed
fixup: Add OurPeerStorage for serialized Peer Storage backups
1 parent 680731c commit 4e4c4ae

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

lightning/src/chain/chainmonitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ where C::Target: chain::Filter,
704704
let our_peer_storage = OurPeerStorage::create_from_data(self.our_peerstorage_encryption_key.clone(), Vec::new(), self.entropy_source.get_secure_random_bytes());
705705
log_debug!(self.logger, "Sending Peer Storage from chainmonitor");
706706
self.pending_send_only_events.lock().unwrap().push(MessageSendEvent::SendPeerStorage { node_id: their_node_id,
707-
msg: msgs::PeerStorage { data: our_peer_storage.encrypted_data() } })
707+
msg: msgs::PeerStorage { data: our_peer_storage.into_vec() } })
708708
}
709709
}
710710

lightning/src/ln/our_peer_storage.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,21 @@ use crate::crypto::chacha20poly1305rfc::ChaCha20Poly1305RFC;
2020
use crate::prelude::*;
2121

2222
/// [`OurPeerStorage`] is used to store channel information that allows for the creation of a
23-
/// `peer_storage` backup. It includes versioning and timestamping for comparison between
24-
/// instances of [`OurPeerStorage`].
23+
/// `peer_storage` backup.
2524
///
2625
/// This structure is designed to serialize channel data for backup and supports encryption
27-
/// and decryption to ensure data integrity and security during exchange or storage.
26+
/// and decryption using `ChaCha20Poly1305RFC` to ensure data integrity and security during exchange or storage.
2827
///
2928
/// # Key Methods
30-
/// - `create_from_data`: Returns an encrypted [`OurPeerStorage`] instance created from the provided data.
31-
/// - `decrypt_our_peer_storage`: Decrypts the [`OurPeerStorage::encrypted_data`] using the key and returns decrypted data.
32-
///
33-
/// # Usage
34-
/// This structure can be used for securely managing and exchanging peer storage backups. It
35-
/// includes methods for encryption and decryption using `ChaCha20Poly1305RFC`, making it
36-
/// suitable for on-the-wire transmission.
29+
/// - [`OurPeerStorage::create_from_data`]: Returns an encrypted [`OurPeerStorage`] instance created from the provided data.
30+
/// - [`OurPeerStorage::decrypt_our_peer_storage`]: Decrypts the [`OurPeerStorage::encrypted_data`] using the key and returns decrypted data.
3731
///
3832
/// ## Example
3933
/// ```
4034
/// use lightning::ln::our_peer_storage::OurPeerStorage;
4135
/// use lightning::sign::PeerStorageKey;
4236
/// let key = PeerStorageKey{inner: [0u8; 32]};
43-
/// let our_peer_storage = OurPeerStorage::create_from_data(key.clone(), vec![1, 2, 3]);
37+
/// let our_peer_storage = OurPeerStorage::create_from_data(key.clone(), vec![1, 2, 3], [0u8; 32]);
4438
/// let decrypted_data = our_peer_storage.decrypt_our_peer_storage(key).unwrap();
4539
/// assert_eq!(decrypted_data, vec![1, 2, 3]);
4640
/// ```
@@ -56,14 +50,15 @@ impl OurPeerStorage {
5650
}
5751

5852
/// Get encrypted data stored inside [`OurPeerStorage`].
59-
pub fn encrypted_data(&self) -> Vec<u8> {
60-
self.encrypted_data.clone()
53+
pub fn into_vec(self) -> Vec<u8> {
54+
self.encrypted_data
6155
}
6256

6357
/// Creates a serialised representation of [`OurPeerStorage`] from the given `ser_channels` data.
6458
///
65-
/// This function takes a `key` (for encryption) and `ser_channels` data
66-
/// (serialised channel information), and returns a serialised [`OurPeerStorage`] as a `Vec<u8>`.
59+
/// This function takes a `key` (for encryption), `ser_channels` data
60+
/// (serialised channel information) and random_bytes (to derive nonce for encryption) and returns a serialised
61+
/// [`OurPeerStorage`] as a `Vec<u8>`.
6762
///
6863
/// The resulting serialised data is intended to be directly used for transmission to the peers.
6964
pub fn create_from_data(

0 commit comments

Comments
 (0)