From ec3baf9afbc7bc01fe71228d2e815df7fa3d9998 Mon Sep 17 00:00:00 2001 From: Chris Waterson Date: Fri, 20 Oct 2023 08:52:01 -0700 Subject: [PATCH] Don't persist commitment point/secret Turns out we don't have to persist the point or secret if we just call `update_holder_per_commitment` after we read the channel. --- lightning/src/ln/channel.rs | 36 ++++-------------------------- lightning/src/ln/channelmanager.rs | 1 + 2 files changed, 5 insertions(+), 32 deletions(-) diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index 422ec5ec9..4b26487c9 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -7613,8 +7613,6 @@ impl Writeable for Channel where SP::Target: SignerProvider { (35, pending_outbound_skimmed_fees, optional_vec), (37, holding_cell_skimmed_fees, optional_vec), (38, self.context.is_batch_funding, option), - (39, self.context.cur_holder_commitment_point, option), - (41, self.context.prev_holder_commitment_secret, option), }); Ok(()) @@ -7900,9 +7898,6 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch let mut is_batch_funding: Option<()> = None; - let mut cur_holder_commitment_point: Option = None; - let mut prev_holder_commitment_secret: Option<[u8; 32]> = None; - read_tlv_fields!(reader, { (0, announcement_sigs, option), (1, minimum_depth, option), @@ -7929,8 +7924,6 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch (35, pending_outbound_skimmed_fees_opt, optional_vec), (37, holding_cell_skimmed_fees_opt, optional_vec), (38, is_batch_funding, option), - (39, cur_holder_commitment_point, option), - (41, prev_holder_commitment_secret, option), }); let (channel_keys_id, holder_signer) = if let Some(channel_keys_id) = channel_keys_id { @@ -7982,27 +7975,6 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch let mut secp_ctx = Secp256k1::new(); secp_ctx.seeded_randomize(&entropy_source.get_secure_random_bytes()); - // If we weren't able to load the cur_holder_commitment_point or prev_holder_commitment_secret, - // ask the signer for it now. - let mut signer_pending_commitment_point = false; - if cur_holder_commitment_point.is_none() { - cur_holder_commitment_point = holder_signer.get_per_commitment_point( - cur_holder_commitment_transaction_number, &secp_ctx - ).ok(); - - signer_pending_commitment_point = cur_holder_commitment_point.is_none(); - } - - let mut signer_pending_released_secret = false; - if prev_holder_commitment_secret.is_none() { - let release_transaction_number = cur_holder_commitment_transaction_number + 2; - prev_holder_commitment_secret = if release_transaction_number <= INITIAL_COMMITMENT_NUMBER { - let secret = holder_signer.release_commitment_secret(release_transaction_number).ok(); - signer_pending_released_secret = secret.is_none(); - secret - } else { None }; - } - // `user_id` used to be a single u64 value. In order to remain backwards // compatible with versions prior to 0.0.113, the u128 is serialized as two // separate u64 values. @@ -8055,8 +8027,8 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch destination_script, cur_holder_commitment_transaction_number, - cur_holder_commitment_point, - prev_holder_commitment_secret, + cur_holder_commitment_point: None, + prev_holder_commitment_secret: None, cur_counterparty_commitment_transaction_number, value_to_self_msat, @@ -8078,8 +8050,8 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch signer_pending_revoke_and_ack: false, signer_pending_funding: false, signer_pending_channel_ready: false, - signer_pending_commitment_point, - signer_pending_released_secret, + signer_pending_commitment_point: true, + signer_pending_released_secret: true, pending_update_fee, holding_cell_update_fee, diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 4180a9ded..e555b8ef7 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -10142,6 +10142,7 @@ where log_info!(args.logger, "Successfully loaded channel {} at update_id {} against monitor at update id {}", &channel.context.channel_id(), channel.context.get_latest_monitor_update_id(), monitor.get_latest_update_id()); + channel.context.update_holder_per_commitment(&args.logger); if let Some(short_channel_id) = channel.context.get_short_channel_id() { short_to_chan_info.insert(short_channel_id, (channel.context.get_counterparty_node_id(), channel.context.channel_id())); } -- 2.39.5