mirror of
https://github.com/aljazceru/lspd.git
synced 2026-02-22 22:44:30 +01:00
share isCurrentChainFeeCheaper method
This commit is contained in:
@@ -24,7 +24,7 @@ type Interceptor struct {
|
||||
client lightning.Client
|
||||
config *config.NodeConfig
|
||||
store InterceptStore
|
||||
openingStore shared.OpeningStore
|
||||
openingService shared.OpeningService
|
||||
feeEstimator chain.FeeEstimator
|
||||
feeStrategy chain.FeeStrategy
|
||||
payHashGroup singleflight.Group
|
||||
@@ -35,7 +35,7 @@ func NewInterceptHandler(
|
||||
client lightning.Client,
|
||||
config *config.NodeConfig,
|
||||
store InterceptStore,
|
||||
openingStore shared.OpeningStore,
|
||||
openingService shared.OpeningService,
|
||||
feeEstimator chain.FeeEstimator,
|
||||
feeStrategy chain.FeeStrategy,
|
||||
notificationService *notifications.NotificationService,
|
||||
@@ -44,7 +44,7 @@ func NewInterceptHandler(
|
||||
client: client,
|
||||
config: config,
|
||||
store: store,
|
||||
openingStore: openingStore,
|
||||
openingService: openingService,
|
||||
feeEstimator: feeEstimator,
|
||||
feeStrategy: feeStrategy,
|
||||
notificationService: notificationService,
|
||||
@@ -190,7 +190,7 @@ func (i *Interceptor) Intercept(req shared.InterceptRequest) shared.InterceptRes
|
||||
// Make sure the opening_fee_params are not expired.
|
||||
// If they are expired, but the current chain fee is fine, open channel anyway.
|
||||
if time.Now().UTC().After(validUntil) {
|
||||
if !i.isCurrentChainFeeCheaper(token, params) {
|
||||
if !i.openingService.IsCurrentChainFeeCheaper(token, params) {
|
||||
log.Printf("Intercepted expired payment registration. Failing payment. payment hash: %x, valid until: %s", paymentHash, params.ValidUntil)
|
||||
return shared.InterceptResult{
|
||||
Action: shared.INTERCEPT_FAIL_HTLC_WITH_CODE,
|
||||
@@ -340,22 +340,6 @@ func (i *Interceptor) notify(reqPaymentHashStr string, nextHop []byte, isRegiste
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *Interceptor) isCurrentChainFeeCheaper(token string, params *shared.OpeningFeeParams) bool {
|
||||
settings, err := i.openingStore.GetFeeParamsSettings(token)
|
||||
if err != nil {
|
||||
log.Printf("Failed to get fee params settings: %v", err)
|
||||
return false
|
||||
}
|
||||
|
||||
for _, setting := range settings {
|
||||
if setting.Params.MinFeeMsat <= params.MinFeeMsat {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (i *Interceptor) openChannel(paymentHash, destination []byte, incomingAmountMsat int64, tag *string) (*wire.OutPoint, error) {
|
||||
capacity := incomingAmountMsat/1000 + i.config.AdditionalChannelCapacity
|
||||
if capacity == i.config.PublicChannelAmount {
|
||||
|
||||
@@ -29,9 +29,10 @@ func (m *mockNodesService) GetNodes() []*shared.Node {
|
||||
}
|
||||
|
||||
type mockOpeningService struct {
|
||||
menu []*shared.OpeningFeeParams
|
||||
err error
|
||||
invalid bool
|
||||
menu []*shared.OpeningFeeParams
|
||||
err error
|
||||
invalid bool
|
||||
isCurrentChainFeeCheaper bool
|
||||
}
|
||||
|
||||
func (m *mockOpeningService) GetFeeParamsMenu(
|
||||
@@ -48,6 +49,13 @@ func (m *mockOpeningService) ValidateOpeningFeeParams(
|
||||
return !m.invalid
|
||||
}
|
||||
|
||||
func (m *mockOpeningService) IsCurrentChainFeeCheaper(
|
||||
token string,
|
||||
params *shared.OpeningFeeParams,
|
||||
) bool {
|
||||
return m.isCurrentChainFeeCheaper
|
||||
}
|
||||
|
||||
type mockLsps2Store struct {
|
||||
err error
|
||||
req *RegisterBuy
|
||||
|
||||
4
main.go
4
main.go
@@ -110,7 +110,7 @@ func main() {
|
||||
|
||||
client.StartListeners()
|
||||
fwsync := lnd.NewForwardingHistorySync(client, interceptStore, forwardingStore)
|
||||
interceptor := interceptor.NewInterceptHandler(client, node.NodeConfig, interceptStore, openingStore, feeEstimator, feeStrategy, notificationService)
|
||||
interceptor := interceptor.NewInterceptHandler(client, node.NodeConfig, interceptStore, openingService, feeEstimator, feeStrategy, notificationService)
|
||||
htlcInterceptor, err = lnd.NewLndHtlcInterceptor(node.NodeConfig, client, fwsync, interceptor)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to initialize LND interceptor: %v", err)
|
||||
@@ -123,7 +123,7 @@ func main() {
|
||||
log.Fatalf("failed to initialize CLN client: %v", err)
|
||||
}
|
||||
|
||||
interceptor := interceptor.NewInterceptHandler(client, node.NodeConfig, interceptStore, openingStore, feeEstimator, feeStrategy, notificationService)
|
||||
interceptor := interceptor.NewInterceptHandler(client, node.NodeConfig, interceptStore, openingService, feeEstimator, feeStrategy, notificationService)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to initialize CLN interceptor: %v", err)
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
type OpeningService interface {
|
||||
GetFeeParamsMenu(token string, privateKey *btcec.PrivateKey) ([]*OpeningFeeParams, error)
|
||||
ValidateOpeningFeeParams(params *OpeningFeeParams, publicKey *btcec.PublicKey) bool
|
||||
IsCurrentChainFeeCheaper(token string, params *OpeningFeeParams) bool
|
||||
}
|
||||
|
||||
type openingService struct {
|
||||
@@ -100,6 +101,22 @@ func (s *openingService) ValidateOpeningFeeParams(params *OpeningFeeParams, publ
|
||||
return true
|
||||
}
|
||||
|
||||
func (s *openingService) IsCurrentChainFeeCheaper(token string, params *OpeningFeeParams) bool {
|
||||
settings, err := s.store.GetFeeParamsSettings(token)
|
||||
if err != nil {
|
||||
log.Printf("Failed to get fee params settings: %v", err)
|
||||
return false
|
||||
}
|
||||
|
||||
for _, setting := range settings {
|
||||
if setting.Params.MinFeeMsat <= params.MinFeeMsat {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func createPromise(lspPrivateKey *btcec.PrivateKey, params *OpeningFeeParams) (*string, error) {
|
||||
hash, err := paramsHash(params)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user