@@ -678,6 +678,9 @@ pub(crate) enum ChannelMonitorUpdateStep {
678
678
holder_commitment_tx : HolderCommitmentTransaction ,
679
679
counterparty_commitment_tx : CommitmentTransaction ,
680
680
} ,
681
+ RenegotiatedFundingLocked {
682
+ funding_txid : Txid ,
683
+ } ,
681
684
}
682
685
683
686
impl ChannelMonitorUpdateStep {
@@ -693,6 +696,7 @@ impl ChannelMonitorUpdateStep {
693
696
ChannelMonitorUpdateStep :: ChannelForceClosed { .. } => "ChannelForceClosed" ,
694
697
ChannelMonitorUpdateStep :: ShutdownScript { .. } => "ShutdownScript" ,
695
698
ChannelMonitorUpdateStep :: RenegotiatedFunding { .. } => "RenegotiatedFunding" ,
699
+ ChannelMonitorUpdateStep :: RenegotiatedFundingLocked { .. } => "RenegotiatedFundingLocked" ,
696
700
}
697
701
}
698
702
}
@@ -741,6 +745,9 @@ impl_writeable_tlv_based_enum_upgradable!(ChannelMonitorUpdateStep,
741
745
( 3 , holder_commitment_tx, required) ,
742
746
( 5 , counterparty_commitment_tx, required) ,
743
747
} ,
748
+ ( 12 , RenegotiatedFundingLocked ) => {
749
+ ( 1 , funding_txid, required) ,
750
+ } ,
744
751
) ;
745
752
746
753
/// Indicates whether the balance is derived from a cooperative close, a force-close
@@ -1088,6 +1095,10 @@ impl FundingScope {
1088
1095
fn funding_txid ( & self ) -> Txid {
1089
1096
self . funding_outpoint ( ) . txid
1090
1097
}
1098
+
1099
+ fn is_splice ( & self ) -> bool {
1100
+ self . channel_parameters . splice_parent_funding_txid . is_some ( )
1101
+ }
1091
1102
}
1092
1103
1093
1104
impl_writeable_tlv_based ! ( FundingScope , {
@@ -1115,7 +1126,7 @@ pub(crate) struct ChannelMonitorImpl<Signer: EcdsaChannelSigner> {
1115
1126
channel_keys_id : [ u8 ; 32 ] ,
1116
1127
holder_revocation_basepoint : RevocationBasepoint ,
1117
1128
channel_id : ChannelId ,
1118
- first_confirmed_funding_txo : OutPoint ,
1129
+ first_negotiated_funding_txo : OutPoint ,
1119
1130
1120
1131
counterparty_commitment_params : CounterpartyCommitmentParameters ,
1121
1132
@@ -1183,8 +1194,6 @@ pub(crate) struct ChannelMonitorImpl<Signer: EcdsaChannelSigner> {
1183
1194
// interface knows about the TXOs that we want to be notified of spends of. We could probably
1184
1195
// be smart and derive them from the above storage fields, but its much simpler and more
1185
1196
// Obviously Correct (tm) if we just keep track of them explicitly.
1186
- //
1187
- // TODO: Remove entries for stale funding transactions on `splice_locked`.
1188
1197
outputs_to_watch : HashMap < Txid , Vec < ( u32 , ScriptBuf ) > > ,
1189
1198
1190
1199
#[ cfg( any( test, feature = "_test_utils" ) ) ]
@@ -1542,7 +1551,7 @@ impl<Signer: EcdsaChannelSigner> Writeable for ChannelMonitorImpl<Signer> {
1542
1551
( 21 , self . balances_empty_height, option) ,
1543
1552
( 23 , self . holder_pays_commitment_tx_fee, option) ,
1544
1553
( 25 , self . payment_preimages, required) ,
1545
- ( 27 , self . first_confirmed_funding_txo , required) ,
1554
+ ( 27 , self . first_negotiated_funding_txo , required) ,
1546
1555
( 29 , self . initial_counterparty_commitment_tx, option) ,
1547
1556
( 31 , self . funding. channel_parameters, required) ,
1548
1557
( 32 , self . pending_funding, optional_vec) ,
@@ -1726,7 +1735,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
1726
1735
channel_keys_id,
1727
1736
holder_revocation_basepoint,
1728
1737
channel_id,
1729
- first_confirmed_funding_txo : funding_outpoint,
1738
+ first_negotiated_funding_txo : funding_outpoint,
1730
1739
1731
1740
counterparty_commitment_params,
1732
1741
their_cur_per_commitment_points : None ,
@@ -1785,7 +1794,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
1785
1794
/// [`Persist`]: crate::chain::chainmonitor::Persist
1786
1795
pub fn persistence_key ( & self ) -> MonitorName {
1787
1796
let inner = self . inner . lock ( ) . unwrap ( ) ;
1788
- let funding_outpoint = inner. first_confirmed_funding_txo ;
1797
+ let funding_outpoint = inner. first_negotiated_funding_txo ;
1789
1798
let channel_id = inner. channel_id ;
1790
1799
if ChannelId :: v1_from_funding_outpoint ( funding_outpoint) == channel_id {
1791
1800
MonitorName :: V1Channel ( funding_outpoint)
@@ -3770,6 +3779,10 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3770
3779
) ;
3771
3780
return Err ( ( ) ) ;
3772
3781
}
3782
+ } else if self . funding . is_splice ( ) {
3783
+ // If we've already spliced at least once, we're no longer able to RBF the original
3784
+ // funding transaction.
3785
+ return Err ( ( ) ) ;
3773
3786
}
3774
3787
3775
3788
let script_pubkey = channel_parameters. make_funding_redeemscript ( ) . to_p2wsh ( ) ;
@@ -3782,6 +3795,30 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3782
3795
Ok ( ( ) )
3783
3796
}
3784
3797
3798
+ fn promote_funding ( & mut self , new_funding_txid : Txid ) -> Result < ( ) , ( ) > {
3799
+ let new_funding = self
3800
+ . pending_funding
3801
+ . iter_mut ( )
3802
+ . find ( |funding| funding. funding_txid ( ) == new_funding_txid) ;
3803
+ if new_funding. is_none ( ) {
3804
+ return Err ( ( ) ) ;
3805
+ }
3806
+ let mut new_funding = new_funding. unwrap ( ) ;
3807
+
3808
+ mem:: swap ( & mut self . funding , & mut new_funding) ;
3809
+ self . onchain_tx_handler . update_after_renegotiated_funding_locked (
3810
+ self . funding . current_holder_commitment_tx . clone ( ) ,
3811
+ self . funding . prev_holder_commitment_tx . clone ( ) ,
3812
+ ) ;
3813
+
3814
+ // The swap above places the previous `FundingScope` into `pending_funding`.
3815
+ for funding in self . pending_funding . drain ( ..) {
3816
+ self . outputs_to_watch . remove ( & funding. funding_txid ( ) ) ;
3817
+ }
3818
+
3819
+ Ok ( ( ) )
3820
+ }
3821
+
3785
3822
#[ rustfmt:: skip]
3786
3823
fn update_monitor < B : Deref , F : Deref , L : Deref > (
3787
3824
& mut self , updates : & ChannelMonitorUpdate , broadcaster : & B , fee_estimator : & F , logger : & WithChannelMonitor < L >
@@ -3900,6 +3937,13 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3900
3937
ret = Err ( ( ) ) ;
3901
3938
}
3902
3939
} ,
3940
+ ChannelMonitorUpdateStep :: RenegotiatedFundingLocked { funding_txid } => {
3941
+ log_trace ! ( logger, "Updating ChannelMonitor with locked renegotiated funding txid {}" , funding_txid) ;
3942
+ if let Err ( _) = self . promote_funding ( * funding_txid) {
3943
+ log_error ! ( logger, "Unknown funding with txid {} became locked" , funding_txid) ;
3944
+ ret = Err ( ( ) ) ;
3945
+ }
3946
+ } ,
3903
3947
ChannelMonitorUpdateStep :: ChannelForceClosed { should_broadcast } => {
3904
3948
log_trace ! ( logger, "Updating ChannelMonitor: channel force closed, should broadcast: {}" , should_broadcast) ;
3905
3949
self . lockdown_from_offchain = true ;
@@ -3953,7 +3997,8 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
3953
3997
|ChannelMonitorUpdateStep :: LatestCounterpartyCommitment { .. }
3954
3998
|ChannelMonitorUpdateStep :: ShutdownScript { .. }
3955
3999
|ChannelMonitorUpdateStep :: CommitmentSecret { .. }
3956
- |ChannelMonitorUpdateStep :: RenegotiatedFunding { .. } =>
4000
+ |ChannelMonitorUpdateStep :: RenegotiatedFunding { .. }
4001
+ |ChannelMonitorUpdateStep :: RenegotiatedFundingLocked { .. } =>
3957
4002
is_pre_close_update = true ,
3958
4003
// After a channel is closed, we don't communicate with our peer about it, so the
3959
4004
// only things we will update is getting a new preimage (from a different channel)
@@ -5822,7 +5867,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
5822
5867
let mut channel_id = None ;
5823
5868
let mut holder_pays_commitment_tx_fee = None ;
5824
5869
let mut payment_preimages_with_info: Option < HashMap < _ , _ > > = None ;
5825
- let mut first_confirmed_funding_txo = RequiredWrapper ( None ) ;
5870
+ let mut first_negotiated_funding_txo = RequiredWrapper ( None ) ;
5826
5871
let mut channel_parameters = None ;
5827
5872
let mut pending_funding = None ;
5828
5873
read_tlv_fields ! ( reader, {
@@ -5839,7 +5884,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
5839
5884
( 21 , balances_empty_height, option) ,
5840
5885
( 23 , holder_pays_commitment_tx_fee, option) ,
5841
5886
( 25 , payment_preimages_with_info, option) ,
5842
- ( 27 , first_confirmed_funding_txo , ( default_value, outpoint) ) ,
5887
+ ( 27 , first_negotiated_funding_txo , ( default_value, outpoint) ) ,
5843
5888
( 29 , initial_counterparty_commitment_tx, option) ,
5844
5889
( 31 , channel_parameters, ( option: ReadableArgs , None ) ) ,
5845
5890
( 32 , pending_funding, optional_vec) ,
@@ -5969,7 +6014,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
5969
6014
channel_keys_id,
5970
6015
holder_revocation_basepoint,
5971
6016
channel_id,
5972
- first_confirmed_funding_txo : first_confirmed_funding_txo . 0 . unwrap ( ) ,
6017
+ first_negotiated_funding_txo : first_negotiated_funding_txo . 0 . unwrap ( ) ,
5973
6018
5974
6019
counterparty_commitment_params,
5975
6020
their_cur_per_commitment_points,
0 commit comments