Skip to content

Commit ec3baf9

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 43d2a40 commit ec3baf9

File tree

2 files changed

+5
-32
lines changed

2 files changed

+5
-32
lines changed

lightning/src/ln/channel.rs

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7613,8 +7613,6 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
76137613
(35, pending_outbound_skimmed_fees, optional_vec),
76147614
(37, holding_cell_skimmed_fees, optional_vec),
76157615
(38, self.context.is_batch_funding, option),
7616-
(39, self.context.cur_holder_commitment_point, option),
7617-
(41, self.context.prev_holder_commitment_secret, option),
76187616
});
76197617

76207618
Ok(())
@@ -7900,9 +7898,6 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
79007898

79017899
let mut is_batch_funding: Option<()> = None;
79027900

7903-
let mut cur_holder_commitment_point: Option<PublicKey> = None;
7904-
let mut prev_holder_commitment_secret: Option<[u8; 32]> = None;
7905-
79067901
read_tlv_fields!(reader, {
79077902
(0, announcement_sigs, option),
79087903
(1, minimum_depth, option),
@@ -7929,8 +7924,6 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
79297924
(35, pending_outbound_skimmed_fees_opt, optional_vec),
79307925
(37, holding_cell_skimmed_fees_opt, optional_vec),
79317926
(38, is_batch_funding, option),
7932-
(39, cur_holder_commitment_point, option),
7933-
(41, prev_holder_commitment_secret, option),
79347927
});
79357928

79367929
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
79827975
let mut secp_ctx = Secp256k1::new();
79837976
secp_ctx.seeded_randomize(&entropy_source.get_secure_random_bytes());
79847977

7985-
// If we weren't able to load the cur_holder_commitment_point or prev_holder_commitment_secret,
7986-
// ask the signer for it now.
7987-
let mut signer_pending_commitment_point = false;
7988-
if cur_holder_commitment_point.is_none() {
7989-
cur_holder_commitment_point = holder_signer.get_per_commitment_point(
7990-
cur_holder_commitment_transaction_number, &secp_ctx
7991-
).ok();
7992-
7993-
signer_pending_commitment_point = cur_holder_commitment_point.is_none();
7994-
}
7995-
7996-
let mut signer_pending_released_secret = false;
7997-
if prev_holder_commitment_secret.is_none() {
7998-
let release_transaction_number = cur_holder_commitment_transaction_number + 2;
7999-
prev_holder_commitment_secret = if release_transaction_number <= INITIAL_COMMITMENT_NUMBER {
8000-
let secret = holder_signer.release_commitment_secret(release_transaction_number).ok();
8001-
signer_pending_released_secret = secret.is_none();
8002-
secret
8003-
} else { None };
8004-
}
8005-
80067978
// `user_id` used to be a single u64 value. In order to remain backwards
80077979
// compatible with versions prior to 0.0.113, the u128 is serialized as two
80087980
// separate u64 values.
@@ -8055,8 +8027,8 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
80558027
destination_script,
80568028

80578029
cur_holder_commitment_transaction_number,
8058-
cur_holder_commitment_point,
8059-
prev_holder_commitment_secret,
8030+
cur_holder_commitment_point: None,
8031+
prev_holder_commitment_secret: None,
80608032
cur_counterparty_commitment_transaction_number,
80618033
value_to_self_msat,
80628034

@@ -8078,8 +8050,8 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
80788050
signer_pending_revoke_and_ack: false,
80798051
signer_pending_funding: false,
80808052
signer_pending_channel_ready: false,
8081-
signer_pending_commitment_point,
8082-
signer_pending_released_secret,
8053+
signer_pending_commitment_point: true,
8054+
signer_pending_released_secret: true,
80838055

80848056
pending_update_fee,
80858057
holding_cell_update_fee,

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10142,6 +10142,7 @@ where
1014210142
log_info!(args.logger, "Successfully loaded channel {} at update_id {} against monitor at update id {}",
1014310143
&channel.context.channel_id(), channel.context.get_latest_monitor_update_id(),
1014410144
monitor.get_latest_update_id());
10145+
channel.context.update_holder_per_commitment(&args.logger);
1014510146
if let Some(short_channel_id) = channel.context.get_short_channel_id() {
1014610147
short_to_chan_info.insert(short_channel_id, (channel.context.get_counterparty_node_id(), channel.context.channel_id()));
1014710148
}

0 commit comments

Comments
 (0)