|
13 | 13 |
|
14 | 14 | use bitcoin::hashes::sha256::Hash as Sha256;
|
15 | 15 | use bitcoin::hashes::{Hash, HashEngine, Hmac, HmacEngine};
|
| 16 | +use bitcoin::secp256k1::PublicKey; |
16 | 17 |
|
| 18 | +use crate::ln::types::ChannelId; |
17 | 19 | use crate::sign::PeerStorageKey;
|
18 | 20 |
|
19 | 21 | use crate::crypto::chacha20poly1305rfc::ChaCha20Poly1305RFC;
|
@@ -146,6 +148,34 @@ fn derive_nonce(key: &PeerStorageKey, random_bytes: &[u8]) -> [u8; 12] {
|
146 | 148 | nonce
|
147 | 149 | }
|
148 | 150 |
|
| 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 | + |
149 | 179 | #[cfg(test)]
|
150 | 180 | mod tests {
|
151 | 181 | use crate::ln::our_peer_storage::{derive_nonce, DecryptedOurPeerStorage};
|
|
0 commit comments