[bug]: a fee decrease by the funder untrims HTLCs, the commitment fee rises and signing fails
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 18/100
Research direction
Start with validateFeeRate and validateCommitmentSanity in lnwallet/channel.go, around lines 9511-9524, where the new feerate is priced on the current view's trimmed HTLCs. Run the payload's TestFeeDecreaseUntrimsPeerHtlcs in lnwallet/ with -run to reproduce the reserve failure. Done means a fee decrease that untrims HTLCs is either priced correctly or refused by UpdateFee, with the test passing for both the 0 and 482 HTLC cases.
Written by the indexing model from the issue text.
Description
Pre-Submission Checklist
- I have searched the existing issues and believe this is a new bug.
- I am not asking a question about how to use lnd, but reporting a bug (otherwise open a discussion).
LND Version
master 8cdbf85c0860 (2026-11-18), v0.21.8-beta and v0.20.8-beta
LND Configuration
Default.
Backend Version
None. The code runs inside lnd's own packages.
Backend Configuration
None.
OS/Distribution
Linux x86_64
Bug Details & Steps to Reproduce
On lnd master 8cdbf85c0860, validateFeeRate prices the new rate on the weight of the current view, where HTLCs near the trim threshold are trimmed at the current rate (channel.go L9511-L9524). A lower rate untrims them, so the commitment at the new rate is heavier than the one that was priced, and validateCommitmentSanity refuses it at signing. UpdateFee accepts the decrease and SignNextCommitment fails.
Test, package lnwallet. The funder has 34,000 sat on its side of a 3,000,000 sat channel with a 30,000 sat reserve, at 5,000 sat/kw. The peer adds 482 HTLCs of 3,000 sat, which are trimmed at 5,000 sat/kw on both commitments and are not trimmed at 1,000 sat/kw. The case with no HTLCs is the control.
// A fee decrease by the funder while the peer holds HTLCs that the current
// feerate trims and the lower feerate does not.
package lnwallet
import (
"context"
"testing"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/stretchr/testify/require"
)
func feeDecreaseWithPeerHtlcs(t *testing.T, numHtlcs int) {
// Alice funds a channel of 3,000,000 sat with 34,000 sat on her side
// (reserve 30,000 sat) at 5,000 sat/kw.
alice, bob, err := createTestChannels(
t, channeldb.SingleFunderTweaklessBit, 3_000_000, 34_000, 5000,
)
require.NoError(t, err)
// Bob adds HTLCs of 3,000 sat. At 5,000 sat/kw they are trimmed on
// both commitments (the thresholds are 3,715 sat on Alice's and 4,615
// sat on Bob's), at 1,000 sat/kw they are not (903 and 1,963 sat).
for i := 0; i < numHtlcs; i++ {
htlc, _ := createHTLC(i, lnwire.NewMSatFromSatoshis(3000))
_, err := bob.AddHTLC(htlc, nil)
require.NoError(t, err)
_, err = alice.ReceiveHTLC(htlc)
require.NoError(t, err)
}
require.NoError(t, ForceStateTransition(bob, alice))
t.Logf("htlcs=%d: alice commitment outputs %d, alice balance %v",
numHtlcs, len(alice.channelState.LocalCommitment.CommitTx.TxOut),
alice.channelState.LocalCommitment.LocalBalance)
// Alice lowers the feerate.
err = alice.UpdateFee(chainfee.SatPerKWeight(1000))
t.Logf("htlcs=%d: UpdateFee(1000): %v", numHtlcs, err)
require.NoError(t, err)
_, err = alice.SignNextCommitment(context.Background())
t.Logf("htlcs=%d: SignNextCommitment: %v", numHtlcs, err)
}
func TestFeeDecreaseUntrimsPeerHtlcs(t *testing.T) {
feeDecreaseWithPeerHtlcs(t, 0)
feeDecreaseWithPeerHtlcs(t, 482)
}
Run go test -count=1 -run TestFeeDecreaseUntrimsPeerHtlcs -v ./lnwallet/. The output is the same on master, v0.21.8-beta and v0.20.8-beta:
fee_untrim_test.go:34: htlcs=0: alice commitment outputs 2, alice balance 30380000 mSAT
fee_untrim_test.go:40: htlcs=0: UpdateFee(1000): <nil>
fee_untrim_test.go:44: htlcs=0: SignNextCommitment: <nil>
fee_untrim_test.go:34: htlcs=482: alice commitment outputs 2, alice balance 30380000 mSAT
fee_untrim_test.go:40: htlcs=482: UpdateFee(1000): <nil>
fee_untrim_test.go:44: htlcs=482: SignNextCommitment: commitment transaction dips peer below chan reserve
Expected Behavior
UpdateFee refuses a decrease whose commitment the funder cannot afford, or the link does not propose it.
Debug Information
No response
Environment
No response
- Dominant language
- Go
- Stars
- 8.2k
- Forks
- 2.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 103
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from lightningnetwork/lnd
-
funding: failure logs print `<nil>` error and zero channel IDPossibly taken @litbot-9000 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
lightningnetwork/lnd#11676 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 Half a day Newbie friendliness 85/100
lightningnetwork/lnd#11674 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
lightningnetwork/lnd#11672 ·
Maintainers usually reply within 1 day
-
test flake
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
lightningnetwork/lnd#11663 · 1 comment ·
Maintainers usually reply within 1 day
-
[flake]: lnwallet/test/bitcoind.TestLightningWalletBitcoindRPCPolling/spend_unconfirmed_outputsOpentest flake
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
lightningnetwork/lnd#11642 · 1 comment ·
Maintainers usually reply within 1 day
All issues in lightningnetwork/lnd
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
containers/gvisor-tap-vsock#796 ·
Maintainers usually reply within 2 days
-
external needs:triage
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
celestiaorg/celestia-node#5448 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
Maintainers usually reply within 1 day
-
[Bug]: Azure SAS signing uses local time instead of UTC, shifting validity window on non-UTC hostsPossibly taken @huanghaoyuanhhy claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
zilliztech/milvus-backup#1418 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
projectdiscovery/nuclei#8423 ·
Maintainers usually reply within 1 day