Use an opaque type to describe monitor updates in Persist
[rust-lightning] / lightning-persister / src / lib.rs
index 88b103c713fa9fee0f06c1289f15ebc61e24763b..4ba6d96ea3f5d2aa1970fb1e622e0c2df14792d5 100644 (file)
@@ -159,13 +159,13 @@ impl FilesystemPersister {
 }
 
 impl<ChannelSigner: Sign> chainmonitor::Persist<ChannelSigner> for FilesystemPersister {
-       fn persist_new_channel(&self, funding_txo: OutPoint, monitor: &ChannelMonitor<ChannelSigner>) -> Result<(), chain::ChannelMonitorUpdateErr> {
+       fn persist_new_channel(&self, funding_txo: OutPoint, monitor: &ChannelMonitor<ChannelSigner>, _update_id: chainmonitor::MonitorUpdateId) -> Result<(), chain::ChannelMonitorUpdateErr> {
                let filename = format!("{}_{}", funding_txo.txid.to_hex(), funding_txo.index);
                util::write_to_file(self.path_to_monitor_data(), filename, monitor)
                        .map_err(|_| chain::ChannelMonitorUpdateErr::PermanentFailure)
        }
 
-       fn update_persisted_channel(&self, funding_txo: OutPoint, _update: &ChannelMonitorUpdate, monitor: &ChannelMonitor<ChannelSigner>) -> Result<(), chain::ChannelMonitorUpdateErr> {
+       fn update_persisted_channel(&self, funding_txo: OutPoint, _update: &ChannelMonitorUpdate, monitor: &ChannelMonitor<ChannelSigner>, _update_id: chainmonitor::MonitorUpdateId) -> Result<(), chain::ChannelMonitorUpdateErr> {
                let filename = format!("{}_{}", funding_txo.txid.to_hex(), funding_txo.index);
                util::write_to_file(self.path_to_monitor_data(), filename, monitor)
                        .map_err(|_| chain::ChannelMonitorUpdateErr::PermanentFailure)
@@ -296,6 +296,8 @@ mod tests {
                nodes[1].node.force_close_channel(&chan.2).unwrap();
                check_closed_event!(nodes[1], 1, ClosureReason::HolderForceClosed);
                let mut added_monitors = nodes[1].chain_monitor.added_monitors.lock().unwrap();
+               let update_map = nodes[1].chain_monitor.latest_monitor_update_id.lock().unwrap();
+               let update_id = update_map.get(&added_monitors[0].0.to_channel_id()).unwrap();
 
                // Set the persister's directory to read-only, which should result in
                // returning a permanent failure when we then attempt to persist a
@@ -309,7 +311,7 @@ mod tests {
                        txid: Txid::from_hex("8984484a580b825b9972d7adb15050b3ab624ccd731946b3eeddb92f4e7ef6be").unwrap(),
                        index: 0
                };
-               match persister.persist_new_channel(test_txo, &added_monitors[0].1) {
+               match persister.persist_new_channel(test_txo, &added_monitors[0].1, update_id.2) {
                        Err(ChannelMonitorUpdateErr::PermanentFailure) => {},
                        _ => panic!("unexpected result from persisting new channel")
                }
@@ -333,6 +335,8 @@ mod tests {
                nodes[1].node.force_close_channel(&chan.2).unwrap();
                check_closed_event!(nodes[1], 1, ClosureReason::HolderForceClosed);
                let mut added_monitors = nodes[1].chain_monitor.added_monitors.lock().unwrap();
+               let update_map = nodes[1].chain_monitor.latest_monitor_update_id.lock().unwrap();
+               let update_id = update_map.get(&added_monitors[0].0.to_channel_id()).unwrap();
 
                // Create the persister with an invalid directory name and test that the
                // channel fails to open because the directories fail to be created. There
@@ -344,7 +348,7 @@ mod tests {
                        txid: Txid::from_hex("8984484a580b825b9972d7adb15050b3ab624ccd731946b3eeddb92f4e7ef6be").unwrap(),
                        index: 0
                };
-               match persister.persist_new_channel(test_txo, &added_monitors[0].1) {
+               match persister.persist_new_channel(test_txo, &added_monitors[0].1, update_id.2) {
                        Err(ChannelMonitorUpdateErr::PermanentFailure) => {},
                        _ => panic!("unexpected result from persisting new channel")
                }