From 282c50e444c39d0d3b856c1effd6d52c99cda145 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 7 Mar 2024 20:13:23 -0800 Subject: [PATCH] peer: attempt to unregister endpoint before registering If we hit an error, we want to wipe the state machine state, which also includes removing the old endpoint. --- peer/brontide.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/peer/brontide.go b/peer/brontide.go index 437aefcfa..f50cba89b 100644 --- a/peer/brontide.go +++ b/peer/brontide.go @@ -3627,6 +3627,9 @@ func newChanErrorReporter(chanID lnwire.ChannelID, // // This is a part of the chancloser.ErrorReporter interface. func (c *chanErrorReporter) ReportError(chanErr error) { + c.peer.log.Errorf("coop close error for channel %v: %v", + c.chanID, chanErr) + var errMsg []byte if errors.Is(chanErr, chancloser.ErrInvalidStateTransition) { errMsg = []byte("unexpected protocol message") @@ -3822,6 +3825,8 @@ func (p *Brontide) initRbfChanCloser( // Finally, we'll register this new endpoint with the message router so // future co-op close messages are handled by this state machine. err = fn.MapOptionZ(p.msgRouter, func(r msgmux.Router) error { + _ = r.UnregisterEndpoint(chanCloser.Name()) + return r.RegisterEndpoint(&chanCloser) }) if err != nil {