@@ -768,9 +768,16 @@ pub struct ChannelMonitor<ChanSigner: ChannelKeys> {
768
768
#[ cfg( not( test) ) ]
769
769
onchain_tx_handler : OnchainTxHandler < ChanSigner > ,
770
770
771
- // Used to detect programming bug due to unsafe monitor update sequence { ChannelForceClosed, LatestLocalCommitmentTXInfo }
771
+ // This is set when the Channel[Manager] generated a ChannelMonitorUpdate which indicated the
772
+ // channel has been force-closed. After this is set, no further local commitment transaction
773
+ // updates may occur, and we panic!() if one is provided.
772
774
lockdown_from_offchain : bool ,
773
775
776
+ // Set once we've signed a local commitment transaction and handed it over to our
777
+ // OnchainTxHandler. After this is set, no future updates to our local commitment transactions
778
+ // may occur, and we fail any such monitor updates.
779
+ local_tx_signed : bool ,
780
+
774
781
// We simply modify last_block_hash in Channel's block_connected so that serialization is
775
782
// consistent but hopefully the users' copy handles block_connected in a consistent way.
776
783
// (we do *not*, however, update them in update_monitor to ensure any local user copies keep
@@ -814,7 +821,9 @@ impl<ChanSigner: ChannelKeys> PartialEq for ChannelMonitor<ChanSigner> {
814
821
self . pending_htlcs_updated != other. pending_htlcs_updated ||
815
822
self . pending_events . len ( ) != other. pending_events . len ( ) || // We trust events to round-trip properly
816
823
self . onchain_events_waiting_threshold_conf != other. onchain_events_waiting_threshold_conf ||
817
- self . outputs_to_watch != other. outputs_to_watch
824
+ self . outputs_to_watch != other. outputs_to_watch ||
825
+ self . lockdown_from_offchain != other. lockdown_from_offchain ||
826
+ self . local_tx_signed != other. local_tx_signed
818
827
{
819
828
false
820
829
} else {
@@ -1015,6 +1024,7 @@ impl<ChanSigner: ChannelKeys + Writeable> ChannelMonitor<ChanSigner> {
1015
1024
self . onchain_tx_handler . write ( writer) ?;
1016
1025
1017
1026
self . lockdown_from_offchain . write ( writer) ?;
1027
+ self . local_tx_signed . write ( writer) ?;
1018
1028
1019
1029
Ok ( ( ) )
1020
1030
}
@@ -1097,6 +1107,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1097
1107
onchain_tx_handler,
1098
1108
1099
1109
lockdown_from_offchain : false ,
1110
+ local_tx_signed : false ,
1100
1111
1101
1112
last_block_hash : Default :: default ( ) ,
1102
1113
secp_ctx : Secp256k1 :: new ( ) ,
@@ -1213,6 +1224,9 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1213
1224
/// up-to-date as our local commitment transaction is updated.
1214
1225
/// Panics if set_their_to_self_delay has never been called.
1215
1226
pub ( super ) fn provide_latest_local_commitment_tx_info ( & mut self , commitment_tx : LocalCommitmentTransaction , htlc_outputs : Vec < ( HTLCOutputInCommitment , Option < Signature > , Option < HTLCSource > ) > ) -> Result < ( ) , MonitorUpdateError > {
1227
+ if self . local_tx_signed {
1228
+ return Err ( MonitorUpdateError ( "A local commitment tx has already been signed, no new local commitment txn can be sent to our counterparty" ) ) ;
1229
+ }
1216
1230
let txid = commitment_tx. txid ( ) ;
1217
1231
let sequence = commitment_tx. without_valid_witness ( ) . input [ 0 ] . sequence as u64 ;
1218
1232
let locktime = commitment_tx. without_valid_witness ( ) . lock_time as u64 ;
@@ -1740,6 +1754,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1740
1754
/// In any-case, choice is up to the user.
1741
1755
pub fn get_latest_local_commitment_txn ( & mut self ) -> Vec < Transaction > {
1742
1756
log_trace ! ( self , "Getting signed latest local commitment transaction!" ) ;
1757
+ self . local_tx_signed = true ;
1743
1758
if let Some ( commitment_tx) = self . onchain_tx_handler . get_fully_signed_local_tx ( ) {
1744
1759
let txid = commitment_tx. txid ( ) ;
1745
1760
let mut res = vec ! [ commitment_tx] ;
@@ -2399,6 +2414,7 @@ impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for (Sha256dH
2399
2414
let onchain_tx_handler = ReadableArgs :: read ( reader, logger. clone ( ) ) ?;
2400
2415
2401
2416
let lockdown_from_offchain = Readable :: read ( reader) ?;
2417
+ let local_tx_signed = Readable :: read ( reader) ?;
2402
2418
2403
2419
Ok ( ( last_block_hash. clone ( ) , ChannelMonitor {
2404
2420
latest_update_id,
@@ -2443,6 +2459,7 @@ impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for (Sha256dH
2443
2459
onchain_tx_handler,
2444
2460
2445
2461
lockdown_from_offchain,
2462
+ local_tx_signed,
2446
2463
2447
2464
last_block_hash,
2448
2465
secp_ctx : Secp256k1 :: new ( ) ,
0 commit comments