Merge pull request #1753 from wpaulino/avoid-redundant-claims-after-initial-conf
[rust-lightning] / lightning / src / ln / chanmon_update_fail_tests.rs
index ef7efdd221f028114e780aba62b5ea6e56bd90e7..a78cf50acb97006ec19456e75e2be45a9e52de2c 100644 (file)
@@ -16,29 +16,29 @@ use bitcoin::blockdata::block::{Block, BlockHeader};
 use bitcoin::blockdata::constants::genesis_block;
 use bitcoin::hash_types::BlockHash;
 use bitcoin::network::constants::Network;
-use chain::channelmonitor::{ANTI_REORG_DELAY, ChannelMonitor};
-use chain::transaction::OutPoint;
-use chain::{ChannelMonitorUpdateStatus, Listen, Watch};
-use ln::channelmanager::{self, ChannelManager, ChannelManagerReadArgs, RAACommitmentOrder, PaymentSendFailure};
-use ln::channel::AnnouncementSigsState;
-use ln::msgs;
-use ln::msgs::{ChannelMessageHandler, RoutingMessageHandler};
-use util::config::UserConfig;
-use util::enforcing_trait_impls::EnforcingSigner;
-use util::events::{Event, MessageSendEvent, MessageSendEventsProvider, PaymentPurpose, ClosureReason, HTLCDestination};
-use util::errors::APIError;
-use util::ser::{ReadableArgs, Writeable};
-use util::test_utils::TestBroadcaster;
-
-use ln::functional_test_utils::*;
-
-use util::test_utils;
-
-use io;
+use crate::chain::channelmonitor::{ANTI_REORG_DELAY, ChannelMonitor};
+use crate::chain::transaction::OutPoint;
+use crate::chain::{ChannelMonitorUpdateStatus, Listen, Watch};
+use crate::ln::channelmanager::{self, ChannelManager, ChannelManagerReadArgs, RAACommitmentOrder, PaymentSendFailure};
+use crate::ln::channel::AnnouncementSigsState;
+use crate::ln::msgs;
+use crate::ln::msgs::{ChannelMessageHandler, RoutingMessageHandler};
+use crate::util::config::UserConfig;
+use crate::util::enforcing_trait_impls::EnforcingSigner;
+use crate::util::events::{Event, MessageSendEvent, MessageSendEventsProvider, PaymentPurpose, ClosureReason, HTLCDestination};
+use crate::util::errors::APIError;
+use crate::util::ser::{ReadableArgs, Writeable};
+use crate::util::test_utils::TestBroadcaster;
+
+use crate::ln::functional_test_utils::*;
+
+use crate::util::test_utils;
+
+use crate::io;
 use bitcoin::hashes::Hash;
 use bitcoin::TxMerkleNode;
-use prelude::*;
-use sync::{Arc, Mutex};
+use crate::prelude::*;
+use crate::sync::{Arc, Mutex};
 
 #[test]
 fn test_simple_monitor_permanent_update_fail() {
@@ -2231,18 +2231,19 @@ fn do_channel_holding_cell_serialize(disconnect: bool, reload_a: bool) {
        let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
        let persister: test_utils::TestPersister;
        let new_chain_monitor: test_utils::TestChainMonitor;
-       let nodes_0_deserialized: ChannelManager<EnforcingSigner, &test_utils::TestChainMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator, &test_utils::TestLogger>;
+       let nodes_0_deserialized: ChannelManager<&test_utils::TestChainMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator, &test_utils::TestLogger>;
        let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs);
 
        let chan_id = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 15_000_000, 7_000_000_000, channelmanager::provided_init_features(), channelmanager::provided_init_features()).2;
        let (route, payment_hash_1, payment_preimage_1, payment_secret_1) = get_route_and_payment_hash!(&nodes[0], nodes[1], 100000);
        let (payment_preimage_2, payment_hash_2, payment_secret_2) = get_payment_preimage_hash!(&nodes[1]);
 
-       // Do a really complicated dance to get an HTLC into the holding cell, with MonitorUpdateFailed
-       // set but AwaitingRemoteRevoke unset. When this test was written, any attempts to send an HTLC
-       // while MonitorUpdateFailed is set are immediately failed-backwards. Thus, the only way to get
-       // an AddHTLC into the holding cell is to add it while AwaitingRemoteRevoke is set but
-       // MonitorUpdateFailed is unset, and then swap the flags.
+       // Do a really complicated dance to get an HTLC into the holding cell, with
+       // MonitorUpdateInProgress set but AwaitingRemoteRevoke unset. When this test was written, any
+       // attempts to send an HTLC while MonitorUpdateInProgress is set are immediately
+       // failed-backwards. Thus, the only way to get an AddHTLC into the holding cell is to add it
+       // while AwaitingRemoteRevoke is set but MonitorUpdateInProgress is unset, and then swap the
+       // flags.
        //
        // We do this by:
        //  a) routing a payment from node B to node A,
@@ -2255,8 +2256,8 @@ fn do_channel_holding_cell_serialize(disconnect: bool, reload_a: bool) {
        //  e) delivering A's commitment_signed from (b) and the resulting B revoke_and_ack message,
        //     clearing AwaitingRemoteRevoke on node A.
        //
-       // Note that because, at the end, MonitorUpdateFailed is still set, the HTLC generated in (c)
-       // will not be freed from the holding cell.
+       // Note that because, at the end, MonitorUpdateInProgress is still set, the HTLC generated in
+       // (c) will not be freed from the holding cell.
        let (payment_preimage_0, payment_hash_0, _) = route_payment(&nodes[1], &[&nodes[0]], 100_000);
 
        nodes[0].node.send_payment(&route, payment_hash_1, &Some(payment_secret_1)).unwrap();
@@ -2304,7 +2305,7 @@ fn do_channel_holding_cell_serialize(disconnect: bool, reload_a: bool) {
                        nodes_0_deserialized = {
                                let mut channel_monitors = HashMap::new();
                                channel_monitors.insert(chan_0_monitor.get_funding_txo().0, &mut chan_0_monitor);
-                               <(BlockHash, ChannelManager<EnforcingSigner, &test_utils::TestChainMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator, &test_utils::TestLogger>)>::read(&mut nodes_0_read, ChannelManagerReadArgs {
+                               <(BlockHash, ChannelManager<&test_utils::TestChainMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator, &test_utils::TestLogger>)>::read(&mut nodes_0_read, ChannelManagerReadArgs {
                                        default_config: config,
                                        keys_manager,
                                        fee_estimator: node_cfgs[0].fee_estimator,
@@ -2755,7 +2756,7 @@ fn do_test_outbound_reload_without_init_mon(use_0conf: bool) {
 
        let persister: test_utils::TestPersister;
        let new_chain_monitor: test_utils::TestChainMonitor;
-       let nodes_0_deserialized: ChannelManager<EnforcingSigner, &test_utils::TestChainMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator, &test_utils::TestLogger>;
+       let nodes_0_deserialized: ChannelManager<&test_utils::TestChainMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator, &test_utils::TestLogger>;
 
        let mut chan_config = test_default_channel_config();
        chan_config.manually_accept_inbound_channels = true;
@@ -2833,7 +2834,7 @@ fn do_test_outbound_reload_without_init_mon(use_0conf: bool) {
        let mut nodes_0_read = &nodes_0_serialized[..];
        let config = UserConfig::default();
        nodes_0_deserialized = {
-               <(BlockHash, ChannelManager<EnforcingSigner, &test_utils::TestChainMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator, &test_utils::TestLogger>)>::read(&mut nodes_0_read, ChannelManagerReadArgs {
+               <(BlockHash, ChannelManager<&test_utils::TestChainMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator, &test_utils::TestLogger>)>::read(&mut nodes_0_read, ChannelManagerReadArgs {
                        default_config: config,
                        keys_manager,
                        fee_estimator: node_cfgs[0].fee_estimator,
@@ -2865,7 +2866,7 @@ fn do_test_inbound_reload_without_init_mon(use_0conf: bool, lock_commitment: boo
 
        let persister: test_utils::TestPersister;
        let new_chain_monitor: test_utils::TestChainMonitor;
-       let nodes_1_deserialized: ChannelManager<EnforcingSigner, &test_utils::TestChainMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator, &test_utils::TestLogger>;
+       let nodes_1_deserialized: ChannelManager<&test_utils::TestChainMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator, &test_utils::TestLogger>;
 
        let mut chan_config = test_default_channel_config();
        chan_config.manually_accept_inbound_channels = true;
@@ -2939,7 +2940,7 @@ fn do_test_inbound_reload_without_init_mon(use_0conf: bool, lock_commitment: boo
        let mut nodes_1_read = &nodes_1_serialized[..];
        let config = UserConfig::default();
        nodes_1_deserialized = {
-               <(BlockHash, ChannelManager<EnforcingSigner, &test_utils::TestChainMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator, &test_utils::TestLogger>)>::read(&mut nodes_1_read, ChannelManagerReadArgs {
+               <(BlockHash, ChannelManager<&test_utils::TestChainMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator, &test_utils::TestLogger>)>::read(&mut nodes_1_read, ChannelManagerReadArgs {
                        default_config: config,
                        keys_manager,
                        fee_estimator: node_cfgs[1].fee_estimator,