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.
This commit is contained in:
Olaoluwa Osuntokun 2024-03-07 20:13:23 -08:00
parent 029fbd22fd
commit 282c50e444

View File

@ -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 {