Slightly clarify comment on safety of only processing HTLCs once
[rust-lightning] / lightning-persister / src / lib.rs
index b277c30ca8cfc9024a6de613f5ad7fea4b7d65c1..a949584a6395a1b8fcf53bec5da6891a7d93f934 100644 (file)
@@ -20,7 +20,7 @@ extern crate libc;
 use bitcoin::hash_types::{BlockHash, Txid};
 use bitcoin::hashes::hex::FromHex;
 use lightning::chain::channelmonitor::ChannelMonitor;
-use lightning::chain::keysinterface::{Sign, KeysInterface};
+use lightning::chain::keysinterface::KeysInterface;
 use lightning::util::ser::{ReadableArgs, Writeable};
 use lightning::util::persist::KVStorePersister;
 use std::fs;
@@ -59,10 +59,10 @@ impl FilesystemPersister {
        }
 
        /// Read `ChannelMonitor`s from disk.
-       pub fn read_channelmonitors<Signer: Sign, K: Deref> (
+       pub fn read_channelmonitors<K: Deref> (
                &self, keys_manager: K
-       ) -> Result<Vec<(BlockHash, ChannelMonitor<Signer>)>, std::io::Error>
-               where K::Target: KeysInterface<Signer=Signer> + Sized,
+       ) -> Result<Vec<(BlockHash, ChannelMonitor<<K::Target as KeysInterface>::Signer>)>, std::io::Error>
+               where K::Target: KeysInterface + Sized,
        {
                let mut path = PathBuf::from(&self.path_to_channel_data);
                path.push("monitors");
@@ -105,7 +105,7 @@ impl FilesystemPersister {
 
                        let contents = fs::read(&file.path())?;
                        let mut buffer = Cursor::new(&contents);
-                       match <(BlockHash, ChannelMonitor<Signer>)>::read(&mut buffer, &*keys_manager) {
+                       match <(BlockHash, ChannelMonitor<<K::Target as KeysInterface>::Signer>)>::read(&mut buffer, &*keys_manager) {
                                Ok((blockhash, channel_monitor)) => {
                                        if channel_monitor.get_funding_txo().0.txid != txid.unwrap() || channel_monitor.get_funding_txo().0.index != index.unwrap() {
                                                return Err(std::io::Error::new(std::io::ErrorKind::InvalidData, "ChannelMonitor was stored in the wrong file"));
@@ -138,11 +138,11 @@ mod tests {
        use bitcoin::blockdata::block::{Block, BlockHeader};
        use bitcoin::hashes::hex::FromHex;
        use bitcoin::{Txid, TxMerkleNode};
-       use lightning::chain::ChannelMonitorUpdateErr;
+       use lightning::chain::ChannelMonitorUpdateStatus;
        use lightning::chain::chainmonitor::Persist;
        use lightning::chain::transaction::OutPoint;
        use lightning::{check_closed_broadcast, check_closed_event, check_added_monitors};
-       use lightning::ln::features::InitFeatures;
+       use lightning::ln::channelmanager;
        use lightning::ln::functional_test_utils::*;
        use lightning::util::events::{ClosureReason, MessageSendEventsProvider};
        use lightning::util::test_utils;
@@ -206,7 +206,7 @@ mod tests {
                }
 
                // Create some initial channel and check that a channel was persisted.
-               let _ = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known());
+               let _ = create_announced_chan_between_nodes(&nodes, 0, 1, channelmanager::provided_init_features(), channelmanager::provided_init_features());
                check_persisted_data!(0);
 
                // Send a few payments and make sure the monitors are updated to the latest.
@@ -250,7 +250,7 @@ mod tests {
                let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
                let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
                let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
-               let chan = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known());
+               let chan = create_announced_chan_between_nodes(&nodes, 0, 1, channelmanager::provided_init_features(), channelmanager::provided_init_features());
                nodes[1].node.force_close_broadcasting_latest_txn(&chan.2, &nodes[0].node.get_our_node_id()).unwrap();
                check_closed_event!(nodes[1], 1, ClosureReason::HolderForceClosed);
                let mut added_monitors = nodes[1].chain_monitor.added_monitors.lock().unwrap();
@@ -270,7 +270,7 @@ mod tests {
                        index: 0
                };
                match persister.persist_new_channel(test_txo, &added_monitors[0].1, update_id.2) {
-                       Err(ChannelMonitorUpdateErr::PermanentFailure) => {},
+                       ChannelMonitorUpdateStatus::PermanentFailure => {},
                        _ => panic!("unexpected result from persisting new channel")
                }
 
@@ -289,7 +289,7 @@ mod tests {
                let mut node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
                let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
                let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
-               let chan = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known());
+               let chan = create_announced_chan_between_nodes(&nodes, 0, 1, channelmanager::provided_init_features(), channelmanager::provided_init_features());
                nodes[1].node.force_close_broadcasting_latest_txn(&chan.2, &nodes[0].node.get_our_node_id()).unwrap();
                check_closed_event!(nodes[1], 1, ClosureReason::HolderForceClosed);
                let mut added_monitors = nodes[1].chain_monitor.added_monitors.lock().unwrap();
@@ -307,7 +307,7 @@ mod tests {
                        index: 0
                };
                match persister.persist_new_channel(test_txo, &added_monitors[0].1, update_id.2) {
-                       Err(ChannelMonitorUpdateErr::PermanentFailure) => {},
+                       ChannelMonitorUpdateStatus::PermanentFailure => {},
                        _ => panic!("unexpected result from persisting new channel")
                }