@@ -4970,9 +4970,36 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4970
4970
}
4971
4971
4972
4972
#[cfg(splicing)]
4973
- fn check_get_splice_locked<L: Deref>(&mut self, funding: &FundingScope, height: u32, logger: &L) -> Option<msgs::SpliceLocked>
4974
- where L::Target: Logger
4973
+ fn check_get_splice_locked<L: Deref>(
4974
+ &mut self, pending_splice: &mut Option<PendingSplice>, funding: &mut FundingScope,
4975
+ height: u32, logger: &L,
4976
+ ) -> Option<msgs::SpliceLocked>
4977
+ where
4978
+ L::Target: Logger,
4975
4979
{
4980
+ // TODO: Check minimum depth has been reached.
4981
+
4982
+ let confirmed_funding_txo = funding.get_funding_txo();
4983
+ if let Some(pending_splice) = pending_splice {
4984
+ if let Some(funding_txid) = pending_splice.confirmed_funding_txid {
4985
+ // splice_lock already received
4986
+ if Some(funding_txid) == confirmed_funding_txo.map(|txo| txo.txid) {
4987
+ // - swap FundingScope
4988
+ // - clear pending_splice
4989
+ // - clear pending_funding
4990
+ // - send splice_locked
4991
+ } else {
4992
+ // splice_txid does not match one in received splice_locked
4993
+ }
4994
+ } else {
4995
+ pending_splice.confirmed_funding_txid = confirmed_funding_txo.map(|txo| txo.txid);
4996
+ debug_assert!(pending_splice.confirmed_funding_txid.is_some());
4997
+ // - send splice_locked
4998
+ // - wait for splice_locked
4999
+ }
5000
+ } else {
5001
+ debug_assert!(false);
5002
+ }
4976
5003
None
4977
5004
}
4978
5005
}
@@ -8388,13 +8415,7 @@ impl<SP: Deref> FundedChannel<SP> where
8388
8415
}
8389
8416
} else {
8390
8417
#[cfg(splicing)] {
8391
- if let Some(pending_splice) = &mut self.pending_splice {
8392
- pending_splice.confirmed_funding_txid = confirmed_funding_txo.map(|txo| txo.txid);
8393
- debug_assert!(pending_splice.confirmed_funding_txid.is_some());
8394
- } else {
8395
- debug_assert!(false);
8396
- }
8397
- if let Some(splice_locked) = self.context.check_get_splice_locked(funding, height, logger) {
8418
+ if let Some(splice_locked) = self.context.check_get_splice_locked(&mut self.pending_splice, funding, height, logger) {
8398
8419
log_info!(logger, "Sending a splice_locked to our peer for channel {}", &self.context.channel_id);
8399
8420
let announcement_sigs = self.context.get_announcement_sigs(funding, node_signer, chain_hash, user_config, height, logger);
8400
8421
return Ok((Some(FundingConfirmedMessage::Splice(splice_locked)), announcement_sigs));
@@ -8501,11 +8522,11 @@ impl<SP: Deref> FundedChannel<SP> where
8501
8522
.and_then(|pending_splice| pending_splice.confirmed_funding_txid)
8502
8523
{
8503
8524
if let Some((funding, _)) = self.pending_funding
8504
- .iter ()
8525
+ .iter_mut ()
8505
8526
.filter_map(|funding| funding.get_funding_txo().map(|txo| (funding, txo.txid)))
8506
8527
.find(|(_, funding_txid)| *funding_txid == confirmed_funding_txid)
8507
8528
{
8508
- if let Some(splice_locked) = self.context.check_get_splice_locked(funding, height, logger) {
8529
+ if let Some(splice_locked) = self.context.check_get_splice_locked(&mut self.pending_splice, funding, height, logger) {
8509
8530
let announcement_sigs = if let Some((chain_hash, node_signer, user_config)) = chain_node_signer {
8510
8531
self.context.get_announcement_sigs(funding, node_signer, chain_hash, user_config, height, logger)
8511
8532
} else {
0 commit comments