Skip to content

Commit 495912f

Browse files
committed
Write structs to serialise-deserialise Channels inside Peer-storage
'PeerStorageMonitorHolder' is used to wrap a single ChannelMonitor, here we are adding some fields separetly so that we do not need to read the whole ChannelMonitor to identify if we have lost some states. `PeerStorageMonitorHolderList` is used to keep the list of all the channels which would be sent over the wire inside Peer Storage.
1 parent fab2a1c commit 495912f

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

lightning/src/ln/our_peer_storage.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
1414
use bitcoin::hashes::sha256::Hash as Sha256;
1515
use bitcoin::hashes::{Hash, HashEngine, Hmac, HmacEngine};
16+
use bitcoin::secp256k1::PublicKey;
1617

18+
use crate::ln::types::ChannelId;
1719
use crate::sign::PeerStorageKey;
1820

1921
use crate::crypto::chacha20poly1305rfc::ChaCha20Poly1305RFC;
@@ -146,6 +148,34 @@ fn derive_nonce(key: &PeerStorageKey, random_bytes: &[u8]) -> [u8; 12] {
146148
nonce
147149
}
148150

151+
/// [`PeerStorageMonitorHolder`] represents a single channel sent over the wire.
152+
/// This would be used inside [`ChannelManager`] to determine
153+
/// if the user has lost channel states so that we can do something about it.
154+
///
155+
/// The main idea here is to just enable node to figure out that it has lost some data
156+
/// using peer storage backups.
157+
///
158+
/// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
159+
///
160+
/// TODO(aditya): Write FundRecoverer to use `monitor_bytes` to drop onchain.
161+
pub(crate) struct PeerStorageMonitorHolder {
162+
/// Channel Id of the channel.
163+
pub(crate) channel_id: ChannelId,
164+
/// Node Id of the channel partner.
165+
pub(crate) counterparty_node_id: PublicKey,
166+
/// Minimum seen secret to determine if we have lost state.
167+
pub(crate) min_seen_secret: u64,
168+
/// Whole serialised ChannelMonitor to recover funds.
169+
pub(crate) monitor_bytes: Vec<u8>,
170+
}
171+
172+
impl_writeable_tlv_based!(PeerStorageMonitorHolder, {
173+
(0, channel_id, required),
174+
(2, counterparty_node_id, required),
175+
(4, min_seen_secret, required),
176+
(6, monitor_bytes, required_vec),
177+
});
178+
149179
#[cfg(test)]
150180
mod tests {
151181
use crate::ln::our_peer_storage::{derive_nonce, DecryptedOurPeerStorage};

lightning/src/util/ser.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,7 @@ impl_for_vec!((A, B), A, B);
10841084
impl_for_vec!(SerialId);
10851085
impl_for_vec!(NegotiatedTxInput);
10861086
impl_for_vec!(InteractiveTxOutput);
1087+
impl_for_vec!(crate::ln::our_peer_storage::PeerStorageMonitorHolder);
10871088
impl_writeable_for_vec!(&crate::routing::router::BlindedTail);
10881089
impl_readable_for_vec!(crate::routing::router::BlindedTail);
10891090
impl_for_vec!(crate::routing::router::TrampolineHop);

0 commit comments

Comments
 (0)