@@ -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,
@@ -6979,12 +6976,8 @@ where
6979
6976
6980
6977
self.monitor_updating_paused(false, false, false, Vec::new(), Vec::new(), Vec::new());
6981
6978
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);
6979
+ if let Some(session) = &mut self.interactive_tx_signing_session {
6980
+ session.received_commitment_signed();
6988
6981
}
6989
6982
6990
6983
Ok(channel_monitor)
@@ -7072,13 +7065,11 @@ where
7072
7065
channel_id: Some(self.context.channel_id()),
7073
7066
};
7074
7067
7075
- let tx_signatures = self
7076
- .interactive_tx_signing_session
7068
+ self.interactive_tx_signing_session
7077
7069
.as_mut()
7078
7070
.expect("Signing session must exist for negotiated pending splice")
7079
7071
.received_commitment_signed();
7080
7072
self.monitor_updating_paused(false, false, false, Vec::new(), Vec::new(), Vec::new());
7081
- self.context.monitor_pending_tx_signatures = tx_signatures;
7082
7073
7083
7074
Ok(self.push_ret_blockable_mon_update(monitor_update))
7084
7075
}
@@ -7988,10 +7979,26 @@ where
7988
7979
}
7989
7980
}
7990
7981
7982
+ pub fn funding_transaction_signed(
7983
+ &mut self, witnesses: Vec<Witness>,
7984
+ ) -> Result<Option<msgs::TxSignatures>, APIError> {
7985
+ self.interactive_tx_signing_session
7986
+ .as_mut()
7987
+ .ok_or_else(|| APIError::APIMisuseError {
7988
+ err: format!(
7989
+ "Channel {} not expecting funding signatures",
7990
+ self.context.channel_id
7991
+ ),
7992
+ })
7993
+ .and_then(|signing_session| {
7994
+ signing_session
7995
+ .provide_holder_witnesses(self.context.channel_id, witnesses)
7996
+ .map_err(|err| APIError::APIMisuseError { err })
7997
+ })
7998
+ }
7999
+
7991
8000
#[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
- {
8001
+ pub fn tx_signatures(&mut self, msg: &msgs::TxSignatures) -> Result<(Option<Transaction>, Option<msgs::TxSignatures>), ChannelError> {
7995
8002
if !self.context.channel_state.is_interactive_signing()
7996
8003
|| self.context.channel_state.is_their_tx_signatures_sent()
7997
8004
{
@@ -8014,23 +8021,12 @@ where
8014
8021
return Err(ChannelError::Close((msg.to_owned(), reason)));
8015
8022
}
8016
8023
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
8024
for witness in &msg.witnesses {
8024
8025
if witness.is_empty() {
8025
8026
let msg = "Unexpected empty witness in tx_signatures received";
8026
8027
let reason = ClosureReason::ProcessingError { err: msg.to_owned() };
8027
8028
return Err(ChannelError::Close((msg.to_owned(), reason)));
8028
8029
}
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
8030
}
8035
8031
8036
8032
let (holder_tx_signatures_opt, funding_tx_opt) = signing_session.received_tx_signatures(msg.clone())
@@ -8044,15 +8040,8 @@ where
8044
8040
self.funding.funding_transaction = funding_tx_opt.clone();
8045
8041
}
8046
8042
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
-
8043
+ // Note that `holder_tx_signatures_opt` will be `None` if we sent `tx_signatures` first or if the
8044
+ // user still needs to provide tx_signatures and we are sending second.
8056
8045
if holder_tx_signatures_opt.is_some() {
8057
8046
self.context.channel_state.set_our_tx_signatures_ready();
8058
8047
}
@@ -8309,25 +8298,14 @@ where
8309
8298
mem::swap(&mut finalized_claimed_htlcs, &mut self.context.monitor_pending_finalized_fulfills);
8310
8299
let mut pending_update_adds = Vec::new();
8311
8300
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
8301
8324
8302
if self.context.channel_state.is_peer_disconnected() {
8325
8303
self.context.monitor_pending_revoke_and_ack = false;
8326
8304
self.context.monitor_pending_commitment_signed = false;
8327
8305
return MonitorRestoreUpdates {
8328
8306
raa: None, commitment_update: None, order: RAACommitmentOrder::RevokeAndACKFirst,
8329
8307
accepted_htlcs, failed_htlcs, finalized_claimed_htlcs, pending_update_adds,
8330
- funding_broadcastable, channel_ready, announcement_sigs, tx_signatures
8308
+ funding_broadcastable, channel_ready, announcement_sigs, tx_signatures: None
8331
8309
};
8332
8310
}
8333
8311
@@ -8357,7 +8335,7 @@ where
8357
8335
match order { RAACommitmentOrder::CommitmentFirst => "commitment", RAACommitmentOrder::RevokeAndACKFirst => "RAA"});
8358
8336
MonitorRestoreUpdates {
8359
8337
raa, commitment_update, order, accepted_htlcs, failed_htlcs, finalized_claimed_htlcs,
8360
- pending_update_adds, funding_broadcastable, channel_ready, announcement_sigs, tx_signatures
8338
+ pending_update_adds, funding_broadcastable, channel_ready, announcement_sigs, tx_signatures: None
8361
8339
}
8362
8340
}
8363
8341
@@ -8632,23 +8610,25 @@ where
8632
8610
log_trace!(logger, "Regenerating latest commitment update in channel {} with{} {} update_adds, {} update_fulfills, {} update_fails, and {} update_fail_malformeds",
8633
8611
&self.context.channel_id(), if update_fee.is_some() { " update_fee," } else { "" },
8634
8612
update_add_htlcs.len(), update_fulfill_htlcs.len(), update_fail_htlcs.len(), update_fail_malformed_htlcs.len());
8635
- let commitment_signed =
8636
- if let Ok(update) = self.send_commitment_no_state_update(logger) {
8637
- if self.context.signer_pending_commitment_update {
8638
- log_trace!(
8639
- logger,
8640
- "Commitment update generated: clearing signer_pending_commitment_update"
8641
- );
8642
- self.context.signer_pending_commitment_update = false;
8643
- }
8644
- update
8645
- } else {
8646
- if !self.context.signer_pending_commitment_update {
8647
- log_trace!(logger, "Commitment update awaiting signer: setting signer_pending_commitment_update");
8648
- self.context.signer_pending_commitment_update = true;
8649
- }
8650
- return Err(());
8651
- };
8613
+ let commitment_signed = if let Ok(update) = self.send_commitment_no_state_update(logger) {
8614
+ if self.context.signer_pending_commitment_update {
8615
+ log_trace!(
8616
+ logger,
8617
+ "Commitment update generated: clearing signer_pending_commitment_update"
8618
+ );
8619
+ self.context.signer_pending_commitment_update = false;
8620
+ }
8621
+ update
8622
+ } else {
8623
+ if !self.context.signer_pending_commitment_update {
8624
+ log_trace!(
8625
+ logger,
8626
+ "Commitment update awaiting signer: setting signer_pending_commitment_update"
8627
+ );
8628
+ self.context.signer_pending_commitment_update = true;
8629
+ }
8630
+ return Err(());
8631
+ };
8652
8632
Ok(msgs::CommitmentUpdate {
8653
8633
update_add_htlcs,
8654
8634
update_fulfill_htlcs,
@@ -8834,7 +8814,6 @@ where
8834
8814
update_fee: None,
8835
8815
})
8836
8816
} else { None };
8837
- // TODO(dual_funding): For async signing support we need to hold back `tx_signatures` until the `commitment_signed` is ready.
8838
8817
let tx_signatures = if (
8839
8818
// if it has not received tx_signatures for that funding transaction AND
8840
8819
// if it has already received commitment_signed AND it should sign first, as specified in the tx_signatures requirements:
@@ -8843,14 +8822,8 @@ where
8843
8822
// else if it has already received tx_signatures for that funding transaction:
8844
8823
// MUST send its tx_signatures for that funding transaction.
8845
8824
) || 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
- }
8825
+ if session.holder_tx_signatures().is_none() {
8826
+ log_debug!(logger, "Not sending tx_signatures: a monitor update is in progress.");
8854
8827
None
8855
8828
} else {
8856
8829
// If `holder_tx_signatures` is `None` here, the `tx_signatures` message will be sent
@@ -11792,6 +11765,10 @@ where
11792
11765
// CHANNEL_ANNOUNCEMENT_PROPAGATION_DELAY confirmations.
11793
11766
self.context.historical_scids.drain(0..end)
11794
11767
}
11768
+
11769
+ pub fn set_our_tx_signatures_ready(&mut self) {
11770
+ self.context.channel_state.set_our_tx_signatures_ready();
11771
+ }
11795
11772
}
11796
11773
11797
11774
/// A not-yet-funded outbound (from holder) channel using V1 channel establishment.
@@ -13956,7 +13933,6 @@ where
13956
13933
monitor_pending_failures,
13957
13934
monitor_pending_finalized_fulfills: monitor_pending_finalized_fulfills.unwrap(),
13958
13935
monitor_pending_update_adds: monitor_pending_update_adds.unwrap_or_default(),
13959
- monitor_pending_tx_signatures: None,
13960
13936
13961
13937
signer_pending_revoke_and_ack: false,
13962
13938
signer_pending_commitment_update: false,
0 commit comments