@@ -13946,7 +13946,7 @@ where
1394613946 pub funding: FundingScope,
1394713947 pub context: ChannelContext<SP>,
1394813948 pub unfunded_context: UnfundedChannelContext,
13949- pub funding_negotiation_context: FundingNegotiationContext,
13949+ pub funding_negotiation_context: Option< FundingNegotiationContext> ,
1395013950 /// The current interactive transaction construction session under negotiation.
1395113951 pub interactive_tx_constructor: Option<InteractiveTxConstructor>,
1395213952}
@@ -14021,7 +14021,7 @@ where
1402114021 funding,
1402214022 context,
1402314023 unfunded_context,
14024- funding_negotiation_context,
14024+ funding_negotiation_context: Some(funding_negotiation_context) ,
1402514025 interactive_tx_constructor: None,
1402614026 };
1402714027 Ok(chan)
@@ -14096,29 +14096,28 @@ where
1409614096 },
1409714097 funding_feerate_sat_per_1000_weight: self.context.feerate_per_kw,
1409814098 second_per_commitment_point,
14099- locktime: self.funding_negotiation_context. funding_tx_locktime.to_consensus_u32(),
14099+ locktime: self.funding_tx_locktime() .to_consensus_u32(),
1410014100 require_confirmed_inputs: None,
1410114101 }
1410214102 }
1410314103
1410414104 /// Creates a new dual-funded channel from a remote side's request for one.
1410514105 /// Assumes chain_hash has already been checked and corresponds with what we expect!
14106- /// TODO(dual_funding): Allow contributions, pass intended amount and inputs
1410714106 #[allow(dead_code)] // TODO(dual_funding): Remove once V2 channels is enabled.
1410814107 #[rustfmt::skip]
1410914108 pub fn new_inbound<ES: Deref, F: Deref, L: Deref>(
1411014109 fee_estimator: &LowerBoundedFeeEstimator<F>, entropy_source: &ES, signer_provider: &SP,
1411114110 holder_node_id: PublicKey, counterparty_node_id: PublicKey, our_supported_features: &ChannelTypeFeatures,
14112- their_features: &InitFeatures, msg: &msgs::OpenChannelV2,
14113- user_id: u128, config: &UserConfig, current_chain_height: u32, logger: &L,
14111+ their_features: &InitFeatures, msg: &msgs::OpenChannelV2, user_id: u128, config: &UserConfig,
14112+ current_chain_height: u32, logger: &L, our_funding_contribution: Amount,
14113+ our_funding_inputs: Vec<FundingTxInput>,
1411414114 ) -> Result<Self, ChannelError>
1411514115 where ES::Target: EntropySource,
1411614116 F::Target: FeeEstimator,
1411714117 L::Target: Logger,
1411814118 {
14119- // TODO(dual_funding): Take these as input once supported
14120- let (our_funding_contribution, our_funding_contribution_sats) = (SignedAmount::ZERO, 0u64);
14121- let our_funding_inputs = Vec::new();
14119+ debug_assert!(our_funding_contribution <= Amount::MAX_MONEY);
14120+ let our_funding_contribution_sats = our_funding_contribution.to_sat();
1412214121
1412314122 let channel_value_satoshis =
1412414123 our_funding_contribution_sats.saturating_add(msg.common_fields.funding_satoshis);
@@ -14163,37 +14162,30 @@ where
1416314162
1416414163 let funding_negotiation_context = FundingNegotiationContext {
1416514164 is_initiator: false,
14166- our_funding_contribution,
14165+ our_funding_contribution: our_funding_contribution
14166+ .to_signed()
14167+ .expect("our_funding_contribution should not be greater than Amount::MAX_MONEY"),
1416714168 funding_tx_locktime: LockTime::from_consensus(msg.locktime),
1416814169 funding_feerate_sat_per_1000_weight: msg.funding_feerate_sat_per_1000_weight,
1416914170 shared_funding_input: None,
1417014171 our_funding_inputs: our_funding_inputs.clone(),
1417114172 our_funding_outputs: Vec::new(),
1417214173 change_script: None,
1417314174 };
14174- let shared_funding_output = TxOut {
14175- value: Amount::from_sat(funding.get_value_satoshis()),
14176- script_pubkey: funding.get_funding_redeemscript().to_p2wsh(),
14177- };
1417814175
14179- let interactive_tx_constructor = Some(InteractiveTxConstructor::new(
14180- InteractiveTxConstructorArgs {
14176+ let mut interactive_tx_constructor = funding_negotiation_context
14177+ .into_interactive_tx_constructor(
14178+ &context,
14179+ &funding,
14180+ signer_provider,
1418114181 entropy_source,
1418214182 holder_node_id,
14183- counterparty_node_id,
14184- channel_id: context.channel_id,
14185- feerate_sat_per_kw: funding_negotiation_context.funding_feerate_sat_per_1000_weight,
14186- funding_tx_locktime: funding_negotiation_context.funding_tx_locktime,
14187- is_initiator: false,
14188- inputs_to_contribute: our_funding_inputs,
14189- shared_funding_input: None,
14190- shared_funding_output: SharedOwnedOutput::new(shared_funding_output, our_funding_contribution_sats),
14191- outputs_to_contribute: funding_negotiation_context.our_funding_outputs.clone(),
14192- }
14193- ).map_err(|err| {
14194- let reason = ClosureReason::ProcessingError { err: err.reason.to_string() };
14195- ChannelError::Close((err.reason.to_string(), reason))
14196- })?);
14183+ )
14184+ .map_err(|err| {
14185+ let reason = ClosureReason::ProcessingError { err: err.reason.to_string() };
14186+ ChannelError::Close((err.reason.to_string(), reason))
14187+ })?;
14188+ debug_assert!(interactive_tx_constructor.take_initiator_first_message().is_none());
1419714189
1419814190 let unfunded_context = UnfundedChannelContext {
1419914191 unfunded_channel_age_ticks: 0,
@@ -14202,8 +14194,8 @@ where
1420214194 Ok(Self {
1420314195 funding,
1420414196 context,
14205- funding_negotiation_context,
14206- interactive_tx_constructor,
14197+ funding_negotiation_context: None ,
14198+ interactive_tx_constructor: Some(interactive_tx_constructor) ,
1420714199 unfunded_context,
1420814200 })
1420914201 }
@@ -14267,8 +14259,7 @@ where
1426714259 }),
1426814260 channel_type: Some(self.funding.get_channel_type().clone()),
1426914261 },
14270- funding_satoshis: self.funding_negotiation_context.our_funding_contribution.to_sat()
14271- as u64,
14262+ funding_satoshis: self.our_funding_contribution().to_sat(),
1427214263 second_per_commitment_point,
1427314264 require_confirmed_inputs: None,
1427414265 }
@@ -14283,6 +14274,24 @@ where
1428314274 pub fn get_accept_channel_v2_message(&self) -> msgs::AcceptChannelV2 {
1428414275 self.generate_accept_channel_v2_message()
1428514276 }
14277+
14278+ pub fn our_funding_contribution(&self) -> Amount {
14279+ Amount::from_sat(self.funding.value_to_self_msat / 1000)
14280+ }
14281+
14282+ pub fn funding_tx_locktime(&self) -> LockTime {
14283+ self.funding_negotiation_context
14284+ .as_ref()
14285+ .map(|context| context.funding_tx_locktime)
14286+ .or_else(|| {
14287+ self.interactive_tx_constructor
14288+ .as_ref()
14289+ .map(|constructor| constructor.funding_tx_locktime())
14290+ })
14291+ .expect(
14292+ "either funding_negotiation_context or interactive_tx_constructor should be set",
14293+ )
14294+ }
1428614295}
1428714296
1428814297// Unfunded channel utilities
0 commit comments