Merge pull request #18 from gimme/fee-limit-percent

Add FEE_LIMIT_PERCENT setting
This commit is contained in:
Peter Rounce 2022-11-19 15:40:02 +00:00 committed by GitHub
commit e0c19f38a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 2 deletions

View file

@ -43,7 +43,9 @@ Environment="LN_PORT=10009"
Environment="LN_TLS_FILE=/home/ubuntu/boltcard/tls.cert" Environment="LN_TLS_FILE=/home/ubuntu/boltcard/tls.cert"
Environment="LN_MACAROON_FILE=/home/ubuntu/boltcard/SendPaymentV2.macaroon" Environment="LN_MACAROON_FILE=/home/ubuntu/boltcard/SendPaymentV2.macaroon"
# FEE_LIMIT_SAT is the maximum lightning network fee to be paid # The maximum lightning network fee to be paid in percent of the payment amount.
Environment="FEE_LIMIT_PERCENT=0.5"
# Acceptable flat fee in sats that can exceed the percentage limit.
Environment="FEE_LIMIT_SAT=10" Environment="FEE_LIMIT_SAT=10"
# email # email

View file

@ -14,7 +14,7 @@ This will give you a new 128 bit random key as a 32 character hex value.
This is due to your payment lightning node not finding a route to the merchant lightning node. This is due to your payment lightning node not finding a route to the merchant lightning node.
It may help to open well funded channels to other well connected nodes. It may help to open well funded channels to other well connected nodes.
It may also help to increase your maximum network fee in your service variables, **FEE_LIMIT_SAT** . It may also help to increase your maximum network fee in your service variables, **FEE_LIMIT_SAT** / **FEE_LIMIT_PERCENT** .
It can be useful to test paying invoices directly from your lightning node. It can be useful to test paying invoices directly from your lightning node.
> Why do my payments take so long ? > Why do my payments take so long ?

View file

@ -12,6 +12,7 @@ import (
"time" "time"
"crypto/sha256" "crypto/sha256"
decodepay "github.com/fiatjaf/ln-decodepay"
lnrpc "github.com/lightningnetwork/lnd/lnrpc" lnrpc "github.com/lightningnetwork/lnd/lnrpc"
invoicesrpc "github.com/lightningnetwork/lnd/lnrpc/invoicesrpc" invoicesrpc "github.com/lightningnetwork/lnd/lnrpc/invoicesrpc"
routerrpc "github.com/lightningnetwork/lnd/lnrpc/routerrpc" routerrpc "github.com/lightningnetwork/lnd/lnrpc/routerrpc"
@ -216,6 +217,21 @@ func pay_invoice(card_payment_id int, invoice string) {
return return
} }
fee_limit_percent_str := os.Getenv("FEE_LIMIT_PERCENT")
fee_limit_percent, err := strconv.ParseFloat(fee_limit_percent_str, 64)
if err != nil {
log.WithFields(log.Fields{"card_payment_id": card_payment_id}).Warn(err)
return
}
bolt11, _ := decodepay.Decodepay(invoice)
invoice_msats := bolt11.MSatoshi
fee_limit_product := int64((fee_limit_percent / 100) * (float64(invoice_msats) / 1000))
if fee_limit_product > fee_limit_sat {
fee_limit_sat = fee_limit_product
}
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel() defer cancel()