reservation: keep processing after notification errors

Log individual reservation initialization failures and continue
consuming later notifications instead of stopping the manager.
This commit is contained in:
Slyghtning 2026-08-11 11:31:08 +02:00
parent 6825e35594
commit a4973caa08
2 changed files with 47 additions and 1 deletions

View file

@ -80,7 +80,8 @@ func (m *Manager) Run(ctx context.Context, height int32,
runCtx, uint32(currentHeight), reservationRes,
)
if err != nil {
return err
log.Errorf("Unable to create reservation %x: %v",
reservationRes.ReservationId, err)
}
case err := <-newBlockErrChan:

View file

@ -99,6 +99,51 @@ func TestManager(t *testing.T) {
require.NoError(t, err)
}
// TestManagerContinuesAfterInvalidNotification verifies that a malformed
// server notification doesn't stop the reservation manager from processing
// later notifications.
func TestManagerContinuesAfterInvalidNotification(t *testing.T) {
testContext := newManagerTestContext(t)
ctx, cancel := context.WithCancel(t.Context())
defer cancel()
initChan := make(chan struct{})
errChan := make(chan error, 1)
go func() {
errChan <- testContext.manager.Run(
ctx, testContext.mockLnd.Height, initChan,
)
}()
<-initChan
// A malformed ID is rejected by newReservation. The manager should log
// the error and continue processing the stream.
testContext.reservationNotificationChan <- &swapserverrpc.ServerReservationNotification{
ReservationId: []byte{1},
}
testContext.reservationNotificationChan <- &swapserverrpc.ServerReservationNotification{
ReservationId: defaultReservationId[:],
Value: uint64(defaultValue),
ServerKey: defaultPubkeyBytes,
Expiry: uint32(testContext.mockLnd.Height) +
defaultExpiry,
}
select {
case <-testContext.mockLnd.RegisterConfChannel:
case err := <-errChan:
require.NoError(t, err)
t.Fatal("reservation manager stopped after malformed notification")
case <-time.After(5 * time.Second):
t.Fatal("valid reservation notification was not processed")
}
cancel()
require.NoError(t, <-errChan)
}
// ManagerTestContext is a helper struct that contains all the necessary
// components to test the reservation manager.
type ManagerTestContext struct {