Skip to content

Commit cad035d

Browse files
committed
Remove automatic channel acceptance
Removes the `manually_accept_inbound_channels` config option. In upcoming commit we will default to anchor channels which requires users checking if they have enough onchain funds to cover fees in case of a force close. Hence, we move to always require users to manually accept inbound channels.
1 parent b6bd386 commit cad035d

26 files changed

Lines changed: 323 additions & 466 deletions

fuzz/src/chanmon_consistency.rs

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,6 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
712712
config.reject_inbound_splices = false;
713713
if anchors {
714714
config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true;
715-
config.manually_accept_inbound_channels = true;
716715
}
717716
let network = Network::Bitcoin;
718717
let best_block_timestamp = genesis_block(network).header.time;
@@ -763,7 +762,6 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out, anchors: bool) {
763762
config.reject_inbound_splices = false;
764763
if anchors {
765764
config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true;
766-
config.manually_accept_inbound_channels = true;
767765
}
768766

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

875873
$dest.handle_open_channel($source.get_our_node_id(), &open_channel);
876874
let accept_channel = {
877-
if anchors {
878-
let events = $dest.get_and_clear_pending_events();
879-
assert_eq!(events.len(), 1);
880-
if let events::Event::OpenChannelRequest {
881-
ref temporary_channel_id,
882-
ref counterparty_node_id,
883-
..
884-
} = events[0]
885-
{
886-
let mut random_bytes = [0u8; 16];
887-
random_bytes
888-
.copy_from_slice(&$dest_keys_manager.get_secure_random_bytes()[..16]);
889-
let user_channel_id = u128::from_be_bytes(random_bytes);
890-
$dest
891-
.accept_inbound_channel(
892-
temporary_channel_id,
893-
counterparty_node_id,
894-
user_channel_id,
895-
None,
896-
)
897-
.unwrap();
898-
} else {
899-
panic!("Wrong event type");
900-
}
875+
let events = $dest.get_and_clear_pending_events();
876+
assert_eq!(events.len(), 1);
877+
if let events::Event::OpenChannelRequest {
878+
ref temporary_channel_id,
879+
ref counterparty_node_id,
880+
..
881+
} = events[0]
882+
{
883+
let mut random_bytes = [0u8; 16];
884+
random_bytes
885+
.copy_from_slice(&$dest_keys_manager.get_secure_random_bytes()[..16]);
886+
let user_channel_id = u128::from_be_bytes(random_bytes);
887+
$dest
888+
.accept_inbound_channel(
889+
temporary_channel_id,
890+
counterparty_node_id,
891+
user_channel_id,
892+
None,
893+
)
894+
.unwrap();
895+
} else {
896+
panic!("Wrong event type");
901897
}
902898
let events = $dest.get_and_clear_pending_msg_events();
903899
assert_eq!(events.len(), 1);

fuzz/src/full_stack.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,13 @@ use lightning::chain::{BestBlock, ChannelMonitorUpdateStatus, Confirm, Listen};
4242
use lightning::events::bump_transaction::sync::WalletSourceSync;
4343
use lightning::events::Event;
4444
use lightning::ln::channel_state::ChannelDetails;
45-
use lightning::ln::channelmanager::{
46-
ChainParameters, ChannelManager, InterceptId, PaymentId,
47-
};
45+
use lightning::ln::channelmanager::{ChainParameters, ChannelManager, InterceptId, PaymentId};
4846
use lightning::ln::functional_test_utils::*;
4947
use lightning::ln::inbound_payment::ExpandedKey;
48+
use lightning::ln::outbound_payment::{RecipientOnionFields, Retry};
5049
use lightning::ln::peer_handler::{
5150
IgnoringMessageHandler, MessageHandler, PeerManager, SocketDescriptor,
5251
};
53-
use lightning::ln::outbound_payment::{RecipientOnionFields, Retry};
5452
use lightning::ln::script::ShutdownScript;
5553
use lightning::ln::types::ChannelId;
5654
use lightning::offers::invoice::UnsignedBolt12Invoice;
@@ -1122,6 +1120,17 @@ pub fn do_test(mut data: &[u8], logger: &Arc<dyn Logger>) {
11221120
Event::SpliceFailed { .. } => {
11231121
// Splice failed, inputs can be re-spent
11241122
},
1123+
Event::OpenChannelRequest {
1124+
temporary_channel_id, counterparty_node_id, ..
1125+
} => {
1126+
let _ = loss_detector.manager.accept_inbound_channel(
1127+
&temporary_channel_id,
1128+
&counterparty_node_id,
1129+
0,
1130+
None,
1131+
);
1132+
loss_detector.handler.process_events();
1133+
},
11251134
_ => {},
11261135
}
11271136
}
@@ -1159,7 +1168,7 @@ fn two_peer_forwarding_seed() -> Vec<u8> {
11591168
// our network key
11601169
ext_from_hex("0100000000000000000000000000000000000000000000000000000000000000", &mut test);
11611170
// config
1162-
ext_from_hex("000000000090000000000000000064000100000000000100ffff0000000000000000ffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff000000ffffffff00ffff1a000400010000020400000000040200000a08ffffffffffffffff000100000000000000", &mut test);
1171+
ext_from_hex("000000000090000000000000000064000100000000000100ffff0000000000000000ffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff000000ffffffff00ffff1a000400010000020400000000040200000a08ffffffffffffffff0001000000000000", &mut test);
11631172

11641173
// new outbound connection with id 0
11651174
ext_from_hex("00", &mut test);
@@ -1613,7 +1622,7 @@ fn gossip_exchange_seed() -> Vec<u8> {
16131622
// our network key
16141623
ext_from_hex("0100000000000000000000000000000000000000000000000000000000000000", &mut test);
16151624
// config
1616-
ext_from_hex("000000000090000000000000000064000100000000000100ffff0000000000000000ffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff000000ffffffff00ffff1a000400010000020400000000040200000a08ffffffffffffffff000100000000000000", &mut test);
1625+
ext_from_hex("000000000090000000000000000064000100000000000100ffff0000000000000000ffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff000000ffffffff00ffff1a000400010000020400000000040200000a08ffffffffffffffff0001000000000000", &mut test);
16171626

16181627
// new outbound connection with id 0
16191628
ext_from_hex("00", &mut test);
@@ -1695,7 +1704,7 @@ fn splice_seed() -> Vec<u8> {
16951704
// our network key
16961705
ext_from_hex("0100000000000000000000000000000000000000000000000000000000000000", &mut test);
16971706
// config
1698-
ext_from_hex("000000000090000000000000000064000100000000000100ffff0000000000000000ffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff000000ffffffff00ffff1a000400010000020400000000040200000a08ffffffffffffffff000100000000000000", &mut test);
1707+
ext_from_hex("000000000090000000000000000064000100000000000100ffff0000000000000000ffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffff000000ffffffff00ffff1a000400010000020400000000040200000a08ffffffffffffffff0001000000000000", &mut test);
16991708

17001709
// new outbound connection with id 0
17011710
ext_from_hex("00", &mut test);

lightning-background-processor/src/lib.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2610,6 +2610,25 @@ mod tests {
26102610
$node_b.node.get_our_node_id()
26112611
);
26122612
$node_b.node.handle_open_channel($node_a.node.get_our_node_id(), &msg_a);
2613+
let events = $node_b.node.get_and_clear_pending_events();
2614+
assert_eq!(events.len(), 1);
2615+
match &events[0] {
2616+
Event::OpenChannelRequest {
2617+
temporary_channel_id, counterparty_node_id, ..
2618+
} => {
2619+
$node_b
2620+
.node
2621+
.accept_inbound_channel(
2622+
temporary_channel_id,
2623+
counterparty_node_id,
2624+
42,
2625+
None,
2626+
)
2627+
.unwrap();
2628+
},
2629+
_ => panic!("Unexpected event"),
2630+
};
2631+
26132632
let msg_b = get_event_msg!(
26142633
$node_b,
26152634
MessageSendEvent::SendAcceptChannel,

lightning-liquidity/tests/lsps2_integration_tests.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,7 +1155,6 @@ fn client_trusts_lsp_end_to_end_test() {
11551155
service_node_config.htlc_interception_flags = HTLCInterceptionFlags::ToInterceptSCIDs as u8;
11561156

11571157
let mut client_node_config = test_default_channel_config();
1158-
client_node_config.manually_accept_inbound_channels = true;
11591158
client_node_config.channel_config.accept_underpaying_htlcs = true;
11601159
let node_chanmgrs = create_node_chanmgrs(
11611160
3,
@@ -1627,7 +1626,6 @@ fn late_payment_forwarded_and_safe_after_force_close_does_not_broadcast() {
16271626
service_node_config.htlc_interception_flags = HTLCInterceptionFlags::ToInterceptSCIDs as u8;
16281627

16291628
let mut client_node_config = test_default_channel_config();
1630-
client_node_config.manually_accept_inbound_channels = true;
16311629
client_node_config.channel_config.accept_underpaying_htlcs = true;
16321630

16331631
let node_chanmgrs = create_node_chanmgrs(
@@ -1817,7 +1815,6 @@ fn htlc_timeout_before_client_claim_results_in_handling_failed() {
18171815
service_node_config.htlc_interception_flags = HTLCInterceptionFlags::ToInterceptSCIDs as u8;
18181816

18191817
let mut client_node_config = test_default_channel_config();
1820-
client_node_config.manually_accept_inbound_channels = true;
18211818
client_node_config.channel_config.accept_underpaying_htlcs = true;
18221819

18231820
let node_chanmgrs = create_node_chanmgrs(
@@ -2152,7 +2149,6 @@ fn client_trusts_lsp_partial_fee_does_not_trigger_broadcast() {
21522149
service_node_config.htlc_interception_flags = HTLCInterceptionFlags::ToInterceptSCIDs as u8;
21532150

21542151
let mut client_node_config = test_default_channel_config();
2155-
client_node_config.manually_accept_inbound_channels = true;
21562152
client_node_config.channel_config.accept_underpaying_htlcs = true;
21572153

21582154
let node_chanmgrs = create_node_chanmgrs(

lightning/src/events/mod.rs

Lines changed: 15 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -245,17 +245,14 @@ pub struct ClaimedHTLC {
245245
pub channel_id: ChannelId,
246246
/// The `user_channel_id` of the channel over which the HTLC was received. This is the value
247247
/// passed in to [`ChannelManager::create_channel`] for outbound channels, or to
248-
/// [`ChannelManager::accept_inbound_channel`] for inbound channels if
249-
/// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
250-
/// `user_channel_id` will be randomized for an inbound channel.
248+
/// [`ChannelManager::accept_inbound_channel`] for inbound channels.
251249
///
252250
/// This field will be zero for a payment that was serialized prior to LDK version 0.0.117. (This
253251
/// should only happen in the case that a payment was claimable prior to LDK version 0.0.117, but
254252
/// was not actually claimed until after upgrading.)
255253
///
256254
/// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
257255
/// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
258-
/// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
259256
pub user_channel_id: u128,
260257
/// The block height at which this HTLC expires.
261258
pub cltv_expiry: u32,
@@ -765,14 +762,11 @@ pub enum Event {
765762
/// The script which should be used in the transaction output.
766763
output_script: ScriptBuf,
767764
/// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
768-
/// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
769-
/// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
770-
/// `user_channel_id` will be randomized for an inbound channel. This may be zero for objects
771-
/// serialized with LDK versions prior to 0.0.113.
765+
/// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels.
766+
/// This may be zero for objects serialized with LDK versions prior to 0.0.113.
772767
///
773768
/// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
774769
/// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
775-
/// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
776770
user_channel_id: u128,
777771
},
778772
/// Used to indicate that the counterparty node has provided the signature(s) required to
@@ -1404,13 +1398,10 @@ pub enum Event {
14041398
/// The `channel_id` of the channel that is pending confirmation.
14051399
channel_id: ChannelId,
14061400
/// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
1407-
/// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
1408-
/// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
1409-
/// `user_channel_id` will be randomized for an inbound channel.
1401+
/// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels.
14101402
///
14111403
/// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
14121404
/// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
1413-
/// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
14141405
user_channel_id: u128,
14151406
/// The `temporary_channel_id` this channel used to be known by during channel establishment.
14161407
///
@@ -1444,13 +1435,10 @@ pub enum Event {
14441435
/// The `channel_id` of the channel that is ready.
14451436
channel_id: ChannelId,
14461437
/// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
1447-
/// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
1448-
/// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
1449-
/// `user_channel_id` will be randomized for an inbound channel.
1438+
/// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels.
14501439
///
14511440
/// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
14521441
/// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
1453-
/// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
14541442
user_channel_id: u128,
14551443
/// The `node_id` of the channel counterparty.
14561444
counterparty_node_id: PublicKey,
@@ -1466,11 +1454,10 @@ pub enum Event {
14661454
/// process of closure. This includes previously opened channels, and channels that time out from not being funded.
14671455
///
14681456
/// Note that this event is only triggered for accepted channels: if the
1469-
/// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true and the channel is
1470-
/// rejected, no `ChannelClosed` event will be sent.
1457+
/// [`Event::OpenChannelRequest`] was rejected, no `ChannelClosed` event will be sent.
14711458
///
14721459
/// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
1473-
/// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
1460+
/// [`Event::OpenChannelRequest`]: Event::OpenChannelRequest
14741461
///
14751462
/// # Failure Behavior and Persistence
14761463
/// This event will eventually be replayed after failures-to-handle (i.e., the event handler
@@ -1480,15 +1467,12 @@ pub enum Event {
14801467
/// resolving the channel are likely still awaiting confirmation.
14811468
channel_id: ChannelId,
14821469
/// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
1483-
/// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
1484-
/// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
1485-
/// `user_channel_id` will be randomized for inbound channels.
1470+
/// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels.
14861471
/// This may be zero for inbound channels serialized prior to 0.0.113 and will always be
14871472
/// zero for objects serialized with LDK versions prior to 0.0.102.
14881473
///
14891474
/// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
14901475
/// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
1491-
/// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
14921476
user_channel_id: u128,
14931477
/// The reason the channel was closed.
14941478
reason: ClosureReason,
@@ -1532,13 +1516,10 @@ pub enum Event {
15321516
/// The `channel_id` of the channel that has a pending splice funding transaction.
15331517
channel_id: ChannelId,
15341518
/// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
1535-
/// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
1536-
/// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
1537-
/// `user_channel_id` will be randomized for an inbound channel.
1519+
/// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels.
15381520
///
15391521
/// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
15401522
/// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
1541-
/// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
15421523
user_channel_id: u128,
15431524
/// The `node_id` of the channel counterparty.
15441525
counterparty_node_id: PublicKey,
@@ -1565,13 +1546,10 @@ pub enum Event {
15651546
/// The `channel_id` of the channel for which the splice failed.
15661547
channel_id: ChannelId,
15671548
/// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
1568-
/// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels if
1569-
/// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
1570-
/// `user_channel_id` will be randomized for an inbound channel.
1549+
/// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels.
15711550
///
15721551
/// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
15731552
/// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
1574-
/// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
15751553
user_channel_id: u128,
15761554
/// The `node_id` of the channel counterparty.
15771555
counterparty_node_id: PublicKey,
@@ -1604,22 +1582,19 @@ pub enum Event {
16041582
},
16051583
/// Indicates a request to open a new channel by a peer.
16061584
///
1585+
/// This event is triggered for all inbound requests to open a new channel.
16071586
/// To accept the request (and in the case of a dual-funded channel, not contribute funds),
16081587
/// call [`ChannelManager::accept_inbound_channel`].
16091588
/// To reject the request, call [`ChannelManager::force_close_broadcasting_latest_txn`].
16101589
/// Note that a [`ChannelClosed`] event will _not_ be triggered if the channel is rejected.
16111590
///
1612-
/// The event is only triggered when a new open channel request is received and the
1613-
/// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true.
1614-
///
16151591
/// # Failure Behavior and Persistence
16161592
/// This event will eventually be replayed after failures-to-handle (i.e., the event handler
16171593
/// returning `Err(ReplayEvent ())`) and won't be persisted across restarts.
16181594
///
16191595
/// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
16201596
/// [`ChannelClosed`]: Event::ChannelClosed
16211597
/// [`ChannelManager::force_close_broadcasting_latest_txn`]: crate::ln::channelmanager::ChannelManager::force_close_broadcasting_latest_txn
1622-
/// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
16231598
OpenChannelRequest {
16241599
/// The temporary channel ID of the channel requested to be opened.
16251600
///
@@ -1861,11 +1836,11 @@ pub enum Event {
18611836
///
18621837
/// [`ChannelManager::funding_transaction_signed`]: crate::ln::channelmanager::ChannelManager::funding_transaction_signed
18631838
counterparty_node_id: PublicKey,
1864-
/// The `user_channel_id` value passed in for outbound channels, or for inbound channels if
1865-
/// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true. Otherwise
1866-
/// `user_channel_id` will be randomized for inbound channels.
1839+
/// The `user_channel_id` value passed in to [`ChannelManager::create_channel`] for outbound
1840+
/// channels, or to [`ChannelManager::accept_inbound_channel`] for inbound channels.
18671841
///
1868-
/// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
1842+
/// [`ChannelManager::create_channel`]: crate::ln::channelmanager::ChannelManager::create_channel
1843+
/// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
18691844
user_channel_id: u128,
18701845
/// The unsigned transaction to be signed and passed back to
18711846
/// [`ChannelManager::funding_transaction_signed`].

lightning/src/ln/async_payments_tests.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3057,7 +3057,6 @@ fn intercepted_hold_htlc() {
30573057
let chanmon_cfgs = create_chanmon_cfgs(4);
30583058
let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
30593059
let (sender_cfg, mut recipient_cfg) = (often_offline_node_cfg(), often_offline_node_cfg());
3060-
recipient_cfg.manually_accept_inbound_channels = true;
30613060
recipient_cfg.channel_handshake_limits.force_announced_channel_preference = false;
30623061

30633062
let mut lsp_cfg = test_default_channel_config();

0 commit comments

Comments
 (0)