Skip to content

Commit 1486b1b

Browse files
committed
Set holder_commitment_point to Available on upgrade
When we upgrade from LDK 0.0.123 or prior, we need to intialize `holder_commitment_point` with commitment point(s). In 1f7f3a3 we changed the point(s) which we fetch from both the current and next per-commitment-point (setting the value to `HolderCommitmentPoint::Available` on upgrade) to only fetching the current per-commitment-point (setting the value to `HolderCommitmentPoint::PendingNext` on upgrade). In `commitment_signed` handling, we expect the next per-commitment-point to be available (allowing us to `advance()` the `holder_commitment_point`), as it was included in the `revoke_and_ack` we most recently sent to our peer, so must've been available at that time. Sadly, these two interact negatively with each other - on upgrade, assuming the channel is at a steady state and there are no pending updates, we'll not make the next per-commitment-point available but if we receive a `commitment_signed` from our peer we'll assume it is. As a result, in debug mode, we'll hit an assertion failure, and in production mode we'll force-close the channel. Instead, here, we fix the upgrade logic to always upgrade directly to `HolderCommitmentPoint::Available`, making the next per-commitment-point available immediately. We also attempt to resolve the next per-commitment-point in `get_channel_reestablish`, allowing any channels which were upgraded to LDK 0.0.124 and are in this broken state to avoid the force-closure, as long as they don't receive a `commitment_signed` in the interim.
1 parent 46d8a0d commit 1486b1b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lightning/src/ln/channel.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7142,6 +7142,12 @@ impl<SP: Deref> Channel<SP> where
71427142
pub fn get_channel_reestablish<L: Deref>(&mut self, logger: &L) -> msgs::ChannelReestablish where L::Target: Logger {
71437143
assert!(self.context.channel_state.is_peer_disconnected());
71447144
assert_ne!(self.context.cur_counterparty_commitment_transaction_number, INITIAL_COMMITMENT_NUMBER);
7145+
// This is generally the first function which gets called on any given channel once we're
7146+
// up and running normally. Thus, we take this opportunity to attempt to resolve the
7147+
// `holder_commitment_point` to get any keys which we are currently missing.
7148+
self.context.holder_commitment_point.try_resolve_pending(
7149+
&self.context.holder_signer, &self.context.secp_ctx, logger,
7150+
);
71457151
// Prior to static_remotekey, my_current_per_commitment_point was critical to claiming
71467152
// current to_remote balances. However, it no longer has any use, and thus is now simply
71477153
// set to a dummy (but valid, as required by the spec) public key.
@@ -9453,8 +9459,10 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
94539459
// TODO(async_signing): remove this expect with the Uninitialized variant
94549460
let current = holder_signer.get_per_commitment_point(cur_holder_commitment_transaction_number, &secp_ctx)
94559461
.expect("Must be able to derive the current commitment point upon channel restoration");
9456-
HolderCommitmentPoint::PendingNext {
9457-
transaction_number: cur_holder_commitment_transaction_number, current,
9462+
let next = holder_signer.get_per_commitment_point(cur_holder_commitment_transaction_number - 1, &secp_ctx)
9463+
.expect("Must be able to derive the next commitment point upon channel restoration");
9464+
HolderCommitmentPoint::Available {
9465+
transaction_number: cur_holder_commitment_transaction_number, current, next,
94589466
}
94599467
},
94609468
};

0 commit comments

Comments
 (0)