mirror of
https://github.com/aljazceru/lspd.git
synced 2026-01-03 22:24:27 +01:00
do open channel if promise expired, but cheap fees
This commit is contained in:
@@ -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"`
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user