Skip to content

Commit c680c0f

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 f68a3ff commit c680c0f

File tree

4 files changed

+67
-66
lines changed

4 files changed

+67
-66
lines changed

fuzz/src/chanmon_consistency.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ struct LatestMonitorState {
173173
/// A set of (monitor id, serialized `ChannelMonitor`)s which we're currently "persisting",
174174
/// from LDK's perspective.
175175
pending_monitors: Vec<(u64, Vec<u8>)>,
176-
funding_txo: OutPoint,
177176
}
178177

179178
struct TestChainMonitor {
@@ -219,14 +218,12 @@ impl chain::Watch<TestChannelSigner> for TestChainMonitor {
219218
let mut ser = VecWriter(Vec::new());
220219
monitor.write(&mut ser).unwrap();
221220
let monitor_id = monitor.get_latest_update_id();
222-
let funding_txo = monitor.get_funding_txo().0;
223221
let res = self.chain_monitor.watch_channel(channel_id, monitor);
224222
let state = match res {
225223
Ok(chain::ChannelMonitorUpdateStatus::Completed) => LatestMonitorState {
226224
persisted_monitor_id: monitor_id,
227225
persisted_monitor: ser.0,
228226
pending_monitors: Vec::new(),
229-
funding_txo,
230227
},
231228
Ok(chain::ChannelMonitorUpdateStatus::InProgress) => {
232229
panic!("The test currently doesn't test initial-persistence via the async pipeline")
@@ -716,7 +713,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
716713
let mut old_monitors = $old_monitors.latest_monitors.lock().unwrap();
717714
for (channel_id, mut prev_state) in old_monitors.drain() {
718715
monitors.insert(
719-
prev_state.funding_txo,
716+
channel_id,
720717
<(BlockHash, ChannelMonitor<TestChannelSigner>)>::read(
721718
&mut Cursor::new(&prev_state.persisted_monitor),
722719
(&*$keys_manager, &*$keys_manager),
@@ -731,8 +728,8 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
731728
chain_monitor.latest_monitors.lock().unwrap().insert(channel_id, prev_state);
732729
}
733730
let mut monitor_refs = new_hash_map();
734-
for (outpoint, monitor) in monitors.iter() {
735-
monitor_refs.insert(*outpoint, monitor);
731+
for (channel_id, monitor) in monitors.iter() {
732+
monitor_refs.insert(*channel_id, monitor);
736733
}
737734

738735
let read_args = ChannelManagerReadArgs {
@@ -755,9 +752,9 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
755752
.1,
756753
chain_monitor.clone(),
757754
);
758-
for (_, mon) in monitors.drain() {
755+
for (channel_id, mon) in monitors.drain() {
759756
assert_eq!(
760-
chain_monitor.chain_monitor.watch_channel(mon.channel_id(), mon),
757+
chain_monitor.chain_monitor.watch_channel(channel_id, mon),
761758
Ok(ChannelMonitorUpdateStatus::Completed)
762759
);
763760
}

0 commit comments

Comments
 (0)