@@ -14,7 +14,7 @@ use bitcoin::constants::ChainHash;
14
14
use bitcoin::script::{Builder, Script, ScriptBuf, WScriptHash};
15
15
use bitcoin::sighash::EcdsaSighashType;
16
16
use bitcoin::transaction::{Transaction, TxIn, TxOut};
17
- use bitcoin::Weight;
17
+ use bitcoin::{ Weight, Witness} ;
18
18
19
19
use bitcoin::hash_types::{BlockHash, Txid};
20
20
use bitcoin::hashes::sha256::Hash as Sha256;
@@ -24,9 +24,9 @@ use bitcoin::hashes::Hash;
24
24
use bitcoin::secp256k1::constants::PUBLIC_KEY_SIZE;
25
25
use bitcoin::secp256k1::{ecdsa::Signature, Secp256k1};
26
26
use bitcoin::secp256k1::{PublicKey, SecretKey};
27
- use bitcoin::{secp256k1, sighash};
28
27
#[cfg(splicing)]
29
- use bitcoin::{Sequence, Witness};
28
+ use bitcoin::Sequence;
29
+ use bitcoin::{secp256k1, sighash};
30
30
31
31
use crate::chain::chaininterface::{
32
32
fee_for_weight, ConfirmationTarget, FeeEstimator, LowerBoundedFeeEstimator,
@@ -2549,7 +2549,6 @@ where
2549
2549
monitor_pending_failures: Vec<(HTLCSource, PaymentHash, HTLCFailReason)>,
2550
2550
monitor_pending_finalized_fulfills: Vec<(HTLCSource, Option<AttributionData>)>,
2551
2551
monitor_pending_update_adds: Vec<msgs::UpdateAddHTLC>,
2552
- monitor_pending_tx_signatures: Option<msgs::TxSignatures>,
2553
2552
2554
2553
/// If we went to send a revoke_and_ack but our signer was unable to give us a signature,
2555
2554
/// we should retry at some point in the future when the signer indicates it may have a
@@ -3269,7 +3268,6 @@ where
3269
3268
monitor_pending_failures: Vec::new(),
3270
3269
monitor_pending_finalized_fulfills: Vec::new(),
3271
3270
monitor_pending_update_adds: Vec::new(),
3272
- monitor_pending_tx_signatures: None,
3273
3271
3274
3272
signer_pending_revoke_and_ack: false,
3275
3273
signer_pending_commitment_update: false,
@@ -3508,7 +3506,6 @@ where
3508
3506
monitor_pending_failures: Vec::new(),
3509
3507
monitor_pending_finalized_fulfills: Vec::new(),
3510
3508
monitor_pending_update_adds: Vec::new(),
3511
- monitor_pending_tx_signatures: None,
3512
3509
3513
3510
signer_pending_revoke_and_ack: false,
3514
3511
signer_pending_commitment_update: false,
@@ -5544,16 +5541,6 @@ where
5544
5541
};
5545
5542
5546
5543
let funding_ready_for_sig_event = if signing_session.local_inputs_count() == 0 {
5547
- if signing_session.provide_holder_witnesses(self.channel_id, Vec::new()).is_err() {
5548
- debug_assert!(
5549
- false,
5550
- "Zero inputs were provided & zero witnesses were provided, but a count mismatch was somehow found",
5551
- );
5552
- return Err(msgs::TxAbort {
5553
- channel_id: self.channel_id(),
5554
- data: "V2 channel rejected due to sender error".to_owned().into_bytes(),
5555
- });
5556
- }
5557
5544
None
5558
5545
} else {
5559
5546
// TODO(dual_funding): Send event for signing if we've contributed funds.
@@ -6979,12 +6966,8 @@ where
6979
6966
6980
6967
self.monitor_updating_paused(false, false, false, Vec::new(), Vec::new(), Vec::new());
6981
6968
6982
- if let Some(tx_signatures) = self.interactive_tx_signing_session.as_mut().and_then(
6983
- |session| session.received_commitment_signed()
6984
- ) {
6985
- // We're up first for submitting our tx_signatures, but our monitor has not persisted yet
6986
- // so they'll be sent as soon as that's done.
6987
- self.context.monitor_pending_tx_signatures = Some(tx_signatures);
6969
+ if let Some(session) = &mut self.interactive_tx_signing_session {
6970
+ session.received_commitment_signed();
6988
6971
}
6989
6972
6990
6973
Ok(channel_monitor)
@@ -7072,13 +7055,11 @@ where
7072
7055
channel_id: Some(self.context.channel_id()),
7073
7056
};
7074
7057
7075
- let tx_signatures = self
7076
- .interactive_tx_signing_session
7058
+ self.interactive_tx_signing_session
7077
7059
.as_mut()
7078
7060
.expect("Signing session must exist for negotiated pending splice")
7079
7061
.received_commitment_signed();
7080
7062
self.monitor_updating_paused(false, false, false, Vec::new(), Vec::new(), Vec::new());
7081
- self.context.monitor_pending_tx_signatures = tx_signatures;
7082
7063
7083
7064
Ok(self.push_ret_blockable_mon_update(monitor_update))
7084
7065
}
@@ -7988,10 +7969,39 @@ where
7988
7969
}
7989
7970
}
7990
7971
7972
+ pub fn funding_transaction_signed(
7973
+ &mut self, witnesses: Vec<Witness>,
7974
+ ) -> Result<Option<msgs::TxSignatures>, APIError> {
7975
+ let (funding_tx_opt, tx_signatures_opt) = self
7976
+ .interactive_tx_signing_session
7977
+ .as_mut()
7978
+ .ok_or_else(|| APIError::APIMisuseError {
7979
+ err: format!(
7980
+ "Channel {} not expecting funding signatures",
7981
+ self.context.channel_id
7982
+ ),
7983
+ })
7984
+ .and_then(|signing_session| {
7985
+ signing_session
7986
+ .provide_holder_witnesses(self.context.channel_id, witnesses)
7987
+ .map_err(|err| APIError::APIMisuseError { err })
7988
+ })?;
7989
+
7990
+ if tx_signatures_opt.is_some() {
7991
+ self.context.channel_state.set_our_tx_signatures_ready();
7992
+ }
7993
+
7994
+ if funding_tx_opt.is_some() {
7995
+ self.funding.funding_transaction = funding_tx_opt;
7996
+ self.context.channel_state =
7997
+ ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new());
7998
+ }
7999
+
8000
+ Ok(tx_signatures_opt)
8001
+ }
8002
+
7991
8003
#[rustfmt::skip]
7992
- pub fn tx_signatures<L: Deref>(&mut self, msg: &msgs::TxSignatures, logger: &L) -> Result<(Option<Transaction>, Option<msgs::TxSignatures>), ChannelError>
7993
- where L::Target: Logger
7994
- {
8004
+ pub fn tx_signatures(&mut self, msg: &msgs::TxSignatures) -> Result<(Option<Transaction>, Option<msgs::TxSignatures>), ChannelError> {
7995
8005
if !self.context.channel_state.is_interactive_signing()
7996
8006
|| self.context.channel_state.is_their_tx_signatures_sent()
7997
8007
{
@@ -8014,23 +8024,12 @@ where
8014
8024
return Err(ChannelError::Close((msg.to_owned(), reason)));
8015
8025
}
8016
8026
8017
- if msg.witnesses.len() != signing_session.remote_inputs_count() {
8018
- return Err(ChannelError::Warn(
8019
- "Witness count did not match contributed input count".to_string()
8020
- ));
8021
- }
8022
-
8023
8027
for witness in &msg.witnesses {
8024
8028
if witness.is_empty() {
8025
8029
let msg = "Unexpected empty witness in tx_signatures received";
8026
8030
let reason = ClosureReason::ProcessingError { err: msg.to_owned() };
8027
8031
return Err(ChannelError::Close((msg.to_owned(), reason)));
8028
8032
}
8029
-
8030
- // TODO(dual_funding): Check all sigs are SIGHASH_ALL.
8031
-
8032
- // TODO(dual_funding): I don't see how we're going to be able to ensure witness-standardness
8033
- // for spending. Doesn't seem to be anything in rust-bitcoin.
8034
8033
}
8035
8034
8036
8035
let (holder_tx_signatures_opt, funding_tx_opt) = signing_session.received_tx_signatures(msg.clone())
@@ -8039,24 +8038,23 @@ where
8039
8038
// Set `THEIR_TX_SIGNATURES_SENT` flag after all potential errors.
8040
8039
self.context.channel_state.set_their_tx_signatures_sent();
8041
8040
8041
+ // Note that `holder_tx_signatures_opt` will be `None` if we sent `tx_signatures` first or if the
8042
+ // user still needs to provide tx_signatures and we are sending second.
8043
+ if holder_tx_signatures_opt.is_some() {
8044
+ self.context.channel_state.set_our_tx_signatures_ready();
8045
+ }
8046
+
8042
8047
if funding_tx_opt.is_some() {
8043
8048
// We have a finalized funding transaction, so we can set the funding transaction.
8044
8049
self.funding.funding_transaction = funding_tx_opt.clone();
8050
+ self.context.channel_state = ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new());
8045
8051
}
8046
8052
8047
- // Note that `holder_tx_signatures_opt` will be `None` if we sent `tx_signatures` first, so this
8048
- // case checks if there is a monitor persist in progress when we need to respond with our `tx_signatures`
8049
- // and sets it as pending.
8050
- if holder_tx_signatures_opt.is_some() && self.is_awaiting_initial_mon_persist() {
8051
- log_debug!(logger, "Not sending tx_signatures: a monitor update is in progress. Setting monitor_pending_tx_signatures.");
8052
- self.context.monitor_pending_tx_signatures = holder_tx_signatures_opt;
8053
- return Ok((None, None));
8054
- }
8055
-
8056
- if holder_tx_signatures_opt.is_some() {
8057
- self.context.channel_state.set_our_tx_signatures_ready();
8053
+ if holder_tx_signatures_opt.is_none() {
8054
+ return Ok((funding_tx_opt, None));
8058
8055
}
8059
8056
8057
+ // TODO(splicing): Transition back to `ChannelReady` and not `AwaitingChannelReady`
8060
8058
self.context.channel_state = ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new());
8061
8059
Ok((funding_tx_opt, holder_tx_signatures_opt))
8062
8060
} else {
@@ -8309,25 +8307,14 @@ where
8309
8307
mem::swap(&mut finalized_claimed_htlcs, &mut self.context.monitor_pending_finalized_fulfills);
8310
8308
let mut pending_update_adds = Vec::new();
8311
8309
mem::swap(&mut pending_update_adds, &mut self.context.monitor_pending_update_adds);
8312
- // For channels established with V2 establishment we won't send a `tx_signatures` when we're in
8313
- // MonitorUpdateInProgress (and we assume the user will never directly broadcast the funding
8314
- // transaction and waits for us to do it).
8315
- let tx_signatures = self.context.monitor_pending_tx_signatures.take();
8316
- if tx_signatures.is_some() {
8317
- if self.context.channel_state.is_their_tx_signatures_sent() {
8318
- self.context.channel_state = ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new());
8319
- } else {
8320
- self.context.channel_state.set_our_tx_signatures_ready();
8321
- }
8322
- }
8323
8310
8324
8311
if self.context.channel_state.is_peer_disconnected() {
8325
8312
self.context.monitor_pending_revoke_and_ack = false;
8326
8313
self.context.monitor_pending_commitment_signed = false;
8327
8314
return MonitorRestoreUpdates {
8328
8315
raa: None, commitment_update: None, order: RAACommitmentOrder::RevokeAndACKFirst,
8329
8316
accepted_htlcs, failed_htlcs, finalized_claimed_htlcs, pending_update_adds,
8330
- funding_broadcastable, channel_ready, announcement_sigs, tx_signatures
8317
+ funding_broadcastable, channel_ready, announcement_sigs, tx_signatures: None
8331
8318
};
8332
8319
}
8333
8320
@@ -8357,7 +8344,7 @@ where
8357
8344
match order { RAACommitmentOrder::CommitmentFirst => "commitment", RAACommitmentOrder::RevokeAndACKFirst => "RAA"});
8358
8345
MonitorRestoreUpdates {
8359
8346
raa, commitment_update, order, accepted_htlcs, failed_htlcs, finalized_claimed_htlcs,
8360
- pending_update_adds, funding_broadcastable, channel_ready, announcement_sigs, tx_signatures
8347
+ pending_update_adds, funding_broadcastable, channel_ready, announcement_sigs, tx_signatures: None
8361
8348
}
8362
8349
}
8363
8350
@@ -8834,7 +8821,6 @@ where
8834
8821
update_fee: None,
8835
8822
})
8836
8823
} else { None };
8837
- // TODO(dual_funding): For async signing support we need to hold back `tx_signatures` until the `commitment_signed` is ready.
8838
8824
let tx_signatures = if (
8839
8825
// if it has not received tx_signatures for that funding transaction AND
8840
8826
// if it has already received commitment_signed AND it should sign first, as specified in the tx_signatures requirements:
@@ -8843,14 +8829,8 @@ where
8843
8829
// else if it has already received tx_signatures for that funding transaction:
8844
8830
// MUST send its tx_signatures for that funding transaction.
8845
8831
) || self.context.channel_state.is_their_tx_signatures_sent() {
8846
- if self.context.channel_state.is_monitor_update_in_progress() {
8847
- // The `monitor_pending_tx_signatures` field should have already been set in `commitment_signed_initial_v2`
8848
- // if we were up first for signing and had a monitor update in progress, but check again just in case.
8849
- debug_assert!(self.context.monitor_pending_tx_signatures.is_some(), "monitor_pending_tx_signatures should already be set");
8850
- log_debug!(logger, "Not sending tx_signatures: a monitor update is in progress. Setting monitor_pending_tx_signatures.");
8851
- if self.context.monitor_pending_tx_signatures.is_none() {
8852
- self.context.monitor_pending_tx_signatures = session.holder_tx_signatures().clone();
8853
- }
8832
+ if session.holder_tx_signatures().is_none() {
8833
+ log_debug!(logger, "Not sending tx_signatures: a monitor update is in progress.");
8854
8834
None
8855
8835
} else {
8856
8836
// If `holder_tx_signatures` is `None` here, the `tx_signatures` message will be sent
@@ -11792,6 +11772,10 @@ where
11792
11772
// CHANNEL_ANNOUNCEMENT_PROPAGATION_DELAY confirmations.
11793
11773
self.context.historical_scids.drain(0..end)
11794
11774
}
11775
+
11776
+ pub fn set_our_tx_signatures_ready(&mut self) {
11777
+ self.context.channel_state.set_our_tx_signatures_ready();
11778
+ }
11795
11779
}
11796
11780
11797
11781
/// A not-yet-funded outbound (from holder) channel using V1 channel establishment.
@@ -13956,7 +13940,6 @@ where
13956
13940
monitor_pending_failures,
13957
13941
monitor_pending_finalized_fulfills: monitor_pending_finalized_fulfills.unwrap(),
13958
13942
monitor_pending_update_adds: monitor_pending_update_adds.unwrap_or_default(),
13959
- monitor_pending_tx_signatures: None,
13960
13943
13961
13944
signer_pending_revoke_and_ack: false,
13962
13945
signer_pending_commitment_update: false,
0 commit comments