Skip to content

Commit 3f850c8

Browse files
committed
Allow ZeroConf channel type and test for it.
1 parent 2a87e30 commit 3f850c8

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

lightning/src/ln/channel.rs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,10 +1084,8 @@ impl<Signer: Sign> Channel<Signer> {
10841084
// We currently only allow two channel types, so write it all out here - we allow
10851085
// `only_static_remote_key` in all contexts, and further allow
10861086
// `static_remote_key|scid_privacy` if the channel is not publicly announced.
1087-
let mut allowed_type = ChannelTypeFeatures::only_static_remote_key();
1088-
if *channel_type != allowed_type {
1089-
allowed_type.set_scid_privacy_required();
1090-
if *channel_type != allowed_type {
1087+
if *channel_type != ChannelTypeFeatures::only_static_remote_key() {
1088+
if !channel_type.requires_scid_privacy() && !channel_type.requires_zero_conf() {
10911089
return Err(ChannelError::Close("Channel Type was not understood".to_owned()));
10921090
}
10931091
if announced_channel {
@@ -6407,7 +6405,7 @@ mod tests {
64076405
use ln::channelmanager::{HTLCSource, PaymentId};
64086406
use ln::channel::{Channel, InboundHTLCOutput, OutboundHTLCOutput, InboundHTLCState, OutboundHTLCState, HTLCCandidate, HTLCInitiator};
64096407
use ln::channel::{MAX_FUNDING_SATOSHIS_NO_WUMBO, TOTAL_BITCOIN_SUPPLY_SATOSHIS};
6410-
use ln::features::InitFeatures;
6408+
use ln::features::{InitFeatures, ChannelTypeFeatures};
64116409
use ln::msgs::{ChannelUpdate, DataLossProtect, DecodeError, OptionalField, UnsignedChannelUpdate};
64126410
use ln::script::ShutdownScript;
64136411
use ln::chan_utils;
@@ -7722,4 +7720,30 @@ mod tests {
77227720
assert_eq!(chan_utils::derive_private_revocation_key(&secp_ctx, &per_commitment_secret, &base_secret).unwrap(),
77237721
SecretKey::from_slice(&hex::decode("d09ffff62ddb2297ab000cc85bcb4283fdeb6aa052affbc9dddcf33b61078110").unwrap()[..]).unwrap());
77247722
}
7723+
7724+
#[test]
7725+
fn test_zero_conf_channel_type_support() {
7726+
let feeest = TestFeeEstimator{fee_est: 15000};
7727+
let secp_ctx = Secp256k1::new();
7728+
let seed = [42; 32];
7729+
let network = Network::Testnet;
7730+
let keys_provider = test_utils::TestKeysInterface::new(&seed, network);
7731+
let logger = test_utils::TestLogger::new();
7732+
7733+
// Create Node A's channel pointing to Node B's pubkey
7734+
let node_b_node_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32]).unwrap());
7735+
let config = UserConfig::default();
7736+
let node_a_chan = Channel::<EnforcingSigner>::new_outbound(&&feeest, &&keys_provider, node_b_node_id, &InitFeatures::known(), 10000000, 100000, 42, &config, 0, 42).unwrap();
7737+
7738+
// Create Node B's channel by receiving Node A's open_channel message
7739+
// Make sure A's dust limit is as we expect.
7740+
let mut channel_type_features = ChannelTypeFeatures::only_static_remote_key();
7741+
channel_type_features.set_zero_conf_required();
7742+
7743+
let mut open_channel_msg = node_a_chan.get_open_channel(genesis_block(network).header.block_hash());
7744+
open_channel_msg.channel_type = Some(channel_type_features);
7745+
let node_b_node_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[7; 32]).unwrap());
7746+
let res = Channel::<EnforcingSigner>::new_from_req(&&feeest, &&keys_provider, node_b_node_id, &InitFeatures::known(), &open_channel_msg, 7, &config, 0, &&logger, 42);
7747+
assert!(res.is_ok());
7748+
}
77257749
}

lightning/src/util/events.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,8 @@ pub enum Event {
469469
/// Furthermore, note that if [`ChannelTypeFeatures::supports_zero_conf`] returns true on this type,
470470
/// the resulting [`ChannelManager`] will not be readable by versions of LDK prior to
471471
/// 0.0.107. Channels setting this type also need to get manually accepted via
472-
/// [`crate::ln::channelmanager::ChannelManager::accept_inbound_channel_from_trusted_peer_0conf`], or will be rejected
473-
/// otherwise.
472+
/// [`crate::ln::channelmanager::ChannelManager::accept_inbound_channel_from_trusted_peer_0conf`],
473+
/// or will be rejected otherwise.
474474
///
475475
/// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
476476
channel_type: ChannelTypeFeatures,

0 commit comments

Comments
 (0)