chancloser: RBF coop close fails for channels without our policy in the graph
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- go
- Domain
- networking
Research direction
Start with lnwallet/chancloser/rbf_coop_transitions.go, where DisableChannel errors prevent the RBF closer from sending shutdown, and compare it with the legacy behavior in lnwallet/chancloser/chancloser.go. Review the channel status logic in netann/chan_status_manager.go and add or adapt the reproducer in lnwallet/chancloser/rbf_disable_channel_test.go. Done means a missing graph policy is logged as a warning while the closer continues to the shutdown state for both local and remote shutdown events; run go test ./lnwallet/chancloser -run TestRbfShutdownDisableChannelFails -count=1.
Written by the indexing model from the issue text.
Description
The RBF closer aborts the close if it can't send a disabling channel_update for the channel. The legacy closer only logs a warning:
DisableChannel re-signs our latest channel_update from the graph, so it fails for any channel that has no policy of ours there (edge not found, or ErrUnableToExtractChanUpdate if the edge exists but our policy doesn't):
The state machine then stops without sending shutdown, and chanErrorReporter sends the peer an error for the channel:
Here is a replay where the peer sends shutdown right after channel_ready:
[INF] CHCL: ChannelPoint(4b72185c...f59c:0): received shutdown msg
[INF] CHCL: ChannelPoint(4b72185c...f59c:0): sending shutdown msg at next clean commit state
[ERR] PEER: Peer(034f355b...71aa): coop close error for channel 9cf511b3...724b: unable to disable channel: edge not found: op=4b72185c...f59c:0
[DBG] PEER: Peer(034f355b...71aa): Sending Error(chan_id=9cf511b3...724b, err=unable to disable channel: edge not found: op=4b72185c...f59c:0) ...
An open channel can be missing our policy:
- For ~1s after every open. The link and the RBF closer start when the peer's
channel_readyarrives, but the funding manager checks for it only once per second before callingaddToGraph:
https://github.com/lightningnetwork/lnd/blob/d5651c62990282fae6930e9e926b463bb74aaee0/funding/manager.go#L1293-L1308 - When
addToGraphfails. The channel stays inchannelReadySentwith its link up. This case was #11608 which should be fixed now by #11632. - "Under unknown circumstances", as the description of
updatechanpolicy --create_missing_edgesays:
https://github.com/lightningnetwork/lnd/blob/d5651c62990282fae6930e9e926b463bb74aaee0/lnrpc/lightning.proto#L4840-L4847
#9444 and #10585 may be examples of this case.
Impact
Low impact. Nodes that negotiate RBF coop close can't cooperatively close these channels when the policy is missing (rare). closechannel fails, and a peer's shutdown gets an error. The legacy closer works normally.
Reproducer
lnwallet/chancloser/rbf_disable_channel_test.go:
package chancloser
import (
"errors"
"testing"
"time"
"github.com/lightningnetwork/lnd/fn/v2"
"github.com/stretchr/testify/mock"
)
// TestRbfShutdownDisableChannelFails checks that the RBF closer still sends
// shutdown when it can't send a disabling channel_update, as the legacy closer
// does. DisableChannel fails for any channel that has no policy of ours in the
// graph, for example one whose funding flow stopped before addToGraph
// finished.
func TestRbfShutdownDisableChannelFails(t *testing.T) {
errNoEdge := errors.New("edge not found")
tests := []struct {
name string
event ProtocolEvent
local bool
}{
{
name: "local shutdown",
event: &SendShutdown{},
local: true,
},
{
name: "remote shutdown",
event: &ShutdownReceived{
ShutdownScript: remoteAddr,
},
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
ctx := t.Context()
h := newCloser(t, &harnessCfg{
localUpfrontAddr: fn.Some(localAddr),
})
defer h.stopAndAssert()
obs := h.chanObserver
obs.On("FinalBalances").Return(
fn.None[ShutdownBalances](),
)
obs.On("NoDanglingUpdates").Return(true).Maybe()
obs.On("DisableIncomingAdds").Return(nil).Maybe()
obs.On("DisableOutgoingAdds").Return(nil).Maybe()
obs.On(
"MarkShutdownSent", mock.Anything, tc.local,
).Return(nil).Maybe()
obs.On("DisableChannel").Return(errNoEdge)
h.daemonAdapters.On(
"SendMessages", mock.Anything, mock.Anything,
).Return(nil).Maybe()
h.errReporter.On("ReportError", mock.Anything).
Return().Maybe()
h.chanCloser.SendEvent(ctx, tc.event)
select {
case err := <-h.errReporter.errorReported:
t.Fatalf("shutdown failed: %v", err)
case state := <-h.stateSub.NewItemCreated.ChanOut():
if _, ok := state.(*ShutdownPending); !ok {
t.Fatalf("unexpected state %T", state)
}
case <-time.After(time.Second):
t.Fatalf("no state transition")
}
})
}
}
$ go test ./lnwallet/chancloser -run TestRbfShutdownDisableChannelFails -count=1
--- FAIL: TestRbfShutdownDisableChannelFails (0.02s)
--- FAIL: TestRbfShutdownDisableChannelFails/local_shutdown (0.01s)
rbf_disable_channel_test.go:68: shutdown failed: unable to disable channel: edge not found
--- FAIL: TestRbfShutdownDisableChannelFails/remote_shutdown (0.01s)
rbf_disable_channel_test.go:68: shutdown failed: unable to disable channel: edge not found
FAIL
Suggested fix
Do what the legacy closer does:
--- a/lnwallet/chancloser/rbf_coop_transitions.go
+++ b/lnwallet/chancloser/rbf_coop_transitions.go
@@ -103,10 +103,12 @@ func sendShutdownEvents(chanID lnwire.ChannelID, chanPoint wire.OutPoint,
// Before closing, we'll attempt to send a disable update for the
// channel. We do so before closing the channel as otherwise the
- // current edge policy won't be retrievable from the graph.
+ // current edge policy won't be retrievable from the graph. A channel
+ // without a policy of ours in the graph can't be disabled, but it can
+ // still be closed, so a failure here isn't fatal.
if err := chanState.DisableChannel(); err != nil {
- return nil, none, fmt.Errorf("unable to disable "+
- "channel: %w", err)
+ chancloserLog.Warnf("ChannelPoint(%v): unable to disable "+
+ "channel on close: %v", chanPoint, err)
}
// If we have a post-send event, then this means that we're the
Discovery
Found incidentally during LLM-assisted analysis of artifacts from a smite fuzzing campaign.
- 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
-
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
-
docker: pin the final alpine base imageMay be free again @danieldzansi claimed this 27 days ago, and no pull request is open. Open
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
lightningnetwork/lnd#11437 · 3 comments ·
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