chancloser: RBF coop close fails for channels without our policy in the graph

Open Beginner friendly
#11,672 0 comments 0 reactions 0 assignees View on GitHub

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:

https://github.com/lightningnetwork/lnd/blob/d5651c62990282fae6930e9e926b463bb74aaee0/lnwallet/chancloser/chancloser.go#L527-L533

https://github.com/lightningnetwork/lnd/blob/d5651c62990282fae6930e9e926b463bb74aaee0/lnwallet/chancloser/rbf_coop_transitions.go#L104-L110

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):

https://github.com/lightningnetwork/lnd/blob/d5651c62990282fae6930e9e926b463bb74aaee0/netann/chan_status_manager.go#L654-L669

The state machine then stops without sending shutdown, and chanErrorReporter sends the peer an error for the channel:

https://github.com/lightningnetwork/lnd/blob/d5651c62990282fae6930e9e926b463bb74aaee0/peer/brontide.go#L4680-L4698

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:

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from lightningnetwork/lnd

All issues in lightningnetwork/lnd

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.