Skip to content

Commit d782143

Browse files
committed
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.
1 parent 0bd7ea7 commit d782143

File tree

2 files changed

+5
-32
lines changed

2 files changed

+5
-32
lines changed

lightning/src/ln/channel.rs

+4-32
Original file line numberDiff line numberDiff line change
@@ -7637,8 +7637,6 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
76377637
(35, pending_outbound_skimmed_fees, optional_vec),
76387638
(37, holding_cell_skimmed_fees, optional_vec),
76397639
(38, self.context.is_batch_funding, option),
7640-
(39, self.context.cur_holder_commitment_point, option),
7641-
(41, self.context.prev_holder_commitment_secret, option),
76427640
});
76437641

76447642
Ok(())
@@ -7924,9 +7922,6 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
79247922

79257923
let mut is_batch_funding: Option<()> = None;
79267924

7927-
let mut cur_holder_commitment_point: Option<PublicKey> = None;
7928-
let mut prev_holder_commitment_secret: Option<[u8; 32]> = None;
7929-
79307925
read_tlv_fields!(reader, {
79317926
(0, announcement_sigs, option),
79327927
(1, minimum_depth, option),
@@ -7953,8 +7948,6 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
79537948
(35, pending_outbound_skimmed_fees_opt, optional_vec),
79547949
(37, holding_cell_skimmed_fees_opt, optional_vec),
79557950
(38, is_batch_funding, option),
7956-
(39, cur_holder_commitment_point, option),
7957-
(41, prev_holder_commitment_secret, option),
79587951
});
79597952

79607953
let (channel_keys_id, holder_signer) = if let Some(channel_keys_id) = channel_keys_id {
@@ -8006,27 +7999,6 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
80067999
let mut secp_ctx = Secp256k1::new();
80078000
secp_ctx.seeded_randomize(&entropy_source.get_secure_random_bytes());
80088001

8009-
// If we weren't able to load the cur_holder_commitment_point or prev_holder_commitment_secret,
8010-
// ask the signer for it now.
8011-
let mut signer_pending_commitment_point = false;
8012-
if cur_holder_commitment_point.is_none() {
8013-
cur_holder_commitment_point = holder_signer.get_per_commitment_point(
8014-
cur_holder_commitment_transaction_number, &secp_ctx
8015-
).ok();
8016-
8017-
signer_pending_commitment_point = cur_holder_commitment_point.is_none();
8018-
}
8019-
8020-
let mut signer_pending_released_secret = false;
8021-
if prev_holder_commitment_secret.is_none() {
8022-
let release_transaction_number = cur_holder_commitment_transaction_number + 2;
8023-
prev_holder_commitment_secret = if release_transaction_number <= INITIAL_COMMITMENT_NUMBER {
8024-
let secret = holder_signer.release_commitment_secret(release_transaction_number).ok();
8025-
signer_pending_released_secret = secret.is_none();
8026-
secret
8027-
} else { None };
8028-
}
8029-
80308002
// `user_id` used to be a single u64 value. In order to remain backwards
80318003
// compatible with versions prior to 0.0.113, the u128 is serialized as two
80328004
// separate u64 values.
@@ -8079,8 +8051,8 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
80798051
destination_script,
80808052

80818053
cur_holder_commitment_transaction_number,
8082-
cur_holder_commitment_point,
8083-
prev_holder_commitment_secret,
8054+
cur_holder_commitment_point: None,
8055+
prev_holder_commitment_secret: None,
80848056
cur_counterparty_commitment_transaction_number,
80858057
value_to_self_msat,
80868058

@@ -8102,8 +8074,8 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
81028074
signer_pending_revoke_and_ack: false,
81038075
signer_pending_funding: false,
81048076
signer_pending_channel_ready: false,
8105-
signer_pending_commitment_point,
8106-
signer_pending_released_secret,
8077+
signer_pending_commitment_point: true,
8078+
signer_pending_released_secret: true,
81078079

81088080
pending_update_fee,
81098081
holding_cell_update_fee,

lightning/src/ln/channelmanager.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10140,6 +10140,7 @@ where
1014010140
log_info!(args.logger, "Successfully loaded channel {} at update_id {} against monitor at update id {}",
1014110141
&channel.context.channel_id(), channel.context.get_latest_monitor_update_id(),
1014210142
monitor.get_latest_update_id());
10143+
channel.context.update_holder_per_commitment(&args.logger);
1014310144
if let Some(short_channel_id) = channel.context.get_short_channel_id() {
1014410145
short_to_chan_info.insert(short_channel_id, (channel.context.get_counterparty_node_id(), channel.context.channel_id()));
1014510146
}

0 commit comments

Comments
 (0)