mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
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:
parent
7cab89d45b
commit
806c1f9356
2 changed files with 47 additions and 1 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue