From 8aeeaefbafe7887ff06b81055a117b239cdda43b Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Fri, 10 Jan 2020 11:21:55 +0100 Subject: [PATCH] loopd+lsat: add LSAT cost configuration parameters --- loopd/config.go | 7 ++++++- lsat/interceptor.go | 14 +++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/loopd/config.go b/loopd/config.go index fdeb496..24e0714 100644 --- a/loopd/config.go +++ b/loopd/config.go @@ -4,6 +4,7 @@ import ( "path/filepath" "github.com/btcsuite/btcutil" + "github.com/lightninglabs/loop/lsat" ) var ( @@ -39,7 +40,9 @@ type config struct { MaxLogFiles int `long:"maxlogfiles" description:"Maximum logfiles to keep (0 for no rotation)"` MaxLogFileSize int `long:"maxlogfilesize" description:"Maximum logfile size in MB"` - DebugLevel string `short:"d" long:"debuglevel" description:"Logging level for all subsystems {trace, debug, info, warn, error, critical} -- You may also specify =,=,... to set the log level for individual subsystems -- Use show to list available subsystems"` + DebugLevel string `short:"d" long:"debuglevel" description:"Logging level for all subsystems {trace, debug, info, warn, error, critical} -- You may also specify =,=,... to set the log level for individual subsystems -- Use show to list available subsystems"` + MaxLSATCost uint32 `long:"maxlsatcost" description:"Maximum cost in satoshis that loopd is going to pay for an LSAT token automatically. Does not include routing fees."` + MaxLSATFee uint32 `long:"maxlsatfee" description:"Maximum routing fee in satoshis that we are willing to pay while paying for an LSAT token."` Lnd *lndConfig `group:"lnd" namespace:"lnd"` @@ -60,6 +63,8 @@ var defaultConfig = config{ MaxLogFiles: defaultMaxLogFiles, MaxLogFileSize: defaultMaxLogFileSize, DebugLevel: defaultLogLevel, + MaxLSATCost: lsat.DefaultMaxCostSats, + MaxLSATFee: lsat.DefaultMaxRoutingFeeSats, Lnd: &lndConfig{ Host: "localhost:10009", }, diff --git a/lsat/interceptor.go b/lsat/interceptor.go index 131a50b..5c70065 100644 --- a/lsat/interceptor.go +++ b/lsat/interceptor.go @@ -33,10 +33,14 @@ const ( // challenge. AuthHeader = "WWW-Authenticate" - // MaxRoutingFee is the maximum routing fee in satoshis that we are - // going to pay to acquire an LSAT token. - // TODO(guggero): make this configurable - MaxRoutingFeeSats = 10 + // DefaultMaxCostSats is the default maximum amount in satoshis that we + // are going to pay for an LSAT automatically. Does not include routing + // fees. + DefaultMaxCostSats = 1000 + + // DefaultMaxRoutingFeeSats is the default maximum routing fee in + // satoshis that we are going to pay to acquire an LSAT token. + DefaultMaxRoutingFeeSats = 10 // PaymentTimeout is the maximum time we allow a payment to take before // we stop waiting for it. @@ -238,7 +242,7 @@ func (i *Interceptor) payLsatToken(ctx context.Context, md *metadata.MD) ( payCtx, cancel := context.WithTimeout(ctx, PaymentTimeout) defer cancel() respChan := i.lnd.Client.PayInvoice( - payCtx, invoiceStr, MaxRoutingFeeSats, nil, + payCtx, invoiceStr, DefaultMaxRoutingFeeSats, nil, ) select { case result := <-respChan: