@@ -1770,57 +1770,16 @@ trait InitialRemoteCommitmentReceiver<SP: Deref> where SP::Target: SignerProvide
17701770
17711771 fn received_msg(&self) -> &'static str;
17721772
1773- fn check_counterparty_commitment_signature<L: Deref>(
1774- &self, sig: &Signature, holder_commitment_point: &mut HolderCommitmentPoint, logger: &L
1775- ) -> Result<CommitmentTransaction, ChannelError> where L::Target: Logger {
1776- let funding_script = self.context().get_funding_redeemscript();
1777-
1778- let keys = self.context().build_holder_transaction_keys(holder_commitment_point.current_point());
1779- let initial_commitment_tx = self.context().build_commitment_transaction(holder_commitment_point.transaction_number(), &keys, true, false, logger).tx;
1780- let trusted_tx = initial_commitment_tx.trust();
1781- let initial_commitment_bitcoin_tx = trusted_tx.built_transaction();
1782- let sighash = initial_commitment_bitcoin_tx.get_sighash_all(&funding_script, self.context().channel_value_satoshis);
1783- // They sign the holder commitment transaction...
1784- log_trace!(logger, "Checking {} tx signature {} by key {} against tx {} (sighash {}) with redeemscript {} for channel {}.",
1785- self.received_msg(), log_bytes!(sig.serialize_compact()[..]), log_bytes!(self.context().counterparty_funding_pubkey().serialize()),
1786- encode::serialize_hex(&initial_commitment_bitcoin_tx.transaction), log_bytes!(sighash[..]),
1787- encode::serialize_hex(&funding_script), &self.context().channel_id());
1788- secp_check!(self.context().secp_ctx.verify_ecdsa(&sighash, sig, self.context().counterparty_funding_pubkey()), format!("Invalid {} signature from peer", self.received_msg()));
1789-
1790- Ok(initial_commitment_tx)
1791- }
1792-
17931773 fn initial_commitment_signed<L: Deref>(
17941774 &mut self, channel_id: ChannelId, counterparty_signature: Signature, holder_commitment_point: &mut HolderCommitmentPoint,
17951775 counterparty_commitment_number: u64, best_block: BestBlock, signer_provider: &SP, logger: &L,
17961776 ) -> Result<(ChannelMonitor<<SP::Target as SignerProvider>::EcdsaSigner>, CommitmentTransaction), ChannelError>
17971777 where
17981778 L::Target: Logger
17991779 {
1800- let initial_commitment_tx = match self.check_counterparty_commitment_signature(&counterparty_signature, holder_commitment_point, logger) {
1801- Ok(res) => res,
1802- Err(ChannelError::Close(e)) => {
1803- // TODO(dual_funding): Update for V2 established channels.
1804- if !self.context().is_outbound() {
1805- self.context_mut().channel_transaction_parameters.funding_outpoint = None;
1806- }
1807- return Err(ChannelError::Close(e));
1808- },
1809- Err(e) => {
1810- // The only error we know how to handle is ChannelError::Close, so we fall over here
1811- // to make sure we don't continue with an inconsistent state.
1812- panic!("unexpected error type from check_counterparty_commitment_signature {:?}", e);
1813- }
1814- };
1815- let context = self.context_mut();
1816- let counterparty_keys = context.build_remote_transaction_keys();
1817- let counterparty_initial_commitment_tx = context.build_commitment_transaction(context.cur_counterparty_commitment_transaction_number, &counterparty_keys, false, false, logger).tx;
1818- let counterparty_trusted_tx = counterparty_initial_commitment_tx.trust();
1819- let counterparty_initial_bitcoin_tx = counterparty_trusted_tx.built_transaction();
1820-
1821- log_trace!(logger, "Initial counterparty tx for channel {} is: txid {} tx {}",
1822- &context.channel_id(), counterparty_initial_bitcoin_tx.txid, encode::serialize_hex(&counterparty_initial_bitcoin_tx.transaction));
1823-
1780+ let context = self.context();
1781+ let keys = context.build_holder_transaction_keys(holder_commitment_point.current_point());
1782+ let initial_commitment_tx = context.build_commitment_transaction(holder_commitment_point.transaction_number(), &keys, true, false, logger).tx;
18241783 let holder_commitment_tx = HolderCommitmentTransaction::new(
18251784 initial_commitment_tx,
18261785 counterparty_signature,
@@ -1830,10 +1789,23 @@ trait InitialRemoteCommitmentReceiver<SP: Deref> where SP::Target: SignerProvide
18301789 );
18311790
18321791 if context.holder_signer.as_ref().validate_holder_commitment(&holder_commitment_tx, Vec::new(), &context.secp_ctx).is_err() {
1792+ // TODO(dual_funding): Update for V2 established channels.
1793+ if !self.context().is_outbound() {
1794+ self.context_mut().channel_transaction_parameters.funding_outpoint = None;
1795+ }
18331796 return Err(ChannelError::close("Failed to validate our commitment".to_owned()));
18341797 }
18351798
1799+ let counterparty_keys = context.build_remote_transaction_keys();
1800+ let counterparty_initial_commitment_tx = context.build_commitment_transaction(context.cur_counterparty_commitment_transaction_number, &counterparty_keys, false, false, logger).tx;
1801+ let counterparty_trusted_tx = counterparty_initial_commitment_tx.trust();
1802+ let counterparty_initial_bitcoin_tx = counterparty_trusted_tx.built_transaction();
1803+
1804+ log_trace!(logger, "Initial counterparty tx for channel {} is: txid {} tx {}",
1805+ &context.channel_id(), counterparty_initial_bitcoin_tx.txid, encode::serialize_hex(&counterparty_initial_bitcoin_tx.transaction));
1806+
18361807 // Now that we're past error-generating stuff, update our local state:
1808+ let context = self.context_mut();
18371809
18381810 context.channel_id = channel_id;
18391811
0 commit comments