loopd: abandon loop-ins

This commit is contained in:
Slyghtning 2023-11-13 14:50:10 +01:00
parent 0fbf253391
commit 5e91c446b8
No known key found for this signature in database
GPG key ID: F82D456EA023C9BF
6 changed files with 161 additions and 3 deletions

View file

@ -13,6 +13,7 @@ import (
"github.com/lightninglabs/lndclient"
"github.com/lightninglabs/loop/loopdb"
"github.com/lightninglabs/loop/sweep"
"github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/queue"
)
@ -46,6 +47,8 @@ type executor struct {
currentHeight uint32
ready chan struct{}
sync.Mutex
executorConfig
}
@ -61,7 +64,8 @@ func newExecutor(cfg *executorConfig) *executor {
// run starts the executor event loop. It accepts and executes new swaps,
// providing them with required config data.
func (s *executor) run(mainCtx context.Context,
statusChan chan<- SwapInfo) error {
statusChan chan<- SwapInfo,
abandonChans map[lntypes.Hash]chan struct{}) error {
var (
err error
@ -167,6 +171,15 @@ func (s *executor) run(mainCtx context.Context,
log.Errorf("Execute error: %v", err)
}
// If a loop-in ended we have to remove its
// abandon channel from our abandonChans map
// since the swap finalized.
if swap, ok := newSwap.(*loopInSwap); ok {
s.Lock()
delete(abandonChans, swap.hash)
s.Unlock()
}
select {
case swapDoneChan <- swapID:
case <-mainCtx.Done():