cleanup: move types to appropriate packages

This commit is contained in:
Jesse de Wit
2023-03-24 16:08:42 +01:00
parent 086d500750
commit c1b80420df
11 changed files with 144 additions and 133 deletions

View File

@@ -1,4 +1,4 @@
package main
package cln
import (
"encoding/hex"

View File

@@ -1,4 +1,4 @@
package main
package cln
import (
"bytes"
@@ -12,6 +12,7 @@ import (
"github.com/breez/lspd/cln_plugin/proto"
"github.com/breez/lspd/config"
"github.com/breez/lspd/interceptor"
sphinx "github.com/lightningnetwork/lightning-onion"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/record"
@@ -24,7 +25,7 @@ import (
)
type ClnHtlcInterceptor struct {
interceptor *Interceptor
interceptor *interceptor.Interceptor
config *config.NodeConfig
pluginAddress string
client *ClnClient
@@ -36,11 +37,12 @@ type ClnHtlcInterceptor struct {
cancel context.CancelFunc
}
func NewClnHtlcInterceptor(conf *config.NodeConfig, client *ClnClient, interceptor *Interceptor) (*ClnHtlcInterceptor, error) {
func NewClnHtlcInterceptor(conf *config.NodeConfig, client *ClnClient, interceptor *interceptor.Interceptor) (*ClnHtlcInterceptor, error) {
i := &ClnHtlcInterceptor{
config: conf,
pluginAddress: conf.Cln.PluginAddress,
client: client,
interceptor: interceptor,
}
i.initWg.Add(1)
@@ -163,14 +165,14 @@ func (i *ClnHtlcInterceptor) intercept() error {
i.doneWg.Done()
}
interceptResult := i.interceptor.Intercept(nextHop, paymentHash, request.Onion.ForwardMsat, request.Onion.OutgoingCltvValue, request.Htlc.CltvExpiry)
switch interceptResult.action {
case INTERCEPT_RESUME_WITH_ONION:
switch interceptResult.Action {
case interceptor.INTERCEPT_RESUME_WITH_ONION:
interceptorClient.Send(i.resumeWithOnion(request, interceptResult))
case INTERCEPT_FAIL_HTLC_WITH_CODE:
case interceptor.INTERCEPT_FAIL_HTLC_WITH_CODE:
interceptorClient.Send(
i.failWithCode(request, interceptResult.failureCode),
i.failWithCode(request, interceptResult.FailureCode),
)
case INTERCEPT_RESUME:
case interceptor.INTERCEPT_RESUME:
fallthrough
default:
interceptorClient.Send(
@@ -202,22 +204,22 @@ func (i *ClnHtlcInterceptor) WaitStarted() {
i.initWg.Wait()
}
func (i *ClnHtlcInterceptor) resumeWithOnion(request *proto.HtlcAccepted, interceptResult interceptResult) *proto.HtlcResolution {
func (i *ClnHtlcInterceptor) resumeWithOnion(request *proto.HtlcAccepted, interceptResult interceptor.InterceptResult) *proto.HtlcResolution {
//decoding and encoding onion with alias in type 6 record.
payload, err := hex.DecodeString(request.Onion.Payload)
if err != nil {
log.Printf("resumeWithOnion: hex.DecodeString(%v) error: %v", request.Onion.Payload, err)
return i.failWithCode(request, FAILURE_TEMPORARY_CHANNEL_FAILURE)
return i.failWithCode(request, interceptor.FAILURE_TEMPORARY_CHANNEL_FAILURE)
}
newPayload, err := encodePayloadWithNextHop(payload, interceptResult.channelId)
newPayload, err := encodePayloadWithNextHop(payload, interceptResult.ChannelId)
if err != nil {
log.Printf("encodePayloadWithNextHop error: %v", err)
return i.failWithCode(request, FAILURE_TEMPORARY_CHANNEL_FAILURE)
return i.failWithCode(request, interceptor.FAILURE_TEMPORARY_CHANNEL_FAILURE)
}
newPayloadStr := hex.EncodeToString(newPayload)
chanId := lnwire.NewChanIDFromOutPoint(interceptResult.channelPoint).String()
chanId := lnwire.NewChanIDFromOutPoint(interceptResult.ChannelPoint).String()
log.Printf("forwarding htlc to the destination node and a new private channel was opened")
return &proto.HtlcResolution{
Correlationid: request.Correlationid,
@@ -239,7 +241,7 @@ func (i *ClnHtlcInterceptor) defaultResolution(request *proto.HtlcAccepted) *pro
}
}
func (i *ClnHtlcInterceptor) failWithCode(request *proto.HtlcAccepted, code interceptFailureCode) *proto.HtlcResolution {
func (i *ClnHtlcInterceptor) failWithCode(request *proto.HtlcAccepted, code interceptor.InterceptFailureCode) *proto.HtlcResolution {
return &proto.HtlcResolution{
Correlationid: request.Correlationid,
Outcome: &proto.HtlcResolution_Fail{
@@ -298,13 +300,13 @@ func encodePayloadWithNextHop(payload []byte, channelId uint64) ([]byte, error)
return newPayloadBuf.Bytes(), nil
}
func (i *ClnHtlcInterceptor) mapFailureCode(original interceptFailureCode) string {
func (i *ClnHtlcInterceptor) mapFailureCode(original interceptor.InterceptFailureCode) string {
switch original {
case FAILURE_TEMPORARY_CHANNEL_FAILURE:
case interceptor.FAILURE_TEMPORARY_CHANNEL_FAILURE:
return "1007"
case FAILURE_TEMPORARY_NODE_FAILURE:
case interceptor.FAILURE_TEMPORARY_NODE_FAILURE:
return "2002"
case FAILURE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS:
case interceptor.FAILURE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS:
return "400F"
default:
log.Printf("Unknown failure code %v, default to temporary channel failure.", original)

View File

@@ -1,4 +1,4 @@
package main
package interceptor
import (
"bytes"

View File

@@ -1,4 +1,4 @@
package main
package interceptor
type HtlcInterceptor interface {
Start() error

View File

@@ -1,4 +1,4 @@
package main
package interceptor
import (
"bytes"
@@ -11,7 +11,6 @@ import (
"github.com/breez/lspd/chain"
"github.com/breez/lspd/config"
"github.com/breez/lspd/interceptor"
"github.com/breez/lspd/lightning"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/wire"
@@ -22,94 +21,97 @@ import (
"golang.org/x/sync/singleflight"
)
type interceptAction int
type InterceptAction int
const (
INTERCEPT_RESUME interceptAction = 0
INTERCEPT_RESUME_WITH_ONION interceptAction = 1
INTERCEPT_FAIL_HTLC_WITH_CODE interceptAction = 2
INTERCEPT_RESUME InterceptAction = 0
INTERCEPT_RESUME_WITH_ONION InterceptAction = 1
INTERCEPT_FAIL_HTLC_WITH_CODE InterceptAction = 2
)
type interceptFailureCode uint16
type InterceptFailureCode uint16
var (
FAILURE_TEMPORARY_CHANNEL_FAILURE interceptFailureCode = 0x1007
FAILURE_TEMPORARY_NODE_FAILURE interceptFailureCode = 0x2002
FAILURE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS interceptFailureCode = 0x400F
FAILURE_TEMPORARY_CHANNEL_FAILURE InterceptFailureCode = 0x1007
FAILURE_TEMPORARY_NODE_FAILURE InterceptFailureCode = 0x2002
FAILURE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS InterceptFailureCode = 0x400F
)
var payHashGroup singleflight.Group
var feeEstimator chain.FeeEstimator
var feeStrategy chain.FeeStrategy
type interceptResult struct {
action interceptAction
failureCode interceptFailureCode
destination []byte
amountMsat uint64
channelPoint *wire.OutPoint
channelId uint64
onionBlob []byte
type InterceptResult struct {
Action InterceptAction
FailureCode InterceptFailureCode
Destination []byte
AmountMsat uint64
ChannelPoint *wire.OutPoint
ChannelId uint64
OnionBlob []byte
}
type Interceptor struct {
client lightning.Client
config *config.NodeConfig
store interceptor.InterceptStore
store InterceptStore
feeEstimator chain.FeeEstimator
feeStrategy chain.FeeStrategy
payHashGroup singleflight.Group
}
func NewInterceptor(
client lightning.Client,
config *config.NodeConfig,
store interceptor.InterceptStore,
store InterceptStore,
feeEstimator chain.FeeEstimator,
feeStrategy chain.FeeStrategy,
) *Interceptor {
return &Interceptor{
client: client,
config: config,
store: store,
feeEstimator: feeEstimator,
feeStrategy: feeStrategy,
}
}
func (i *Interceptor) Intercept(nextHop string, reqPaymentHash []byte, reqOutgoingAmountMsat uint64, reqOutgoingExpiry uint32, reqIncomingExpiry uint32) interceptResult {
func (i *Interceptor) Intercept(nextHop string, reqPaymentHash []byte, reqOutgoingAmountMsat uint64, reqOutgoingExpiry uint32, reqIncomingExpiry uint32) InterceptResult {
reqPaymentHashStr := hex.EncodeToString(reqPaymentHash)
resp, _, _ := payHashGroup.Do(reqPaymentHashStr, func() (interface{}, error) {
resp, _, _ := i.payHashGroup.Do(reqPaymentHashStr, func() (interface{}, error) {
paymentHash, paymentSecret, destination, incomingAmountMsat, outgoingAmountMsat, channelPoint, err := i.store.PaymentInfo(reqPaymentHash)
if err != nil {
log.Printf("paymentInfo(%x) error: %v", reqPaymentHash, err)
return interceptResult{
action: INTERCEPT_FAIL_HTLC_WITH_CODE,
failureCode: FAILURE_TEMPORARY_NODE_FAILURE,
return InterceptResult{
Action: INTERCEPT_FAIL_HTLC_WITH_CODE,
FailureCode: FAILURE_TEMPORARY_NODE_FAILURE,
}, nil
}
log.Printf("paymentHash:%x\npaymentSecret:%x\ndestination:%x\nincomingAmountMsat:%v\noutgoingAmountMsat:%v",
paymentHash, paymentSecret, destination, incomingAmountMsat, outgoingAmountMsat)
if paymentSecret == nil || (nextHop != "<unknown>" && nextHop != hex.EncodeToString(destination)) {
return interceptResult{
action: INTERCEPT_RESUME,
return InterceptResult{
Action: INTERCEPT_RESUME,
}, nil
}
if channelPoint == nil {
if bytes.Equal(paymentHash, reqPaymentHash) {
if int64(reqIncomingExpiry)-int64(reqOutgoingExpiry) < int64(i.config.TimeLockDelta) {
return interceptResult{
action: INTERCEPT_FAIL_HTLC_WITH_CODE,
failureCode: FAILURE_TEMPORARY_CHANNEL_FAILURE,
return InterceptResult{
Action: INTERCEPT_FAIL_HTLC_WITH_CODE,
FailureCode: FAILURE_TEMPORARY_CHANNEL_FAILURE,
}, nil
}
channelPoint, err = i.openChannel(reqPaymentHash, destination, incomingAmountMsat)
if err != nil {
log.Printf("openChannel(%x, %v) err: %v", destination, incomingAmountMsat, err)
return interceptResult{
action: INTERCEPT_FAIL_HTLC_WITH_CODE,
failureCode: FAILURE_TEMPORARY_CHANNEL_FAILURE,
return InterceptResult{
Action: INTERCEPT_FAIL_HTLC_WITH_CODE,
FailureCode: FAILURE_TEMPORARY_CHANNEL_FAILURE,
}, nil
}
} else { //probing
return interceptResult{
action: INTERCEPT_FAIL_HTLC_WITH_CODE,
failureCode: FAILURE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS,
return InterceptResult{
Action: INTERCEPT_FAIL_HTLC_WITH_CODE,
FailureCode: FAILURE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS,
}, nil
}
}
@@ -117,18 +119,18 @@ func (i *Interceptor) Intercept(nextHop string, reqPaymentHash []byte, reqOutgoi
pubKey, err := btcec.ParsePubKey(destination)
if err != nil {
log.Printf("btcec.ParsePubKey(%x): %v", destination, err)
return interceptResult{
action: INTERCEPT_FAIL_HTLC_WITH_CODE,
failureCode: FAILURE_TEMPORARY_CHANNEL_FAILURE,
return InterceptResult{
Action: INTERCEPT_FAIL_HTLC_WITH_CODE,
FailureCode: FAILURE_TEMPORARY_CHANNEL_FAILURE,
}, nil
}
sessionKey, err := btcec.NewPrivateKey()
if err != nil {
log.Printf("btcec.NewPrivateKey(): %v", err)
return interceptResult{
action: INTERCEPT_FAIL_HTLC_WITH_CODE,
failureCode: FAILURE_TEMPORARY_CHANNEL_FAILURE,
return InterceptResult{
Action: INTERCEPT_FAIL_HTLC_WITH_CODE,
FailureCode: FAILURE_TEMPORARY_CHANNEL_FAILURE,
}, nil
}
@@ -148,18 +150,18 @@ func (i *Interceptor) Intercept(nextHop string, reqPaymentHash []byte, reqOutgoi
err = hop.PackHopPayload(&b, uint64(0))
if err != nil {
log.Printf("hop.PackHopPayload(): %v", err)
return interceptResult{
action: INTERCEPT_FAIL_HTLC_WITH_CODE,
failureCode: FAILURE_TEMPORARY_CHANNEL_FAILURE,
return InterceptResult{
Action: INTERCEPT_FAIL_HTLC_WITH_CODE,
FailureCode: FAILURE_TEMPORARY_CHANNEL_FAILURE,
}, nil
}
payload, err := sphinx.NewHopPayload(nil, b.Bytes())
if err != nil {
log.Printf("sphinx.NewHopPayload(): %v", err)
return interceptResult{
action: INTERCEPT_FAIL_HTLC_WITH_CODE,
failureCode: FAILURE_TEMPORARY_CHANNEL_FAILURE,
return InterceptResult{
Action: INTERCEPT_FAIL_HTLC_WITH_CODE,
FailureCode: FAILURE_TEMPORARY_CHANNEL_FAILURE,
}, nil
}
@@ -174,18 +176,18 @@ func (i *Interceptor) Intercept(nextHop string, reqPaymentHash []byte, reqOutgoi
)
if err != nil {
log.Printf("sphinx.NewOnionPacket(): %v", err)
return interceptResult{
action: INTERCEPT_FAIL_HTLC_WITH_CODE,
failureCode: FAILURE_TEMPORARY_CHANNEL_FAILURE,
return InterceptResult{
Action: INTERCEPT_FAIL_HTLC_WITH_CODE,
FailureCode: FAILURE_TEMPORARY_CHANNEL_FAILURE,
}, nil
}
var onionBlob bytes.Buffer
err = sphinxPacket.Encode(&onionBlob)
if err != nil {
log.Printf("sphinxPacket.Encode(): %v", err)
return interceptResult{
action: INTERCEPT_FAIL_HTLC_WITH_CODE,
failureCode: FAILURE_TEMPORARY_CHANNEL_FAILURE,
return InterceptResult{
Action: INTERCEPT_FAIL_HTLC_WITH_CODE,
FailureCode: FAILURE_TEMPORARY_CHANNEL_FAILURE,
}, nil
}
@@ -206,9 +208,9 @@ func (i *Interceptor) Intercept(nextHop string, reqPaymentHash []byte, reqOutgoi
if err != nil {
log.Printf("insertChannel error: %v", err)
return interceptResult{
action: INTERCEPT_FAIL_HTLC_WITH_CODE,
failureCode: FAILURE_TEMPORARY_CHANNEL_FAILURE,
return InterceptResult{
Action: INTERCEPT_FAIL_HTLC_WITH_CODE,
FailureCode: FAILURE_TEMPORARY_CHANNEL_FAILURE,
}, nil
}
@@ -217,13 +219,13 @@ func (i *Interceptor) Intercept(nextHop string, reqPaymentHash []byte, reqOutgoi
channelID = uint64(chanResult.InitialChannelID)
}
return interceptResult{
action: INTERCEPT_RESUME_WITH_ONION,
destination: destination,
channelPoint: channelPoint,
channelId: channelID,
amountMsat: uint64(amt),
onionBlob: onionBlob.Bytes(),
return InterceptResult{
Action: INTERCEPT_RESUME_WITH_ONION,
Destination: destination,
ChannelPoint: channelPoint,
ChannelId: channelID,
AmountMsat: uint64(amt),
OnionBlob: onionBlob.Bytes(),
}, nil
}
@@ -236,13 +238,13 @@ func (i *Interceptor) Intercept(nextHop string, reqPaymentHash []byte, reqOutgoi
}
log.Printf("Error: Channel failed to opened... timed out. ")
return interceptResult{
action: INTERCEPT_FAIL_HTLC_WITH_CODE,
failureCode: FAILURE_TEMPORARY_CHANNEL_FAILURE,
return InterceptResult{
Action: INTERCEPT_FAIL_HTLC_WITH_CODE,
FailureCode: FAILURE_TEMPORARY_CHANNEL_FAILURE,
}, nil
})
return resp.(interceptResult)
return resp.(InterceptResult)
}
func (i *Interceptor) openChannel(paymentHash, destination []byte, incomingAmountMsat int64) (*wire.OutPoint, error) {
@@ -255,10 +257,10 @@ func (i *Interceptor) openChannel(paymentHash, destination []byte, incomingAmoun
confStr := "<nil>"
var feeEstimation *float64
feeStr := "<nil>"
if feeEstimator != nil {
fee, err := feeEstimator.EstimateFeeRate(
if i.feeEstimator != nil {
fee, err := i.feeEstimator.EstimateFeeRate(
context.Background(),
feeStrategy,
i.feeStrategy,
)
if err == nil {
feeEstimation = &fee.SatPerVByte

View File

@@ -1,4 +1,4 @@
package main
package lnd
import (
"context"

View File

@@ -1,4 +1,4 @@
package main
package lnd
import (
"context"
@@ -8,7 +8,6 @@ import (
"time"
"github.com/breez/lspd/interceptor"
"github.com/breez/lspd/lnd"
"github.com/lightningnetwork/lnd/htlcswitch/hop"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnrpc/chainrpc"
@@ -41,13 +40,13 @@ func (cfe *copyFromEvents) Err() error {
type ForwardingHistorySync struct {
client *LndClient
interceptStore interceptor.InterceptStore
forwardingStore lnd.ForwardingEventStore
forwardingStore ForwardingEventStore
}
func NewForwardingHistorySync(
client *LndClient,
interceptStore interceptor.InterceptStore,
forwardingStore lnd.ForwardingEventStore,
forwardingStore ForwardingEventStore,
) *ForwardingHistorySync {
return &ForwardingHistorySync{
client: client,

View File

@@ -1,4 +1,4 @@
package main
package lnd
import (
"context"
@@ -8,6 +8,7 @@ import (
"time"
"github.com/breez/lspd/config"
"github.com/breez/lspd/interceptor"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
"google.golang.org/grpc/codes"
@@ -16,7 +17,7 @@ import (
type LndHtlcInterceptor struct {
fwsync *ForwardingHistorySync
interceptor *Interceptor
interceptor *interceptor.Interceptor
config *config.NodeConfig
client *LndClient
stopRequested bool
@@ -30,7 +31,7 @@ func NewLndHtlcInterceptor(
conf *config.NodeConfig,
client *LndClient,
fwsync *ForwardingHistorySync,
interceptor *Interceptor,
interceptor *interceptor.Interceptor,
) (*LndHtlcInterceptor, error) {
i := &LndHtlcInterceptor{
config: conf,
@@ -152,22 +153,22 @@ func (i *LndHtlcInterceptor) intercept() error {
i.doneWg.Add(1)
go func() {
interceptResult := i.interceptor.Intercept(nextHop, request.PaymentHash, request.OutgoingAmountMsat, request.OutgoingExpiry, request.IncomingExpiry)
switch interceptResult.action {
case INTERCEPT_RESUME_WITH_ONION:
switch interceptResult.Action {
case interceptor.INTERCEPT_RESUME_WITH_ONION:
interceptorClient.Send(&routerrpc.ForwardHtlcInterceptResponse{
IncomingCircuitKey: request.IncomingCircuitKey,
Action: routerrpc.ResolveHoldForwardAction_RESUME,
OutgoingAmountMsat: interceptResult.amountMsat,
OutgoingRequestedChanId: uint64(interceptResult.channelId),
OnionBlob: interceptResult.onionBlob,
OutgoingAmountMsat: interceptResult.AmountMsat,
OutgoingRequestedChanId: uint64(interceptResult.ChannelId),
OnionBlob: interceptResult.OnionBlob,
})
case INTERCEPT_FAIL_HTLC_WITH_CODE:
case interceptor.INTERCEPT_FAIL_HTLC_WITH_CODE:
interceptorClient.Send(&routerrpc.ForwardHtlcInterceptResponse{
IncomingCircuitKey: request.IncomingCircuitKey,
Action: routerrpc.ResolveHoldForwardAction_FAIL,
FailureCode: i.mapFailureCode(interceptResult.failureCode),
FailureCode: i.mapFailureCode(interceptResult.FailureCode),
})
case INTERCEPT_RESUME:
case interceptor.INTERCEPT_RESUME:
fallthrough
default:
interceptorClient.Send(&routerrpc.ForwardHtlcInterceptResponse{
@@ -187,13 +188,13 @@ func (i *LndHtlcInterceptor) intercept() error {
}
}
func (i *LndHtlcInterceptor) mapFailureCode(original interceptFailureCode) lnrpc.Failure_FailureCode {
func (i *LndHtlcInterceptor) mapFailureCode(original interceptor.InterceptFailureCode) lnrpc.Failure_FailureCode {
switch original {
case FAILURE_TEMPORARY_CHANNEL_FAILURE:
case interceptor.FAILURE_TEMPORARY_CHANNEL_FAILURE:
return lnrpc.Failure_TEMPORARY_CHANNEL_FAILURE
case FAILURE_TEMPORARY_NODE_FAILURE:
case interceptor.FAILURE_TEMPORARY_NODE_FAILURE:
return lnrpc.Failure_TEMPORARY_NODE_FAILURE
case FAILURE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS:
case interceptor.FAILURE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS:
return lnrpc.Failure_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS
default:
log.Printf("Unknown failure code %v, default to temporary channel failure.", original)

View File

@@ -1,4 +1,4 @@
package main
package lnd
import (
"context"

23
main.go
View File

@@ -11,7 +11,10 @@ import (
"syscall"
"github.com/breez/lspd/chain"
"github.com/breez/lspd/cln"
"github.com/breez/lspd/config"
"github.com/breez/lspd/interceptor"
"github.com/breez/lspd/lnd"
"github.com/breez/lspd/mempool"
"github.com/breez/lspd/postgresql"
"github.com/btcsuite/btcd/btcec/v2"
@@ -38,6 +41,8 @@ func main() {
log.Fatalf("need at least one node configured in NODES.")
}
var feeEstimator chain.FeeEstimator
var feeStrategy chain.FeeStrategy
useMempool := os.Getenv("USE_MEMPOOL_FEE_ESTIMATION") == "true"
if useMempool {
mempoolUrl := os.Getenv("MEMPOOL_API_BASE_URL")
@@ -73,31 +78,31 @@ func main() {
interceptStore := postgresql.NewPostgresInterceptStore(pool)
forwardingStore := postgresql.NewForwardingEventStore(pool)
var interceptors []HtlcInterceptor
var interceptors []interceptor.HtlcInterceptor
for _, node := range nodes {
var htlcInterceptor HtlcInterceptor
var htlcInterceptor interceptor.HtlcInterceptor
if node.Lnd != nil {
client, err := NewLndClient(node.Lnd)
client, err := lnd.NewLndClient(node.Lnd)
if err != nil {
log.Fatalf("failed to initialize LND client: %v", err)
}
fwsync := NewForwardingHistorySync(client, interceptStore, forwardingStore)
interceptor := NewInterceptor(client, node, interceptStore)
htlcInterceptor, err = NewLndHtlcInterceptor(node, client, fwsync, interceptor)
fwsync := lnd.NewForwardingHistorySync(client, interceptStore, forwardingStore)
interceptor := interceptor.NewInterceptor(client, node, interceptStore, feeEstimator, feeStrategy)
htlcInterceptor, err = lnd.NewLndHtlcInterceptor(node, client, fwsync, interceptor)
if err != nil {
log.Fatalf("failed to initialize LND interceptor: %v", err)
}
}
if node.Cln != nil {
client, err := NewClnClient(node.Cln.SocketPath)
client, err := cln.NewClnClient(node.Cln.SocketPath)
if err != nil {
log.Fatalf("failed to initialize CLN client: %v", err)
}
interceptor := NewInterceptor(client, node, interceptStore)
htlcInterceptor, err = NewClnHtlcInterceptor(node, client, interceptor)
interceptor := interceptor.NewInterceptor(client, node, interceptStore, feeEstimator, feeStrategy)
htlcInterceptor, err = cln.NewClnHtlcInterceptor(node, client, interceptor)
if err != nil {
log.Fatalf("failed to initialize CLN interceptor: %v", err)
}

View File

@@ -11,9 +11,11 @@ import (
"strings"
"github.com/breez/lspd/btceclegacy"
"github.com/breez/lspd/cln"
"github.com/breez/lspd/config"
"github.com/breez/lspd/interceptor"
"github.com/breez/lspd/lightning"
"github.com/breez/lspd/lnd"
lspdrpc "github.com/breez/lspd/rpc"
ecies "github.com/ecies/go/v2"
"github.com/golang/protobuf/proto"
@@ -301,14 +303,14 @@ func NewGrpcServer(
}
if config.Lnd != nil {
node.client, err = NewLndClient(config.Lnd)
node.client, err = lnd.NewLndClient(config.Lnd)
if err != nil {
return nil, err
}
}
if config.Cln != nil {
node.client, err = NewClnClient(config.Cln.SocketPath)
node.client, err = cln.NewClnClient(config.Cln.SocketPath)
if err != nil {
return nil, err
}