X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fchannel.rs;h=f702fc4843eea3d8f8a4db11a2eda446aa9d6392;hb=fe0f845582ae707ac523edc6e4b9cab64cb4306a;hp=e74f659fbd09ba04a6fc537fd9525b3c8f56a7c6;hpb=16311f98b3ba6d0e707b21acd002f1dee4971010;p=rust-lightning diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index e74f659f..f702fc48 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -65,8 +65,6 @@ pub struct ChannelValueStat { } pub struct AvailableBalances { - /// The amount that would go to us if we close the channel, ignoring any on-chain fees. - pub balance_msat: u64, /// Total amount available for our counterparty to send to us. pub inbound_capacity_msat: u64, /// Total amount available for us to send to our counterparty. @@ -250,38 +248,38 @@ enum HTLCUpdateAwaitingACK { } /// There are a few "states" and then a number of flags which can be applied: -/// We first move through init with OurInitSent -> TheirInitSent -> FundingCreated -> FundingSent. -/// TheirChannelReady and OurChannelReady then get set on FundingSent, and when both are set we -/// move on to ChannelReady. -/// Note that PeerDisconnected can be set on both ChannelReady and FundingSent. -/// ChannelReady can then get all remaining flags set on it, until we finish shutdown, then we -/// move on to ShutdownComplete, at which point most calls into this channel are disallowed. +/// We first move through init with `OurInitSent` -> `TheirInitSent` -> `FundingCreated` -> `FundingSent`. +/// `TheirChannelReady` and `OurChannelReady` then get set on `FundingSent`, and when both are set we +/// move on to `ChannelReady`. +/// Note that `PeerDisconnected` can be set on both `ChannelReady` and `FundingSent`. +/// `ChannelReady` can then get all remaining flags set on it, until we finish shutdown, then we +/// move on to `ShutdownComplete`, at which point most calls into this channel are disallowed. enum ChannelState { /// Implies we have (or are prepared to) send our open_channel/accept_channel message OurInitSent = 1 << 0, - /// Implies we have received their open_channel/accept_channel message + /// Implies we have received their `open_channel`/`accept_channel` message TheirInitSent = 1 << 1, - /// We have sent funding_created and are awaiting a funding_signed to advance to FundingSent. - /// Note that this is nonsense for an inbound channel as we immediately generate funding_signed - /// upon receipt of funding_created, so simply skip this state. + /// We have sent `funding_created` and are awaiting a `funding_signed` to advance to `FundingSent`. + /// Note that this is nonsense for an inbound channel as we immediately generate `funding_signed` + /// upon receipt of `funding_created`, so simply skip this state. FundingCreated = 4, - /// Set when we have received/sent funding_created and funding_signed and are thus now waiting - /// on the funding transaction to confirm. The ChannelReady flags are set to indicate when we + /// Set when we have received/sent `funding_created` and `funding_signed` and are thus now waiting + /// on the funding transaction to confirm. The `ChannelReady` flags are set to indicate when we /// and our counterparty consider the funding transaction confirmed. FundingSent = 8, - /// Flag which can be set on FundingSent to indicate they sent us a channel_ready message. - /// Once both TheirChannelReady and OurChannelReady are set, state moves on to ChannelReady. + /// Flag which can be set on `FundingSent` to indicate they sent us a `channel_ready` message. + /// Once both `TheirChannelReady` and `OurChannelReady` are set, state moves on to `ChannelReady`. TheirChannelReady = 1 << 4, - /// Flag which can be set on FundingSent to indicate we sent them a channel_ready message. - /// Once both TheirChannelReady and OurChannelReady are set, state moves on to ChannelReady. + /// Flag which can be set on `FundingSent` to indicate we sent them a `channel_ready` message. + /// Once both `TheirChannelReady` and `OurChannelReady` are set, state moves on to `ChannelReady`. OurChannelReady = 1 << 5, ChannelReady = 64, - /// Flag which is set on ChannelReady and FundingSent indicating remote side is considered - /// "disconnected" and no updates are allowed until after we've done a channel_reestablish + /// Flag which is set on `ChannelReady` and `FundingSent` indicating remote side is considered + /// "disconnected" and no updates are allowed until after we've done a `channel_reestablish` /// dance. PeerDisconnected = 1 << 7, - /// Flag which is set on ChannelReady, FundingCreated, and FundingSent indicating the user has - /// told us a ChannelMonitor update is pending async persistence somewhere and we should pause + /// Flag which is set on `ChannelReady`, FundingCreated, and `FundingSent` indicating the user has + /// told us a `ChannelMonitor` update is pending async persistence somewhere and we should pause /// sending any outbound messages until they've managed to finish. MonitorUpdateInProgress = 1 << 8, /// Flag which implies that we have sent a commitment_signed but are awaiting the responding @@ -289,13 +287,13 @@ enum ChannelState { /// messages as then we will be unable to determine which HTLCs they included in their /// revoke_and_ack implicit ACK, so instead we have to hold them away temporarily to be sent /// later. - /// Flag is set on ChannelReady. + /// Flag is set on `ChannelReady`. AwaitingRemoteRevoke = 1 << 9, - /// Flag which is set on ChannelReady or FundingSent after receiving a shutdown message from + /// Flag which is set on `ChannelReady` or `FundingSent` after receiving a shutdown message from /// the remote end. If set, they may not add any new HTLCs to the channel, and we are expected /// to respond with our own shutdown message when possible. RemoteShutdownSent = 1 << 10, - /// Flag which is set on ChannelReady or FundingSent after sending a shutdown message. At this + /// Flag which is set on `ChannelReady` or `FundingSent` after sending a shutdown message. At this /// point, we may not add any new HTLCs to the channel. LocalShutdownSent = 1 << 11, /// We've successfully negotiated a closing_signed dance. At this point ChannelManager is about @@ -740,19 +738,6 @@ pub(super) struct ChannelContext { #[cfg(not(test))] closing_fee_limits: Option<(u64, u64)>, - /// Flag that ensures that `accept_inbound_channel` must be called before `funding_created` - /// is executed successfully. The reason for this flag is that when the - /// `UserConfig::manually_accept_inbound_channels` config flag is set to true, inbound channels - /// are required to be manually accepted by the node operator before the `msgs::AcceptChannel` - /// message is created and sent out. During the manual accept process, `accept_inbound_channel` - /// is called by `ChannelManager::accept_inbound_channel`. - /// - /// The flag counteracts that a counterparty node could theoretically send a - /// `msgs::FundingCreated` message before the node operator has manually accepted an inbound - /// channel request made by the counterparty node. That would execute `funding_created` before - /// `accept_inbound_channel`, and `funding_created` should therefore not execute successfully. - inbound_awaiting_accept: bool, - /// The hash of the block in which the funding transaction was included. funding_tx_confirmed_in: Option, funding_tx_confirmation_height: u32, @@ -997,9 +982,9 @@ impl ChannelContext { &self.channel_type } - /// Guaranteed to be Some after both ChannelReady messages have been exchanged (and, thus, - /// is_usable() returns true). - /// Allowed in any state (including after shutdown) + /// Gets the channel's `short_channel_id`. + /// + /// Will return `None` if the channel hasn't been confirmed yet. pub fn get_short_channel_id(&self) -> Option { self.short_channel_id } @@ -1611,14 +1596,6 @@ impl ChannelContext { let inbound_stats = context.get_inbound_pending_htlc_stats(None); let outbound_stats = context.get_outbound_pending_htlc_stats(None); - let mut balance_msat = context.value_to_self_msat; - for ref htlc in context.pending_inbound_htlcs.iter() { - if let InboundHTLCState::LocalRemoved(InboundHTLCRemovalReason::Fulfill(_)) = htlc.state { - balance_msat += htlc.amount_msat; - } - } - balance_msat -= outbound_stats.pending_htlcs_value_msat; - let outbound_capacity_msat = context.value_to_self_msat .saturating_sub(outbound_stats.pending_htlcs_value_msat) .saturating_sub( @@ -1735,7 +1712,6 @@ impl ChannelContext { outbound_capacity_msat, next_outbound_htlc_limit_msat: available_capacity_msat, next_outbound_htlc_minimum_msat, - balance_msat, } } @@ -3119,9 +3095,9 @@ impl Channel { let mut htlc_updates = Vec::new(); mem::swap(&mut htlc_updates, &mut self.context.holding_cell_htlc_updates); - let mut update_add_htlcs = Vec::with_capacity(htlc_updates.len()); - let mut update_fulfill_htlcs = Vec::with_capacity(htlc_updates.len()); - let mut update_fail_htlcs = Vec::with_capacity(htlc_updates.len()); + let mut update_add_count = 0; + let mut update_fulfill_count = 0; + let mut update_fail_count = 0; let mut htlcs_to_fail = Vec::new(); for htlc_update in htlc_updates.drain(..) { // Note that this *can* fail, though it should be due to rather-rare conditions on @@ -3137,7 +3113,7 @@ impl Channel { match self.send_htlc(amount_msat, *payment_hash, cltv_expiry, source.clone(), onion_routing_packet.clone(), false, skimmed_fee_msat, fee_estimator, logger) { - Ok(update_add_msg_option) => update_add_htlcs.push(update_add_msg_option.unwrap()), + Ok(_) => update_add_count += 1, Err(e) => { match e { ChannelError::Ignore(ref msg) => { @@ -3164,11 +3140,11 @@ impl Channel { // not fail - any in between attempts to claim the HTLC will have resulted // in it hitting the holding cell again and we cannot change the state of a // holding cell HTLC from fulfill to anything else. - let (update_fulfill_msg_option, mut additional_monitor_update) = - if let UpdateFulfillFetch::NewClaim { msg, monitor_update, .. } = self.get_update_fulfill_htlc(htlc_id, *payment_preimage, logger) { - (msg, monitor_update) - } else { unreachable!() }; - update_fulfill_htlcs.push(update_fulfill_msg_option.unwrap()); + let mut additional_monitor_update = + if let UpdateFulfillFetch::NewClaim { monitor_update, .. } = + self.get_update_fulfill_htlc(htlc_id, *payment_preimage, logger) + { monitor_update } else { unreachable!() }; + update_fulfill_count += 1; monitor_update.updates.append(&mut additional_monitor_update.updates); }, &HTLCUpdateAwaitingACK::FailHTLC { htlc_id, ref err_packet } => { @@ -3179,7 +3155,8 @@ impl Channel { // not fail - we should never end up in a state where we double-fail // an HTLC or fail-then-claim an HTLC as it indicates we didn't wait // for a full revocation before failing. - update_fail_htlcs.push(update_fail_msg_option.unwrap()) + debug_assert!(update_fail_msg_option.is_some()); + update_fail_count += 1; }, Err(e) => { if let ChannelError::Ignore(_) = e {} @@ -3191,7 +3168,7 @@ impl Channel { }, } } - if update_add_htlcs.is_empty() && update_fulfill_htlcs.is_empty() && update_fail_htlcs.is_empty() && self.context.holding_cell_update_fee.is_none() { + if update_add_count == 0 && update_fulfill_count == 0 && update_fail_count == 0 && self.context.holding_cell_update_fee.is_none() { return (None, htlcs_to_fail); } let update_fee = if let Some(feerate) = self.context.holding_cell_update_fee.take() { @@ -3208,7 +3185,7 @@ impl Channel { log_debug!(logger, "Freeing holding cell in channel {} resulted in {}{} HTLCs added, {} HTLCs fulfilled, and {} HTLCs failed.", log_bytes!(self.context.channel_id()), if update_fee.is_some() { "a fee update, " } else { "" }, - update_add_htlcs.len(), update_fulfill_htlcs.len(), update_fail_htlcs.len()); + update_add_count, update_fulfill_count, update_fail_count); self.monitor_updating_paused(false, true, false, Vec::new(), Vec::new(), Vec::new()); (self.push_ret_blockable_mon_update(monitor_update), htlcs_to_fail) @@ -4869,7 +4846,7 @@ impl Channel { // something in the handler for the message that prompted this message): /// Gets an UnsignedChannelAnnouncement for this channel. The channel must be publicly - /// announceable and available for use (have exchanged ChannelReady messages in both + /// announceable and available for use (have exchanged [`ChannelReady`] messages in both /// directions). Should be used for both broadcasted announcements and in response to an /// AnnouncementSignatures message from the remote peer. /// @@ -4877,6 +4854,8 @@ impl Channel { /// closing). /// /// This will only return ChannelError::Ignore upon failure. + /// + /// [`ChannelReady`]: crate::ln::msgs::ChannelReady fn get_channel_announcement( &self, node_signer: &NS, chain_hash: BlockHash, user_config: &UserConfig, ) -> Result where NS::Target: NodeSigner { @@ -4887,6 +4866,8 @@ impl Channel { return Err(ChannelError::Ignore("Cannot get a ChannelAnnouncement if the channel is not currently usable".to_owned())); } + let short_channel_id = self.context.get_short_channel_id() + .ok_or(ChannelError::Ignore("Cannot get a ChannelAnnouncement if the channel has not been confirmed yet".to_owned()))?; let node_id = NodeId::from_pubkey(&node_signer.get_node_id(Recipient::Node) .map_err(|_| ChannelError::Ignore("Failed to retrieve own public key".to_owned()))?); let counterparty_node_id = NodeId::from_pubkey(&self.context.get_counterparty_node_id()); @@ -4895,7 +4876,7 @@ impl Channel { let msg = msgs::UnsignedChannelAnnouncement { features: channelmanager::provided_channel_features(&user_config), chain_hash, - short_channel_id: self.context.get_short_channel_id().unwrap(), + short_channel_id, node_id_1: if were_node_one { node_id } else { counterparty_node_id }, node_id_2: if were_node_one { counterparty_node_id } else { node_id }, bitcoin_key_1: NodeId::from_pubkey(if were_node_one { &self.context.get_holder_pubkeys().funding_pubkey } else { self.context.counterparty_funding_pubkey() }), @@ -4953,11 +4934,16 @@ impl Channel { }, Ok(v) => v }; + let short_channel_id = match self.context.get_short_channel_id() { + Some(scid) => scid, + None => return None, + }; + self.context.announcement_sigs_state = AnnouncementSigsState::MessageSent; Some(msgs::AnnouncementSignatures { channel_id: self.context.channel_id(), - short_channel_id: self.context.get_short_channel_id().unwrap(), + short_channel_id, node_signature: our_node_sig, bitcoin_signature: our_bitcoin_sig, }) @@ -5640,8 +5626,6 @@ impl OutboundV1Channel { closing_fee_limits: None, target_closing_feerate_sats_per_kw: None, - inbound_awaiting_accept: false, - funding_tx_confirmed_in: None, funding_tx_confirmation_height: 0, short_channel_id: None, @@ -6022,7 +6006,7 @@ impl InboundV1Channel { fee_estimator: &LowerBoundedFeeEstimator, entropy_source: &ES, signer_provider: &SP, counterparty_node_id: PublicKey, our_supported_features: &ChannelTypeFeatures, their_features: &InitFeatures, msg: &msgs::OpenChannel, user_id: u128, config: &UserConfig, - current_chain_height: u32, logger: &L, outbound_scid_alias: u64 + current_chain_height: u32, logger: &L, outbound_scid_alias: u64, is_0conf: bool, ) -> Result, ChannelError> where ES::Target: EntropySource, SP::Target: SignerProvider, @@ -6212,6 +6196,12 @@ impl InboundV1Channel { let mut secp_ctx = Secp256k1::new(); secp_ctx.seeded_randomize(&entropy_source.get_secure_random_bytes()); + let minimum_depth = if is_0conf { + Some(0) + } else { + Some(cmp::max(config.channel_handshake_config.minimum_depth, 1)) + }; + let chan = Self { context: ChannelContext { user_id, @@ -6270,8 +6260,6 @@ impl InboundV1Channel { closing_fee_limits: None, target_closing_feerate_sats_per_kw: None, - inbound_awaiting_accept: true, - funding_tx_confirmed_in: None, funding_tx_confirmation_height: 0, short_channel_id: None, @@ -6289,7 +6277,7 @@ impl InboundV1Channel { holder_htlc_minimum_msat: if config.channel_handshake_config.our_htlc_minimum_msat == 0 { 1 } else { config.channel_handshake_config.our_htlc_minimum_msat }, counterparty_max_accepted_htlcs: msg.max_accepted_htlcs, holder_max_accepted_htlcs: cmp::min(config.channel_handshake_config.our_max_accepted_htlcs, MAX_HTLCS), - minimum_depth: Some(cmp::max(config.channel_handshake_config.minimum_depth, 1)), + minimum_depth, counterparty_forwarding_info: None, @@ -6347,21 +6335,11 @@ impl InboundV1Channel { Ok(chan) } - pub fn is_awaiting_accept(&self) -> bool { - self.context.inbound_awaiting_accept - } - - /// Sets this channel to accepting 0conf, must be done before `get_accept_channel` - pub fn set_0conf(&mut self) { - assert!(self.context.inbound_awaiting_accept); - self.context.minimum_depth = Some(0); - } - /// Marks an inbound channel as accepted and generates a [`msgs::AcceptChannel`] message which /// should be sent back to the counterparty node. /// /// [`msgs::AcceptChannel`]: crate::ln::msgs::AcceptChannel - pub fn accept_inbound_channel(&mut self, user_id: u128) -> msgs::AcceptChannel { + pub fn accept_inbound_channel(&mut self) -> msgs::AcceptChannel { if self.context.is_outbound() { panic!("Tried to send accept_channel for an outbound channel?"); } @@ -6371,12 +6349,6 @@ impl InboundV1Channel { if self.context.cur_holder_commitment_transaction_number != INITIAL_COMMITMENT_NUMBER { panic!("Tried to send an accept_channel for a channel that has already advanced"); } - if !self.context.inbound_awaiting_accept { - panic!("The inbound channel has already been accepted"); - } - - self.context.user_id = user_id; - self.context.inbound_awaiting_accept = false; self.generate_accept_channel_message() } @@ -6472,9 +6444,6 @@ impl InboundV1Channel { // channel. return Err((self, ChannelError::Close("Received funding_created after we got the channel!".to_owned()))); } - if self.context.inbound_awaiting_accept { - return Err((self, ChannelError::Close("FundingCreated message received before the channel was accepted".to_owned()))); - } if self.context.commitment_secrets.get_min_seen_secret() != (1 << 48) || self.context.cur_counterparty_commitment_transaction_number != INITIAL_COMMITMENT_NUMBER || self.context.cur_holder_commitment_transaction_number != INITIAL_COMMITMENT_NUMBER { @@ -7374,8 +7343,6 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch closing_fee_limits: None, target_closing_feerate_sats_per_kw, - inbound_awaiting_accept: false, - funding_tx_confirmed_in, funding_tx_confirmation_height, short_channel_id, @@ -7615,10 +7582,10 @@ mod tests { // Make sure A's dust limit is as we expect. let open_channel_msg = node_a_chan.get_open_channel(genesis_block(network).header.block_hash()); let node_b_node_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[7; 32]).unwrap()); - let mut node_b_chan = InboundV1Channel::::new(&feeest, &&keys_provider, &&keys_provider, node_b_node_id, &channelmanager::provided_channel_type_features(&config), &channelmanager::provided_init_features(&config), &open_channel_msg, 7, &config, 0, &&logger, 42).unwrap(); + let mut node_b_chan = InboundV1Channel::::new(&feeest, &&keys_provider, &&keys_provider, node_b_node_id, &channelmanager::provided_channel_type_features(&config), &channelmanager::provided_init_features(&config), &open_channel_msg, 7, &config, 0, &&logger, 42, /*is_0conf=*/false).unwrap(); // Node B --> Node A: accept channel, explicitly setting B's dust limit. - let mut accept_channel_msg = node_b_chan.accept_inbound_channel(0); + let mut accept_channel_msg = node_b_chan.accept_inbound_channel(); accept_channel_msg.dust_limit_satoshis = 546; node_a_chan.accept_channel(&accept_channel_msg, &config.channel_handshake_limits, &channelmanager::provided_init_features(&config)).unwrap(); node_a_chan.context.holder_dust_limit_satoshis = 1560; @@ -7744,10 +7711,10 @@ mod tests { // Create Node B's channel by receiving Node A's open_channel message let open_channel_msg = node_a_chan.get_open_channel(chain_hash); let node_b_node_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[7; 32]).unwrap()); - let mut node_b_chan = InboundV1Channel::::new(&feeest, &&keys_provider, &&keys_provider, node_b_node_id, &channelmanager::provided_channel_type_features(&config), &channelmanager::provided_init_features(&config), &open_channel_msg, 7, &config, 0, &&logger, 42).unwrap(); + let mut node_b_chan = InboundV1Channel::::new(&feeest, &&keys_provider, &&keys_provider, node_b_node_id, &channelmanager::provided_channel_type_features(&config), &channelmanager::provided_init_features(&config), &open_channel_msg, 7, &config, 0, &&logger, 42, /*is_0conf=*/false).unwrap(); // Node B --> Node A: accept channel - let accept_channel_msg = node_b_chan.accept_inbound_channel(0); + let accept_channel_msg = node_b_chan.accept_inbound_channel(); node_a_chan.accept_channel(&accept_channel_msg, &config.channel_handshake_limits, &channelmanager::provided_init_features(&config)).unwrap(); // Node A --> Node B: funding created @@ -7816,12 +7783,12 @@ mod tests { // Test that `InboundV1Channel::new` creates a channel with the correct value for // `holder_max_htlc_value_in_flight_msat`, when configured with a valid percentage value, // which is set to the lower bound - 1 (2%) of the `channel_value`. - let chan_3 = InboundV1Channel::::new(&feeest, &&keys_provider, &&keys_provider, inbound_node_id, &channelmanager::provided_channel_type_features(&config_2_percent), &channelmanager::provided_init_features(&config_2_percent), &chan_1_open_channel_msg, 7, &config_2_percent, 0, &&logger, 42).unwrap(); + let chan_3 = InboundV1Channel::::new(&feeest, &&keys_provider, &&keys_provider, inbound_node_id, &channelmanager::provided_channel_type_features(&config_2_percent), &channelmanager::provided_init_features(&config_2_percent), &chan_1_open_channel_msg, 7, &config_2_percent, 0, &&logger, 42, /*is_0conf=*/false).unwrap(); let chan_3_value_msat = chan_3.context.channel_value_satoshis * 1000; assert_eq!(chan_3.context.holder_max_htlc_value_in_flight_msat, (chan_3_value_msat as f64 * 0.02) as u64); // Test with the upper bound - 1 of valid values (99%). - let chan_4 = InboundV1Channel::::new(&feeest, &&keys_provider, &&keys_provider, inbound_node_id, &channelmanager::provided_channel_type_features(&config_99_percent), &channelmanager::provided_init_features(&config_99_percent), &chan_1_open_channel_msg, 7, &config_99_percent, 0, &&logger, 42).unwrap(); + let chan_4 = InboundV1Channel::::new(&feeest, &&keys_provider, &&keys_provider, inbound_node_id, &channelmanager::provided_channel_type_features(&config_99_percent), &channelmanager::provided_init_features(&config_99_percent), &chan_1_open_channel_msg, 7, &config_99_percent, 0, &&logger, 42, /*is_0conf=*/false).unwrap(); let chan_4_value_msat = chan_4.context.channel_value_satoshis * 1000; assert_eq!(chan_4.context.holder_max_htlc_value_in_flight_msat, (chan_4_value_msat as f64 * 0.99) as u64); @@ -7840,14 +7807,14 @@ mod tests { // Test that `InboundV1Channel::new` uses the lower bound of the configurable percentage values (1%) // if `max_inbound_htlc_value_in_flight_percent_of_channel` is set to a value less than 1. - let chan_7 = InboundV1Channel::::new(&feeest, &&keys_provider, &&keys_provider, inbound_node_id, &channelmanager::provided_channel_type_features(&config_0_percent), &channelmanager::provided_init_features(&config_0_percent), &chan_1_open_channel_msg, 7, &config_0_percent, 0, &&logger, 42).unwrap(); + let chan_7 = InboundV1Channel::::new(&feeest, &&keys_provider, &&keys_provider, inbound_node_id, &channelmanager::provided_channel_type_features(&config_0_percent), &channelmanager::provided_init_features(&config_0_percent), &chan_1_open_channel_msg, 7, &config_0_percent, 0, &&logger, 42, /*is_0conf=*/false).unwrap(); let chan_7_value_msat = chan_7.context.channel_value_satoshis * 1000; assert_eq!(chan_7.context.holder_max_htlc_value_in_flight_msat, (chan_7_value_msat as f64 * 0.01) as u64); // Test that `InboundV1Channel::new` uses the upper bound of the configurable percentage values // (100%) if `max_inbound_htlc_value_in_flight_percent_of_channel` is set to a larger value // than 100. - let chan_8 = InboundV1Channel::::new(&feeest, &&keys_provider, &&keys_provider, inbound_node_id, &channelmanager::provided_channel_type_features(&config_101_percent), &channelmanager::provided_init_features(&config_101_percent), &chan_1_open_channel_msg, 7, &config_101_percent, 0, &&logger, 42).unwrap(); + let chan_8 = InboundV1Channel::::new(&feeest, &&keys_provider, &&keys_provider, inbound_node_id, &channelmanager::provided_channel_type_features(&config_101_percent), &channelmanager::provided_init_features(&config_101_percent), &chan_1_open_channel_msg, 7, &config_101_percent, 0, &&logger, 42, /*is_0conf=*/false).unwrap(); let chan_8_value_msat = chan_8.context.channel_value_satoshis * 1000; assert_eq!(chan_8.context.holder_max_htlc_value_in_flight_msat, chan_8_value_msat); } @@ -7897,7 +7864,7 @@ mod tests { inbound_node_config.channel_handshake_config.their_channel_reserve_proportional_millionths = (inbound_selected_channel_reserve_perc * 1_000_000.0) as u32; if outbound_selected_channel_reserve_perc + inbound_selected_channel_reserve_perc < 1.0 { - let chan_inbound_node = InboundV1Channel::::new(&&fee_est, &&keys_provider, &&keys_provider, inbound_node_id, &channelmanager::provided_channel_type_features(&inbound_node_config), &channelmanager::provided_init_features(&outbound_node_config), &chan_open_channel_msg, 7, &inbound_node_config, 0, &&logger, 42).unwrap(); + let chan_inbound_node = InboundV1Channel::::new(&&fee_est, &&keys_provider, &&keys_provider, inbound_node_id, &channelmanager::provided_channel_type_features(&inbound_node_config), &channelmanager::provided_init_features(&outbound_node_config), &chan_open_channel_msg, 7, &inbound_node_config, 0, &&logger, 42, /*is_0conf=*/false).unwrap(); let expected_inbound_selected_chan_reserve = cmp::max(MIN_THEIR_CHAN_RESERVE_SATOSHIS, (chan.context.channel_value_satoshis as f64 * inbound_selected_channel_reserve_perc) as u64); @@ -7905,7 +7872,7 @@ mod tests { assert_eq!(chan_inbound_node.context.counterparty_selected_channel_reserve_satoshis.unwrap(), expected_outbound_selected_chan_reserve); } else { // Channel Negotiations failed - let result = InboundV1Channel::::new(&&fee_est, &&keys_provider, &&keys_provider, inbound_node_id, &channelmanager::provided_channel_type_features(&inbound_node_config), &channelmanager::provided_init_features(&outbound_node_config), &chan_open_channel_msg, 7, &inbound_node_config, 0, &&logger, 42); + let result = InboundV1Channel::::new(&&fee_est, &&keys_provider, &&keys_provider, inbound_node_id, &channelmanager::provided_channel_type_features(&inbound_node_config), &channelmanager::provided_init_features(&outbound_node_config), &chan_open_channel_msg, 7, &inbound_node_config, 0, &&logger, 42, /*is_0conf=*/false); assert!(result.is_err()); } } @@ -7930,10 +7897,10 @@ mod tests { // Make sure A's dust limit is as we expect. let open_channel_msg = node_a_chan.get_open_channel(genesis_block(network).header.block_hash()); let node_b_node_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[7; 32]).unwrap()); - let mut node_b_chan = InboundV1Channel::::new(&feeest, &&keys_provider, &&keys_provider, node_b_node_id, &channelmanager::provided_channel_type_features(&config), &channelmanager::provided_init_features(&config), &open_channel_msg, 7, &config, 0, &&logger, 42).unwrap(); + let mut node_b_chan = InboundV1Channel::::new(&feeest, &&keys_provider, &&keys_provider, node_b_node_id, &channelmanager::provided_channel_type_features(&config), &channelmanager::provided_init_features(&config), &open_channel_msg, 7, &config, 0, &&logger, 42, /*is_0conf=*/false).unwrap(); // Node B --> Node A: accept channel, explicitly setting B's dust limit. - let mut accept_channel_msg = node_b_chan.accept_inbound_channel(0); + let mut accept_channel_msg = node_b_chan.accept_inbound_channel(); accept_channel_msg.dust_limit_satoshis = 546; node_a_chan.accept_channel(&accept_channel_msg, &config.channel_handshake_limits, &channelmanager::provided_init_features(&config)).unwrap(); node_a_chan.context.holder_dust_limit_satoshis = 1560; @@ -8768,7 +8735,7 @@ mod tests { let node_b_node_id = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[7; 32]).unwrap()); let res = InboundV1Channel::::new(&feeest, &&keys_provider, &&keys_provider, node_b_node_id, &channelmanager::provided_channel_type_features(&config), - &channelmanager::provided_init_features(&config), &open_channel_msg, 7, &config, 0, &&logger, 42); + &channelmanager::provided_init_features(&config), &open_channel_msg, 7, &config, 0, &&logger, 42, /*is_0conf=*/false); assert!(res.is_ok()); } @@ -8810,7 +8777,7 @@ mod tests { let channel_b = InboundV1Channel::::new( &fee_estimator, &&keys_provider, &&keys_provider, node_id_a, &channelmanager::provided_channel_type_features(&config), &channelmanager::provided_init_features(&config), - &open_channel_msg, 7, &config, 0, &&logger, 42 + &open_channel_msg, 7, &config, 0, &&logger, 42, /*is_0conf=*/false ).unwrap(); assert_eq!(channel_a.context.channel_type, expected_channel_type); @@ -8852,7 +8819,7 @@ mod tests { let channel_b = InboundV1Channel::::new( &fee_estimator, &&keys_provider, &&keys_provider, node_id_a, &channelmanager::provided_channel_type_features(&config), &init_features_with_simple_anchors, - &open_channel_msg, 7, &config, 0, &&logger, 42 + &open_channel_msg, 7, &config, 0, &&logger, 42, /*is_0conf=*/false ); assert!(channel_b.is_err()); } @@ -8895,7 +8862,7 @@ mod tests { let res = InboundV1Channel::::new( &fee_estimator, &&keys_provider, &&keys_provider, node_id_a, &channelmanager::provided_channel_type_features(&config), &simple_anchors_init, - &open_channel_msg, 7, &config, 0, &&logger, 42 + &open_channel_msg, 7, &config, 0, &&logger, 42, /*is_0conf=*/false ); assert!(res.is_err()); @@ -8913,7 +8880,7 @@ mod tests { let channel_b = InboundV1Channel::::new( &fee_estimator, &&keys_provider, &&keys_provider, node_id_a, &channelmanager::provided_channel_type_features(&config), &channelmanager::provided_init_features(&config), - &open_channel_msg, 7, &config, 0, &&logger, 42 + &open_channel_msg, 7, &config, 0, &&logger, 42, /*is_0conf=*/false ).unwrap(); let mut accept_channel_msg = channel_b.get_accept_channel_message();