projects
/
rust-lightning
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add a few notes about deserializing stale ChannelManagers
[rust-lightning]
/
lightning
/
src
/
chain
/
channelmonitor.rs
diff --git
a/lightning/src/chain/channelmonitor.rs
b/lightning/src/chain/channelmonitor.rs
index a997694722f4c908e7c9f61698363617310ebc5f..4d2d1b848aecb187471c203e1f962675a37fdbf8 100644
(file)
--- a/
lightning/src/chain/channelmonitor.rs
+++ b/
lightning/src/chain/channelmonitor.rs
@@
-50,7
+50,6
@@
use util::ser::{Readable, ReadableArgs, MaybeReadable, Writer, Writeable, U48};
use util::byte_utils;
use util::events::Event;
use util::byte_utils;
use util::events::Event;
-use std::cell::RefCell;
use std::collections::{HashMap, HashSet, hash_map};
use std::{cmp, mem};
use std::io::Error;
use std::collections::{HashMap, HashSet, hash_map};
use std::{cmp, mem};
use std::io::Error;
@@
-621,7
+620,7
@@
impl Readable for ChannelMonitorUpdateStep {
/// reloaded at deserialize-time. Thus, you must ensure that, when handling events, all events
/// gotten are fully handled before re-serializing the new state.
///
/// reloaded at deserialize-time. Thus, you must ensure that, when handling events, all events
/// gotten are fully handled before re-serializing the new state.
///
-/// Note that the deserializer is only implemented for (
Sha256dHash
, ChannelMonitor), which
+/// Note that the deserializer is only implemented for (
Option<BlockHash>
, ChannelMonitor), which
/// tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along
/// the "reorg path" (ie disconnecting blocks until you find a common ancestor from both the
/// returned block hash and the the current chain and then reconnecting blocks to get to the
/// tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along
/// the "reorg path" (ie disconnecting blocks until you find a common ancestor from both the
/// returned block hash and the the current chain and then reconnecting blocks to get to the
@@
-2474,7
+2473,7
@@
pub trait Persist<ChannelSigner: Sign>: Send + Sync {
fn update_persisted_channel(&self, id: OutPoint, update: &ChannelMonitorUpdate, data: &ChannelMonitor<ChannelSigner>) -> Result<(), ChannelMonitorUpdateErr>;
}
fn update_persisted_channel(&self, id: OutPoint, update: &ChannelMonitorUpdate, data: &ChannelMonitor<ChannelSigner>) -> Result<(), ChannelMonitorUpdateErr>;
}
-impl<Signer: Sign, T: Deref, F: Deref, L: Deref> chain::Listen for (
RefCell<ChannelMonitor<Signer>
>, T, F, L)
+impl<Signer: Sign, T: Deref, F: Deref, L: Deref> chain::Listen for (
ChannelMonitor<Signer
>, T, F, L)
where
T::Target: BroadcasterInterface,
F::Target: FeeEstimator,
where
T::Target: BroadcasterInterface,
F::Target: FeeEstimator,
@@
-2482,18
+2481,18
@@
where
{
fn block_connected(&self, block: &Block, height: u32) {
let txdata: Vec<_> = block.txdata.iter().enumerate().collect();
{
fn block_connected(&self, block: &Block, height: u32) {
let txdata: Vec<_> = block.txdata.iter().enumerate().collect();
- self.0.b
orrow_mut().b
lock_connected(&block.header, &txdata, height, &*self.1, &*self.2, &*self.3);
+ self.0.block_connected(&block.header, &txdata, height, &*self.1, &*self.2, &*self.3);
}
fn block_disconnected(&self, header: &BlockHeader, height: u32) {
}
fn block_disconnected(&self, header: &BlockHeader, height: u32) {
- self.0.b
orrow_mut().b
lock_disconnected(header, height, &*self.1, &*self.2, &*self.3);
+ self.0.block_disconnected(header, height, &*self.1, &*self.2, &*self.3);
}
}
const MAX_ALLOC_SIZE: usize = 64*1024;
impl<'a, Signer: Sign, K: KeysInterface<Signer = Signer>> ReadableArgs<&'a K>
}
}
const MAX_ALLOC_SIZE: usize = 64*1024;
impl<'a, Signer: Sign, K: KeysInterface<Signer = Signer>> ReadableArgs<&'a K>
- for (
BlockHash
, ChannelMonitor<Signer>) {
+ for (
Option<BlockHash>
, ChannelMonitor<Signer>) {
fn read<R: ::std::io::Read>(reader: &mut R, keys_manager: &'a K) -> Result<Self, DecodeError> {
macro_rules! unwrap_obj {
($key: expr) => {
fn read<R: ::std::io::Read>(reader: &mut R, keys_manager: &'a K) -> Result<Self, DecodeError> {
macro_rules! unwrap_obj {
($key: expr) => {
@@
-2736,7
+2735,13
@@
impl<'a, Signer: Sign, K: KeysInterface<Signer = Signer>> ReadableArgs<&'a K>
let mut secp_ctx = Secp256k1::new();
secp_ctx.seeded_randomize(&keys_manager.get_secure_random_bytes());
let mut secp_ctx = Secp256k1::new();
secp_ctx.seeded_randomize(&keys_manager.get_secure_random_bytes());
- Ok((last_block_hash.clone(), ChannelMonitor {
+ let last_seen_block_hash = if last_block_hash == Default::default() {
+ None
+ } else {
+ Some(last_block_hash)
+ };
+
+ Ok((last_seen_block_hash, ChannelMonitor {
inner: Mutex::new(ChannelMonitorImpl {
latest_update_id,
commitment_transaction_number_obscure_factor,
inner: Mutex::new(ChannelMonitorImpl {
latest_update_id,
commitment_transaction_number_obscure_factor,