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

Aperta Adatta ai principianti
#11,672 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go
Ambito
networking

Direzione di ricerca

Inizia da lnwallet/chancloser/rbf_coop_transitions.go, dove gli errori di DisableChannel impediscono al closer RBF di inviare shutdown, e confrontalo con il comportamento legacy in lnwallet/chancloser/chancloser.go. Esamina la logica dello stato del canale in netann/chan_status_manager.go e aggiungi o adatta il riproduttore in lnwallet/chancloser/rbf_disable_channel_test.go. Il lavoro è completo quando una policy del grafo mancante viene registrata come avviso mentre il closer prosegue verso lo stato di shutdown sia per gli eventi di shutdown locali sia per quelli remoti; esegui go test ./lnwallet/chancloser -run TestRbfShutdownDisableChannelFails -count=1.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Go
Stelle
8.2k
Fork
2.3k
Merge medio
1g 11h
PR unite (30g)
103

Preparare l'ambiente

  • Include un Dockerfile o un file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di lightningnetwork/lnd

Tutte le issue di lightningnetwork/lnd

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.