@@ -590,11 +590,6 @@ pub(super) enum ChannelMonitorUpdateStep {
590
590
idx : u64 ,
591
591
secret : [ u8 ; 32 ] ,
592
592
} ,
593
- /// Indicates our channel is likely a stale version, we're closing, but this update should
594
- /// allow us to spend what is ours if our counterparty broadcasts their latest state.
595
- RescueRemoteCommitmentTXInfo {
596
- their_current_per_commitment_point : PublicKey ,
597
- } ,
598
593
/// Used to indicate that the no future updates will occur, and likely that the latest local
599
594
/// commitment transaction(s) should be broadcast, as the channel has been force-closed.
600
595
ChannelForceClosed {
@@ -637,12 +632,8 @@ impl Writeable for ChannelMonitorUpdateStep {
637
632
idx. write ( w) ?;
638
633
secret. write ( w) ?;
639
634
} ,
640
- & ChannelMonitorUpdateStep :: RescueRemoteCommitmentTXInfo { ref their_current_per_commitment_point } => {
641
- 4u8 . write ( w) ?;
642
- their_current_per_commitment_point. write ( w) ?;
643
- } ,
644
635
& ChannelMonitorUpdateStep :: ChannelForceClosed { ref should_broadcast } => {
645
- 5u8 . write ( w) ?;
636
+ 4u8 . write ( w) ?;
646
637
should_broadcast. write ( w) ?;
647
638
} ,
648
639
}
@@ -692,11 +683,6 @@ impl Readable for ChannelMonitorUpdateStep {
692
683
} )
693
684
} ,
694
685
4u8 => {
695
- Ok ( ChannelMonitorUpdateStep :: RescueRemoteCommitmentTXInfo {
696
- their_current_per_commitment_point : Readable :: read ( r) ?,
697
- } )
698
- } ,
699
- 5u8 => {
700
686
Ok ( ChannelMonitorUpdateStep :: ChannelForceClosed {
701
687
should_broadcast : Readable :: read ( r) ?
702
688
} )
@@ -722,7 +708,7 @@ pub struct ChannelMonitor<ChanSigner: ChannelKeys> {
722
708
723
709
destination_script : Script ,
724
710
broadcasted_local_revokable_script : Option < ( Script , SecretKey , Script ) > ,
725
- broadcasted_remote_payment_script : Option < ( Script , SecretKey ) > ,
711
+ remote_payment_script : Script ,
726
712
shutdown_script : Script ,
727
713
728
714
keys : ChanSigner ,
@@ -818,7 +804,7 @@ impl<ChanSigner: ChannelKeys> PartialEq for ChannelMonitor<ChanSigner> {
818
804
self . commitment_transaction_number_obscure_factor != other. commitment_transaction_number_obscure_factor ||
819
805
self . destination_script != other. destination_script ||
820
806
self . broadcasted_local_revokable_script != other. broadcasted_local_revokable_script ||
821
- self . broadcasted_remote_payment_script != other. broadcasted_remote_payment_script ||
807
+ self . remote_payment_script != other. remote_payment_script ||
822
808
self . keys . pubkeys ( ) != other. keys . pubkeys ( ) ||
823
809
self . funding_info != other. funding_info ||
824
810
self . current_remote_commitment_txid != other. current_remote_commitment_txid ||
@@ -882,13 +868,7 @@ impl<ChanSigner: ChannelKeys + Writeable> ChannelMonitor<ChanSigner> {
882
868
writer. write_all ( & [ 1 ; 1 ] ) ?;
883
869
}
884
870
885
- if let Some ( ref broadcasted_remote_payment_script) = self . broadcasted_remote_payment_script {
886
- writer. write_all ( & [ 0 ; 1 ] ) ?;
887
- broadcasted_remote_payment_script. 0 . write ( writer) ?;
888
- broadcasted_remote_payment_script. 1 . write ( writer) ?;
889
- } else {
890
- writer. write_all ( & [ 1 ; 1 ] ) ?;
891
- }
871
+ self . remote_payment_script . write ( writer) ?;
892
872
self . shutdown_script . write ( writer) ?;
893
873
894
874
self . keys . write ( writer) ?;
@@ -1063,6 +1043,8 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1063
1043
assert ! ( commitment_transaction_number_obscure_factor <= ( 1 << 48 ) ) ;
1064
1044
let our_channel_close_key_hash = Hash160 :: hash ( & shutdown_pubkey. serialize ( ) ) ;
1065
1045
let shutdown_script = Builder :: new ( ) . push_opcode ( opcodes:: all:: OP_PUSHBYTES_0 ) . push_slice ( & our_channel_close_key_hash[ ..] ) . into_script ( ) ;
1046
+ let payment_base_key_hash = Hash160 :: hash ( & keys. pubkeys ( ) . payment_basepoint . serialize ( ) ) ;
1047
+ let remote_payment_script = Builder :: new ( ) . push_opcode ( opcodes:: all:: OP_PUSHBYTES_0 ) . push_slice ( & payment_base_key_hash[ ..] ) . into_script ( ) ;
1066
1048
1067
1049
let mut onchain_tx_handler = OnchainTxHandler :: new ( destination_script. clone ( ) , keys. clone ( ) , their_to_self_delay, logger. clone ( ) ) ;
1068
1050
@@ -1091,7 +1073,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1091
1073
1092
1074
destination_script : destination_script. clone ( ) ,
1093
1075
broadcasted_local_revokable_script : None ,
1094
- broadcasted_remote_payment_script : None ,
1076
+ remote_payment_script ,
1095
1077
shutdown_script,
1096
1078
1097
1079
keys,
@@ -1228,17 +1210,6 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1228
1210
}
1229
1211
}
1230
1212
1231
- pub ( super ) fn provide_rescue_remote_commitment_tx_info ( & mut self , their_revocation_point : PublicKey ) {
1232
- if let Ok ( payment_key) = chan_utils:: derive_public_key ( & self . secp_ctx , & their_revocation_point, & self . keys . pubkeys ( ) . payment_basepoint ) {
1233
- let to_remote_script = Builder :: new ( ) . push_opcode ( opcodes:: all:: OP_PUSHBYTES_0 )
1234
- . push_slice ( & Hash160 :: hash ( & payment_key. serialize ( ) ) [ ..] )
1235
- . into_script ( ) ;
1236
- if let Ok ( to_remote_key) = chan_utils:: derive_private_key ( & self . secp_ctx , & their_revocation_point, & self . keys . payment_base_key ( ) ) {
1237
- self . broadcasted_remote_payment_script = Some ( ( to_remote_script, to_remote_key) ) ;
1238
- }
1239
- }
1240
- }
1241
-
1242
1213
/// Informs this monitor of the latest local (ie broadcastable) commitment transaction. The
1243
1214
/// monitor watches for timeouts and may broadcast it if we approach such a timeout. Thus, it
1244
1215
/// is important that any clones of this channel monitor (including remote clones) by kept
@@ -1303,8 +1274,6 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1303
1274
self . provide_payment_preimage ( & PaymentHash ( Sha256 :: hash ( & payment_preimage. 0 [ ..] ) . into_inner ( ) ) , & payment_preimage) ,
1304
1275
ChannelMonitorUpdateStep :: CommitmentSecret { idx, secret } =>
1305
1276
self . provide_secret ( idx, secret) ?,
1306
- ChannelMonitorUpdateStep :: RescueRemoteCommitmentTXInfo { their_current_per_commitment_point } =>
1307
- self . provide_rescue_remote_commitment_tx_info ( their_current_per_commitment_point) ,
1308
1277
ChannelMonitorUpdateStep :: ChannelForceClosed { .. } => { } ,
1309
1278
}
1310
1279
}
@@ -1334,8 +1303,6 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1334
1303
self . provide_payment_preimage ( & PaymentHash ( Sha256 :: hash ( & payment_preimage. 0 [ ..] ) . into_inner ( ) ) , & payment_preimage) ,
1335
1304
ChannelMonitorUpdateStep :: CommitmentSecret { idx, secret } =>
1336
1305
self . provide_secret ( idx, secret) ?,
1337
- ChannelMonitorUpdateStep :: RescueRemoteCommitmentTXInfo { their_current_per_commitment_point } =>
1338
- self . provide_rescue_remote_commitment_tx_info ( their_current_per_commitment_point) ,
1339
1306
ChannelMonitorUpdateStep :: ChannelForceClosed { should_broadcast } => {
1340
1307
self . lockdown_from_offchain = true ;
1341
1308
if should_broadcast {
@@ -1450,20 +1417,12 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1450
1417
let revocation_pubkey = ignore_error ! ( chan_utils:: derive_public_revocation_key( & self . secp_ctx, & per_commitment_point, & self . keys. pubkeys( ) . revocation_basepoint) ) ;
1451
1418
let revocation_key = ignore_error ! ( chan_utils:: derive_private_revocation_key( & self . secp_ctx, & per_commitment_key, & self . keys. revocation_base_key( ) ) ) ;
1452
1419
let b_htlc_key = ignore_error ! ( chan_utils:: derive_public_key( & self . secp_ctx, & per_commitment_point, & self . keys. pubkeys( ) . htlc_basepoint) ) ;
1453
- let local_payment_key = ignore_error ! ( chan_utils:: derive_private_key( & self . secp_ctx, & per_commitment_point, & self . keys. payment_base_key( ) ) ) ;
1454
1420
let delayed_key = ignore_error ! ( chan_utils:: derive_public_key( & self . secp_ctx, & PublicKey :: from_secret_key( & self . secp_ctx, & per_commitment_key) , & self . their_delayed_payment_base_key) ) ;
1455
1421
let a_htlc_key = ignore_error ! ( chan_utils:: derive_public_key( & self . secp_ctx, & PublicKey :: from_secret_key( & self . secp_ctx, & per_commitment_key) , & self . their_htlc_base_key) ) ;
1456
1422
1457
1423
let revokeable_redeemscript = chan_utils:: get_revokeable_redeemscript ( & revocation_pubkey, self . our_to_self_delay , & delayed_key) ;
1458
1424
let revokeable_p2wsh = revokeable_redeemscript. to_v0_p2wsh ( ) ;
1459
1425
1460
- self . broadcasted_remote_payment_script = {
1461
- // Note that the Network here is ignored as we immediately drop the address for the
1462
- // script_pubkey version
1463
- let payment_hash160 = Hash160 :: hash ( & PublicKey :: from_secret_key ( & self . secp_ctx , & local_payment_key) . serialize ( ) ) ;
1464
- Some ( ( Builder :: new ( ) . push_opcode ( opcodes:: all:: OP_PUSHBYTES_0 ) . push_slice ( & payment_hash160[ ..] ) . into_script ( ) , local_payment_key) )
1465
- } ;
1466
-
1467
1426
// First, process non-htlc outputs (to_local & to_remote)
1468
1427
for ( idx, outp) in tx. output . iter ( ) . enumerate ( ) {
1469
1428
if outp. script_pubkey == revokeable_p2wsh {
@@ -1604,14 +1563,6 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
1604
1563
let b_htlc_key = ignore_error ! ( chan_utils:: derive_public_key( & self . secp_ctx, revocation_point, & self . keys. pubkeys( ) . htlc_basepoint) ) ;
1605
1564
let htlc_privkey = ignore_error ! ( chan_utils:: derive_private_key( & self . secp_ctx, revocation_point, & self . keys. htlc_base_key( ) ) ) ;
1606
1565
let a_htlc_key = ignore_error ! ( chan_utils:: derive_public_key( & self . secp_ctx, revocation_point, & self . their_htlc_base_key) ) ;
1607
- let local_payment_key = ignore_error ! ( chan_utils:: derive_private_key( & self . secp_ctx, revocation_point, & self . keys. payment_base_key( ) ) ) ;
1608
-
1609
- self . broadcasted_remote_payment_script = {
1610
- // Note that the Network here is ignored as we immediately drop the address for the
1611
- // script_pubkey version
1612
- let payment_hash160 = Hash160 :: hash ( & PublicKey :: from_secret_key ( & self . secp_ctx , & local_payment_key) . serialize ( ) ) ;
1613
- Some ( ( Builder :: new ( ) . push_opcode ( opcodes:: all:: OP_PUSHBYTES_0 ) . push_slice ( & payment_hash160[ ..] ) . into_script ( ) , local_payment_key) )
1614
- } ;
1615
1566
1616
1567
// Then, try to find htlc outputs
1617
1568
for ( _, & ( ref htlc, _) ) in per_commitment_data. iter ( ) . enumerate ( ) {
@@ -2177,15 +2128,13 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
2177
2128
} ) ;
2178
2129
break ;
2179
2130
}
2180
- } else if let Some ( ref broadcasted_remote_payment_script) = self . broadcasted_remote_payment_script {
2181
- if broadcasted_remote_payment_script. 0 == outp. script_pubkey {
2182
- spendable_output = Some ( SpendableOutputDescriptor :: DynamicOutputP2WPKH {
2183
- outpoint : BitcoinOutPoint { txid : tx. txid ( ) , vout : i as u32 } ,
2184
- key : broadcasted_remote_payment_script. 1 ,
2185
- output : outp. clone ( ) ,
2186
- } ) ;
2187
- break ;
2188
- }
2131
+ } else if self . remote_payment_script == outp. script_pubkey {
2132
+ spendable_output = Some ( SpendableOutputDescriptor :: DynamicOutputP2WPKH {
2133
+ outpoint : BitcoinOutPoint { txid : tx. txid ( ) , vout : i as u32 } ,
2134
+ key : self . keys . payment_base_key ( ) . clone ( ) ,
2135
+ output : outp. clone ( ) ,
2136
+ } ) ;
2137
+ break ;
2189
2138
} else if outp. script_pubkey == self . shutdown_script {
2190
2139
spendable_output = Some ( SpendableOutputDescriptor :: StaticOutput {
2191
2140
outpoint : BitcoinOutPoint { txid : tx. txid ( ) , vout : i as u32 } ,
@@ -2241,15 +2190,7 @@ impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for (Sha256dH
2241
2190
1 => { None } ,
2242
2191
_ => return Err ( DecodeError :: InvalidValue ) ,
2243
2192
} ;
2244
- let broadcasted_remote_payment_script = match <u8 as Readable >:: read ( reader) ? {
2245
- 0 => {
2246
- let payment_address = Readable :: read ( reader) ?;
2247
- let payment_key = Readable :: read ( reader) ?;
2248
- Some ( ( payment_address, payment_key) )
2249
- } ,
2250
- 1 => { None } ,
2251
- _ => return Err ( DecodeError :: InvalidValue ) ,
2252
- } ;
2193
+ let remote_payment_script = Readable :: read ( reader) ?;
2253
2194
let shutdown_script = Readable :: read ( reader) ?;
2254
2195
2255
2196
let keys = Readable :: read ( reader) ?;
@@ -2465,7 +2406,7 @@ impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for (Sha256dH
2465
2406
2466
2407
destination_script,
2467
2408
broadcasted_local_revokable_script,
2468
- broadcasted_remote_payment_script ,
2409
+ remote_payment_script ,
2469
2410
shutdown_script,
2470
2411
2471
2412
keys,
0 commit comments