Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 26 additions & 30 deletions fuzz/src/chanmon_consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -710,9 +710,8 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
config.channel_config.forwarding_fee_proportional_millionths = 0;
config.channel_handshake_config.announce_for_forwarding = true;
config.reject_inbound_splices = false;
if anchors {
config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true;
config.manually_accept_inbound_channels = true;
if !anchors {
config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = false;
}
let network = Network::Bitcoin;
let best_block_timestamp = genesis_block(network).header.time;
Expand Down Expand Up @@ -761,9 +760,8 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
config.channel_config.forwarding_fee_proportional_millionths = 0;
config.channel_handshake_config.announce_for_forwarding = true;
config.reject_inbound_splices = false;
if anchors {
config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true;
config.manually_accept_inbound_channels = true;
if !anchors {
config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = false;
}

let mut monitors = new_hash_map();
Expand Down Expand Up @@ -874,30 +872,28 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {

$dest.handle_open_channel($source.get_our_node_id(), &open_channel);
let accept_channel = {
if anchors {
let events = $dest.get_and_clear_pending_events();
assert_eq!(events.len(), 1);
if let events::Event::OpenChannelRequest {
ref temporary_channel_id,
ref counterparty_node_id,
..
} = events[0]
{
let mut random_bytes = [0u8; 16];
random_bytes
.copy_from_slice(&$dest_keys_manager.get_secure_random_bytes()[..16]);
let user_channel_id = u128::from_be_bytes(random_bytes);
$dest
.accept_inbound_channel(
temporary_channel_id,
counterparty_node_id,
user_channel_id,
None,
)
.unwrap();
} else {
panic!("Wrong event type");
}
let events = $dest.get_and_clear_pending_events();
assert_eq!(events.len(), 1);
if let events::Event::OpenChannelRequest {
ref temporary_channel_id,
ref counterparty_node_id,
..
} = events[0]
{
let mut random_bytes = [0u8; 16];
random_bytes
.copy_from_slice(&$dest_keys_manager.get_secure_random_bytes()[..16]);
let user_channel_id = u128::from_be_bytes(random_bytes);
$dest
.accept_inbound_channel(
temporary_channel_id,
counterparty_node_id,
user_channel_id,
None,
)
.unwrap();
} else {
panic!("Wrong event type");
}
let events = $dest.get_and_clear_pending_msg_events();
assert_eq!(events.len(), 1);
Expand Down
23 changes: 22 additions & 1 deletion lightning-background-processor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2465,6 +2465,8 @@ mod tests {
));
let best_block = BestBlock::from_network(network);
let params = ChainParameters { network, best_block };
let mut config = UserConfig::default();
config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = false;
let manager = Arc::new(ChannelManager::new(
Arc::clone(&fee_estimator),
Arc::clone(&chain_monitor),
Expand All @@ -2475,7 +2477,7 @@ mod tests {
Arc::clone(&keys_manager),
Arc::clone(&keys_manager),
Arc::clone(&keys_manager),
UserConfig::default(),
config,
params,
genesis_block.header.time,
));
Expand Down Expand Up @@ -2628,6 +2630,25 @@ mod tests {
$node_b.node.get_our_node_id()
);
$node_b.node.handle_open_channel($node_a.node.get_our_node_id(), &msg_a);
let events = $node_b.node.get_and_clear_pending_events();
assert_eq!(events.len(), 1);
match &events[0] {
Event::OpenChannelRequest {
temporary_channel_id, counterparty_node_id, ..
} => {
$node_b
.node
.accept_inbound_channel(
temporary_channel_id,
counterparty_node_id,
42,
None,
)
.unwrap();
},
_ => panic!("Unexpected event"),
};

let msg_b = get_event_msg!(
$node_b,
MessageSendEvent::SendAcceptChannel,
Expand Down
4 changes: 0 additions & 4 deletions lightning-liquidity/tests/lsps2_integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,6 @@ fn client_trusts_lsp_end_to_end_test() {
service_node_config.accept_intercept_htlcs = true;

let mut client_node_config = test_default_channel_config();
client_node_config.manually_accept_inbound_channels = true;
client_node_config.channel_config.accept_underpaying_htlcs = true;
let node_chanmgrs = create_node_chanmgrs(
3,
Expand Down Expand Up @@ -1633,7 +1632,6 @@ fn late_payment_forwarded_and_safe_after_force_close_does_not_broadcast() {
service_node_config.accept_intercept_htlcs = true;

let mut client_node_config = test_default_channel_config();
client_node_config.manually_accept_inbound_channels = true;
client_node_config.channel_config.accept_underpaying_htlcs = true;

let node_chanmgrs = create_node_chanmgrs(
Expand Down Expand Up @@ -1824,7 +1822,6 @@ fn htlc_timeout_before_client_claim_results_in_handling_failed() {
service_node_config.accept_intercept_htlcs = true;

let mut client_node_config = test_default_channel_config();
client_node_config.manually_accept_inbound_channels = true;
client_node_config.channel_config.accept_underpaying_htlcs = true;

let node_chanmgrs = create_node_chanmgrs(
Expand Down Expand Up @@ -2160,7 +2157,6 @@ fn client_trusts_lsp_partial_fee_does_not_trigger_broadcast() {
service_node_config.accept_intercept_htlcs = true;

let mut client_node_config = test_default_channel_config();
client_node_config.manually_accept_inbound_channels = true;
client_node_config.channel_config.accept_underpaying_htlcs = true;

let node_chanmgrs = create_node_chanmgrs(
Expand Down
54 changes: 13 additions & 41 deletions lightning/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,17 +244,14 @@ pub struct ClaimedHTLC {
pub channel_id: ChannelId,
/// The `user_channel_id` of the channel over which the HTLC was received. This is the value
/// passed in to [`ChannelManager::create_channel`] for outbound channels, or to
/// [`ChannelManager::accept_inbound_channel`] for inbound channels if
/// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
/// `user_channel_id` will be randomized for an inbound channel.
/// [`ChannelManager::accept_inbound_channel`].
///
/// This field will be zero for a payment that was serialized prior to LDK version 0.0.117. (This
/// should only happen in the case that a payment was claimable prior to LDK version 0.0.117, but
/// was not actually claimed until after upgrading.)
///
/// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
/// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
/// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
pub user_channel_id: u128,
/// The block height at which this HTLC expires.
pub cltv_expiry: u32,
Expand Down Expand Up @@ -764,14 +761,11 @@ pub enum Event {
/// The script which should be used in the transaction output.
output_script: ScriptBuf,
/// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
/// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
/// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
/// `user_channel_id` will be randomized for an inbound channel. This may be zero for objects
/// serialized with LDK versions prior to 0.0.113.
/// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels.
/// This may be zero for objects serialized with LDK versions prior to 0.0.113.
///
/// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
/// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
/// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
user_channel_id: u128,
},
/// Used to indicate that the counterparty node has provided the signature(s) required to
Expand Down Expand Up @@ -1394,13 +1388,10 @@ pub enum Event {
/// The `channel_id` of the channel that is pending confirmation.
channel_id: ChannelId,
/// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
/// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
/// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
/// `user_channel_id` will be randomized for an inbound channel.
/// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels.
///
/// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
/// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
/// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
user_channel_id: u128,
/// The `temporary_channel_id` this channel used to be known by during channel establishment.
///
Expand Down Expand Up @@ -1434,13 +1425,10 @@ pub enum Event {
/// The `channel_id` of the channel that is ready.
channel_id: ChannelId,
/// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
/// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
/// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
/// `user_channel_id` will be randomized for an inbound channel.
/// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels.
///
/// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
/// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
/// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
user_channel_id: u128,
/// The `node_id` of the channel counterparty.
counterparty_node_id: PublicKey,
Expand All @@ -1456,11 +1444,10 @@ pub enum Event {
/// process of closure. This includes previously opened channels, and channels that time out from not being funded.
///
/// Note that this event is only triggered for accepted channels: if the
/// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true and the channel is
/// rejected, no `ChannelClosed` event will be sent.
/// [`Event::OpenChannelRequest`] was rejected, no `ChannelClosed` event will be sent.
///
/// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
/// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
/// [`Event::OpenChannelRequest`]: Event::OpenChannelRequest
///
/// # Failure Behavior and Persistence
/// This event will eventually be replayed after failures-to-handle (i.e., the event handler
Expand All @@ -1470,15 +1457,12 @@ pub enum Event {
/// resolving the channel are likely still awaiting confirmation.
channel_id: ChannelId,
/// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
/// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
/// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
/// `user_channel_id` will be randomized for inbound channels.
/// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels.
/// This may be zero for inbound channels serialized prior to 0.0.113 and will always be
/// zero for objects serialized with LDK versions prior to 0.0.102.
///
/// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
/// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
/// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
user_channel_id: u128,
/// The reason the channel was closed.
reason: ClosureReason,
Expand Down Expand Up @@ -1522,13 +1506,10 @@ pub enum Event {
/// The `channel_id` of the channel that has a pending splice funding transaction.
channel_id: ChannelId,
/// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
/// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
/// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
/// `user_channel_id` will be randomized for an inbound channel.
/// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels.
///
/// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
/// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
/// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
user_channel_id: u128,
/// The `node_id` of the channel counterparty.
counterparty_node_id: PublicKey,
Expand All @@ -1555,13 +1536,10 @@ pub enum Event {
/// The `channel_id` of the channel for which the splice failed.
channel_id: ChannelId,
/// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
/// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
/// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
/// `user_channel_id` will be randomized for an inbound channel.
/// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels.
///
/// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
/// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
/// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
user_channel_id: u128,
/// The `node_id` of the channel counterparty.
counterparty_node_id: PublicKey,
Expand Down Expand Up @@ -1594,22 +1572,19 @@ pub enum Event {
},
/// Indicates a request to open a new channel by a peer.
///
/// This event is triggered for all inbound requests to open a new channel.
/// To accept the request (and in the case of a dual-funded channel, not contribute funds),
/// call [`ChannelManager::accept_inbound_channel`].
/// To reject the request, call [`ChannelManager::force_close_broadcasting_latest_txn`].
/// Note that a [`ChannelClosed`] event will _not_ be triggered if the channel is rejected.
///
/// The event is only triggered when a new open channel request is received and the
/// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true.
///
/// # Failure Behavior and Persistence
/// This event will eventually be replayed after failures-to-handle (i.e., the event handler
/// returning `Err(ReplayEvent ())`) and won't be persisted across restarts.
///
/// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
/// [`ChannelClosed`]: Event::ChannelClosed
/// [`ChannelManager::force_close_broadcasting_latest_txn`]: crate::ln::channelmanager::ChannelManager::force_close_broadcasting_latest_txn
/// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
OpenChannelRequest {
/// The temporary channel ID of the channel requested to be opened.
///
Expand Down Expand Up @@ -1851,11 +1826,8 @@ pub enum Event {
///
/// [`ChannelManager::funding_transaction_signed`]: crate::ln::channelmanager::ChannelManager::funding_transaction_signed
counterparty_node_id: PublicKey,
/// The `user_channel_id` value passed in for outbound channels, or for inbound channels if
/// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
/// `user_channel_id` will be randomized for inbound channels.
///
/// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
/// The `user_channel_id` value passed in for outbound channels, or for inbound
/// channels.
user_channel_id: u128,
/// The unsigned transaction to be signed and passed back to
/// [`ChannelManager::funding_transaction_signed`].
Expand Down
1 change: 0 additions & 1 deletion lightning/src/ln/async_payments_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3059,7 +3059,6 @@ fn intercepted_hold_htlc() {
let chanmon_cfgs = create_chanmon_cfgs(4);
let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
let (sender_cfg, mut recipient_cfg) = (often_offline_node_cfg(), often_offline_node_cfg());
recipient_cfg.manually_accept_inbound_channels = true;
recipient_cfg.channel_handshake_limits.force_announced_channel_preference = false;

let mut lsp_cfg = test_default_channel_config();
Expand Down
22 changes: 12 additions & 10 deletions lightning/src/ln/async_signer_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,9 @@ fn test_open_channel() {

fn do_test_open_channel(zero_conf: bool) {
// Simulate acquiring the commitment point for `open_channel` and `accept_channel` asynchronously.
let mut manually_accept_config = test_default_channel_config();
manually_accept_config.manually_accept_inbound_channels = zero_conf;

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_config)]);
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
let node_a_id = nodes[0].node.get_our_node_id();
let node_b_id = nodes[1].node.get_our_node_id();
Expand Down Expand Up @@ -88,8 +85,15 @@ fn do_test_open_channel(zero_conf: bool) {
ev => panic!("Expected OpenChannelRequest, not {:?}", ev),
}
} else {
let msgs = nodes[1].node.get_and_clear_pending_msg_events();
assert!(msgs.is_empty(), "Expected no message events; got {:?}", msgs);
let events = nodes[1].node.get_and_clear_pending_events();
assert_eq!(events.len(), 1, "Expected one event, got {}", events.len());
match &events[0] {
Event::OpenChannelRequest { temporary_channel_id, .. } => nodes[1]
.node
.accept_inbound_channel(temporary_channel_id, &node_a_id, 0, None)
.unwrap(),
ev => panic!("Expected OpenChannelRequest, not {:?}", ev),
}
}

let channel_id_1 = {
Expand Down Expand Up @@ -130,7 +134,7 @@ fn do_test_funding_created(signer_ops: Vec<SignerOp>) {

// nodes[0] --- open_channel --> nodes[1]
let mut open_chan_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, node_b_id);
nodes[1].node.handle_open_channel(node_a_id, &open_chan_msg);
handle_and_accept_open_channel(&nodes[1], node_a_id, &open_chan_msg);

// nodes[0] <-- accept_channel --- nodes[1]
nodes[0].node.handle_accept_channel(
Expand Down Expand Up @@ -207,7 +211,7 @@ fn do_test_funding_signed(signer_ops: Vec<SignerOp>) {

// nodes[0] --- open_channel --> nodes[1]
let mut open_chan_msg = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, node_b_id);
nodes[1].node.handle_open_channel(node_a_id, &open_chan_msg);
handle_and_accept_open_channel(&nodes[1], node_a_id, &open_chan_msg);

// nodes[0] <-- accept_channel --- nodes[1]
nodes[0].node.handle_accept_channel(
Expand Down Expand Up @@ -364,7 +368,6 @@ fn test_funding_signed_0conf() {
fn do_test_funding_signed_0conf(signer_ops: Vec<SignerOp>) {
// Simulate acquiring the signature for `funding_signed` asynchronously for a zero-conf channel.
let mut manually_accept_config = test_default_channel_config();
manually_accept_config.manually_accept_inbound_channels = true;

let chanmon_cfgs = create_chanmon_cfgs(2);
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
Expand Down Expand Up @@ -998,7 +1001,6 @@ fn do_test_async_holder_signatures(keyed_anchors: bool, p2a_anchor: bool, remote
let mut config = test_default_channel_config();
config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = keyed_anchors;
config.channel_handshake_config.negotiate_anchor_zero_fee_commitments = p2a_anchor;
config.manually_accept_inbound_channels = keyed_anchors || p2a_anchor;

let chanmon_cfgs = create_chanmon_cfgs(2);
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
Expand Down
Loading
Loading