mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
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:
parent
c650cdc8a8
commit
f40ef193e9
4 changed files with 380 additions and 3 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue