Skip to content

Commit 83ee68e

Browse files
committed
Use channel ID over funding outpoint to track monitors in ChannelManager
As motivated by the previous commit, we do some of the same work here at the `ChannelManager` level instead. Unfortunately, we still need to track the funding outpoint to support downgrades by writing the in flight monitor updates as two separate TLVs, one using the channel IDs, and the other using the funding outpoints. Once we are willing to stop supporting downgrades past this version, we can fully drop it.
1 parent 008ba95 commit 83ee68e

File tree

4 files changed

+74
-66
lines changed

4 files changed

+74
-66
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ struct LatestMonitorState {
182182
/// A set of (monitor id, serialized `ChannelMonitor`)s which we're currently "persisting",
183183
/// from LDK's perspective.
184184
pending_monitors: Vec<(u64, Vec<u8>)>,
185-
funding_txo: OutPoint,
186185
}
187186

188187
struct TestChainMonitor {
@@ -228,14 +227,12 @@ impl chain::Watch<TestChannelSigner> for TestChainMonitor {
228227
let mut ser = VecWriter(Vec::new());
229228
monitor.write(&mut ser).unwrap();
230229
let monitor_id = monitor.get_latest_update_id();
231-
let funding_txo = monitor.get_funding_txo().0;
232230
let res = self.chain_monitor.watch_channel(channel_id, monitor);
233231
let state = match res {
234232
Ok(chain::ChannelMonitorUpdateStatus::Completed) => LatestMonitorState {
235233
persisted_monitor_id: monitor_id,
236234
persisted_monitor: ser.0,
237235
pending_monitors: Vec::new(),
238-
funding_txo,
239236
},
240237
Ok(chain::ChannelMonitorUpdateStatus::InProgress) => {
241238
panic!("The test currently doesn't test initial-persistence via the async pipeline")
@@ -727,7 +724,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
727724
let mut old_monitors = $old_monitors.latest_monitors.lock().unwrap();
728725
for (channel_id, mut prev_state) in old_monitors.drain() {
729726
monitors.insert(
730-
prev_state.funding_txo,
727+
channel_id,
731728
<(BlockHash, ChannelMonitor<TestChannelSigner>)>::read(
732729
&mut Cursor::new(&prev_state.persisted_monitor),
733730
(&*$keys_manager, &*$keys_manager),
@@ -742,8 +739,8 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
742739
chain_monitor.latest_monitors.lock().unwrap().insert(channel_id, prev_state);
743740
}
744741
let mut monitor_refs = new_hash_map();
745-
for (outpoint, monitor) in monitors.iter() {
746-
monitor_refs.insert(*outpoint, monitor);
742+
for (channel_id, monitor) in monitors.iter() {
743+
monitor_refs.insert(*channel_id, monitor);
747744
}
748745

749746
let read_args = ChannelManagerReadArgs {
@@ -766,9 +763,9 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
766763
.1,
767764
chain_monitor.clone(),
768765
);
769-
for (_, mon) in monitors.drain() {
766+
for (channel_id, mon) in monitors.drain() {
770767
assert_eq!(
771-
chain_monitor.chain_monitor.watch_channel(mon.channel_id(), mon),
768+
chain_monitor.chain_monitor.watch_channel(channel_id, mon),
772769
Ok(ChannelMonitorUpdateStatus::Completed)
773770
);
774771
}

0 commit comments

Comments
 (0)