Skip to content

Commit

Permalink
loop+loopd+liquidity: use isWalletAddr flag
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeTsagk committed Sep 27, 2023
1 parent 8e25029 commit 844f27e
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 3 deletions.
3 changes: 3 additions & 0 deletions cmd/loop/loopout.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,11 @@ func loopOut(ctx *cli.Context) error {

var destAddr string
var account string
isWalletAddr := true
switch {
case ctx.IsSet("addr"):
destAddr = ctx.String("addr")
isWalletAddr = false

case ctx.IsSet("account"):
account = ctx.String("account")
Expand Down Expand Up @@ -235,6 +237,7 @@ func loopOut(ctx *cli.Context) error {
resp, err := client.LoopOut(context.Background(), &looprpc.LoopOutRequest{
Amt: int64(amt),
Dest: destAddr,
IsWalletAddr: isWalletAddr,
Account: account,
AccountAddrType: accountAddrType,
MaxMinerFee: int64(limits.maxMinerFee),
Expand Down
5 changes: 5 additions & 0 deletions interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ type OutRequest struct {
// Destination address for the swap.
DestAddr btcutil.Address

// IsWalletAddr indicates whether the provided destination address
// belongs to the underlying wallet. This helps indicate whether the
// sweep of this swap can be batched or not.
IsWalletAddr bool

// MaxSwapRoutingFee is the maximum off-chain fee in msat that may be
// paid for payment to the server. This limit is applied during path
// finding. Typically this value is taken from the response of the
Expand Down
1 change: 1 addition & 0 deletions liquidity/liquidity.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ func (m *Manager) autoloop(ctx context.Context) error {
// outs.
if m.params.DestAddr != nil {
swap.DestAddr = m.params.DestAddr
swap.IsWalletAddr = false
}

go m.dispatchStickyLoopOut(
Expand Down
2 changes: 2 additions & 0 deletions liquidity/loopout_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ func (b *loopOutBuilder) buildSwap(ctx context.Context, pubkey route.Vertex,
// already validated them.
request := loop.OutRequest{
Amount: amount,
IsWalletAddr: true,
OutgoingChanSet: chanSet,
MaxPrepayRoutingFee: prepayMaxFee,
MaxSwapRoutingFee: routeMaxFee,
Expand All @@ -160,6 +161,7 @@ func (b *loopOutBuilder) buildSwap(ctx context.Context, pubkey route.Vertex,
if len(params.Account) > 0 {
account = params.Account
addrType = params.AccountAddrType
request.IsWalletAddr = false
}

addr, err := b.cfg.Lnd.WalletKit.NextAddr(
Expand Down
4 changes: 4 additions & 0 deletions loopd/swapclient_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func (s *swapClientServer) LoopOut(ctx context.Context,
log.Infof("Loop out request received")

var sweepAddr btcutil.Address
var isWalletAddr bool
var err error
//nolint:lll
switch {
Expand Down Expand Up @@ -146,6 +147,8 @@ func (s *swapClientServer) LoopOut(ctx context.Context,
if err != nil {
return nil, fmt.Errorf("NextAddr error: %v", err)
}

isWalletAddr = true
}

sweepConfTarget, err := validateLoopOutRequest(
Expand All @@ -162,6 +165,7 @@ func (s *swapClientServer) LoopOut(ctx context.Context,
req := &loop.OutRequest{
Amount: btcutil.Amount(in.Amt),
DestAddr: sweepAddr,
IsWalletAddr: isWalletAddr,
MaxMinerFee: btcutil.Amount(in.MaxMinerFee),
MaxPrepayAmount: btcutil.Amount(in.MaxPrepayAmt),
MaxPrepayRoutingFee: btcutil.Amount(in.MaxPrepayRoutingFee),
Expand Down
4 changes: 1 addition & 3 deletions loopout.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ func newLoopOutSwap(globalCtx context.Context, cfg *swapConfig,
contract := loopdb.LoopOutContract{
SwapInvoice: swapResp.swapInvoice,
DestAddr: request.DestAddr,
IsWalletAddr: request.IsWalletAddr,
MaxSwapRoutingFee: request.MaxSwapRoutingFee,
SweepConfTarget: request.SweepConfTarget,
HtlcConfirmations: confs,
Expand Down Expand Up @@ -1654,9 +1655,6 @@ func (s *loopOutSwap) sweep(ctx context.Context, htlcOutpoint wire.OutPoint,
return nil
}

s.executeConfig.batcher.SweepReqs <- sweep
return nil

confTarget, canSweep := s.sweepConfTarget()
if !canSweep {
return nil
Expand Down

0 comments on commit 844f27e

Please sign in to comment.