@@ -74,15 +74,6 @@ use crate::sync::{Mutex, LockTestExt};
7474#[ must_use]
7575pub struct ChannelMonitorUpdate {
7676 pub ( crate ) updates : Vec < ChannelMonitorUpdateStep > ,
77- /// Historically, [`ChannelMonitor`]s didn't know their counterparty node id. However,
78- /// `ChannelManager` really wants to know it so that it can easily look up the corresponding
79- /// channel. For now, this results in a temporary map in `ChannelManager` to look up channels
80- /// by only the funding outpoint.
81- ///
82- /// To eventually remove that, we repeat the counterparty node id here so that we can upgrade
83- /// `ChannelMonitor`s to become aware of the counterparty node id if they were generated prior
84- /// to when it was stored directly in them.
85- pub ( crate ) counterparty_node_id : Option < PublicKey > ,
8677 /// The sequence number of this update. Updates *must* be replayed in-order according to this
8778 /// sequence number (and updates may panic if they are not). The update_id values are strictly
8879 /// increasing and increase by one for each new update, with two exceptions specified below.
@@ -117,7 +108,7 @@ impl Writeable for ChannelMonitorUpdate {
117108 update_step. write ( w) ?;
118109 }
119110 write_tlv_fields ! ( w, {
120- ( 1 , self . counterparty_node_id , option ) ,
111+ // 1 was previously used to store `counterparty_node_id`
121112 ( 3 , self . channel_id, option) ,
122113 } ) ;
123114 Ok ( ( ) )
@@ -134,13 +125,12 @@ impl Readable for ChannelMonitorUpdate {
134125 updates. push ( upd) ;
135126 }
136127 }
137- let mut counterparty_node_id = None ;
138128 let mut channel_id = None ;
139129 read_tlv_fields ! ( r, {
140- ( 1 , counterparty_node_id , option ) ,
130+ // 1 was previously used to store `counterparty_node_id`
141131 ( 3 , channel_id, option) ,
142132 } ) ;
143- Ok ( Self { update_id, counterparty_node_id , updates, channel_id } )
133+ Ok ( Self { update_id, updates, channel_id } )
144134 }
145135}
146136
@@ -1020,7 +1010,7 @@ pub(crate) struct ChannelMonitorImpl<Signer: EcdsaChannelSigner> {
10201010 best_block : BestBlock ,
10211011
10221012 /// The node_id of our counterparty
1023- counterparty_node_id : Option < PublicKey > ,
1013+ counterparty_node_id : PublicKey ,
10241014
10251015 /// Initial counterparty commmitment data needed to recreate the commitment tx
10261016 /// in the persistence pipeline for third-party watchtowers. This will only be present on
@@ -1242,7 +1232,7 @@ impl<Signer: EcdsaChannelSigner> Writeable for ChannelMonitorImpl<Signer> {
12421232 ( 3 , self . htlcs_resolved_on_chain, required_vec) ,
12431233 ( 5 , pending_monitor_events, required_vec) ,
12441234 ( 7 , self . funding_spend_seen, required) ,
1245- ( 9 , self . counterparty_node_id, option ) ,
1235+ ( 9 , self . counterparty_node_id, required ) ,
12461236 ( 11 , self . confirmed_commitment_tx_counterparty_output, option) ,
12471237 ( 13 , self . spendable_txids_confirmed, required_vec) ,
12481238 ( 15 , self . counterparty_fulfilled_htlcs, required) ,
@@ -1338,7 +1328,7 @@ impl<'a, L: Deref> WithChannelMonitor<'a, L> where L::Target: Logger {
13381328 }
13391329
13401330 pub ( crate ) fn from_impl < S : EcdsaChannelSigner > ( logger : & ' a L , monitor_impl : & ChannelMonitorImpl < S > , payment_hash : Option < PaymentHash > ) -> Self {
1341- let peer_id = monitor_impl. counterparty_node_id ;
1331+ let peer_id = Some ( monitor_impl. counterparty_node_id ) ;
13421332 let channel_id = Some ( monitor_impl. channel_id ( ) ) ;
13431333 WithChannelMonitor {
13441334 logger, peer_id, channel_id, payment_hash,
@@ -1462,7 +1452,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
14621452 spendable_txids_confirmed : Vec :: new ( ) ,
14631453
14641454 best_block,
1465- counterparty_node_id : Some ( counterparty_node_id) ,
1455+ counterparty_node_id : counterparty_node_id,
14661456 initial_counterparty_commitment_info : None ,
14671457 balances_empty_height : None ,
14681458
@@ -1788,10 +1778,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
17881778 }
17891779
17901780 /// Gets the `node_id` of the counterparty for this channel.
1791- ///
1792- /// Will be `None` for channels constructed on LDK versions prior to 0.0.110 and always `Some`
1793- /// otherwise.
1794- pub fn get_counterparty_node_id ( & self ) -> Option < PublicKey > {
1781+ pub fn get_counterparty_node_id ( & self ) -> PublicKey {
17951782 self . inner . lock ( ) . unwrap ( ) . counterparty_node_id
17961783 }
17971784
@@ -3200,14 +3187,6 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
32003187 log_funding_info!( self ) , self . latest_update_id, updates. update_id, updates. updates. len( ) ) ;
32013188 }
32023189
3203- if updates. counterparty_node_id . is_some ( ) {
3204- if self . counterparty_node_id . is_none ( ) {
3205- self . counterparty_node_id = updates. counterparty_node_id ;
3206- } else {
3207- debug_assert_eq ! ( self . counterparty_node_id, updates. counterparty_node_id) ;
3208- }
3209- }
3210-
32113190 // ChannelMonitor updates may be applied after force close if we receive a preimage for a
32123191 // broadcasted commitment transaction HTLC output that we'd like to claim on-chain. If this
32133192 // is the case, we no longer have guaranteed access to the monitor's update ID, so we use a
@@ -3376,10 +3355,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
33763355 package_target_feerate_sat_per_1000_weight, commitment_tx, anchor_output_idx,
33773356 } => {
33783357 let channel_id = self . channel_id ;
3379- // unwrap safety: `ClaimEvent`s are only available for Anchor channels,
3380- // introduced with v0.0.116. counterparty_node_id is guaranteed to be `Some`
3381- // since v0.0.110.
3382- let counterparty_node_id = self . counterparty_node_id . unwrap ( ) ;
3358+ let counterparty_node_id = self . counterparty_node_id ;
33833359 let commitment_txid = commitment_tx. compute_txid ( ) ;
33843360 debug_assert_eq ! ( self . current_holder_commitment_tx. txid, commitment_txid) ;
33853361 let pending_htlcs = self . current_holder_commitment_tx . non_dust_htlcs ( ) ;
@@ -3410,10 +3386,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
34103386 target_feerate_sat_per_1000_weight, htlcs, tx_lock_time,
34113387 } => {
34123388 let channel_id = self . channel_id ;
3413- // unwrap safety: `ClaimEvent`s are only available for Anchor channels,
3414- // introduced with v0.0.116. counterparty_node_id is guaranteed to be `Some`
3415- // since v0.0.110.
3416- let counterparty_node_id = self . counterparty_node_id . unwrap ( ) ;
3389+ let counterparty_node_id = self . counterparty_node_id ;
34173390 let mut htlc_descriptors = Vec :: with_capacity ( htlcs. len ( ) ) ;
34183391 for htlc in htlcs {
34193392 htlc_descriptors. push ( HTLCDescriptor {
@@ -5129,6 +5102,13 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
51295102 chan_utils:: get_to_countersignatory_with_anchors_redeemscript ( & payment_point) . to_p2wsh ( ) ;
51305103 }
51315104
5105+ let channel_id = channel_id. unwrap_or ( ChannelId :: v1_from_funding_outpoint ( outpoint) ) ;
5106+ if counterparty_node_id. is_none ( ) {
5107+ panic ! ( "Found monitor for channel {} with no updates since v0.0.118.\
5108+ These monitors are no longer supported.\
5109+ To continue, run a v0.1 release, send/route a payment over the channel or close it.", channel_id) ;
5110+ }
5111+
51325112 Ok ( ( best_block. block_hash , ChannelMonitor :: from_impl ( ChannelMonitorImpl {
51335113 latest_update_id,
51345114 commitment_transaction_number_obscure_factor,
@@ -5140,7 +5120,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
51405120
51415121 channel_keys_id,
51425122 holder_revocation_basepoint,
5143- channel_id : channel_id . unwrap_or ( ChannelId :: v1_from_funding_outpoint ( outpoint ) ) ,
5123+ channel_id,
51445124 funding_info,
51455125 first_confirmed_funding_txo : first_confirmed_funding_txo. 0 . unwrap ( ) ,
51465126 current_counterparty_commitment_txid,
@@ -5184,7 +5164,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
51845164 spendable_txids_confirmed : spendable_txids_confirmed. unwrap ( ) ,
51855165
51865166 best_block,
5187- counterparty_node_id,
5167+ counterparty_node_id : counterparty_node_id . unwrap ( ) ,
51885168 initial_counterparty_commitment_info,
51895169 balances_empty_height,
51905170 failed_back_htlc_ids : new_hash_set ( ) ,
0 commit comments