loop: add migration for loopout swaps to fix negative stored costs

Previously we may have stored negative costs for some loop out swaps
which this commit attempts to correct by fetching all completed swap,
calculating the correct costs and overriding them in the database.
This commit is contained in:
Andras Banki-Horvath 2024-05-30 22:38:56 +02:00
parent c650cdc8a8
commit f40ef193e9
No known key found for this signature in database
GPG key ID: 80E5375C094198D8
4 changed files with 380 additions and 3 deletions

View file

@ -24,6 +24,8 @@ type StoreMock struct {
loopInStoreChan chan LoopInContract
loopInUpdateChan chan SwapStateData
migrations map[string]struct{}
t *testing.T
}
@ -39,6 +41,7 @@ func NewStoreMock(t *testing.T) *StoreMock {
loopInUpdateChan: make(chan SwapStateData, 1),
LoopInSwaps: make(map[lntypes.Hash]*LoopInContract),
LoopInUpdates: make(map[lntypes.Hash][]SwapStateData),
migrations: make(map[string]struct{}),
t: t,
}
}
@ -364,12 +367,20 @@ func (s *StoreMock) BatchUpdateLoopOutSwapCosts(ctx context.Context,
func (s *StoreMock) HasMigration(ctx context.Context, migrationID string) (
bool, error) {
return false, errUnimplemented
_, ok := s.migrations[migrationID]
return ok, nil
}
// SetMigration marks the migration with the given ID as done.
func (s *StoreMock) SetMigration(ctx context.Context,
migrationID string) error {
return errUnimplemented
if _, ok := s.migrations[migrationID]; ok {
return errors.New("migration already done")
}
s.migrations[migrationID] = struct{}{}
return nil
}