channeldb: persist local updates the peer acked before our first revoke (#11268)
What changed, and why it matters
This commit fixes a bug in LND's channel database where a specific type of fee update could be lost if a node restarted at a very precise moment during a Lightning channel's setup. If triggered, the node would reject a valid signature from its peer and force-close the channel, potentially causing funds to be locked on-chain and transaction fees to be paid unnecessarily. The bug only affects the channel initiator's first update if it is a fee change, and only if the connection drops before the peer sends a commitment signature. The fix ensures these acknowledged-but-not-yet-signed local updates are always saved to disk.
Apply the patch and include the regression test. Nodes running affected versions should upgrade, especially those that frequently initiate fee updates on newly opened channels. Monitor for unexpected force-closures after restarts.
Security signals we found
Force-closure of a Lightning channel due to state desynchronization after restart
Loss of locally initiated fee updates before first local revocation
Regression test reproduces restart scenario leading to signature rejection
Fix removes early return that skipped persisting unsigned acknowledged updates
Release notes explicitly describe the bug and its force-close consequence
Evidence from the diff
The patch modifies AdvanceCommitChainTail in channeldb/channel.go. Previously, the function returned early when no unsignedAckedUpdatesKey bucket existed, which is always the case for a new channel until the local node first revokes a commitment. This skipped persisting local updates the peer had acknowledged but not yet signed for. The fix removes the early return and always proceeds to persist local updates. A regression test TestRestoreFeeUpdateBeforeFirstRevocation demonstrates that a fee update sent by the initiator, acknowledged by the peer via revocation, and then lost on restart before the peer’s commitment_signed arrives, would cause the restored node to reject the peer’s valid signature and force-close. The release notes describe this as a bug fix for a force-close scenario.
Changed components
channeldb/channel.go: AdvanceCommitChainTaillnwallet/restore_unsigned_test.godocs/release-notes/release-notes-0.22.0.mdInspect captured patch +78 / −13
### channeldb/channel.go
@@ -1457,20 +1457,17 @@ func (c *ChannelStateDB) AdvanceCommitChainTail(channel *OpenChannel,
}
// Persist the unsigned acked updates that are not included
- // in their new commitment.
+ // in their new commitment. None are stored until we first
+ // revoke a commitment of our own, so a new channel has none,
+ // but we must still go on to persist the local updates below.
+ var unsignedUpdates []LogUpdate
updateBytes := chanBucket.Get(unsignedAckedUpdatesKey)
- if updateBytes == nil {
- // This shouldn't normally happen as we always store
- // the number of updates, but could still be
- // encountered by nodes that are upgrading.
- newRemoteCommit = &newCommit.Commitment
- return nil
- }
-
- r := bytes.NewReader(updateBytes)
- unsignedUpdates, err := deserializeLogUpdates(r)
- if err != nil {
- return err
+ if updateBytes != nil {
+ r := bytes.NewReader(updateBytes)
+ unsignedUpdates, err = deserializeLogUpdates(r)
+ if err != nil {
+ return err
+ }
}
var validUpdates []LogUpdate
### docs/release-notes/release-notes-0.22.0.md
@@ -66,6 +66,13 @@
`NodeAnnouncement2` address decoders, where all decoded addresses aliased
one scratch array and truncated records decoded without an error.
+* [Fixed a bug](https://github.com/lightningnetwork/lnd/pull/11268) where a
+ channel didn't persist the updates the peer had acknowledged but not yet
+ signed for until we first revoked a commitment of our own. If the
+ initiator's first update was a fee update and the connection dropped in
+ that window, the initiator restored without it, rejected the peer's valid
+ signature, and force closed the channel.
+
# New Features
## Functional Enhancements
@@ -246,4 +253,5 @@
* Jared Tobin
* Vandit Singh
* Viktor Torstensson
+* Olaoluwa Osuntokun
* s1ns3nz0
### lnwallet/restore_unsigned_test.go
@@ -0,0 +1,60 @@
+package lnwallet
+
+import (
+ "testing"
+
+ "github.com/lightningnetwork/lnd/channeldb"
+ "github.com/stretchr/testify/require"
+)
+
+// TestRestoreFeeUpdateBeforeFirstRevocation checks that a fee update the
+// peer acknowledged survives a restart that happens before we ever revoked a
+// commitment of our own. The peer's next commitment_signed covers the fee
+// update, so if we lost it we'd reject a valid signature and force close.
+func TestRestoreFeeUpdateBeforeFirstRevocation(t *testing.T) {
+ t.Parallel()
+
+ ctx := t.Context()
+ alice, bob, err := CreateTestChannels(
+ t, channeldb.SingleFunderTweaklessBit,
+ )
+ require.NoError(t, err)
+
+ // Alice, the initiator, updates the fee and signs. Bob revokes, and
+ // Alice receives his revocation. Alice has never revoked, so the
+ // fee update is now on Bob's current commitment only.
+ fee := alice.CommitFeeRate() + 10
+ require.NoError(t, alice.UpdateFee(fee))
+ require.NoError(t, bob.ReceiveUpdateFee(fee))
+ aliceSig, err := alice.SignNextCommitment(ctx)
+ require.NoError(t, err)
+ require.NoError(t, bob.ReceiveNewCommitment(aliceSig.CommitSigs))
+ bobRevocation, _, _, err := bob.RevokeCurrentCommitment()
+ require.NoError(t, err)
+ _, _, err = alice.ReceiveRevocation(bobRevocation)
+ require.NoError(t, err)
+
+ // Both restart before Bob's commitment_signed reaches Alice.
+ alice, err = restartChannel(alice)
+ require.NoError(t, err)
+ bob, err = restartChannel(bob)
+ require.NoError(t, err)
+
+ aliceSync, err := alice.channelState.ChanSyncMsg()
+ require.NoError(t, err)
+ bobSync, err := bob.channelState.ChanSyncMsg()
+ require.NoError(t, err)
+ _, _, _, err = alice.ProcessChanSyncMsg(ctx, bobSync)
+ require.NoError(t, err)
+ _, _, _, err = bob.ProcessChanSyncMsg(ctx, aliceSync)
+ require.NoError(t, err)
+
+ // Bob signs the commitment he owes Alice, which covers the fee
+ // update, and Alice must accept it.
+ bobSig, err := bob.SignNextCommitment(ctx)
+ require.NoError(t, err)
+ require.NoError(t, alice.ReceiveNewCommitment(bobSig.CommitSigs))
+ _, _, _, err = alice.RevokeCurrentCommitment()
+ require.NoError(t, err)
+ require.Equal(t, fee, alice.CommitFeeRate())
+}Why this scored 66/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.