@@ -794,6 +794,9 @@ pub struct ChannelMonitor<ChanSigner: ChannelKeys> {
794
794
#[ cfg( not( test) ) ]
795
795
onchain_tx_handler : OnchainTxHandler < ChanSigner > ,
796
796
797
+ // Used to detect programming bug due to unsafe monitor update sequence { ChannelForceClosed, LatestLocalCommitmentTXInfo }
798
+ lockdown_from_offchain : bool ,
799
+
797
800
// We simply modify last_block_hash in Channel's block_connected so that serialization is
798
801
// consistent but hopefully the users' copy handles block_connected in a consistent way.
799
802
// (we do *not*, however, update them in update_monitor to ensure any local user copies keep
@@ -1053,6 +1056,8 @@ impl<ChanSigner: ChannelKeys + Writeable> ChannelMonitor<ChanSigner> {
1053
1056
}
1054
1057
self . onchain_tx_handler . write ( writer) ?;
1055
1058
1059
+ self . lockdown_from_offchain . write ( writer) ?;
1060
+
1056
1061
Ok ( ( ) )
1057
1062
}
1058
1063
@@ -1136,6 +1141,8 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1136
1141
1137
1142
onchain_tx_handler : OnchainTxHandler :: new ( destination_script. clone ( ) , keys, funding_redeemscript, their_to_self_delay, logger. clone ( ) ) ,
1138
1143
1144
+ lockdown_from_offchain : false ,
1145
+
1139
1146
last_block_hash : Default :: default ( ) ,
1140
1147
secp_ctx : Secp256k1 :: new ( ) ,
1141
1148
logger,
@@ -1303,8 +1310,10 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1303
1310
pub ( super ) fn update_monitor_ooo ( & mut self , mut updates : ChannelMonitorUpdate ) -> Result < ( ) , MonitorUpdateError > {
1304
1311
for update in updates. updates . drain ( ..) {
1305
1312
match update {
1306
- ChannelMonitorUpdateStep :: LatestLocalCommitmentTXInfo { commitment_tx, local_keys, feerate_per_kw, htlc_outputs } =>
1307
- self . provide_latest_local_commitment_tx_info ( commitment_tx, local_keys, feerate_per_kw, htlc_outputs) ?,
1313
+ ChannelMonitorUpdateStep :: LatestLocalCommitmentTXInfo { commitment_tx, local_keys, feerate_per_kw, htlc_outputs } => {
1314
+ if self . lockdown_from_offchain { panic ! ( ) ; }
1315
+ self . provide_latest_local_commitment_tx_info ( commitment_tx, local_keys, feerate_per_kw, htlc_outputs) ?
1316
+ } ,
1308
1317
ChannelMonitorUpdateStep :: LatestRemoteCommitmentTXInfo { unsigned_commitment_tx, htlc_outputs, commitment_number, their_revocation_point } =>
1309
1318
self . provide_latest_remote_commitment_tx_info ( & unsigned_commitment_tx, htlc_outputs, commitment_number, their_revocation_point) ,
1310
1319
ChannelMonitorUpdateStep :: PaymentPreimage { payment_preimage } =>
@@ -1332,8 +1341,10 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1332
1341
}
1333
1342
for update in updates. updates . drain ( ..) {
1334
1343
match update {
1335
- ChannelMonitorUpdateStep :: LatestLocalCommitmentTXInfo { commitment_tx, local_keys, feerate_per_kw, htlc_outputs } =>
1336
- self . provide_latest_local_commitment_tx_info ( commitment_tx, local_keys, feerate_per_kw, htlc_outputs) ?,
1344
+ ChannelMonitorUpdateStep :: LatestLocalCommitmentTXInfo { commitment_tx, local_keys, feerate_per_kw, htlc_outputs } => {
1345
+ if self . lockdown_from_offchain { panic ! ( ) ; }
1346
+ self . provide_latest_local_commitment_tx_info ( commitment_tx, local_keys, feerate_per_kw, htlc_outputs) ?
1347
+ } ,
1337
1348
ChannelMonitorUpdateStep :: LatestRemoteCommitmentTXInfo { unsigned_commitment_tx, htlc_outputs, commitment_number, their_revocation_point } =>
1338
1349
self . provide_latest_remote_commitment_tx_info ( & unsigned_commitment_tx, htlc_outputs, commitment_number, their_revocation_point) ,
1339
1350
ChannelMonitorUpdateStep :: PaymentPreimage { payment_preimage } =>
@@ -1343,6 +1354,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1343
1354
ChannelMonitorUpdateStep :: RescueRemoteCommitmentTXInfo { their_current_per_commitment_point } =>
1344
1355
self . provide_rescue_remote_commitment_tx_info ( their_current_per_commitment_point) ,
1345
1356
ChannelMonitorUpdateStep :: ChannelForceClosed { should_broadcast } => {
1357
+ self . lockdown_from_offchain = true ;
1346
1358
if should_broadcast {
1347
1359
self . broadcast_latest_local_commitment_txn ( broadcaster) ;
1348
1360
} else {
@@ -2483,6 +2495,8 @@ impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for (Sha256dH
2483
2495
}
2484
2496
let onchain_tx_handler = ReadableArgs :: read ( reader, logger. clone ( ) ) ?;
2485
2497
2498
+ let lockdown_from_offchain = Readable :: read ( reader) ?;
2499
+
2486
2500
Ok ( ( last_block_hash. clone ( ) , ChannelMonitor {
2487
2501
latest_update_id,
2488
2502
commitment_transaction_number_obscure_factor,
@@ -2521,6 +2535,8 @@ impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for (Sha256dH
2521
2535
2522
2536
onchain_tx_handler,
2523
2537
2538
+ lockdown_from_offchain,
2539
+
2524
2540
last_block_hash,
2525
2541
secp_ctx : Secp256k1 :: new ( ) ,
2526
2542
logger,
0 commit comments