@@ -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,
@@ -1305,8 +1312,10 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1305
1312
pub ( super ) fn update_monitor_ooo ( & mut self , mut updates : ChannelMonitorUpdate ) -> Result < ( ) , MonitorUpdateError > {
1306
1313
for update in updates. updates . drain ( ..) {
1307
1314
match update {
1308
- ChannelMonitorUpdateStep :: LatestLocalCommitmentTXInfo { commitment_tx, local_keys, feerate_per_kw, htlc_outputs } =>
1309
- self . provide_latest_local_commitment_tx_info ( commitment_tx, local_keys, feerate_per_kw, htlc_outputs) ?,
1315
+ ChannelMonitorUpdateStep :: LatestLocalCommitmentTXInfo { commitment_tx, local_keys, feerate_per_kw, htlc_outputs } => {
1316
+ if self . lockdown_from_offchain { panic ! ( ) ; }
1317
+ self . provide_latest_local_commitment_tx_info ( commitment_tx, local_keys, feerate_per_kw, htlc_outputs) ?
1318
+ } ,
1310
1319
ChannelMonitorUpdateStep :: LatestRemoteCommitmentTXInfo { unsigned_commitment_tx, htlc_outputs, commitment_number, their_revocation_point } =>
1311
1320
self . provide_latest_remote_commitment_tx_info ( & unsigned_commitment_tx, htlc_outputs, commitment_number, their_revocation_point) ,
1312
1321
ChannelMonitorUpdateStep :: PaymentPreimage { payment_preimage } =>
@@ -1334,8 +1343,10 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1334
1343
}
1335
1344
for update in updates. updates . drain ( ..) {
1336
1345
match update {
1337
- ChannelMonitorUpdateStep :: LatestLocalCommitmentTXInfo { commitment_tx, local_keys, feerate_per_kw, htlc_outputs } =>
1338
- self . provide_latest_local_commitment_tx_info ( commitment_tx, local_keys, feerate_per_kw, htlc_outputs) ?,
1346
+ ChannelMonitorUpdateStep :: LatestLocalCommitmentTXInfo { commitment_tx, local_keys, feerate_per_kw, htlc_outputs } => {
1347
+ if self . lockdown_from_offchain { panic ! ( ) ; }
1348
+ self . provide_latest_local_commitment_tx_info ( commitment_tx, local_keys, feerate_per_kw, htlc_outputs) ?
1349
+ } ,
1339
1350
ChannelMonitorUpdateStep :: LatestRemoteCommitmentTXInfo { unsigned_commitment_tx, htlc_outputs, commitment_number, their_revocation_point } =>
1340
1351
self . provide_latest_remote_commitment_tx_info ( & unsigned_commitment_tx, htlc_outputs, commitment_number, their_revocation_point) ,
1341
1352
ChannelMonitorUpdateStep :: PaymentPreimage { payment_preimage } =>
@@ -1345,6 +1356,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1345
1356
ChannelMonitorUpdateStep :: RescueRemoteCommitmentTXInfo { their_current_per_commitment_point } =>
1346
1357
self . provide_rescue_remote_commitment_tx_info ( their_current_per_commitment_point) ,
1347
1358
ChannelMonitorUpdateStep :: ChannelForceClosed { should_broadcast } => {
1359
+ self . lockdown_from_offchain = true ;
1348
1360
if should_broadcast {
1349
1361
self . broadcast_latest_local_commitment_txn ( broadcaster) ;
1350
1362
} else {
@@ -2485,6 +2497,8 @@ impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for (Sha256dH
2485
2497
}
2486
2498
let onchain_tx_handler = ReadableArgs :: read ( reader, logger. clone ( ) ) ?;
2487
2499
2500
+ let lockdown_from_offchain = Readable :: read ( reader) ?;
2501
+
2488
2502
Ok ( ( last_block_hash. clone ( ) , ChannelMonitor {
2489
2503
latest_update_id,
2490
2504
commitment_transaction_number_obscure_factor,
@@ -2523,6 +2537,8 @@ impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for (Sha256dH
2523
2537
2524
2538
onchain_tx_handler,
2525
2539
2540
+ lockdown_from_offchain,
2541
+
2526
2542
last_block_hash,
2527
2543
secp_ctx : Secp256k1 :: new ( ) ,
2528
2544
logger,
0 commit comments