Skip to content

Commit 1d430e2

Browse files
committed
staticaddr: fast-flag support
--fast allows the client to expedite the publishing of on-chain swap transactions with change, e.g. if --amount was specified.
1 parent 6f9218b commit 1d430e2

File tree

6 files changed

+24
-5
lines changed

6 files changed

+24
-5
lines changed

interface.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,11 @@ type StaticAddressLoopInRequest struct {
343343
// the user did not select an amount, the amount of the selected
344344
// deposits is used.
345345
SelectedAmount btcutil.Amount
346+
347+
// Fast indicates whether the user requested a fast static loop-in. If
348+
// set, the flag is passed to the server which may alter its behavior
349+
// (for example, publish sooner) and is stored in the database.
350+
Fast bool
346351
}
347352

348353
// LoopInTerms are the server terms on which it executes loop in swaps.
@@ -405,6 +410,12 @@ type LoopInQuoteRequest struct {
405410
// per-input service fee. This is to cover for the increased on-chain
406411
// fee the server has to pay when the sweeping transaction is broadcast.
407412
NumDeposits uint32
413+
414+
// Fast indicates whether the user requested a fast static loop-in
415+
// publication on-chain. This is helpful if swap change needs to get
416+
// confirmed fast. This comes at a higher swap cost since the server has
417+
// to pay more on-chain fees.
418+
Fast bool
408419
}
409420

410421
// LoopInQuote contains estimates for the fees making up the total swap cost

staticaddr/loopin/actions.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ func (f *FSM) InitHtlcAction(ctx context.Context,
135135
ProtocolVersion: version.CurrentRPCProtocolVersion(),
136136
UserAgent: loop.UserAgent(f.loopIn.Initiator),
137137
PaymentTimeoutSeconds: f.loopIn.PaymentTimeoutSeconds,
138+
Fast: f.loopIn.Fast,
138139
}
139140
if f.loopIn.LastHop != nil {
140141
loopInReq.LastHop = f.loopIn.LastHop

staticaddr/loopin/interface.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ type QuoteGetter interface {
9191
// GetLoopInQuote returns a quote for a loop-in swap.
9292
GetLoopInQuote(ctx context.Context, amt btcutil.Amount,
9393
pubKey route.Vertex, lastHop *route.Vertex,
94-
routeHints [][]zpay32.HopHint,
95-
initiator string, numDeposits uint32) (*loop.LoopInQuote, error)
94+
routeHints [][]zpay32.HopHint, initiator string,
95+
numDeposits uint32, fast bool) (*loop.LoopInQuote, error)
9696
}
9797

9898
type NotificationManager interface {

staticaddr/loopin/loopin.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ type StaticAddressLoopIn struct {
101101
// used.
102102
SelectedAmount btcutil.Amount
103103

104+
// Fast indicates whether the client requested fast publication behavior
105+
// on the server side for this static loop in.
106+
Fast bool
107+
104108
// state is the current state of the swap.
105109
state fsm.StateType
106110

staticaddr/loopin/manager.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -743,14 +743,14 @@ func (m *Manager) initiateLoopIn(ctx context.Context,
743743
numDeposits := uint32(len(selectedDeposits))
744744
quote, err := m.cfg.QuoteGetter.GetLoopInQuote(
745745
ctx, swapAmount, m.cfg.NodePubkey, req.LastHop, req.RouteHints,
746-
req.Initiator, numDeposits,
746+
req.Initiator, numDeposits, req.Fast,
747747
)
748748
if err != nil {
749749
return nil, fmt.Errorf("unable to get loop in quote: %w", err)
750750
}
751751

752-
// If the previously accepted quote fee is lower than what is quoted now
753-
// we abort the swap.
752+
// If the previously accepted quote fee is lower than what is quoted, we
753+
// abort the swap.
754754
if quote.SwapFee > req.MaxSwapFee {
755755
log.Warnf("Swap fee %v exceeding maximum of %v",
756756
quote.SwapFee, req.MaxSwapFee)
@@ -774,6 +774,7 @@ func (m *Manager) initiateLoopIn(ctx context.Context,
774774
QuotedSwapFee: quote.SwapFee,
775775
MaxSwapFee: req.MaxSwapFee,
776776
PaymentTimeoutSeconds: paymentTimeoutSeconds,
777+
Fast: req.Fast,
777778
}
778779
if req.LastHop != nil {
779780
swap.LastHop = req.LastHop[:]

staticaddr/loopin/sql_store.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ func (s *SqlStore) CreateLoopIn(ctx context.Context,
278278
DepositOutpoints: joinedOutpoints,
279279
SelectedAmount: int64(loopIn.SelectedAmount),
280280
PaymentTimeoutSeconds: int32(loopIn.PaymentTimeoutSeconds),
281+
Fast: loopIn.Fast,
281282
}
282283

283284
updateArgs := sqlc.InsertStaticAddressMetaUpdateParams{
@@ -581,6 +582,7 @@ func toStaticAddressLoopIn(_ context.Context, network *chaincfg.Params,
581582
QuotedSwapFee: btcutil.Amount(swap.QuotedSwapFeeSatoshis),
582583
DepositOutpoints: depositOutpoints,
583584
SelectedAmount: btcutil.Amount(swap.SelectedAmount),
585+
Fast: swap.Fast,
584586
HtlcTxFeeRate: chainfee.SatPerKWeight(
585587
swap.HtlcTxFeeRateSatKw,
586588
),

0 commit comments

Comments
 (0)