loopdb: add batch insert

This commit adds a batch insert to the interface. This greatly reduces
the time the migration will take. It is not implemented for the boltdb, as
we will not be supporting migrating to the boltdb.
pull/585/head
sputn1ck 11 months ago
parent becc8a38d8
commit 5d9d7c5c6e
No known key found for this signature in database
GPG Key ID: 671103D881A5F0E4

@ -20,6 +20,10 @@ type SwapStore interface {
CreateLoopOut(ctx context.Context, hash lntypes.Hash,
swap *LoopOutContract) error
// BatchCreateLoopOut creates a batch of loop out swaps to the store.
BatchCreateLoopOut(ctx context.Context,
swaps map[lntypes.Hash]*LoopOutContract) error
// UpdateLoopOut stores a new event for a target loop out swap. This
// appends to the event log for a particular swap as it goes through
// the various stages in its lifetime.
@ -33,12 +37,20 @@ type SwapStore interface {
CreateLoopIn(ctx context.Context, hash lntypes.Hash,
swap *LoopInContract) error
// BatchCreateLoopIn creates a batch of loop in swaps to the store.
BatchCreateLoopIn(ctx context.Context,
swaps map[lntypes.Hash]*LoopInContract) error
// UpdateLoopIn stores a new event for a target loop in swap. This
// appends to the event log for a particular swap as it goes through
// the various stages in its lifetime.
UpdateLoopIn(ctx context.Context, hash lntypes.Hash, time time.Time,
state SwapStateData) error
// BatchInsertUpdate inserts batch of swap updates to the store.
BatchInsertUpdate(ctx context.Context,
updateData map[lntypes.Hash][]BatchInsertUpdateData) error
// PutLiquidityParams writes the serialized `manager.Parameters` bytes
// into the bucket.
//
@ -57,4 +69,11 @@ type SwapStore interface {
Close() error
}
// BatchInsertUpdateData is a struct that holds the data for the
// BatchInsertUpdate function.
type BatchInsertUpdateData struct {
Time time.Time
State SwapStateData
}
// TODO(roasbeef): back up method in interface?

@ -985,3 +985,24 @@ func (s *boltSwapStore) fetchLoopInSwap(rootBucket *bbolt.Bucket,
return &loop, nil
}
// BatchCreateLoopOut creates a batch of swaps to the store.
func (b *boltSwapStore) BatchCreateLoopOut(ctx context.Context,
swaps map[lntypes.Hash]*LoopOutContract) error {
return errors.New("not implemented")
}
// BatchCreateLoopIn creates a batch of loop in swaps to the store.
func (b *boltSwapStore) BatchCreateLoopIn(ctx context.Context,
swaps map[lntypes.Hash]*LoopInContract) error {
return errors.New("not implemented")
}
// BatchInsertUpdate inserts batch of swap updates to the store.
func (b *boltSwapStore) BatchInsertUpdate(ctx context.Context,
updateData map[lntypes.Hash][]BatchInsertUpdateData) error {
return errors.New("not implemented")
}

@ -303,3 +303,20 @@ func (s *storeMock) assertStoreFinished(expectedResult loopdb.SwapState) {
s.t.Fatalf("expected swap to be finished")
}
}
func (b *storeMock) BatchCreateLoopOut(ctx context.Context,
swaps map[lntypes.Hash]*loopdb.LoopOutContract) error {
return errors.New("not implemented")
}
func (b *storeMock) BatchCreateLoopIn(ctx context.Context,
swaps map[lntypes.Hash]*loopdb.LoopInContract) error {
return errors.New("not implemented")
}
func (b *storeMock) BatchInsertUpdate(ctx context.Context,
updateData map[lntypes.Hash][]loopdb.BatchInsertUpdateData) error {
return errors.New("not implemented")
}

Loading…
Cancel
Save