Skip to content

Commit b1a27f2

Browse files
committed
Split update_holder_per_commitment
Split `update_holder_per_commitment` into two parts: 1. `update_holder_per_commitment_point`, which we call to retrieve a new commitment point. 2. `update_holder_commitment_secret`, which we call when we're ready to release the commitment secret. This delays releasing the secret until we actually need it for the revoke-and-ack. By doing this, we restore the signer check to its original condition, as well.
1 parent 0967961 commit b1a27f2

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

lightning/src/ln/channel.rs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,7 +1284,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
12841284
}
12851285

12861286
/// Retrieves the next commitment point and previous commitment secret from the signer.
1287-
pub fn update_holder_per_commitment<L: Deref>(&mut self, logger: &L) where L::Target: Logger
1287+
pub fn update_holder_per_commitment_point<L: Deref>(&mut self, logger: &L) where L::Target: Logger
12881288
{
12891289
let transaction_number = self.cur_holder_commitment_transaction_number;
12901290
let signer = self.holder_signer.as_ref();
@@ -1309,6 +1309,12 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
13091309
None
13101310
}
13111311
};
1312+
}
1313+
1314+
pub fn update_holder_commitment_secret<L: Deref>(&mut self, logger: &L) where L::Target: Logger
1315+
{
1316+
let transaction_number = self.cur_holder_commitment_transaction_number;
1317+
let signer = self.holder_signer.as_ref();
13121318

13131319
let releasing_transaction_number = transaction_number + 2;
13141320
if releasing_transaction_number <= INITIAL_COMMITMENT_NUMBER {
@@ -2842,7 +2848,7 @@ impl<SP: Deref> Channel<SP> where
28422848
self.context.channel_state = ChannelState::FundingSent as u32;
28432849
}
28442850
self.context.cur_holder_commitment_transaction_number -= 1;
2845-
self.context.update_holder_per_commitment(logger);
2851+
self.context.update_holder_per_commitment_point(logger);
28462852
self.context.cur_counterparty_commitment_transaction_number -= 1;
28472853

28482854
log_info!(logger, "Received funding_signed from peer for channel {}", &self.context.channel_id());
@@ -3355,7 +3361,7 @@ impl<SP: Deref> Channel<SP> where
33553361
};
33563362

33573363
self.context.cur_holder_commitment_transaction_number -= 1;
3358-
self.context.update_holder_per_commitment(logger);
3364+
self.context.update_holder_per_commitment_point(logger);
33593365

33603366
// Note that if we need_commitment & !AwaitingRemoteRevoke we'll call
33613367
// build_commitment_no_status_check() next which will reset this to RAAFirst.
@@ -4045,6 +4051,7 @@ impl<SP: Deref> Channel<SP> where
40454051
}
40464052

40474053
let raa = if self.context.monitor_pending_revoke_and_ack {
4054+
self.context.update_holder_commitment_secret(logger);
40484055
self.get_last_revoke_and_ack(logger).or_else(|| {
40494056
log_trace!(logger, "Monitor was pending RAA, but RAA is not available; setting signer_pending_revoke_and_ack");
40504057
self.context.signer_pending_revoke_and_ack = true;
@@ -4138,9 +4145,14 @@ impl<SP: Deref> Channel<SP> where
41384145
log_trace!(logger, "Signing unblocked in channel {} at sequence {}",
41394146
&self.context.channel_id(), self.context.cur_holder_commitment_transaction_number);
41404147

4141-
if self.context.signer_pending_commitment_point || self.context.signer_pending_released_secret {
4142-
log_trace!(logger, "Attempting to update holder per-commitment for pending commitment point and secret...");
4143-
self.context.update_holder_per_commitment(logger);
4148+
if self.context.signer_pending_commitment_point {
4149+
log_trace!(logger, "Attempting to update holder per-commitment point...");
4150+
self.context.update_holder_per_commitment_point(logger);
4151+
}
4152+
4153+
if self.context.signer_pending_released_secret {
4154+
log_trace!(logger, "Attempting to update holder commitment secret...");
4155+
self.context.update_holder_commitment_secret(logger);
41444156
}
41454157

41464158
if self.context.channel_state & (ChannelState::PeerDisconnected as u32) != 0 {
@@ -4494,6 +4506,7 @@ impl<SP: Deref> Channel<SP> where
44944506
self.context.monitor_pending_revoke_and_ack = true;
44954507
None
44964508
} else {
4509+
self.context.update_holder_commitment_secret(logger);
44974510
self.get_last_revoke_and_ack(logger).map(|raa| {
44984511
if self.context.signer_pending_revoke_and_ack {
44994512
log_trace!(logger, "Generated RAA for channel_reestablish; clearing signer_pending_revoke_and_ack");
@@ -6667,7 +6680,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
66676680
where L::Target: Logger
66686681
{
66696682
let open_channel = if self.signer_pending_open_channel {
6670-
self.context.update_holder_per_commitment(logger);
6683+
self.context.update_holder_per_commitment_point(logger);
66716684
self.get_open_channel(chain_hash.clone()).map(|msg| {
66726685
log_trace!(logger, "Clearing signer_pending_open_channel");
66736686
self.signer_pending_open_channel = false;
@@ -7176,7 +7189,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
71767189
self.context.channel_id = funding_txo.to_channel_id();
71777190
self.context.cur_counterparty_commitment_transaction_number -= 1;
71787191
self.context.cur_holder_commitment_transaction_number -= 1;
7179-
self.context.update_holder_per_commitment(logger);
7192+
self.context.update_holder_per_commitment_point(logger);
71807193

71817194
let (counterparty_initial_commitment_tx, funding_signed) = self.context.get_funding_signed_msg(logger);
71827195

@@ -7224,7 +7237,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
72247237
where L::Target: Logger
72257238
{
72267239
let accept_channel = if self.signer_pending_accept_channel {
7227-
self.context.update_holder_per_commitment(logger);
7240+
self.context.update_holder_per_commitment_point(logger);
72287241
self.generate_accept_channel_message().map(|msg| {
72297242
log_trace!(logger, "Clearing signer_pending_accept_channel");
72307243
self.signer_pending_accept_channel = false;

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10142,7 +10142,8 @@ 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);
10145+
channel.context.update_holder_per_commitment_point(&args.logger);
10146+
channel.context.update_holder_commitment_secret(&args.logger);
1014610147
if let Some(short_channel_id) = channel.context.get_short_channel_id() {
1014710148
short_to_chan_info.insert(short_channel_id, (channel.context.get_counterparty_node_id(), channel.context.channel_id()));
1014810149
}

lightning/src/util/test_channel_signer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ impl EcdsaChannelSigner for TestChannelSigner {
238238
let trusted_tx = self.verify_holder_commitment_tx(commitment_tx, secp_ctx);
239239
let state = self.state.lock().unwrap();
240240
let commitment_number = trusted_tx.commitment_number();
241-
if state.last_holder_revoked_commitment != commitment_number && state.last_holder_revoked_commitment - 1 != commitment_number {
241+
if state.last_holder_revoked_commitment - 1 != commitment_number && state.last_holder_revoked_commitment - 2 != commitment_number {
242242
if !self.disable_revocation_policy_check {
243243
panic!("can only sign the next two unrevoked commitment numbers, revoked={} vs requested={} for {}",
244244
state.last_holder_revoked_commitment, commitment_number, self.inner.commitment_seed[0])

0 commit comments

Comments
 (0)