mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
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.
This commit is contained in:
parent
422bcd7077
commit
51258af025
6 changed files with 24 additions and 5 deletions
11
interface.go
11
interface.go
|
|
@ -343,6 +343,11 @@ type StaticAddressLoopInRequest struct {
|
|||
// the user did not select an amount, the amount of the selected
|
||||
// deposits is used.
|
||||
SelectedAmount btcutil.Amount
|
||||
|
||||
// Fast indicates whether the user requested a fast static loop-in. If
|
||||
// set, the flag is passed to the server which may alter its behavior
|
||||
// (for example, publish sooner) and is stored in the database.
|
||||
Fast bool
|
||||
}
|
||||
|
||||
// LoopInTerms are the server terms on which it executes loop in swaps.
|
||||
|
|
@ -405,6 +410,12 @@ type LoopInQuoteRequest struct {
|
|||
// per-input service fee. This is to cover for the increased on-chain
|
||||
// fee the server has to pay when the sweeping transaction is broadcast.
|
||||
NumDeposits uint32
|
||||
|
||||
// Fast indicates whether the user requested a fast static loop-in
|
||||
// publication on-chain. This is helpful if swap change needs to get
|
||||
// confirmed fast. This comes at a higher swap cost since the server has
|
||||
// to pay more on-chain fees.
|
||||
Fast bool
|
||||
}
|
||||
|
||||
// LoopInQuote contains estimates for the fees making up the total swap cost
|
||||
|
|
|
|||
|
|
@ -135,6 +135,7 @@ func (f *FSM) InitHtlcAction(ctx context.Context,
|
|||
ProtocolVersion: version.CurrentRPCProtocolVersion(),
|
||||
UserAgent: loop.UserAgent(f.loopIn.Initiator),
|
||||
PaymentTimeoutSeconds: f.loopIn.PaymentTimeoutSeconds,
|
||||
Fast: f.loopIn.Fast,
|
||||
}
|
||||
if f.loopIn.LastHop != nil {
|
||||
loopInReq.LastHop = f.loopIn.LastHop
|
||||
|
|
|
|||
|
|
@ -91,8 +91,8 @@ type QuoteGetter interface {
|
|||
// GetLoopInQuote returns a quote for a loop-in swap.
|
||||
GetLoopInQuote(ctx context.Context, amt btcutil.Amount,
|
||||
pubKey route.Vertex, lastHop *route.Vertex,
|
||||
routeHints [][]zpay32.HopHint,
|
||||
initiator string, numDeposits uint32) (*loop.LoopInQuote, error)
|
||||
routeHints [][]zpay32.HopHint, initiator string,
|
||||
numDeposits uint32, fast bool) (*loop.LoopInQuote, error)
|
||||
}
|
||||
|
||||
type NotificationManager interface {
|
||||
|
|
|
|||
|
|
@ -101,6 +101,10 @@ type StaticAddressLoopIn struct {
|
|||
// used.
|
||||
SelectedAmount btcutil.Amount
|
||||
|
||||
// Fast indicates whether the client requested fast publication behavior
|
||||
// on the server side for this static loop in.
|
||||
Fast bool
|
||||
|
||||
// state is the current state of the swap.
|
||||
state fsm.StateType
|
||||
|
||||
|
|
|
|||
|
|
@ -743,14 +743,14 @@ func (m *Manager) initiateLoopIn(ctx context.Context,
|
|||
numDeposits := uint32(len(selectedDeposits))
|
||||
quote, err := m.cfg.QuoteGetter.GetLoopInQuote(
|
||||
ctx, swapAmount, m.cfg.NodePubkey, req.LastHop, req.RouteHints,
|
||||
req.Initiator, numDeposits,
|
||||
req.Initiator, numDeposits, req.Fast,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to get loop in quote: %w", err)
|
||||
}
|
||||
|
||||
// If the previously accepted quote fee is lower than what is quoted now
|
||||
// we abort the swap.
|
||||
// If the previously accepted quote fee is lower than what is quoted, we
|
||||
// abort the swap.
|
||||
if quote.SwapFee > req.MaxSwapFee {
|
||||
log.Warnf("Swap fee %v exceeding maximum of %v",
|
||||
quote.SwapFee, req.MaxSwapFee)
|
||||
|
|
@ -774,6 +774,7 @@ func (m *Manager) initiateLoopIn(ctx context.Context,
|
|||
QuotedSwapFee: quote.SwapFee,
|
||||
MaxSwapFee: req.MaxSwapFee,
|
||||
PaymentTimeoutSeconds: paymentTimeoutSeconds,
|
||||
Fast: req.Fast,
|
||||
}
|
||||
if req.LastHop != nil {
|
||||
swap.LastHop = req.LastHop[:]
|
||||
|
|
|
|||
|
|
@ -278,6 +278,7 @@ func (s *SqlStore) CreateLoopIn(ctx context.Context,
|
|||
DepositOutpoints: joinedOutpoints,
|
||||
SelectedAmount: int64(loopIn.SelectedAmount),
|
||||
PaymentTimeoutSeconds: int32(loopIn.PaymentTimeoutSeconds),
|
||||
Fast: loopIn.Fast,
|
||||
}
|
||||
|
||||
updateArgs := sqlc.InsertStaticAddressMetaUpdateParams{
|
||||
|
|
@ -581,6 +582,7 @@ func toStaticAddressLoopIn(_ context.Context, network *chaincfg.Params,
|
|||
QuotedSwapFee: btcutil.Amount(swap.QuotedSwapFeeSatoshis),
|
||||
DepositOutpoints: depositOutpoints,
|
||||
SelectedAmount: btcutil.Amount(swap.SelectedAmount),
|
||||
Fast: swap.Fast,
|
||||
HtlcTxFeeRate: chainfee.SatPerKWeight(
|
||||
swap.HtlcTxFeeRateSatKw,
|
||||
),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue