Skip to content

Commit 63cc5f6

Browse files
committed
f more comments
1 parent 613622a commit 63cc5f6

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,20 @@ impl Writer for VecWriter {
142142
}
143143
}
144144

145+
/// The LDK API requires that any time we tell it we're done persisting a `ChannelMonitor[Update]`
146+
/// we never pass it in as the "latest" `ChannelMonitor` on startup. However, we can pass
147+
/// out-of-date monitors as long as we never told LDK we finished persisting them, which we do by
148+
/// storing both old `ChannelMonitor`s and ones that are "being persisted" here.
149+
///
150+
/// Note that such "being persisted" `ChannelMonitor`s are stored in `ChannelManager` and will
151+
/// simply be replayed on startup.
145152
struct LatestMonitorState {
153+
/// The latest monitor id which we told LDK we've persisted
146154
persisted_monitor_id: u64,
155+
/// The latest serialized `ChannelMonitor` that we told LDK we persisted.
147156
persisted_monitor: Vec<u8>,
157+
/// A set of (monitor id, serialized `ChannelMonitor`)s which we're currently "persisting",
158+
/// from LDK's perspective.
148159
pending_monitor_updates: Vec<(u64, Vec<u8>)>,
149160
}
150161

@@ -153,14 +164,6 @@ struct TestChainMonitor {
153164
pub keys: Arc<KeyProvider>,
154165
pub persister: Arc<TestPersister>,
155166
pub chain_monitor: Arc<chainmonitor::ChainMonitor<TestChannelSigner, Arc<dyn chain::Filter>, Arc<TestBroadcaster>, Arc<FuzzEstimator>, Arc<dyn Logger>, Arc<TestPersister>>>,
156-
// If we reload a node with an old copy of ChannelMonitors, the ChannelManager deserialization
157-
// logic will automatically force-close our channels for us (as we don't have an up-to-date
158-
// monitor implying we are not able to punish misbehaving counterparties). Because this test
159-
// "fails" if we ever force-close a channel, we avoid doing so, always saving the latest
160-
// fully-serialized monitor state here, as well as the corresponding update_id.
161-
//
162-
// Note that this doesn't apply to monitors which are pending persistence, so we store the
163-
// latest pending monitor separately.
164167
pub latest_monitors: Mutex<HashMap<OutPoint, LatestMonitorState>>,
165168
}
166169
impl TestChainMonitor {
@@ -549,6 +552,9 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
549552
monitors.insert(outpoint, <(BlockHash, ChannelMonitor<TestChannelSigner>)>::read(
550553
&mut Cursor::new(&prev_state.persisted_monitor), (&*$keys_manager, &*$keys_manager)
551554
).expect("Failed to read monitor").1);
555+
// Wipe any `ChannelMonitor`s which we never told LDK we finished persisting,
556+
// considering them discarded. LDK should replay these for us as they're stored in
557+
// the `ChannelManager`.
552558
prev_state.pending_monitor_updates.clear();
553559
chain_monitor.latest_monitors.lock().unwrap().insert(outpoint, prev_state);
554560
}

0 commit comments

Comments
 (0)