@@ -1770,57 +1770,16 @@ trait InitialRemoteCommitmentReceiver<SP: Deref> where SP::Target: SignerProvide
1770
1770
1771
1771
fn received_msg(&self) -> &'static str;
1772
1772
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
-
1793
1773
fn initial_commitment_signed<L: Deref>(
1794
1774
&mut self, channel_id: ChannelId, counterparty_signature: Signature, holder_commitment_point: &mut HolderCommitmentPoint,
1795
1775
counterparty_commitment_number: u64, best_block: BestBlock, signer_provider: &SP, logger: &L,
1796
1776
) -> Result<(ChannelMonitor<<SP::Target as SignerProvider>::EcdsaSigner>, CommitmentTransaction), ChannelError>
1797
1777
where
1798
1778
L::Target: Logger
1799
1779
{
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;
1824
1783
let holder_commitment_tx = HolderCommitmentTransaction::new(
1825
1784
initial_commitment_tx,
1826
1785
counterparty_signature,
@@ -1830,10 +1789,23 @@ trait InitialRemoteCommitmentReceiver<SP: Deref> where SP::Target: SignerProvide
1830
1789
);
1831
1790
1832
1791
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
+ }
1833
1796
return Err(ChannelError::close("Failed to validate our commitment".to_owned()));
1834
1797
}
1835
1798
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
+
1836
1807
// Now that we're past error-generating stuff, update our local state:
1808
+ let context = self.context_mut();
1837
1809
1838
1810
context.channel_id = channel_id;
1839
1811
0 commit comments