@@ -616,11 +616,6 @@ pub(super) enum ChannelMonitorUpdateStep {
616616 idx : u64 ,
617617 secret : [ u8 ; 32 ] ,
618618 } ,
619- /// Indicates our channel is likely a stale version, we're closing, but this update should
620- /// allow us to spend what is ours if our counterparty broadcasts their latest state.
621- RescueRemoteCommitmentTXInfo {
622- their_current_per_commitment_point : PublicKey ,
623- } ,
624619}
625620
626621impl Writeable for ChannelMonitorUpdateStep {
@@ -658,10 +653,6 @@ impl Writeable for ChannelMonitorUpdateStep {
658653 idx. write ( w) ?;
659654 secret. write ( w) ?;
660655 } ,
661- & ChannelMonitorUpdateStep :: RescueRemoteCommitmentTXInfo { ref their_current_per_commitment_point } => {
662- 4u8 . write ( w) ?;
663- their_current_per_commitment_point. write ( w) ?;
664- } ,
665656 }
666657 Ok ( ( ) )
667658 }
@@ -710,11 +701,6 @@ impl Readable for ChannelMonitorUpdateStep {
710701 secret : Readable :: read ( r) ?,
711702 } )
712703 } ,
713- 4u8 => {
714- Ok ( ChannelMonitorUpdateStep :: RescueRemoteCommitmentTXInfo {
715- their_current_per_commitment_point : Readable :: read ( r) ?,
716- } )
717- } ,
718704 _ => Err ( DecodeError :: InvalidValue ) ,
719705 }
720706 }
@@ -775,11 +761,6 @@ pub struct ChannelMonitor<ChanSigner: ChannelKeys> {
775761 pending_htlcs_updated : Vec < HTLCUpdate > ,
776762 pending_events : Vec < events:: Event > ,
777763
778- // Thanks to data loss protection, we may be able to claim our non-htlc funds
779- // back, this is the script we have to spend from but we need to
780- // scan every commitment transaction for that
781- to_remote_rescue : Option < ( Script , SecretKey ) > ,
782-
783764 // Used to track onchain events, i.e transactions parts of channels confirmed on chain, on which
784765 // we have to take actions once they reach enough confs. Key is a block height timer, i.e we enforce
785766 // actions when we receive a block with given height. Actions depend on OnchainEvent type.
@@ -831,7 +812,6 @@ impl<ChanSigner: ChannelKeys> PartialEq for ChannelMonitor<ChanSigner> {
831812 self . payment_preimages != other. payment_preimages ||
832813 self . pending_htlcs_updated != other. pending_htlcs_updated ||
833814 self . pending_events . len ( ) != other. pending_events . len ( ) || // We trust events to round-trip properly
834- self . to_remote_rescue != other. to_remote_rescue ||
835815 self . onchain_events_waiting_threshold_conf != other. onchain_events_waiting_threshold_conf ||
836816 self . outputs_to_watch != other. outputs_to_watch
837817 {
@@ -1009,13 +989,6 @@ impl<ChanSigner: ChannelKeys + Writeable> ChannelMonitor<ChanSigner> {
1009989 }
1010990
1011991 self . last_block_hash . write ( writer) ?;
1012- if let Some ( ( ref to_remote_script, ref local_key) ) = self . to_remote_rescue {
1013- writer. write_all ( & [ 1 ; 1 ] ) ?;
1014- to_remote_script. write ( writer) ?;
1015- local_key. write ( writer) ?;
1016- } else {
1017- writer. write_all ( & [ 0 ; 1 ] ) ?;
1018- }
1019992
1020993 writer. write_all ( & byte_utils:: be64_to_array ( self . onchain_events_waiting_threshold_conf . len ( ) as u64 ) ) ?;
1021994 for ( ref target, ref events) in self . onchain_events_waiting_threshold_conf . iter ( ) {
@@ -1120,8 +1093,6 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
11201093 pending_htlcs_updated : Vec :: new ( ) ,
11211094 pending_events : Vec :: new ( ) ,
11221095
1123- to_remote_rescue : None ,
1124-
11251096 onchain_events_waiting_threshold_conf : HashMap :: new ( ) ,
11261097 outputs_to_watch : HashMap :: new ( ) ,
11271098
@@ -1229,22 +1200,6 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
12291200 }
12301201 }
12311202
1232- pub ( super ) fn provide_rescue_remote_commitment_tx_info ( & mut self , their_revocation_point : PublicKey ) {
1233- match self . key_storage {
1234- Storage :: Local { ref payment_base_key, ref keys, .. } => {
1235- if let Ok ( payment_key) = chan_utils:: derive_public_key ( & self . secp_ctx , & their_revocation_point, & keys. pubkeys ( ) . payment_basepoint ) {
1236- let to_remote_script = Builder :: new ( ) . push_opcode ( opcodes:: all:: OP_PUSHBYTES_0 )
1237- . push_slice ( & Hash160 :: hash ( & payment_key. serialize ( ) ) [ ..] )
1238- . into_script ( ) ;
1239- if let Ok ( to_remote_key) = chan_utils:: derive_private_key ( & self . secp_ctx , & their_revocation_point, & payment_base_key) {
1240- self . to_remote_rescue = Some ( ( to_remote_script, to_remote_key) ) ;
1241- }
1242- }
1243- } ,
1244- Storage :: Watchtower { .. } => { }
1245- }
1246- }
1247-
12481203 /// Informs this monitor of the latest local (ie broadcastable) commitment transaction. The
12491204 /// monitor watches for timeouts and may broadcast it if we approach such a timeout. Thus, it
12501205 /// is important that any clones of this channel monitor (including remote clones) by kept
@@ -1287,8 +1242,6 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
12871242 self . provide_payment_preimage ( & PaymentHash ( Sha256 :: hash ( & payment_preimage. 0 [ ..] ) . into_inner ( ) ) , & payment_preimage) ,
12881243 ChannelMonitorUpdateStep :: CommitmentSecret { idx, secret } =>
12891244 self . provide_secret ( idx, secret) ?,
1290- ChannelMonitorUpdateStep :: RescueRemoteCommitmentTXInfo { their_current_per_commitment_point } =>
1291- self . provide_rescue_remote_commitment_tx_info ( their_current_per_commitment_point) ,
12921245 }
12931246 }
12941247 self . latest_update_id = updates. update_id ;
@@ -1313,8 +1266,6 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
13131266 self . provide_payment_preimage ( & PaymentHash ( Sha256 :: hash ( & payment_preimage. 0 [ ..] ) . into_inner ( ) ) , & payment_preimage) ,
13141267 ChannelMonitorUpdateStep :: CommitmentSecret { idx, secret } =>
13151268 self . provide_secret ( idx, secret) ?,
1316- ChannelMonitorUpdateStep :: RescueRemoteCommitmentTXInfo { their_current_per_commitment_point } =>
1317- self . provide_rescue_remote_commitment_tx_info ( their_current_per_commitment_point) ,
13181269 }
13191270 }
13201271 self . latest_update_id = updates. update_id ;
@@ -1436,7 +1387,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
14361387 ( ignore_error ! ( chan_utils:: derive_public_revocation_key( & self . secp_ctx, & per_commitment_point, & keys. pubkeys( ) . revocation_basepoint) ) ,
14371388 ignore_error ! ( chan_utils:: derive_private_revocation_key( & self . secp_ctx, & per_commitment_key, & revocation_base_key) ) ,
14381389 ignore_error ! ( chan_utils:: derive_public_key( & self . secp_ctx, & per_commitment_point, & keys. pubkeys( ) . htlc_basepoint) ) ,
1439- Some ( ignore_error ! ( chan_utils :: derive_private_key ( & self . secp_ctx , & per_commitment_point , & payment_base_key) ) ) )
1390+ Some ( payment_base_key) )
14401391 } ,
14411392 Storage :: Watchtower { .. } => {
14421393 unimplemented ! ( )
@@ -1466,7 +1417,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
14661417 } else if Some ( & outp. script_pubkey ) == local_payment_p2wpkh. as_ref ( ) {
14671418 spendable_outputs. push ( SpendableOutputDescriptor :: DynamicOutputP2WPKH {
14681419 outpoint : BitcoinOutPoint { txid : commitment_txid, vout : idx as u32 } ,
1469- key : local_payment_key. unwrap ( ) ,
1420+ key : local_payment_key. unwrap ( ) . clone ( ) ,
14701421 output : outp. clone ( ) ,
14711422 } ) ;
14721423 }
@@ -1620,13 +1571,11 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
16201571 if outp. script_pubkey . is_v0_p2wpkh ( ) {
16211572 match self . key_storage {
16221573 Storage :: Local { ref payment_base_key, .. } => {
1623- if let Ok ( local_key) = chan_utils:: derive_private_key ( & self . secp_ctx , & revocation_point, & payment_base_key) {
1624- spendable_outputs. push ( SpendableOutputDescriptor :: DynamicOutputP2WPKH {
1625- outpoint : BitcoinOutPoint { txid : commitment_txid, vout : idx as u32 } ,
1626- key : local_key,
1627- output : outp. clone ( ) ,
1628- } ) ;
1629- }
1574+ spendable_outputs. push ( SpendableOutputDescriptor :: DynamicOutputP2WPKH {
1575+ outpoint : BitcoinOutPoint { txid : commitment_txid, vout : idx as u32 } ,
1576+ key : payment_base_key. clone ( ) ,
1577+ output : outp. clone ( ) ,
1578+ } ) ;
16301579 } ,
16311580 Storage :: Watchtower { .. } => { }
16321581 }
@@ -1653,15 +1602,24 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
16531602 }
16541603 }
16551604 }
1656- } else if let Some ( ( ref to_remote_rescue, ref local_key) ) = self . to_remote_rescue {
1657- for ( idx, outp) in tx. output . iter ( ) . enumerate ( ) {
1658- if to_remote_rescue == & outp. script_pubkey {
1659- spendable_outputs. push ( SpendableOutputDescriptor :: DynamicOutputP2WPKH {
1660- outpoint : BitcoinOutPoint { txid : commitment_txid, vout : idx as u32 } ,
1661- key : local_key. clone ( ) ,
1662- output : outp. clone ( ) ,
1663- } ) ;
1664- }
1605+ } else {
1606+ match self . key_storage {
1607+ Storage :: Local { ref payment_base_key, .. } => {
1608+ let payment_hash160 = Hash160 :: hash ( & PublicKey :: from_secret_key ( & self . secp_ctx , & payment_base_key) . serialize ( ) ) ;
1609+ let our_payment_script = Builder :: new ( ) . push_opcode ( opcodes:: all:: OP_PUSHBYTES_0 )
1610+ . push_slice ( & payment_hash160)
1611+ . into_script ( ) ;
1612+ for ( idx, outp) in tx. output . iter ( ) . enumerate ( ) {
1613+ if our_payment_script == outp. script_pubkey {
1614+ spendable_outputs. push ( SpendableOutputDescriptor :: DynamicOutputP2WPKH {
1615+ outpoint : BitcoinOutPoint { txid : commitment_txid, vout : idx as u32 } ,
1616+ key : payment_base_key. clone ( ) ,
1617+ output : outp. clone ( ) ,
1618+ } ) ;
1619+ }
1620+ }
1621+ } ,
1622+ Storage :: Watchtower { .. } => unimplemented ! ( ) ,
16651623 }
16661624 }
16671625 ( claimable_outpoints, ( commitment_txid, watch_outputs) , spendable_outputs)
@@ -2524,15 +2482,6 @@ impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for (Sha256dH
25242482 }
25252483
25262484 let last_block_hash: Sha256dHash = Readable :: read ( reader) ?;
2527- let to_remote_rescue = match <u8 as Readable >:: read ( reader) ? {
2528- 0 => None ,
2529- 1 => {
2530- let to_remote_script = Readable :: read ( reader) ?;
2531- let local_key = Readable :: read ( reader) ?;
2532- Some ( ( to_remote_script, local_key) )
2533- }
2534- _ => return Err ( DecodeError :: InvalidValue ) ,
2535- } ;
25362485
25372486 let waiting_threshold_conf_len: u64 = Readable :: read ( reader) ?;
25382487 let mut onchain_events_waiting_threshold_conf = HashMap :: with_capacity ( cmp:: min ( waiting_threshold_conf_len as usize , MAX_ALLOC_SIZE / 128 ) ) ;
@@ -2598,8 +2547,6 @@ impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for (Sha256dH
25982547 pending_htlcs_updated,
25992548 pending_events,
26002549
2601- to_remote_rescue,
2602-
26032550 onchain_events_waiting_threshold_conf,
26042551 outputs_to_watch,
26052552
@@ -2652,7 +2599,6 @@ mod tests {
26522599 a_htlc_key: dummy_key. clone( ) ,
26532600 b_htlc_key: dummy_key. clone( ) ,
26542601 a_delayed_payment_key: dummy_key. clone( ) ,
2655- b_payment_key: dummy_key. clone( ) ,
26562602 }
26572603 }
26582604 }
0 commit comments