//! responsible for tracking which channels are open, HTLCs are in flight and reestablishing those
//! upon reconnect to the relevant peer(s).
//!
- //! It does not manage routing logic (see routing::router::get_route for that) nor does it manage constructing
+ //! It does not manage routing logic (see [`find_route`] for that) nor does it manage constructing
//! on-chain transactions (it only monitors the chain to watch for any force-closes that might
//! imply it needs to fail HTLCs/payments/channels it manages).
//!
+ //! [`find_route`]: crate::routing::router::find_route
use bitcoin::blockdata::block::BlockHeader;
use bitcoin::blockdata::transaction::Transaction;
self.list_channels_with_filter(|_| true)
}
- /// Gets the list of usable channels, in random order. Useful as an argument to
- /// get_route to ensure non-announced channels are used.
+ /// Gets the list of usable channels, in random order. Useful as an argument to [`find_route`]
+ /// to ensure non-announced channels are used.
///
/// These are guaranteed to have their [`ChannelDetails::is_usable`] value set to true, see the
/// documentation for [`ChannelDetails::is_usable`] for more info on exactly what the criteria
/// are.
+ ///
+ /// [`find_route`]: crate::routing::router::find_route
pub fn list_usable_channels(&self) -> Vec<ChannelDetails> {
// Note we use is_live here instead of usable which leads to somewhat confused
// internal/external nomenclature, but that's ok cause that's probably what the user
.. } => {
// we get a fail_malformed_htlc from the first hop
// TODO: We'd like to generate a NetworkUpdate for temporary
- // failures here, but that would be insufficient as get_route
+ // failures here, but that would be insufficient as find_route
// generally ignores its view of our own channels as we provide them via
// ChannelDetails.
// TODO: For non-temporary failures, we really should be closing the
/// [`Event::ChannelClosed::user_channel_id`] to allow tracking of which events correspond
/// with which `accept_inbound_channel`/`accept_inbound_channel_from_trusted_peer_0conf` call.
///
+ /// Note that this method will return an error and reject the channel, if it requires support
+ /// for zero confirmations. Instead, `accept_inbound_channel_from_trusted_peer_0conf` must be
+ /// used to accept such channels.
+ ///
/// [`Event::OpenChannelRequest`]: events::Event::OpenChannelRequest
/// [`Event::ChannelClosed::user_channel_id`]: events::Event::ChannelClosed::user_channel_id
pub fn accept_inbound_channel(&self, temporary_channel_id: &[u8; 32], counterparty_node_id: &PublicKey, user_channel_id: u64) -> Result<(), APIError> {
if *counterparty_node_id != channel.get().get_counterparty_node_id() {
return Err(APIError::APIMisuseError { err: "The passed counterparty_node_id doesn't match the channel's counterparty node_id".to_owned() });
}
- if accept_0conf { channel.get_mut().set_0conf(); }
+ if accept_0conf {
+ channel.get_mut().set_0conf();
+ } else if channel.get().get_channel_type().requires_zero_conf() {
+ let send_msg_err_event = events::MessageSendEvent::HandleError {
+ node_id: channel.get().get_counterparty_node_id(),
+ action: msgs::ErrorAction::SendErrorMessage{
+ msg: msgs::ErrorMessage { channel_id: temporary_channel_id.clone(), data: "No zero confirmation channels accepted".to_owned(), }
+ }
+ };
+ channel_state.pending_msg_events.push(send_msg_err_event);
+ let _ = remove_channel!(self, channel_state, channel);
+ return Err(APIError::APIMisuseError { err: "Please use accept_inbound_channel_from_trusted_peer_0conf to accept channels with zero confirmations.".to_owned() });
+ }
+
channel_state.pending_msg_events.push(events::MessageSendEvent::SendAcceptChannel {
node_id: channel.get().get_counterparty_node_id(),
msg: channel.get_mut().accept_inbound_channel(user_channel_id),
},
hash_map::Entry::Vacant(entry) => {
if !self.default_configuration.manually_accept_inbound_channels {
+ if channel.get_channel_type().requires_zero_conf() {
+ return Err(MsgHandleErrInternal::send_err_msg_no_close("No zero confirmation channels accepted".to_owned(), msg.temporary_channel_id.clone()));
+ }
channel_state.pending_msg_events.push(events::MessageSendEvent::SendAcceptChannel {
node_id: counterparty_node_id.clone(),
msg: channel.accept_inbound_channel(0),
use ln::features::{InitFeatures, InvoiceFeatures};
use ln::functional_test_utils::*;
use ln::msgs::{ChannelMessageHandler, Init};
- use routing::network_graph::NetworkGraph;
+ use routing::gossip::NetworkGraph;
use routing::router::{PaymentParameters, get_route};
use util::test_utils;
use util::config::UserConfig;
use chain::channelmonitor::ChannelMonitor;
use chain::keysinterface::{Recipient, KeysInterface};
use ln::channelmanager::{ChannelManager, ChannelManagerReadArgs, MIN_CLTV_EXPIRY_DELTA};
- use routing::network_graph::RoutingFees;
+ use routing::gossip::RoutingFees;
use routing::router::{PaymentParameters, RouteHint, RouteHintHop};
-use ln::features::{InitFeatures, InvoiceFeatures};
+use ln::features::{InitFeatures, InvoiceFeatures, ChannelTypeFeatures};
use ln::msgs;
-use ln::msgs::{ChannelMessageHandler, RoutingMessageHandler, OptionalField, ChannelUpdate};
+use ln::msgs::{ChannelMessageHandler, RoutingMessageHandler, OptionalField, ChannelUpdate, ErrorAction};
use ln::wire::Encode;
use util::enforcing_trait_impls::EnforcingSigner;
use util::events::{ClosureReason, Event, MessageSendEvent, MessageSendEventsProvider};
assert_eq!(announcement, bs_announcement);
for node in nodes {
- assert!(node.net_graph_msg_handler.handle_channel_announcement(&announcement).unwrap());
- node.net_graph_msg_handler.handle_channel_update(&as_update).unwrap();
- node.net_graph_msg_handler.handle_channel_update(&bs_update).unwrap();
+ assert!(node.gossip_sync.handle_channel_announcement(&announcement).unwrap());
+ node.gossip_sync.handle_channel_update(&as_update).unwrap();
+ node.gossip_sync.handle_channel_update(&bs_update).unwrap();
}
}
#[test]
});
check_closed_broadcast!(nodes[1], true);
}
+
+#[test]
+fn test_zero_conf_accept_reject() {
+ let mut channel_type_features = ChannelTypeFeatures::only_static_remote_key();
+ channel_type_features.set_zero_conf_required();
+
+ // 1. Check we reject zero conf channels by default
+ let chanmon_cfgs = create_chanmon_cfgs(2);
+ 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);
+
+ nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100000, 10001, 42, None).unwrap();
+ let mut open_channel_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id());
+
+ open_channel_msg.channel_type = Some(channel_type_features.clone());
+
+ nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), InitFeatures::known(), &open_channel_msg);
+
+ let msg_events = nodes[1].node.get_and_clear_pending_msg_events();
+ match msg_events[0] {
+ MessageSendEvent::HandleError { action: ErrorAction::SendErrorMessage { ref msg, .. }, .. } => {
+ assert_eq!(msg.data, "No zero confirmation channels accepted".to_owned());
+ },
+ _ => panic!(),
+ }
+
+ // 2. Check we can manually accept zero conf channels via the right method
+ let mut manually_accept_conf = UserConfig::default();
+ manually_accept_conf.manually_accept_inbound_channels = true;
+
+ let chanmon_cfgs = create_chanmon_cfgs(2);
+ let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
+ let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs,
+ &[None, Some(manually_accept_conf.clone())]);
+ let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
+
+ // 2.1 First try the non-0conf method to manually accept
+ nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100000, 10001, 42,
+ Some(manually_accept_conf)).unwrap();
+ let mut open_channel_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel,
+ nodes[1].node.get_our_node_id());
+
+ open_channel_msg.channel_type = Some(channel_type_features.clone());
+
+ nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), InitFeatures::known(),
+ &open_channel_msg);
+
+ // Assert that `nodes[1]` has no `MessageSendEvent::SendAcceptChannel` in the `msg_events`.
+ assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
+
+ let events = nodes[1].node.get_and_clear_pending_events();
+
+ match events[0] {
+ Event::OpenChannelRequest { temporary_channel_id, .. } => {
+ // Assert we fail to accept via the non-0conf method
+ assert!(nodes[1].node.accept_inbound_channel(&temporary_channel_id,
+ &nodes[0].node.get_our_node_id(), 0).is_err());
+ },
+ _ => panic!(),
+ }
+
+ let msg_events = nodes[1].node.get_and_clear_pending_msg_events();
+ match msg_events[0] {
+ MessageSendEvent::HandleError { action: ErrorAction::SendErrorMessage { ref msg, .. }, .. } => {
+ assert_eq!(msg.data, "No zero confirmation channels accepted".to_owned());
+ },
+ _ => panic!(),
+ }
+
+ // 2.2 Try again with the 0conf method to manually accept
+ nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 100000, 10001, 42,
+ Some(manually_accept_conf)).unwrap();
+ let mut open_channel_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel,
+ nodes[1].node.get_our_node_id());
+
+ open_channel_msg.channel_type = Some(channel_type_features);
+
+ nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), InitFeatures::known(),
+ &open_channel_msg);
+
+ let events = nodes[1].node.get_and_clear_pending_events();
+
+ match events[0] {
+ Event::OpenChannelRequest { temporary_channel_id, .. } => {
+ // Assert we can accept via the 0conf method
+ assert!(nodes[1].node.accept_inbound_channel_from_trusted_peer_0conf(
+ &temporary_channel_id, &nodes[0].node.get_our_node_id(), 0).is_ok());
+ },
+ _ => panic!(),
+ }
+
+ // Check we would send accept
+ let msg_events = nodes[1].node.get_and_clear_pending_msg_events();
+ match msg_events[0] {
+ MessageSendEvent::SendAcceptChannel { .. } => {},
+ _ => panic!(),
+ }
+}
use ln::msgs;
use ln::msgs::DecodeError;
use ln::{PaymentPreimage, PaymentHash, PaymentSecret};
- use routing::network_graph::NetworkUpdate;
+ use routing::gossip::NetworkUpdate;
use util::ser::{BigSize, FixedLengthReader, Writeable, Writer, MaybeReadable, Readable, VecReadWrapper, VecWriteWrapper};
use routing::router::{RouteHop, RouteParameters};
/// payment route.
///
/// Should be applied to the [`NetworkGraph`] so that routing decisions can take into
- /// account the update. [`NetGraphMsgHandler`] is capable of doing this.
+ /// account the update. [`P2PGossipSync`] is capable of doing this.
///
- /// [`NetworkGraph`]: crate::routing::network_graph::NetworkGraph
- /// [`NetGraphMsgHandler`]: crate::routing::network_graph::NetGraphMsgHandler
+ /// [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
+ /// [`P2PGossipSync`]: crate::routing::gossip::P2PGossipSync
network_update: Option<NetworkUpdate>,
/// For both single-path and multi-path payments, this is set if all paths of the payment have
/// failed. This will be set to false if (1) this is an MPP payment and (2) other parts of the
/// transaction.
claim_from_onchain_tx: bool,
},
- /// Used to indicate that a channel with the given `channel_id` is in the process of closure.
+ /// Used to indicate that a previously opened channel with the given `channel_id` is in the
+ /// process of closure.
ChannelClosed {
/// The channel_id of the channel which has been closed. Note that on-chain transactions
/// resolving the channel are likely still awaiting confirmation.
/// the resulting [`ChannelManager`] will not be readable by versions of LDK prior to
/// 0.0.106.
///
+ /// Furthermore, note that if [`ChannelTypeFeatures::supports_zero_conf`] returns true on this type,
+ /// the resulting [`ChannelManager`] will not be readable by versions of LDK prior to
+ /// 0.0.107. Channels setting this type also need to get manually accepted via
+ /// [`crate::ln::channelmanager::ChannelManager::accept_inbound_channel_from_trusted_peer_0conf`],
+ /// or will be rejected otherwise.
+ ///
/// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
channel_type: ChannelTypeFeatures,
},