@@ -784,9 +784,16 @@ pub struct ChannelMonitor<ChanSigner: ChannelKeys> {
784
784
#[ cfg( not( test) ) ]
785
785
onchain_tx_handler : OnchainTxHandler < ChanSigner > ,
786
786
787
- // Used to detect programming bug due to unsafe monitor update sequence { ChannelForceClosed, LatestLocalCommitmentTXInfo }
787
+ // This is set when the Channel[Manager] generated a ChannelMonitorUpdate which indicated the
788
+ // channel has been force-closed. After this is set, no further local commitment transaction
789
+ // updates may occur, and we panic!() if one is provided.
788
790
lockdown_from_offchain : bool ,
789
791
792
+ // Set once we've signed a local commitment transaction and handed it over to our
793
+ // OnchainTxHandler. After this is set, no future updates to our local commitment transactions
794
+ // may occur, and we fail any such monitor updates.
795
+ local_tx_signed : bool ,
796
+
790
797
// We simply modify last_block_hash in Channel's block_connected so that serialization is
791
798
// consistent but hopefully the users' copy handles block_connected in a consistent way.
792
799
// (we do *not*, however, update them in update_monitor to ensure any local user copies keep
@@ -830,7 +837,9 @@ impl<ChanSigner: ChannelKeys> PartialEq for ChannelMonitor<ChanSigner> {
830
837
self . pending_htlcs_updated != other. pending_htlcs_updated ||
831
838
self . pending_events . len ( ) != other. pending_events . len ( ) || // We trust events to round-trip properly
832
839
self . onchain_events_waiting_threshold_conf != other. onchain_events_waiting_threshold_conf ||
833
- self . outputs_to_watch != other. outputs_to_watch
840
+ self . outputs_to_watch != other. outputs_to_watch ||
841
+ self . lockdown_from_offchain != other. lockdown_from_offchain ||
842
+ self . local_tx_signed != other. local_tx_signed
834
843
{
835
844
false
836
845
} else {
@@ -1031,6 +1040,7 @@ impl<ChanSigner: ChannelKeys + Writeable> ChannelMonitor<ChanSigner> {
1031
1040
self . onchain_tx_handler . write ( writer) ?;
1032
1041
1033
1042
self . lockdown_from_offchain . write ( writer) ?;
1043
+ self . local_tx_signed . write ( writer) ?;
1034
1044
1035
1045
Ok ( ( ) )
1036
1046
}
@@ -1113,6 +1123,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1113
1123
onchain_tx_handler,
1114
1124
1115
1125
lockdown_from_offchain : false ,
1126
+ local_tx_signed : false ,
1116
1127
1117
1128
last_block_hash : Default :: default ( ) ,
1118
1129
secp_ctx : Secp256k1 :: new ( ) ,
@@ -1229,6 +1240,9 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1229
1240
/// up-to-date as our local commitment transaction is updated.
1230
1241
/// Panics if set_their_to_self_delay has never been called.
1231
1242
pub ( super ) fn provide_latest_local_commitment_tx_info ( & mut self , commitment_tx : LocalCommitmentTransaction , htlc_outputs : Vec < ( HTLCOutputInCommitment , Option < Signature > , Option < HTLCSource > ) > ) -> Result < ( ) , MonitorUpdateError > {
1243
+ if self . local_tx_signed {
1244
+ return Err ( MonitorUpdateError ( "A local commitment tx has already been signed, no new local commitment txn can be sent to our counterparty" ) ) ;
1245
+ }
1232
1246
let txid = commitment_tx. txid ( ) ;
1233
1247
let sequence = commitment_tx. without_valid_witness ( ) . input [ 0 ] . sequence as u64 ;
1234
1248
let locktime = commitment_tx. without_valid_witness ( ) . lock_time as u64 ;
@@ -1756,6 +1770,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1756
1770
/// In any-case, choice is up to the user.
1757
1771
pub fn get_latest_local_commitment_txn ( & mut self ) -> Vec < Transaction > {
1758
1772
log_trace ! ( self , "Getting signed latest local commitment transaction!" ) ;
1773
+ self . local_tx_signed = true ;
1759
1774
if let Some ( commitment_tx) = self . onchain_tx_handler . get_fully_signed_local_tx ( ) {
1760
1775
let txid = commitment_tx. txid ( ) ;
1761
1776
let mut res = vec ! [ commitment_tx] ;
@@ -2415,6 +2430,7 @@ impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for (Sha256dH
2415
2430
let onchain_tx_handler = ReadableArgs :: read ( reader, logger. clone ( ) ) ?;
2416
2431
2417
2432
let lockdown_from_offchain = Readable :: read ( reader) ?;
2433
+ let local_tx_signed = Readable :: read ( reader) ?;
2418
2434
2419
2435
Ok ( ( last_block_hash. clone ( ) , ChannelMonitor {
2420
2436
latest_update_id,
@@ -2459,6 +2475,7 @@ impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for (Sha256dH
2459
2475
onchain_tx_handler,
2460
2476
2461
2477
lockdown_from_offchain,
2478
+ local_tx_signed,
2462
2479
2463
2480
last_block_hash,
2464
2481
secp_ctx : Secp256k1 :: new ( ) ,
0 commit comments