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