diff --git a/config/config.go b/config/config.go index 9cd3cce..a2dd6b6 100644 --- a/config/config.go +++ b/config/config.go @@ -68,6 +68,14 @@ type NodeConfig struct { FeeParams []*FeeParamsSettings `json:"feeParams"` + // When a htlc comes in where a channel open is needed, and that payment + // was registered with a promise, but the promise has expired, lspd may + // open the channel anyway if the fee is low enough right now (the promise + // fee was higher than the current fee). ExpiredPromiseMultiplicationFactor + // is the multiplication factor to use on the mempool fee rate to check + // whether the min fee of the promise is lower than the current min fee. + ExpiredPromiseMultiplicationFactor uint64 + // Set this field to connect to an LND node. Lnd *LndConfig `json:"lnd,omitempty"` diff --git a/interceptor/intercept.go b/interceptor/intercept.go index c0a299e..d2fa842 100644 --- a/interceptor/intercept.go +++ b/interceptor/intercept.go @@ -123,11 +123,25 @@ func (i *Interceptor) Intercept(nextHop string, reqPaymentHash []byte, reqOutgoi } if time.Now().UTC().After(validUntil) { - log.Printf("Intercepted expired payment registration. Failing payment. payment hash: %x, valid until: %s", paymentHash, params.ValidUntil) - return InterceptResult{ - Action: INTERCEPT_FAIL_HTLC_WITH_CODE, - FailureCode: FAILURE_TEMPORARY_CHANNEL_FAILURE, - }, nil + feeEstimate, err := i.feeEstimator.EstimateFeeRate(context.Background(), i.feeStrategy) + if err != nil { + log.Printf("Intercepted expired payment registration. Failing payment. payment hash: %x, valid until: %s", paymentHash, params.ValidUntil) + return InterceptResult{ + Action: INTERCEPT_FAIL_HTLC_WITH_CODE, + FailureCode: FAILURE_TEMPORARY_CHANNEL_FAILURE, + }, nil + } + + minMsat := uint64(feeEstimate.SatPerVByte * float64(i.config.ExpiredPromiseMultiplicationFactor)) + if minMsat >= params.MinMsat { + log.Printf("Intercepted expired payment registration. Failing payment. payment hash: %x, valid until: %s", paymentHash, params.ValidUntil) + return InterceptResult{ + Action: INTERCEPT_FAIL_HTLC_WITH_CODE, + FailureCode: FAILURE_TEMPORARY_CHANNEL_FAILURE, + }, nil + } + + log.Printf("Intercepted expired payment registration. Opening channel anyway, because it's cheaper at the current rate. feeEstimate: %v minMsat: %v, params: %+v", feeEstimate.SatPerVByte, minMsat, params) } channelPoint, err = i.openChannel(reqPaymentHash, destination, incomingAmountMsat)