Enforce `max_balance_dust_htlc_msat` at HTLC reception/forward
[rust-lightning] / fuzz / src / chanmon_consistency.rs
index 085e4cb7402b4545fff6415ae871459977d6e3f5..36d12ad5bb00c9567f141e68634ef7fbe0b6f7ef 100644 (file)
@@ -30,13 +30,13 @@ use bitcoin::hashes::sha256::Hash as Sha256;
 use bitcoin::hash_types::{BlockHash, WPubkeyHash};
 
 use lightning::chain;
-use lightning::chain::{chainmonitor, channelmonitor, Confirm, Watch};
+use lightning::chain::{BestBlock, chainmonitor, channelmonitor, Confirm, Watch};
 use lightning::chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdateErr, MonitorEvent};
 use lightning::chain::transaction::OutPoint;
 use lightning::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator};
 use lightning::chain::keysinterface::{KeysInterface, InMemorySigner};
 use lightning::ln::{PaymentHash, PaymentPreimage, PaymentSecret};
-use lightning::ln::channelmanager::{BestBlock, ChainParameters, ChannelManager, PaymentSendFailure, ChannelManagerReadArgs};
+use lightning::ln::channelmanager::{ChainParameters, ChannelManager, PaymentSendFailure, ChannelManagerReadArgs};
 use lightning::ln::features::{ChannelFeatures, InitFeatures, NodeFeatures};
 use lightning::ln::msgs::{CommitmentUpdate, ChannelMessageHandler, DecodeError, UpdateAddHTLC, Init};
 use lightning::util::enforcing_trait_impls::{EnforcingSigner, INITIAL_REVOKED_COMMITMENT_NUMBER};
@@ -241,8 +241,10 @@ fn check_api_err(api_err: APIError) {
                                _ if err.starts_with("Cannot push more than their max accepted HTLCs ") => {},
                                _ if err.starts_with("Cannot send value that would put us over the max HTLC value in flight our peer will accept ") => {},
                                _ if err.starts_with("Cannot send value that would put our balance under counterparty-announced channel reserve value") => {},
+                               _ if err.starts_with("Cannot send value that would put counterparty balance under holder-announced channel reserve value") => {},
                                _ if err.starts_with("Cannot send value that would overdraw remaining funds.") => {},
                                _ if err.starts_with("Cannot send value that would not leave enough to pay for fees.") => {},
+                               _ if err.starts_with("Cannot send value that would put our exposure to dust HTLCs at") => {},
                                _ => panic!("{}", err),
                        }
                },
@@ -338,7 +340,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
                        let monitor = Arc::new(TestChainMonitor::new(broadcast.clone(), logger.clone(), fee_est.clone(), Arc::new(TestPersister{}), Arc::clone(&keys_manager)));
 
                        let mut config = UserConfig::default();
-                       config.channel_options.fee_proportional_millionths = 0;
+                       config.channel_options.forwarding_fee_proportional_millionths = 0;
                        config.channel_options.announced_channel = true;
                        let network = Network::Bitcoin;
                        let params = ChainParameters {
@@ -357,7 +359,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
                        let chain_monitor = Arc::new(TestChainMonitor::new(broadcast.clone(), logger.clone(), fee_est.clone(), Arc::new(TestPersister{}), Arc::clone(& $keys_manager)));
 
                        let mut config = UserConfig::default();
-                       config.channel_options.fee_proportional_millionths = 0;
+                       config.channel_options.forwarding_fee_proportional_millionths = 0;
                        config.channel_options.announced_channel = true;
 
                        let mut monitors = HashMap::new();
@@ -571,7 +573,12 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
                                                events::MessageSendEvent::SendFundingLocked { .. } => continue,
                                                events::MessageSendEvent::SendAnnouncementSignatures { .. } => continue,
                                                events::MessageSendEvent::PaymentFailureNetworkUpdate { .. } => continue,
-                                               _ => panic!("Unhandled message event"),
+                                               events::MessageSendEvent::SendChannelUpdate { ref node_id, ref msg } => {
+                                                       assert_eq!(msg.contents.flags & 2, 0); // The disable bit must never be set!
+                                                       if Some(*node_id) == expect_drop_id { panic!("peer_disconnected should drop msgs bound for the disconnected peer"); }
+                                                       *node_id == a_id
+                                               },
+                                               _ => panic!("Unhandled message event {:?}", event),
                                        };
                                        if push_a { ba_events.push(event); } else { bc_events.push(event); }
                                }
@@ -692,7 +699,16 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
                                                        // Can be generated due to a payment forward being rejected due to a
                                                        // channel having previously failed a monitor update
                                                },
-                                               _ => panic!("Unhandled message event"),
+                                               events::MessageSendEvent::SendChannelUpdate { ref msg, .. } => {
+                                                       // When we reconnect we will resend a channel_update to make sure our
+                                                       // counterparty has the latest parameters for receiving payments
+                                                       // through us. We do, however, check that the message does not include
+                                                       // the "disabled" bit, as we should never ever have a channel which is
+                                                       // disabled when we send such an update (or it may indicate channel
+                                                       // force-close which we should detect as an error).
+                                                       assert_eq!(msg.contents.flags & 2, 0);
+                                               },
+                                               _ => panic!("Unhandled message event {:?}", event),
                                        }
                                        if $limit_events != ProcessMessages::AllMessages {
                                                break;
@@ -722,6 +738,9 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
                                                        events::MessageSendEvent::SendFundingLocked { .. } => {},
                                                        events::MessageSendEvent::SendAnnouncementSignatures { .. } => {},
                                                        events::MessageSendEvent::PaymentFailureNetworkUpdate { .. } => {},
+                                                       events::MessageSendEvent::SendChannelUpdate { ref msg, .. } => {
+                                                               assert_eq!(msg.contents.flags & 2, 0); // The disable bit must never be set!
+                                                       },
                                                        _ => panic!("Unhandled message event"),
                                                }
                                        }
@@ -737,6 +756,9 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
                                                        events::MessageSendEvent::SendFundingLocked { .. } => {},
                                                        events::MessageSendEvent::SendAnnouncementSignatures { .. } => {},
                                                        events::MessageSendEvent::PaymentFailureNetworkUpdate { .. } => {},
+                                                       events::MessageSendEvent::SendChannelUpdate { ref msg, .. } => {
+                                                               assert_eq!(msg.contents.flags & 2, 0); // The disable bit must never be set!
+                                                       },
                                                        _ => panic!("Unhandled message event"),
                                                }
                                        }
@@ -784,6 +806,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
                                                },
                                                events::Event::PaymentSent { .. } => {},
                                                events::Event::PaymentFailed { .. } => {},
+                                               events::Event::PaymentForwarded { .. } if $node == 1 => {},
                                                events::Event::PendingHTLCsForwardable { .. } => {
                                                        nodes[$node].process_pending_htlc_forwards();
                                                },