@@ -1541,66 +1541,64 @@ trait InitialRemoteCommitmentReceiver<SP: Deref> where SP::Target: SignerProvide
1541
1541
panic!("unexpected error type from check_counterparty_commitment_signature {:?}", e);
1542
1542
}
1543
1543
};
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;
1546
1547
let counterparty_trusted_tx = counterparty_initial_commitment_tx.trust();
1547
1548
let counterparty_initial_bitcoin_tx = counterparty_trusted_tx.built_transaction();
1548
1549
1549
1550
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));
1551
1552
1552
1553
let holder_commitment_tx = HolderCommitmentTransaction::new(
1553
1554
initial_commitment_tx,
1554
1555
counterparty_signature,
1555
1556
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()
1558
1559
);
1559
1560
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() {
1561
1562
return Err(ChannelError::close("Failed to validate our commitment".to_owned()));
1562
1563
}
1563
1564
1564
1565
// Now that we're past error-generating stuff, update our local state:
1565
1566
1566
- self.context_mut() .channel_id = channel_id;
1567
+ context .channel_id = channel_id;
1567
1568
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);
1571
1572
} else {
1572
- self.context_mut() .channel_state = ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new());
1573
+ context .channel_state = ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new());
1573
1574
}
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()));
1584
1582
}
1585
1583
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();
1588
1586
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,
1598
1596
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());
1600
1598
channel_monitor.provide_initial_counterparty_commitment_tx(
1601
1599
counterparty_txid, Vec::new(),
1602
1600
counterparty_commitment_number,
1603
- self. context() .counterparty_cur_commitment_point.unwrap(),
1601
+ context.counterparty_cur_commitment_point.unwrap(),
1604
1602
counterparty_initial_commitment_tx.feerate_per_kw(),
1605
1603
counterparty_initial_commitment_tx.to_broadcaster_value_sat(),
1606
1604
counterparty_initial_commitment_tx.to_countersignatory_value_sat(),
@@ -8012,7 +8010,8 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
8012
8010
self.context.channel_id(),
8013
8011
msg.signature, counterparty_initial_bitcoin_tx.txid,
8014
8012
self.context.cur_counterparty_commitment_transaction_number,
8015
- best_block, signer_provider, logger) {
8013
+ best_block, signer_provider, logger
8014
+ ) {
8016
8015
Ok(channel_monitor) => channel_monitor,
8017
8016
Err(err) => return Err((self, err)),
8018
8017
};
@@ -8242,7 +8241,8 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
8242
8241
ChannelId::v1_from_funding_outpoint(funding_txo),
8243
8242
msg.signature, counterparty_initial_commitment_tx.trust().txid(),
8244
8243
self.context.cur_counterparty_commitment_transaction_number + 1,
8245
- best_block, signer_provider, logger) {
8244
+ best_block, signer_provider, logger
8245
+ ) {
8246
8246
Ok(channel_monitor) => channel_monitor,
8247
8247
Err(err) => return Err((self, err)),
8248
8248
};
0 commit comments