@@ -1541,66 +1541,64 @@ trait InitialRemoteCommitmentReceiver<SP: Deref> where SP::Target: SignerProvide
15411541 panic!("unexpected error type from check_counterparty_commitment_signature {:?}", e);
15421542 }
15431543 };
1544- let counterparty_keys = self.context().build_remote_transaction_keys();
1545- let counterparty_initial_commitment_tx = self.context().build_commitment_transaction(self.context().cur_counterparty_commitment_transaction_number, &counterparty_keys, false, false, logger).tx;
1544+ let context = self.context_mut();
1545+ let counterparty_keys = context.build_remote_transaction_keys();
1546+ let counterparty_initial_commitment_tx = context.build_commitment_transaction(context.cur_counterparty_commitment_transaction_number, &counterparty_keys, false, false, logger).tx;
15461547 let counterparty_trusted_tx = counterparty_initial_commitment_tx.trust();
15471548 let counterparty_initial_bitcoin_tx = counterparty_trusted_tx.built_transaction();
15481549
15491550 log_trace!(logger, "Initial counterparty tx for channel {} is: txid {} tx {}",
1550- &self. context() .channel_id(), counterparty_initial_bitcoin_tx.txid, encode::serialize_hex(&counterparty_initial_bitcoin_tx.transaction));
1551+ &context.channel_id(), counterparty_initial_bitcoin_tx.txid, encode::serialize_hex(&counterparty_initial_bitcoin_tx.transaction));
15511552
15521553 let holder_commitment_tx = HolderCommitmentTransaction::new(
15531554 initial_commitment_tx,
15541555 counterparty_signature,
15551556 Vec::new(),
1556- &self. context() .get_holder_pubkeys().funding_pubkey,
1557- self. context() .counterparty_funding_pubkey()
1557+ &context.get_holder_pubkeys().funding_pubkey,
1558+ context.counterparty_funding_pubkey()
15581559 );
15591560
1560- if self. context() .holder_signer.as_ref().validate_holder_commitment(&holder_commitment_tx, Vec::new()).is_err() {
1561+ if context.holder_signer.as_ref().validate_holder_commitment(&holder_commitment_tx, Vec::new()).is_err() {
15611562 return Err(ChannelError::close("Failed to validate our commitment".to_owned()));
15621563 }
15631564
15641565 // Now that we're past error-generating stuff, update our local state:
15651566
1566- self.context_mut() .channel_id = channel_id;
1567+ context .channel_id = channel_id;
15671568
1568- assert!(!self. context() .channel_state.is_monitor_update_in_progress()); // We have not had any monitor(s) yet to fail update!
1569- if self. context() .is_batch_funding() {
1570- self.context_mut() .channel_state = ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::WAITING_FOR_BATCH);
1569+ assert!(!context.channel_state.is_monitor_update_in_progress()); // We have not had any monitor(s) yet to fail update!
1570+ if context.is_batch_funding() {
1571+ context .channel_state = ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::WAITING_FOR_BATCH);
15711572 } else {
1572- self.context_mut() .channel_state = ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new());
1573+ context .channel_state = ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new());
15731574 }
1574- {
1575- let context = self.context_mut();
1576- if context.holder_commitment_point.advance(&context.holder_signer, &context.secp_ctx, logger).is_err() {
1577- // We only fail to advance our commitment point/number if we're currently
1578- // waiting for our signer to unblock and provide a commitment point.
1579- // We cannot send accept_channel/open_channel before this has occurred, so if we
1580- // err here by the time we receive funding_created/funding_signed, something has gone wrong.
1581- debug_assert!(false, "We should be ready to advance our commitment point by the time we receive {}", self.received_msg());
1582- return Err(ChannelError::close("Failed to advance holder commitment point".to_owned()));
1583- }
1575+ if context.holder_commitment_point.advance(&context.holder_signer, &context.secp_ctx, logger).is_err() {
1576+ // We only fail to advance our commitment point/number if we're currently
1577+ // waiting for our signer to unblock and provide a commitment point.
1578+ // We cannot send accept_channel/open_channel before this has occurred, so if we
1579+ // err here by the time we receive funding_created/funding_signed, something has gone wrong.
1580+ debug_assert!(false, "We should be ready to advance our commitment point by the time we receive {}", self.received_msg());
1581+ return Err(ChannelError::close("Failed to advance holder commitment point".to_owned()));
15841582 }
15851583
1586- let funding_redeemscript = self. context() .get_funding_redeemscript();
1587- let funding_txo = self. context() .get_funding_txo().unwrap();
1584+ let funding_redeemscript = context.get_funding_redeemscript();
1585+ let funding_txo = context.get_funding_txo().unwrap();
15881586 let funding_txo_script = funding_redeemscript.to_p2wsh();
1589- let obscure_factor = get_commitment_transaction_number_obscure_factor(&self. context() .get_holder_pubkeys().payment_point, &self. context() .get_counterparty_pubkeys().payment_point, self. context() .is_outbound());
1590- let shutdown_script = self. context() .shutdown_scriptpubkey.clone().map(|script| script.into_inner());
1591- let mut monitor_signer = signer_provider.derive_channel_signer(self. context() .channel_value_satoshis, self. context() .channel_keys_id);
1592- monitor_signer.provide_channel_parameters(&self. context() .channel_transaction_parameters);
1593- let channel_monitor = ChannelMonitor::new(self. context() .secp_ctx.clone(), monitor_signer,
1594- shutdown_script, self. context() .get_holder_selected_contest_delay(),
1595- &self. context() .destination_script, (funding_txo, funding_txo_script),
1596- &self. context() .channel_transaction_parameters, self. context() .is_outbound(),
1597- funding_redeemscript.clone(), self. context() .channel_value_satoshis,
1587+ let obscure_factor = get_commitment_transaction_number_obscure_factor(&context.get_holder_pubkeys().payment_point, &context.get_counterparty_pubkeys().payment_point, context.is_outbound());
1588+ let shutdown_script = context.shutdown_scriptpubkey.clone().map(|script| script.into_inner());
1589+ let mut monitor_signer = signer_provider.derive_channel_signer(context.channel_value_satoshis, context.channel_keys_id);
1590+ monitor_signer.provide_channel_parameters(&context.channel_transaction_parameters);
1591+ let channel_monitor = ChannelMonitor::new(context.secp_ctx.clone(), monitor_signer,
1592+ shutdown_script, context.get_holder_selected_contest_delay(),
1593+ &context.destination_script, (funding_txo, funding_txo_script),
1594+ &context.channel_transaction_parameters, context.is_outbound(),
1595+ funding_redeemscript.clone(), context.channel_value_satoshis,
15981596 obscure_factor,
1599- holder_commitment_tx, best_block, self. context() .counterparty_node_id, self. context() .channel_id());
1597+ holder_commitment_tx, best_block, context.counterparty_node_id, context.channel_id());
16001598 channel_monitor.provide_initial_counterparty_commitment_tx(
16011599 counterparty_txid, Vec::new(),
16021600 counterparty_commitment_number,
1603- self. context() .counterparty_cur_commitment_point.unwrap(),
1601+ context.counterparty_cur_commitment_point.unwrap(),
16041602 counterparty_initial_commitment_tx.feerate_per_kw(),
16051603 counterparty_initial_commitment_tx.to_broadcaster_value_sat(),
16061604 counterparty_initial_commitment_tx.to_countersignatory_value_sat(),
@@ -8012,7 +8010,8 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
80128010 self.context.channel_id(),
80138011 msg.signature, counterparty_initial_bitcoin_tx.txid,
80148012 self.context.cur_counterparty_commitment_transaction_number,
8015- best_block, signer_provider, logger) {
8013+ best_block, signer_provider, logger
8014+ ) {
80168015 Ok(channel_monitor) => channel_monitor,
80178016 Err(err) => return Err((self, err)),
80188017 };
@@ -8242,7 +8241,8 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
82428241 ChannelId::v1_from_funding_outpoint(funding_txo),
82438242 msg.signature, counterparty_initial_commitment_tx.trust().txid(),
82448243 self.context.cur_counterparty_commitment_transaction_number + 1,
8245- best_block, signer_provider, logger) {
8244+ best_block, signer_provider, logger
8245+ ) {
82468246 Ok(channel_monitor) => channel_monitor,
82478247 Err(err) => return Err((self, err)),
82488248 };
0 commit comments