rename shared package to common

This commit is contained in:
Jesse de Wit
2023-10-26 14:39:03 +02:00
parent fb3b051d02
commit 3cf4b714a9
22 changed files with 251 additions and 251 deletions

View File

@@ -9,11 +9,11 @@ import (
"time" "time"
"github.com/breez/lspd/btceclegacy" "github.com/breez/lspd/btceclegacy"
"github.com/breez/lspd/common"
"github.com/breez/lspd/interceptor" "github.com/breez/lspd/interceptor"
"github.com/breez/lspd/lightning" "github.com/breez/lspd/lightning"
"github.com/breez/lspd/lsps0" "github.com/breez/lspd/lsps0"
lspdrpc "github.com/breez/lspd/rpc" lspdrpc "github.com/breez/lspd/rpc"
"github.com/breez/lspd/shared"
ecies "github.com/ecies/go/v2" ecies "github.com/ecies/go/v2"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
@@ -28,12 +28,12 @@ import (
type channelOpenerServer struct { type channelOpenerServer struct {
lspdrpc.ChannelOpenerServer lspdrpc.ChannelOpenerServer
store interceptor.InterceptStore store interceptor.InterceptStore
openingService shared.OpeningService openingService common.OpeningService
} }
func NewChannelOpenerServer( func NewChannelOpenerServer(
store interceptor.InterceptStore, store interceptor.InterceptStore,
openingService shared.OpeningService, openingService common.OpeningService,
) *channelOpenerServer { ) *channelOpenerServer {
return &channelOpenerServer{ return &channelOpenerServer{
store: store, store: store,
@@ -128,7 +128,7 @@ func (s *channelOpenerServer) RegisterPayment(
// clients to use opening_fee_params. // clients to use opening_fee_params.
if pi.OpeningFeeParams != nil { if pi.OpeningFeeParams != nil {
valid := s.openingService.ValidateOpeningFeeParams( valid := s.openingService.ValidateOpeningFeeParams(
&shared.OpeningFeeParams{ &common.OpeningFeeParams{
MinFeeMsat: pi.OpeningFeeParams.MinMsat, MinFeeMsat: pi.OpeningFeeParams.MinMsat,
Proportional: pi.OpeningFeeParams.Proportional, Proportional: pi.OpeningFeeParams.Proportional,
ValidUntil: pi.OpeningFeeParams.ValidUntil, ValidUntil: pi.OpeningFeeParams.ValidUntil,
@@ -157,7 +157,7 @@ func (s *channelOpenerServer) RegisterPayment(
log.Printf("checkPayment(%v, %v) error: %v", pi.IncomingAmountMsat, pi.OutgoingAmountMsat, err) log.Printf("checkPayment(%v, %v) error: %v", pi.IncomingAmountMsat, pi.OutgoingAmountMsat, err)
return nil, fmt.Errorf("checkPayment(%v, %v) error: %v", pi.IncomingAmountMsat, pi.OutgoingAmountMsat, err) return nil, fmt.Errorf("checkPayment(%v, %v) error: %v", pi.IncomingAmountMsat, pi.OutgoingAmountMsat, err)
} }
params := &shared.OpeningFeeParams{ params := &common.OpeningFeeParams{
MinFeeMsat: pi.OpeningFeeParams.MinMsat, MinFeeMsat: pi.OpeningFeeParams.MinMsat,
Proportional: pi.OpeningFeeParams.Proportional, Proportional: pi.OpeningFeeParams.Proportional,
ValidUntil: pi.OpeningFeeParams.ValidUntil, ValidUntil: pi.OpeningFeeParams.ValidUntil,
@@ -217,7 +217,7 @@ func (s *channelOpenerServer) OpenChannel(ctx context.Context, in *lspdrpc.OpenC
return r.(*lspdrpc.OpenChannelReply), err return r.(*lspdrpc.OpenChannelReply), err
} }
func getSignedEncryptedData(n *shared.Node, in *lspdrpc.Encrypted) (string, []byte, bool, error) { func getSignedEncryptedData(n *common.Node, in *lspdrpc.Encrypted) (string, []byte, bool, error) {
usedEcies := true usedEcies := true
signedBlob, err := ecies.Decrypt(n.EciesPrivateKey, in.Data) signedBlob, err := ecies.Decrypt(n.EciesPrivateKey, in.Data)
if err != nil { if err != nil {
@@ -312,7 +312,7 @@ func (s *channelOpenerServer) CheckChannels(ctx context.Context, in *lspdrpc.Enc
return &lspdrpc.Encrypted{Data: encrypted}, nil return &lspdrpc.Encrypted{Data: encrypted}, nil
} }
func (s *channelOpenerServer) getNode(ctx context.Context) (*shared.Node, string, error) { func (s *channelOpenerServer) getNode(ctx context.Context) (*common.Node, string, error) {
nd := ctx.Value(contextKey("node")) nd := ctx.Value(contextKey("node"))
if nd == nil { if nd == nil {
return nil, "", status.Errorf(codes.PermissionDenied, "Not authorized") return nil, "", status.Errorf(codes.PermissionDenied, "Not authorized")

View File

@@ -11,9 +11,9 @@ import (
"time" "time"
"github.com/breez/lspd/cln_plugin/proto" "github.com/breez/lspd/cln_plugin/proto"
"github.com/breez/lspd/common"
"github.com/breez/lspd/config" "github.com/breez/lspd/config"
"github.com/breez/lspd/lightning" "github.com/breez/lspd/lightning"
"github.com/breez/lspd/shared"
sphinx "github.com/lightningnetwork/lightning-onion" sphinx "github.com/lightningnetwork/lightning-onion"
"github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/record" "github.com/lightningnetwork/lnd/record"
@@ -26,7 +26,7 @@ import (
) )
type ClnHtlcInterceptor struct { type ClnHtlcInterceptor struct {
interceptor shared.InterceptHandler interceptor common.InterceptHandler
config *config.NodeConfig config *config.NodeConfig
pluginAddress string pluginAddress string
client *ClnClient client *ClnClient
@@ -38,7 +38,7 @@ type ClnHtlcInterceptor struct {
cancel context.CancelFunc cancel context.CancelFunc
} }
func NewClnHtlcInterceptor(conf *config.NodeConfig, client *ClnClient, interceptor shared.InterceptHandler) (*ClnHtlcInterceptor, error) { func NewClnHtlcInterceptor(conf *config.NodeConfig, client *ClnClient, interceptor common.InterceptHandler) (*ClnHtlcInterceptor, error) {
i := &ClnHtlcInterceptor{ i := &ClnHtlcInterceptor{
config: conf, config: conf,
pluginAddress: conf.Cln.PluginAddress, pluginAddress: conf.Cln.PluginAddress,
@@ -147,7 +147,7 @@ func (i *ClnHtlcInterceptor) intercept() error {
return return
} }
interceptResult := i.interceptor.Intercept(shared.InterceptRequest{ interceptResult := i.interceptor.Intercept(common.InterceptRequest{
Identifier: request.Onion.SharedSecret, Identifier: request.Onion.SharedSecret,
Scid: *scid, Scid: *scid,
PaymentHash: paymentHash, PaymentHash: paymentHash,
@@ -157,15 +157,15 @@ func (i *ClnHtlcInterceptor) intercept() error {
OutgoingExpiry: request.Onion.OutgoingCltvValue, OutgoingExpiry: request.Onion.OutgoingCltvValue,
}) })
switch interceptResult.Action { switch interceptResult.Action {
case shared.INTERCEPT_RESUME_WITH_ONION: case common.INTERCEPT_RESUME_WITH_ONION:
interceptorClient.Send(i.resumeWithOnion(request, interceptResult)) interceptorClient.Send(i.resumeWithOnion(request, interceptResult))
case shared.INTERCEPT_FAIL_HTLC_WITH_CODE: case common.INTERCEPT_FAIL_HTLC_WITH_CODE:
interceptorClient.Send( interceptorClient.Send(
i.failWithCode(request, interceptResult.FailureCode), i.failWithCode(request, interceptResult.FailureCode),
) )
case shared.INTERCEPT_IGNORE: case common.INTERCEPT_IGNORE:
// Do nothing // Do nothing
case shared.INTERCEPT_RESUME: case common.INTERCEPT_RESUME:
fallthrough fallthrough
default: default:
interceptorClient.Send( interceptorClient.Send(
@@ -197,17 +197,17 @@ func (i *ClnHtlcInterceptor) WaitStarted() {
i.initWg.Wait() i.initWg.Wait()
} }
func (i *ClnHtlcInterceptor) resumeWithOnion(request *proto.HtlcAccepted, interceptResult shared.InterceptResult) *proto.HtlcResolution { func (i *ClnHtlcInterceptor) resumeWithOnion(request *proto.HtlcAccepted, interceptResult common.InterceptResult) *proto.HtlcResolution {
//decoding and encoding onion with alias in type 6 record. //decoding and encoding onion with alias in type 6 record.
payload, err := hex.DecodeString(request.Onion.Payload) payload, err := hex.DecodeString(request.Onion.Payload)
if err != nil { if err != nil {
log.Printf("resumeWithOnion: hex.DecodeString(%v) error: %v", request.Onion.Payload, err) log.Printf("resumeWithOnion: hex.DecodeString(%v) error: %v", request.Onion.Payload, err)
return i.failWithCode(request, shared.FAILURE_TEMPORARY_CHANNEL_FAILURE) return i.failWithCode(request, common.FAILURE_TEMPORARY_CHANNEL_FAILURE)
} }
newPayload, err := encodePayloadWithNextHop(payload, interceptResult.Scid, interceptResult.AmountMsat, interceptResult.FeeMsat) newPayload, err := encodePayloadWithNextHop(payload, interceptResult.Scid, interceptResult.AmountMsat, interceptResult.FeeMsat)
if err != nil { if err != nil {
log.Printf("encodePayloadWithNextHop error: %v", err) log.Printf("encodePayloadWithNextHop error: %v", err)
return i.failWithCode(request, shared.FAILURE_TEMPORARY_CHANNEL_FAILURE) return i.failWithCode(request, common.FAILURE_TEMPORARY_CHANNEL_FAILURE)
} }
newPayloadStr := hex.EncodeToString(newPayload) newPayloadStr := hex.EncodeToString(newPayload)
@@ -234,7 +234,7 @@ func (i *ClnHtlcInterceptor) defaultResolution(request *proto.HtlcAccepted) *pro
} }
} }
func (i *ClnHtlcInterceptor) failWithCode(request *proto.HtlcAccepted, code shared.InterceptFailureCode) *proto.HtlcResolution { func (i *ClnHtlcInterceptor) failWithCode(request *proto.HtlcAccepted, code common.InterceptFailureCode) *proto.HtlcResolution {
return &proto.HtlcResolution{ return &proto.HtlcResolution{
Correlationid: request.Correlationid, Correlationid: request.Correlationid,
Outcome: &proto.HtlcResolution_Fail{ Outcome: &proto.HtlcResolution_Fail{
@@ -305,19 +305,19 @@ func encodePayloadWithNextHop(payload []byte, scid lightning.ShortChannelID, amo
return newPayloadBuf.Bytes(), nil return newPayloadBuf.Bytes(), nil
} }
func (i *ClnHtlcInterceptor) mapFailureCode(original shared.InterceptFailureCode) string { func (i *ClnHtlcInterceptor) mapFailureCode(original common.InterceptFailureCode) string {
switch original { switch original {
case shared.FAILURE_TEMPORARY_CHANNEL_FAILURE: case common.FAILURE_TEMPORARY_CHANNEL_FAILURE:
return "1007" return "1007"
case shared.FAILURE_AMOUNT_BELOW_MINIMUM: case common.FAILURE_AMOUNT_BELOW_MINIMUM:
return "100B" return "100B"
case shared.FAILURE_INCORRECT_CLTV_EXPIRY: case common.FAILURE_INCORRECT_CLTV_EXPIRY:
return "100D" return "100D"
case shared.FAILURE_TEMPORARY_NODE_FAILURE: case common.FAILURE_TEMPORARY_NODE_FAILURE:
return "2002" return "2002"
case shared.FAILURE_UNKNOWN_NEXT_PEER: case common.FAILURE_UNKNOWN_NEXT_PEER:
return "400A" return "400A"
case shared.FAILURE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS: case common.FAILURE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS:
return "400F" return "400F"
default: default:
log.Printf("Unknown failure code %v, default to temporary channel failure.", original) log.Printf("Unknown failure code %v, default to temporary channel failure.", original)

View File

@@ -1,4 +1,4 @@
package shared package common
import "log" import "log"

View File

@@ -1,4 +1,4 @@
package shared package common
import "github.com/lightningnetwork/lnd/tlv" import "github.com/lightningnetwork/lnd/tlv"

View File

@@ -1,4 +1,4 @@
package shared package common
import ( import (
"fmt" "fmt"

View File

@@ -1,4 +1,4 @@
package shared package common
import ( import (
"errors" "errors"

View File

@@ -1,4 +1,4 @@
package shared package common
import ( import (
"crypto/sha256" "crypto/sha256"

View File

@@ -1,4 +1,4 @@
package shared package common
import "time" import "time"

View File

@@ -8,9 +8,9 @@ import (
"net" "net"
"strings" "strings"
"github.com/breez/lspd/common"
"github.com/breez/lspd/notifications" "github.com/breez/lspd/notifications"
lspdrpc "github.com/breez/lspd/rpc" lspdrpc "github.com/breez/lspd/rpc"
"github.com/breez/lspd/shared"
"github.com/caddyserver/certmagic" "github.com/caddyserver/certmagic"
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware" grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
"google.golang.org/grpc" "google.golang.org/grpc"
@@ -20,7 +20,7 @@ import (
) )
type grpcServer struct { type grpcServer struct {
nodesService shared.NodesService nodesService common.NodesService
address string address string
certmagicDomain string certmagicDomain string
lis net.Listener lis net.Listener
@@ -31,11 +31,11 @@ type grpcServer struct {
type nodeContext struct { type nodeContext struct {
token string token string
node *shared.Node node *common.Node
} }
func NewGrpcServer( func NewGrpcServer(
nodesService shared.NodesService, nodesService common.NodesService,
address string, address string,
certmagicDomain string, certmagicDomain string,
c lspdrpc.ChannelOpenerServer, c lspdrpc.ChannelOpenerServer,

View File

@@ -10,11 +10,11 @@ import (
"time" "time"
"github.com/breez/lspd/chain" "github.com/breez/lspd/chain"
"github.com/breez/lspd/common"
"github.com/breez/lspd/config" "github.com/breez/lspd/config"
"github.com/breez/lspd/lightning" "github.com/breez/lspd/lightning"
"github.com/breez/lspd/lsps0" "github.com/breez/lspd/lsps0"
"github.com/breez/lspd/notifications" "github.com/breez/lspd/notifications"
"github.com/breez/lspd/shared"
"github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcd/wire"
"golang.org/x/exp/slices" "golang.org/x/exp/slices"
"golang.org/x/sync/singleflight" "golang.org/x/sync/singleflight"
@@ -24,7 +24,7 @@ type Interceptor struct {
client lightning.Client client lightning.Client
config *config.NodeConfig config *config.NodeConfig
store InterceptStore store InterceptStore
openingService shared.OpeningService openingService common.OpeningService
feeEstimator chain.FeeEstimator feeEstimator chain.FeeEstimator
feeStrategy chain.FeeStrategy feeStrategy chain.FeeStrategy
payHashGroup singleflight.Group payHashGroup singleflight.Group
@@ -35,7 +35,7 @@ func NewInterceptHandler(
client lightning.Client, client lightning.Client,
config *config.NodeConfig, config *config.NodeConfig,
store InterceptStore, store InterceptStore,
openingService shared.OpeningService, openingService common.OpeningService,
feeEstimator chain.FeeEstimator, feeEstimator chain.FeeEstimator,
feeStrategy chain.FeeStrategy, feeStrategy chain.FeeStrategy,
notificationService *notifications.NotificationService, notificationService *notifications.NotificationService,
@@ -51,16 +51,16 @@ func NewInterceptHandler(
} }
} }
func (i *Interceptor) Intercept(req shared.InterceptRequest) shared.InterceptResult { func (i *Interceptor) Intercept(req common.InterceptRequest) common.InterceptResult {
reqPaymentHashStr := hex.EncodeToString(req.PaymentHash) reqPaymentHashStr := hex.EncodeToString(req.PaymentHash)
log.Printf("Intercept: scid: %s, paymentHash: %x, outgoindAmount: %v, outgoingExpiry: %v, incomingExpiry: %v", req.Scid.ToString(), reqPaymentHashStr, req.OutgoingAmountMsat, req.OutgoingExpiry, req.IncomingExpiry) log.Printf("Intercept: scid: %s, paymentHash: %x, outgoindAmount: %v, outgoingExpiry: %v, incomingExpiry: %v", req.Scid.ToString(), reqPaymentHashStr, req.OutgoingAmountMsat, req.OutgoingExpiry, req.IncomingExpiry)
resp, _, _ := i.payHashGroup.Do(reqPaymentHashStr, func() (interface{}, error) { resp, _, _ := i.payHashGroup.Do(reqPaymentHashStr, func() (interface{}, error) {
token, params, paymentHash, paymentSecret, destination, incomingAmountMsat, outgoingAmountMsat, channelPoint, tag, err := i.store.PaymentInfo(req.PaymentHash) token, params, paymentHash, paymentSecret, destination, incomingAmountMsat, outgoingAmountMsat, channelPoint, tag, err := i.store.PaymentInfo(req.PaymentHash)
if err != nil { if err != nil {
log.Printf("paymentInfo(%x) error: %v", req.PaymentHash, err) log.Printf("paymentInfo(%x) error: %v", req.PaymentHash, err)
return shared.InterceptResult{ return common.InterceptResult{
Action: shared.INTERCEPT_FAIL_HTLC_WITH_CODE, Action: common.INTERCEPT_FAIL_HTLC_WITH_CODE,
FailureCode: shared.FAILURE_TEMPORARY_NODE_FAILURE, FailureCode: common.FAILURE_TEMPORARY_NODE_FAILURE,
}, nil }, nil
} }
@@ -74,8 +74,8 @@ func (i *Interceptor) Intercept(req shared.InterceptRequest) shared.InterceptRes
nextHop, _ := i.client.GetPeerId(&req.Scid) nextHop, _ := i.client.GetPeerId(&req.Scid)
if err != nil { if err != nil {
log.Printf("GetPeerId(%s) error: %v", req.Scid.ToString(), err) log.Printf("GetPeerId(%s) error: %v", req.Scid.ToString(), err)
return shared.InterceptResult{ return common.InterceptResult{
Action: shared.INTERCEPT_RESUME, Action: common.INTERCEPT_RESUME,
}, nil }, nil
} }
@@ -83,8 +83,8 @@ func (i *Interceptor) Intercept(req shared.InterceptRequest) shared.InterceptRes
// that means we are not the last hop of the payment, so we'll just forward. // that means we are not the last hop of the payment, so we'll just forward.
if isRegistered && nextHop != nil && !bytes.Equal(nextHop, destination) { if isRegistered && nextHop != nil && !bytes.Equal(nextHop, destination) {
log.Printf("paymentHash: %s, nextHop (%s) != destination (%s)", reqPaymentHashStr, hex.EncodeToString(nextHop), hex.EncodeToString(destination)) log.Printf("paymentHash: %s, nextHop (%s) != destination (%s)", reqPaymentHashStr, hex.EncodeToString(nextHop), hex.EncodeToString(destination))
return shared.InterceptResult{ return common.InterceptResult{
Action: shared.INTERCEPT_RESUME, Action: common.INTERCEPT_RESUME,
}, nil }, nil
} }
@@ -97,8 +97,8 @@ func (i *Interceptor) Intercept(req shared.InterceptRequest) shared.InterceptRes
// is not registered, there's nothing left to be done. Just continue. // is not registered, there's nothing left to be done. Just continue.
if !isRegistered { if !isRegistered {
log.Printf("paymentHash: %s, nextHop == nil and not registered", reqPaymentHashStr) log.Printf("paymentHash: %s, nextHop == nil and not registered", reqPaymentHashStr)
return shared.InterceptResult{ return common.InterceptResult{
Action: shared.INTERCEPT_RESUME, Action: common.INTERCEPT_RESUME,
}, nil }, nil
} }
@@ -110,9 +110,9 @@ func (i *Interceptor) Intercept(req shared.InterceptRequest) shared.InterceptRes
isConnected, err := i.client.IsConnected(nextHop) isConnected, err := i.client.IsConnected(nextHop)
if err != nil { if err != nil {
log.Printf("IsConnected(%x) error: %v", nextHop, err) log.Printf("IsConnected(%x) error: %v", nextHop, err)
return &shared.InterceptResult{ return &common.InterceptResult{
Action: shared.INTERCEPT_FAIL_HTLC_WITH_CODE, Action: common.INTERCEPT_FAIL_HTLC_WITH_CODE,
FailureCode: shared.FAILURE_TEMPORARY_CHANNEL_FAILURE, FailureCode: common.FAILURE_TEMPORARY_CHANNEL_FAILURE,
}, nil }, nil
} }
@@ -120,8 +120,8 @@ func (i *Interceptor) Intercept(req shared.InterceptRequest) shared.InterceptRes
// If this is a known probe, we'll quit early for non-connected clients. // If this is a known probe, we'll quit early for non-connected clients.
if !isConnected { if !isConnected {
log.Printf("paymentHash: %s, probe and not connected", reqPaymentHashStr) log.Printf("paymentHash: %s, probe and not connected", reqPaymentHashStr)
return shared.InterceptResult{ return common.InterceptResult{
Action: shared.INTERCEPT_RESUME, Action: common.INTERCEPT_RESUME,
}, nil }, nil
} }
@@ -132,9 +132,9 @@ func (i *Interceptor) Intercept(req shared.InterceptRequest) shared.InterceptRes
// know that the actual payment would probably succeed. // know that the actual payment would probably succeed.
if channelPoint == nil { if channelPoint == nil {
log.Printf("paymentHash: %s, probe and channelPoint == nil", reqPaymentHashStr) log.Printf("paymentHash: %s, probe and channelPoint == nil", reqPaymentHashStr)
return shared.InterceptResult{ return common.InterceptResult{
Action: shared.INTERCEPT_FAIL_HTLC_WITH_CODE, Action: common.INTERCEPT_FAIL_HTLC_WITH_CODE,
FailureCode: shared.FAILURE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS, FailureCode: common.FAILURE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS,
}, nil }, nil
} }
} }
@@ -150,8 +150,8 @@ func (i *Interceptor) Intercept(req shared.InterceptRequest) shared.InterceptRes
// The peer is online, we can resume the htlc if it's not a channel open. // The peer is online, we can resume the htlc if it's not a channel open.
if !isRegistered { if !isRegistered {
return shared.InterceptResult{ return common.InterceptResult{
Action: shared.INTERCEPT_RESUME, Action: common.INTERCEPT_RESUME,
}, nil }, nil
} }
@@ -160,7 +160,7 @@ func (i *Interceptor) Intercept(req shared.InterceptRequest) shared.InterceptRes
// TODO: When opening_fee_params is enforced, turn this check in a temporary channel failure. // TODO: When opening_fee_params is enforced, turn this check in a temporary channel failure.
if params == nil { if params == nil {
log.Printf("DEPRECATED: Intercepted htlc with deprecated fee mechanism. Using default fees. payment hash: %s", reqPaymentHashStr) log.Printf("DEPRECATED: Intercepted htlc with deprecated fee mechanism. Using default fees. payment hash: %s", reqPaymentHashStr)
params = &shared.OpeningFeeParams{ params = &common.OpeningFeeParams{
MinFeeMsat: uint64(i.config.ChannelMinimumFeeMsat), MinFeeMsat: uint64(i.config.ChannelMinimumFeeMsat),
Proportional: uint32(i.config.ChannelFeePermyriad * 100), Proportional: uint32(i.config.ChannelFeePermyriad * 100),
ValidUntil: time.Now().UTC().Add(time.Duration(time.Hour * 24)).Format(lsps0.TIME_FORMAT), ValidUntil: time.Now().UTC().Add(time.Duration(time.Hour * 24)).Format(lsps0.TIME_FORMAT),
@@ -172,18 +172,18 @@ func (i *Interceptor) Intercept(req shared.InterceptRequest) shared.InterceptRes
// Make sure the cltv delta is enough. // Make sure the cltv delta is enough.
if int64(req.IncomingExpiry)-int64(req.OutgoingExpiry) < int64(i.config.TimeLockDelta) { if int64(req.IncomingExpiry)-int64(req.OutgoingExpiry) < int64(i.config.TimeLockDelta) {
log.Printf("paymentHash: %s, outgoingExpiry: %v, incomingExpiry: %v, i.config.TimeLockDelta: %v", reqPaymentHashStr, req.OutgoingExpiry, req.IncomingExpiry, i.config.TimeLockDelta) log.Printf("paymentHash: %s, outgoingExpiry: %v, incomingExpiry: %v, i.config.TimeLockDelta: %v", reqPaymentHashStr, req.OutgoingExpiry, req.IncomingExpiry, i.config.TimeLockDelta)
return shared.InterceptResult{ return common.InterceptResult{
Action: shared.INTERCEPT_FAIL_HTLC_WITH_CODE, Action: common.INTERCEPT_FAIL_HTLC_WITH_CODE,
FailureCode: shared.FAILURE_TEMPORARY_CHANNEL_FAILURE, FailureCode: common.FAILURE_TEMPORARY_CHANNEL_FAILURE,
}, nil }, nil
} }
validUntil, err := time.Parse(lsps0.TIME_FORMAT, params.ValidUntil) validUntil, err := time.Parse(lsps0.TIME_FORMAT, params.ValidUntil)
if err != nil { if err != nil {
log.Printf("time.Parse(%s, %s) failed. Failing channel open: %v", lsps0.TIME_FORMAT, params.ValidUntil, err) log.Printf("time.Parse(%s, %s) failed. Failing channel open: %v", lsps0.TIME_FORMAT, params.ValidUntil, err)
return shared.InterceptResult{ return common.InterceptResult{
Action: shared.INTERCEPT_FAIL_HTLC_WITH_CODE, Action: common.INTERCEPT_FAIL_HTLC_WITH_CODE,
FailureCode: shared.FAILURE_TEMPORARY_CHANNEL_FAILURE, FailureCode: common.FAILURE_TEMPORARY_CHANNEL_FAILURE,
}, nil }, nil
} }
@@ -192,9 +192,9 @@ func (i *Interceptor) Intercept(req shared.InterceptRequest) shared.InterceptRes
if time.Now().UTC().After(validUntil) { if time.Now().UTC().After(validUntil) {
if !i.openingService.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) log.Printf("Intercepted expired payment registration. Failing payment. payment hash: %x, valid until: %s", paymentHash, params.ValidUntil)
return shared.InterceptResult{ return common.InterceptResult{
Action: shared.INTERCEPT_FAIL_HTLC_WITH_CODE, Action: common.INTERCEPT_FAIL_HTLC_WITH_CODE,
FailureCode: shared.FAILURE_TEMPORARY_CHANNEL_FAILURE, FailureCode: common.FAILURE_TEMPORARY_CHANNEL_FAILURE,
}, nil }, nil
} }
@@ -204,9 +204,9 @@ func (i *Interceptor) Intercept(req shared.InterceptRequest) shared.InterceptRes
channelPoint, err = i.openChannel(req.PaymentHash, destination, incomingAmountMsat, tag) channelPoint, err = i.openChannel(req.PaymentHash, destination, incomingAmountMsat, tag)
if err != nil { if err != nil {
log.Printf("openChannel(%x, %v) err: %v", destination, incomingAmountMsat, err) log.Printf("openChannel(%x, %v) err: %v", destination, incomingAmountMsat, err)
return shared.InterceptResult{ return common.InterceptResult{
Action: shared.INTERCEPT_FAIL_HTLC_WITH_CODE, Action: common.INTERCEPT_FAIL_HTLC_WITH_CODE,
FailureCode: shared.FAILURE_TEMPORARY_CHANNEL_FAILURE, FailureCode: common.FAILURE_TEMPORARY_CHANNEL_FAILURE,
}, nil }, nil
} }
} }
@@ -231,9 +231,9 @@ func (i *Interceptor) Intercept(req shared.InterceptRequest) shared.InterceptRes
if err != nil { if err != nil {
log.Printf("insertChannel error: %v", err) log.Printf("insertChannel error: %v", err)
return shared.InterceptResult{ return common.InterceptResult{
Action: shared.INTERCEPT_FAIL_HTLC_WITH_CODE, Action: common.INTERCEPT_FAIL_HTLC_WITH_CODE,
FailureCode: shared.FAILURE_TEMPORARY_CHANNEL_FAILURE, FailureCode: common.FAILURE_TEMPORARY_CHANNEL_FAILURE,
}, nil }, nil
} }
@@ -243,8 +243,8 @@ func (i *Interceptor) Intercept(req shared.InterceptRequest) shared.InterceptRes
} }
useLegacyOnionBlob := slices.Contains(i.config.LegacyOnionTokens, token) useLegacyOnionBlob := slices.Contains(i.config.LegacyOnionTokens, token)
return shared.InterceptResult{ return common.InterceptResult{
Action: shared.INTERCEPT_RESUME_WITH_ONION, Action: common.INTERCEPT_RESUME_WITH_ONION,
Destination: destination, Destination: destination,
ChannelPoint: channelPoint, ChannelPoint: channelPoint,
Scid: channelID, Scid: channelID,
@@ -264,16 +264,16 @@ func (i *Interceptor) Intercept(req shared.InterceptRequest) shared.InterceptRes
} }
log.Printf("Error: Channel failed to open... timed out. ") log.Printf("Error: Channel failed to open... timed out. ")
return shared.InterceptResult{ return common.InterceptResult{
Action: shared.INTERCEPT_FAIL_HTLC_WITH_CODE, Action: common.INTERCEPT_FAIL_HTLC_WITH_CODE,
FailureCode: shared.FAILURE_TEMPORARY_CHANNEL_FAILURE, FailureCode: common.FAILURE_TEMPORARY_CHANNEL_FAILURE,
}, nil }, nil
}) })
return resp.(shared.InterceptResult) return resp.(common.InterceptResult)
} }
func (i *Interceptor) notify(reqPaymentHashStr string, nextHop []byte, isRegistered bool) *shared.InterceptResult { func (i *Interceptor) notify(reqPaymentHashStr string, nextHop []byte, isRegistered bool) *common.InterceptResult {
// If not connected, send a notification to the registered // If not connected, send a notification to the registered
// notification service for this client if available. // notification service for this client if available.
notified, err := i.notificationService.Notify( notified, err := i.notificationService.Notify(
@@ -285,8 +285,8 @@ func (i *Interceptor) notify(reqPaymentHashStr string, nextHop []byte, isRegiste
// is offline or unknown. We'll resume the HTLC (which will // is offline or unknown. We'll resume the HTLC (which will
// result in UNKOWN_NEXT_PEER) // result in UNKOWN_NEXT_PEER)
if err != nil || !notified { if err != nil || !notified {
return &shared.InterceptResult{ return &common.InterceptResult{
Action: shared.INTERCEPT_RESUME, Action: common.INTERCEPT_RESUME,
} }
} }
@@ -309,8 +309,8 @@ func (i *Interceptor) notify(reqPaymentHashStr string, nextHop []byte, isRegiste
nextHop, nextHop,
err, err,
) )
return &shared.InterceptResult{ return &common.InterceptResult{
Action: shared.INTERCEPT_RESUME, Action: common.INTERCEPT_RESUME,
} }
} }
@@ -331,8 +331,8 @@ func (i *Interceptor) notify(reqPaymentHashStr string, nextHop []byte, isRegiste
nextHop, nextHop,
err, err,
) )
return &shared.InterceptResult{ return &common.InterceptResult{
Action: shared.INTERCEPT_RESUME, Action: common.INTERCEPT_RESUME,
} }
} }
} }

View File

@@ -3,13 +3,13 @@ package interceptor
import ( import (
"time" "time"
"github.com/breez/lspd/shared" "github.com/breez/lspd/common"
"github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcd/wire"
) )
type InterceptStore interface { type InterceptStore interface {
PaymentInfo(htlcPaymentHash []byte) (string, *shared.OpeningFeeParams, []byte, []byte, []byte, int64, int64, *wire.OutPoint, *string, error) PaymentInfo(htlcPaymentHash []byte) (string, *common.OpeningFeeParams, []byte, []byte, []byte, int64, int64, *wire.OutPoint, *string, error)
SetFundingTx(paymentHash []byte, channelPoint *wire.OutPoint) error SetFundingTx(paymentHash []byte, channelPoint *wire.OutPoint) error
RegisterPayment(token string, params *shared.OpeningFeeParams, destination, paymentHash, paymentSecret []byte, incomingAmountMsat, outgoingAmountMsat int64, tag string) error RegisterPayment(token string, params *common.OpeningFeeParams, destination, paymentHash, paymentSecret []byte, incomingAmountMsat, outgoingAmountMsat int64, tag string) error
InsertChannel(initialChanID, confirmedChanId uint64, channelPoint string, nodeID []byte, lastUpdate time.Time) error InsertChannel(initialChanID, confirmedChanId uint64, channelPoint string, nodeID []byte, lastUpdate time.Time) error
} }

View File

@@ -7,10 +7,10 @@ import (
"sync" "sync"
"time" "time"
"github.com/breez/lspd/common"
"github.com/breez/lspd/config" "github.com/breez/lspd/config"
"github.com/breez/lspd/interceptor" "github.com/breez/lspd/interceptor"
"github.com/breez/lspd/lightning" "github.com/breez/lspd/lightning"
"github.com/breez/lspd/shared"
"github.com/btcsuite/btcd/btcec/v2" "github.com/btcsuite/btcd/btcec/v2"
sphinx "github.com/lightningnetwork/lightning-onion" sphinx "github.com/lightningnetwork/lightning-onion"
"github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc"
@@ -137,7 +137,7 @@ func (i *LndHtlcInterceptor) intercept() error {
i.doneWg.Add(1) i.doneWg.Add(1)
go func() { go func() {
scid := lightning.ShortChannelID(request.OutgoingRequestedChanId) scid := lightning.ShortChannelID(request.OutgoingRequestedChanId)
interceptResult := i.interceptor.Intercept(shared.InterceptRequest{ interceptResult := i.interceptor.Intercept(common.InterceptRequest{
Identifier: request.IncomingCircuitKey.String(), Identifier: request.IncomingCircuitKey.String(),
Scid: scid, Scid: scid,
PaymentHash: request.PaymentHash, PaymentHash: request.PaymentHash,
@@ -147,15 +147,15 @@ func (i *LndHtlcInterceptor) intercept() error {
OutgoingExpiry: request.OutgoingExpiry, OutgoingExpiry: request.OutgoingExpiry,
}) })
switch interceptResult.Action { switch interceptResult.Action {
case shared.INTERCEPT_RESUME_WITH_ONION: case common.INTERCEPT_RESUME_WITH_ONION:
interceptorClient.Send(i.createOnionResponse(interceptResult, request)) interceptorClient.Send(i.createOnionResponse(interceptResult, request))
case shared.INTERCEPT_FAIL_HTLC_WITH_CODE: case common.INTERCEPT_FAIL_HTLC_WITH_CODE:
interceptorClient.Send(&routerrpc.ForwardHtlcInterceptResponse{ interceptorClient.Send(&routerrpc.ForwardHtlcInterceptResponse{
IncomingCircuitKey: request.IncomingCircuitKey, IncomingCircuitKey: request.IncomingCircuitKey,
Action: routerrpc.ResolveHoldForwardAction_FAIL, Action: routerrpc.ResolveHoldForwardAction_FAIL,
FailureCode: i.mapFailureCode(interceptResult.FailureCode), FailureCode: i.mapFailureCode(interceptResult.FailureCode),
}) })
case shared.INTERCEPT_RESUME: case common.INTERCEPT_RESUME:
fallthrough fallthrough
default: default:
interceptorClient.Send(&routerrpc.ForwardHtlcInterceptResponse{ interceptorClient.Send(&routerrpc.ForwardHtlcInterceptResponse{
@@ -175,13 +175,13 @@ func (i *LndHtlcInterceptor) intercept() error {
} }
} }
func (i *LndHtlcInterceptor) mapFailureCode(original shared.InterceptFailureCode) lnrpc.Failure_FailureCode { func (i *LndHtlcInterceptor) mapFailureCode(original common.InterceptFailureCode) lnrpc.Failure_FailureCode {
switch original { switch original {
case shared.FAILURE_TEMPORARY_CHANNEL_FAILURE: case common.FAILURE_TEMPORARY_CHANNEL_FAILURE:
return lnrpc.Failure_TEMPORARY_CHANNEL_FAILURE return lnrpc.Failure_TEMPORARY_CHANNEL_FAILURE
case shared.FAILURE_TEMPORARY_NODE_FAILURE: case common.FAILURE_TEMPORARY_NODE_FAILURE:
return lnrpc.Failure_TEMPORARY_NODE_FAILURE return lnrpc.Failure_TEMPORARY_NODE_FAILURE
case shared.FAILURE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS: case common.FAILURE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS:
return lnrpc.Failure_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS return lnrpc.Failure_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS
default: default:
log.Printf("Unknown failure code %v, default to temporary channel failure.", original) log.Printf("Unknown failure code %v, default to temporary channel failure.", original)
@@ -190,7 +190,7 @@ func (i *LndHtlcInterceptor) mapFailureCode(original shared.InterceptFailureCode
} }
func (i *LndHtlcInterceptor) constructOnion( func (i *LndHtlcInterceptor) constructOnion(
interceptResult shared.InterceptResult, interceptResult common.InterceptResult,
reqOutgoingExpiry uint32, reqOutgoingExpiry uint32,
reqPaymentHash []byte, reqPaymentHash []byte,
) ([]byte, error) { ) ([]byte, error) {
@@ -251,7 +251,7 @@ func (i *LndHtlcInterceptor) constructOnion(
return onionBlob.Bytes(), nil return onionBlob.Bytes(), nil
} }
func (i *LndHtlcInterceptor) createOnionResponse(interceptResult shared.InterceptResult, request *routerrpc.ForwardHtlcInterceptRequest) *routerrpc.ForwardHtlcInterceptResponse { func (i *LndHtlcInterceptor) createOnionResponse(interceptResult common.InterceptResult, request *routerrpc.ForwardHtlcInterceptRequest) *routerrpc.ForwardHtlcInterceptResponse {
onionBlob := request.OnionBlob onionBlob := request.OnionBlob
if interceptResult.UseLegacyOnionBlob { if interceptResult.UseLegacyOnionBlob {

View File

@@ -10,9 +10,9 @@ import (
"time" "time"
"github.com/breez/lspd/chain" "github.com/breez/lspd/chain"
"github.com/breez/lspd/common"
"github.com/breez/lspd/lightning" "github.com/breez/lspd/lightning"
"github.com/breez/lspd/lsps0" "github.com/breez/lspd/lsps0"
"github.com/breez/lspd/shared"
"github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcd/wire"
) )
@@ -30,7 +30,7 @@ type InterceptorConfig struct {
type Interceptor struct { type Interceptor struct {
store Lsps2Store store Lsps2Store
openingService shared.OpeningService openingService common.OpeningService
client lightning.Client client lightning.Client
feeEstimator chain.FeeEstimator feeEstimator chain.FeeEstimator
config *InterceptorConfig config *InterceptorConfig
@@ -44,7 +44,7 @@ type Interceptor struct {
func NewInterceptHandler( func NewInterceptHandler(
store Lsps2Store, store Lsps2Store,
openingService shared.OpeningService, openingService common.OpeningService,
client lightning.Client, client lightning.Client,
feeEstimator chain.FeeEstimator, feeEstimator chain.FeeEstimator,
config *InterceptorConfig, config *InterceptorConfig,
@@ -92,8 +92,8 @@ func (p *paymentState) closeTimeoutChan() {
} }
type partState struct { type partState struct {
req *shared.InterceptRequest req *common.InterceptRequest
resolution chan *shared.InterceptResult resolution chan *common.InterceptResult
} }
type registrationFetchedEvent struct { type registrationFetchedEvent struct {
@@ -111,7 +111,7 @@ type paymentChanOpenedEvent struct {
type paymentFailureEvent struct { type paymentFailureEvent struct {
paymentId string paymentId string
code shared.InterceptFailureCode code common.InterceptFailureCode
} }
func (i *Interceptor) Start(ctx context.Context) { func (i *Interceptor) Start(ctx context.Context) {
@@ -168,8 +168,8 @@ func (i *Interceptor) handleNewPart(part *partState) {
// able to reply to that htlc anyway. Keep the last replayed version for // able to reply to that htlc anyway. Keep the last replayed version for
// further processing. This result below tells the caller to ignore the // further processing. This result below tells the caller to ignore the
// htlc. // htlc.
existingPart.resolution <- &shared.InterceptResult{ existingPart.resolution <- &common.InterceptResult{
Action: shared.INTERCEPT_IGNORE, Action: common.INTERCEPT_IGNORE,
} }
return return
@@ -186,7 +186,7 @@ func (i *Interceptor) handleNewPart(part *partState) {
// a goroutine. // a goroutine.
i.paymentFailure <- &paymentFailureEvent{ i.paymentFailure <- &paymentFailureEvent{
paymentId: paymentId, paymentId: paymentId,
code: shared.FAILURE_TEMPORARY_CHANNEL_FAILURE, code: common.FAILURE_TEMPORARY_CHANNEL_FAILURE,
} }
case <-payment.timeoutChan: case <-payment.timeoutChan:
// Stop listening for timeouts when the payment is ready. // Stop listening for timeouts when the payment is ready.
@@ -208,14 +208,14 @@ func (i *Interceptor) handleNewPart(part *partState) {
func (i *Interceptor) processPart(payment *paymentState, part *partState) { func (i *Interceptor) processPart(payment *paymentState, part *partState) {
if payment.registration.IsComplete { if payment.registration.IsComplete {
i.failPart(payment, part, shared.FAILURE_UNKNOWN_NEXT_PEER) i.failPart(payment, part, common.FAILURE_UNKNOWN_NEXT_PEER)
return return
} }
// Fail parts that come in after the payment is already final. To avoid // Fail parts that come in after the payment is already final. To avoid
// inconsistencies in the payment state. // inconsistencies in the payment state.
if payment.isFinal { if payment.isFinal {
i.failPart(payment, part, shared.FAILURE_UNKNOWN_NEXT_PEER) i.failPart(payment, part, common.FAILURE_UNKNOWN_NEXT_PEER)
return return
} }
@@ -226,7 +226,7 @@ func (i *Interceptor) processPart(payment *paymentState, part *partState) {
// Another part is already processed for this payment, and with // Another part is already processed for this payment, and with
// no-MPP+var-invoice there can be only a single part, so this // no-MPP+var-invoice there can be only a single part, so this
// part will be failed back. // part will be failed back.
i.failPart(payment, part, shared.FAILURE_UNKNOWN_NEXT_PEER) i.failPart(payment, part, common.FAILURE_UNKNOWN_NEXT_PEER)
return return
} }
@@ -237,7 +237,7 @@ func (i *Interceptor) processPart(payment *paymentState, part *partState) {
// Make sure the minimum and maximum are not exceeded. // Make sure the minimum and maximum are not exceeded.
if payment.paymentSizeMsat > i.config.MaxPaymentSizeMsat || if payment.paymentSizeMsat > i.config.MaxPaymentSizeMsat ||
payment.paymentSizeMsat < i.config.MinPaymentSizeMsat { payment.paymentSizeMsat < i.config.MinPaymentSizeMsat {
i.failPart(payment, part, shared.FAILURE_UNKNOWN_NEXT_PEER) i.failPart(payment, part, common.FAILURE_UNKNOWN_NEXT_PEER)
return return
} }
@@ -248,14 +248,14 @@ func (i *Interceptor) processPart(payment *paymentState, part *partState) {
payment.registration.OpeningFeeParams.MinFeeMsat, payment.registration.OpeningFeeParams.MinFeeMsat,
) )
if err != nil { if err != nil {
i.failPart(payment, part, shared.FAILURE_UNKNOWN_NEXT_PEER) i.failPart(payment, part, common.FAILURE_UNKNOWN_NEXT_PEER)
return return
} }
// Make sure the part fits the htlc and fee constraints. // Make sure the part fits the htlc and fee constraints.
if payment.feeMsat+i.config.HtlcMinimumMsat > if payment.feeMsat+i.config.HtlcMinimumMsat >
payment.paymentSizeMsat { payment.paymentSizeMsat {
i.failPart(payment, part, shared.FAILURE_UNKNOWN_NEXT_PEER) i.failPart(payment, part, common.FAILURE_UNKNOWN_NEXT_PEER)
return return
} }
} else { } else {
@@ -273,7 +273,7 @@ func (i *Interceptor) processPart(payment *paymentState, part *partState) {
payment.registration.Scid.ToString(), payment.registration.Scid.ToString(),
err, err,
) )
i.failPart(payment, part, shared.FAILURE_UNKNOWN_NEXT_PEER) i.failPart(payment, part, common.FAILURE_UNKNOWN_NEXT_PEER)
return return
} }
} }
@@ -281,19 +281,19 @@ func (i *Interceptor) processPart(payment *paymentState, part *partState) {
// Make sure the cltv delta is enough (actual cltv delta + 2). // Make sure the cltv delta is enough (actual cltv delta + 2).
if int64(part.req.IncomingExpiry)-int64(part.req.OutgoingExpiry) < if int64(part.req.IncomingExpiry)-int64(part.req.OutgoingExpiry) <
int64(i.config.TimeLockDelta)+2 { int64(i.config.TimeLockDelta)+2 {
i.failPart(payment, part, shared.FAILURE_INCORRECT_CLTV_EXPIRY) i.failPart(payment, part, common.FAILURE_INCORRECT_CLTV_EXPIRY)
return return
} }
// Make sure htlc minimum is enough // Make sure htlc minimum is enough
if part.req.OutgoingAmountMsat < i.config.HtlcMinimumMsat { if part.req.OutgoingAmountMsat < i.config.HtlcMinimumMsat {
i.failPart(payment, part, shared.FAILURE_AMOUNT_BELOW_MINIMUM) i.failPart(payment, part, common.FAILURE_AMOUNT_BELOW_MINIMUM)
return return
} }
// Make sure we're not getting tricked // Make sure we're not getting tricked
if part.req.IncomingAmountMsat < part.req.OutgoingAmountMsat { if part.req.IncomingAmountMsat < part.req.OutgoingAmountMsat {
i.failPart(payment, part, shared.FAILURE_AMOUNT_BELOW_MINIMUM) i.failPart(payment, part, common.FAILURE_AMOUNT_BELOW_MINIMUM)
return return
} }
@@ -336,8 +336,8 @@ func (i *Interceptor) fetchRegistration(
func (i *Interceptor) handleRegistrationFetched(ev *registrationFetchedEvent) { func (i *Interceptor) handleRegistrationFetched(ev *registrationFetchedEvent) {
if !ev.isRegistered { if !ev.isRegistered {
i.finalizeAllParts(ev.paymentId, &shared.InterceptResult{ i.finalizeAllParts(ev.paymentId, &common.InterceptResult{
Action: shared.INTERCEPT_RESUME, Action: common.INTERCEPT_RESUME,
}) })
return return
} }
@@ -389,7 +389,7 @@ func (i *Interceptor) ensureChannelOpen(payment *paymentState) {
) )
i.paymentFailure <- &paymentFailureEvent{ i.paymentFailure <- &paymentFailureEvent{
paymentId: payment.id, paymentId: payment.id,
code: shared.FAILURE_UNKNOWN_NEXT_PEER, code: common.FAILURE_UNKNOWN_NEXT_PEER,
} }
return return
} }
@@ -409,7 +409,7 @@ func (i *Interceptor) ensureChannelOpen(payment *paymentState) {
) )
i.paymentFailure <- &paymentFailureEvent{ i.paymentFailure <- &paymentFailureEvent{
paymentId: payment.id, paymentId: payment.id,
code: shared.FAILURE_UNKNOWN_NEXT_PEER, code: common.FAILURE_UNKNOWN_NEXT_PEER,
} }
return return
} }
@@ -463,9 +463,9 @@ func (i *Interceptor) ensureChannelOpen(payment *paymentState) {
err, err,
) )
code := shared.FAILURE_UNKNOWN_NEXT_PEER code := common.FAILURE_UNKNOWN_NEXT_PEER
if strings.Contains(err.Error(), "not enough funds") { if strings.Contains(err.Error(), "not enough funds") {
code = shared.FAILURE_TEMPORARY_CHANNEL_FAILURE code = common.FAILURE_TEMPORARY_CHANNEL_FAILURE
} }
// TODO: Verify that a client disconnect before receiving // TODO: Verify that a client disconnect before receiving
@@ -499,7 +499,7 @@ func (i *Interceptor) ensureChannelOpen(payment *paymentState) {
) )
i.paymentFailure <- &paymentFailureEvent{ i.paymentFailure <- &paymentFailureEvent{
paymentId: payment.id, paymentId: payment.id,
code: shared.FAILURE_TEMPORARY_CHANNEL_FAILURE, code: common.FAILURE_TEMPORARY_CHANNEL_FAILURE,
} }
return return
} }
@@ -521,7 +521,7 @@ func (i *Interceptor) ensureChannelOpen(payment *paymentState) {
case <-time.After(time.Until(deadline)): case <-time.After(time.Until(deadline)):
i.paymentFailure <- &paymentFailureEvent{ i.paymentFailure <- &paymentFailureEvent{
paymentId: payment.id, paymentId: payment.id,
code: shared.FAILURE_TEMPORARY_CHANNEL_FAILURE, code: common.FAILURE_TEMPORARY_CHANNEL_FAILURE,
} }
return return
} }
@@ -560,7 +560,7 @@ func (i *Interceptor) handlePaymentChanOpened(event *paymentChanOpenedEvent) {
// Deduct the lsp fee from the parts to forward. // Deduct the lsp fee from the parts to forward.
resolutions := []*struct { resolutions := []*struct {
part *partState part *partState
resolution *shared.InterceptResult resolution *common.InterceptResult
}{} }{}
for _, part := range payment.parts { for _, part := range payment.parts {
deductMsat := uint64(math.Min( deductMsat := uint64(math.Min(
@@ -575,11 +575,11 @@ func (i *Interceptor) handlePaymentChanOpened(event *paymentChanOpenedEvent) {
} }
resolutions = append(resolutions, &struct { resolutions = append(resolutions, &struct {
part *partState part *partState
resolution *shared.InterceptResult resolution *common.InterceptResult
}{ }{
part: part, part: part,
resolution: &shared.InterceptResult{ resolution: &common.InterceptResult{
Action: shared.INTERCEPT_RESUME_WITH_ONION, Action: common.INTERCEPT_RESUME_WITH_ONION,
Destination: destination, Destination: destination,
ChannelPoint: event.channelPoint, ChannelPoint: event.channelPoint,
AmountMsat: amountMsat, AmountMsat: amountMsat,
@@ -604,7 +604,7 @@ func (i *Interceptor) handlePaymentChanOpened(event *paymentChanOpenedEvent) {
// unknown_next_peer is more appropriate. // unknown_next_peer is more appropriate.
i.paymentFailure <- &paymentFailureEvent{ i.paymentFailure <- &paymentFailureEvent{
paymentId: event.paymentId, paymentId: event.paymentId,
code: shared.FAILURE_TEMPORARY_CHANNEL_FAILURE, code: common.FAILURE_TEMPORARY_CHANNEL_FAILURE,
} }
return return
} }
@@ -620,17 +620,17 @@ func (i *Interceptor) handlePaymentChanOpened(event *paymentChanOpenedEvent) {
func (i *Interceptor) handlePaymentFailure( func (i *Interceptor) handlePaymentFailure(
paymentId string, paymentId string,
code shared.InterceptFailureCode, code common.InterceptFailureCode,
) { ) {
i.finalizeAllParts(paymentId, &shared.InterceptResult{ i.finalizeAllParts(paymentId, &common.InterceptResult{
Action: shared.INTERCEPT_FAIL_HTLC_WITH_CODE, Action: common.INTERCEPT_FAIL_HTLC_WITH_CODE,
FailureCode: code, FailureCode: code,
}) })
} }
func (i *Interceptor) finalizeAllParts( func (i *Interceptor) finalizeAllParts(
paymentId string, paymentId string,
result *shared.InterceptResult, result *common.InterceptResult,
) { ) {
payment, ok := i.inflightPayments[paymentId] payment, ok := i.inflightPayments[paymentId]
if !ok { if !ok {
@@ -647,8 +647,8 @@ func (i *Interceptor) finalizeAllParts(
delete(i.inflightPayments, paymentId) delete(i.inflightPayments, paymentId)
} }
func (i *Interceptor) Intercept(req shared.InterceptRequest) shared.InterceptResult { func (i *Interceptor) Intercept(req common.InterceptRequest) common.InterceptResult {
resolution := make(chan *shared.InterceptResult, 1) resolution := make(chan *common.InterceptResult, 1)
i.newPart <- &partState{ i.newPart <- &partState{
req: &req, req: &req,
resolution: resolution, resolution: resolution,
@@ -660,10 +660,10 @@ func (i *Interceptor) Intercept(req shared.InterceptRequest) shared.InterceptRes
func (i *Interceptor) failPart( func (i *Interceptor) failPart(
payment *paymentState, payment *paymentState,
part *partState, part *partState,
code shared.InterceptFailureCode, code common.InterceptFailureCode,
) { ) {
part.resolution <- &shared.InterceptResult{ part.resolution <- &common.InterceptResult{
Action: shared.INTERCEPT_FAIL_HTLC_WITH_CODE, Action: common.INTERCEPT_FAIL_HTLC_WITH_CODE,
FailureCode: code, FailureCode: code,
} }
delete(payment.parts, part.req.HtlcId()) delete(payment.parts, part.req.HtlcId())

View File

@@ -11,9 +11,9 @@ import (
"time" "time"
"github.com/breez/lspd/chain" "github.com/breez/lspd/chain"
"github.com/breez/lspd/common"
"github.com/breez/lspd/lightning" "github.com/breez/lspd/lightning"
"github.com/breez/lspd/lsps0" "github.com/breez/lspd/lsps0"
"github.com/breez/lspd/shared"
"github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcd/wire"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@@ -36,8 +36,8 @@ var defaultChanResult = &lightning.GetChannelResult{
ConfirmedChannelID: lightning.ShortChannelID(defaultChannelScid), ConfirmedChannelID: lightning.ShortChannelID(defaultChannelScid),
} }
func defaultOpeningFeeParams() shared.OpeningFeeParams { func defaultOpeningFeeParams() common.OpeningFeeParams {
return shared.OpeningFeeParams{ return common.OpeningFeeParams{
MinFeeMsat: 1000, MinFeeMsat: 1000,
Proportional: 1000, Proportional: 1000,
ValidUntil: time.Now().UTC().Add(5 * time.Hour).Format(lsps0.TIME_FORMAT), ValidUntil: time.Now().UTC().Add(5 * time.Hour).Format(lsps0.TIME_FORMAT),
@@ -163,7 +163,7 @@ type part struct {
cltvDelta uint32 cltvDelta uint32
} }
func createPart(p *part) shared.InterceptRequest { func createPart(p *part) common.InterceptRequest {
id := "first" id := "first"
if p != nil && p.id != "" { if p != nil && p.id != "" {
id = p.id id = p.id
@@ -189,7 +189,7 @@ func createPart(p *part) shared.InterceptRequest {
cltv = p.cltvDelta cltv = p.cltvDelta
} }
return shared.InterceptRequest{ return common.InterceptRequest{
Identifier: id, Identifier: id,
Scid: scid, Scid: scid,
PaymentHash: ph, PaymentHash: ph,
@@ -200,7 +200,7 @@ func createPart(p *part) shared.InterceptRequest {
} }
} }
func runIntercept(i *Interceptor, req shared.InterceptRequest, res *shared.InterceptResult, wg *sync.WaitGroup) { func runIntercept(i *Interceptor, req common.InterceptRequest, res *common.InterceptResult, wg *sync.WaitGroup) {
go func() { go func() {
*res = i.Intercept(req) *res = i.Intercept(req)
wg.Done() wg.Done()
@@ -224,7 +224,7 @@ func Test_NotBought_SinglePart(t *testing.T) {
defer cancel() defer cancel()
i := setupInterceptor(ctx, nil) i := setupInterceptor(ctx, nil)
res := i.Intercept(createPart(&part{scid: 999})) res := i.Intercept(createPart(&part{scid: 999}))
assert.Equal(t, shared.INTERCEPT_RESUME, res.Action) assert.Equal(t, common.INTERCEPT_RESUME, res.Action)
assertEmpty(t, i) assertEmpty(t, i)
} }
@@ -235,14 +235,14 @@ func Test_NotBought_TwoParts(t *testing.T) {
var wg sync.WaitGroup var wg sync.WaitGroup
wg.Add(2) wg.Add(2)
var res1 shared.InterceptResult var res1 common.InterceptResult
runIntercept(i, createPart(&part{id: "first", scid: 999}), &res1, &wg) runIntercept(i, createPart(&part{id: "first", scid: 999}), &res1, &wg)
var res2 shared.InterceptResult var res2 common.InterceptResult
runIntercept(i, createPart(&part{id: "second", scid: 999}), &res2, &wg) runIntercept(i, createPart(&part{id: "second", scid: 999}), &res2, &wg)
wg.Wait() wg.Wait()
assert.Equal(t, shared.INTERCEPT_RESUME, res1.Action) assert.Equal(t, common.INTERCEPT_RESUME, res1.Action)
assert.Equal(t, shared.INTERCEPT_RESUME, res2.Action) assert.Equal(t, common.INTERCEPT_RESUME, res2.Action)
assertEmpty(t, i) assertEmpty(t, i)
} }
@@ -253,7 +253,7 @@ func Test_NoMpp_Happyflow(t *testing.T) {
i := setupInterceptor(ctx, nil) i := setupInterceptor(ctx, nil)
res := i.Intercept(createPart(nil)) res := i.Intercept(createPart(nil))
assert.Equal(t, shared.INTERCEPT_RESUME_WITH_ONION, res.Action) assert.Equal(t, common.INTERCEPT_RESUME_WITH_ONION, res.Action)
assert.Equal(t, defaultPaymentSizeMsat-defaultFee, res.AmountMsat) assert.Equal(t, defaultPaymentSizeMsat-defaultFee, res.AmountMsat)
assert.Equal(t, defaultFee, *res.FeeMsat) assert.Equal(t, defaultFee, *res.FeeMsat)
assert.Equal(t, defaultChannelScid, uint64(res.Scid)) assert.Equal(t, defaultChannelScid, uint64(res.Scid))
@@ -268,7 +268,7 @@ func Test_NoMpp_AmountMinFeePlusHtlcMinPlusOne(t *testing.T) {
i := setupInterceptor(ctx, nil) i := setupInterceptor(ctx, nil)
res := i.Intercept(createPart(&part{amt: defaultMinViableAmount})) res := i.Intercept(createPart(&part{amt: defaultMinViableAmount}))
assert.Equal(t, shared.INTERCEPT_RESUME_WITH_ONION, res.Action) assert.Equal(t, common.INTERCEPT_RESUME_WITH_ONION, res.Action)
assert.Equal(t, defaultConfig().HtlcMinimumMsat, res.AmountMsat) assert.Equal(t, defaultConfig().HtlcMinimumMsat, res.AmountMsat)
assert.Equal(t, defaultOpeningFeeParams().MinFeeMsat, *res.FeeMsat) assert.Equal(t, defaultOpeningFeeParams().MinFeeMsat, *res.FeeMsat)
assert.Equal(t, defaultChannelScid, uint64(res.Scid)) assert.Equal(t, defaultChannelScid, uint64(res.Scid))
@@ -283,8 +283,8 @@ func Test_NoMpp_AmtBelowMinimum(t *testing.T) {
i := setupInterceptor(ctx, nil) i := setupInterceptor(ctx, nil)
res := i.Intercept(createPart(&part{amt: defaultMinViableAmount - 1})) res := i.Intercept(createPart(&part{amt: defaultMinViableAmount - 1}))
assert.Equal(t, shared.INTERCEPT_FAIL_HTLC_WITH_CODE, res.Action) assert.Equal(t, common.INTERCEPT_FAIL_HTLC_WITH_CODE, res.Action)
assert.Equal(t, shared.FAILURE_UNKNOWN_NEXT_PEER, res.FailureCode) assert.Equal(t, common.FAILURE_UNKNOWN_NEXT_PEER, res.FailureCode)
assertEmpty(t, i) assertEmpty(t, i)
} }
@@ -296,7 +296,7 @@ func Test_NoMpp_AmtAtMaximum(t *testing.T) {
i := setupInterceptor(ctx, nil) i := setupInterceptor(ctx, nil)
res := i.Intercept(createPart(&part{amt: defaultConfig().MaxPaymentSizeMsat})) res := i.Intercept(createPart(&part{amt: defaultConfig().MaxPaymentSizeMsat}))
assert.Equal(t, shared.INTERCEPT_RESUME_WITH_ONION, res.Action) assert.Equal(t, common.INTERCEPT_RESUME_WITH_ONION, res.Action)
assertEmpty(t, i) assertEmpty(t, i)
} }
@@ -308,8 +308,8 @@ func Test_NoMpp_AmtAboveMaximum(t *testing.T) {
i := setupInterceptor(ctx, nil) i := setupInterceptor(ctx, nil)
res := i.Intercept(createPart(&part{amt: defaultConfig().MaxPaymentSizeMsat + 1})) res := i.Intercept(createPart(&part{amt: defaultConfig().MaxPaymentSizeMsat + 1}))
assert.Equal(t, shared.INTERCEPT_FAIL_HTLC_WITH_CODE, res.Action) assert.Equal(t, common.INTERCEPT_FAIL_HTLC_WITH_CODE, res.Action)
assert.Equal(t, shared.FAILURE_UNKNOWN_NEXT_PEER, res.FailureCode) assert.Equal(t, common.FAILURE_UNKNOWN_NEXT_PEER, res.FailureCode)
assertEmpty(t, i) assertEmpty(t, i)
} }
@@ -321,8 +321,8 @@ func Test_NoMpp_CltvDeltaBelowMinimum(t *testing.T) {
i := setupInterceptor(ctx, nil) i := setupInterceptor(ctx, nil)
res := i.Intercept(createPart(&part{cltvDelta: 145})) res := i.Intercept(createPart(&part{cltvDelta: 145}))
assert.Equal(t, shared.INTERCEPT_FAIL_HTLC_WITH_CODE, res.Action) assert.Equal(t, common.INTERCEPT_FAIL_HTLC_WITH_CODE, res.Action)
assert.Equal(t, shared.FAILURE_INCORRECT_CLTV_EXPIRY, res.FailureCode) assert.Equal(t, common.FAILURE_INCORRECT_CLTV_EXPIRY, res.FailureCode)
assertEmpty(t, i) assertEmpty(t, i)
} }
@@ -334,7 +334,7 @@ func Test_NoMpp_HigherCltvDelta(t *testing.T) {
i := setupInterceptor(ctx, nil) i := setupInterceptor(ctx, nil)
res := i.Intercept(createPart(&part{cltvDelta: 1000})) res := i.Intercept(createPart(&part{cltvDelta: 1000}))
assert.Equal(t, shared.INTERCEPT_RESUME_WITH_ONION, res.Action) assert.Equal(t, common.INTERCEPT_RESUME_WITH_ONION, res.Action)
assertEmpty(t, i) assertEmpty(t, i)
} }
@@ -349,8 +349,8 @@ func Test_NoMpp_ParamsExpired(t *testing.T) {
i := setupInterceptor(ctx, &interceptP{store: store}) i := setupInterceptor(ctx, &interceptP{store: store})
res := i.Intercept(createPart(nil)) res := i.Intercept(createPart(nil))
assert.Equal(t, shared.INTERCEPT_FAIL_HTLC_WITH_CODE, res.Action) assert.Equal(t, common.INTERCEPT_FAIL_HTLC_WITH_CODE, res.Action)
assert.Equal(t, shared.FAILURE_UNKNOWN_NEXT_PEER, res.FailureCode) assert.Equal(t, common.FAILURE_UNKNOWN_NEXT_PEER, res.FailureCode)
assertEmpty(t, i) assertEmpty(t, i)
} }
@@ -362,7 +362,7 @@ func Test_NoMpp_ChannelAlreadyOpened_NotComplete_Forwards(t *testing.T) {
i := setupInterceptor(ctx, &interceptP{store: store}) i := setupInterceptor(ctx, &interceptP{store: store})
res := i.Intercept(createPart(nil)) res := i.Intercept(createPart(nil))
assert.Equal(t, shared.INTERCEPT_RESUME_WITH_ONION, res.Action) assert.Equal(t, common.INTERCEPT_RESUME_WITH_ONION, res.Action)
assertEmpty(t, i) assertEmpty(t, i)
} }
@@ -375,8 +375,8 @@ func Test_NoMpp_ChannelAlreadyOpened_Complete_Fails(t *testing.T) {
i := setupInterceptor(ctx, &interceptP{store: store}) i := setupInterceptor(ctx, &interceptP{store: store})
res := i.Intercept(createPart(nil)) res := i.Intercept(createPart(nil))
assert.Equal(t, shared.INTERCEPT_FAIL_HTLC_WITH_CODE, res.Action) assert.Equal(t, common.INTERCEPT_FAIL_HTLC_WITH_CODE, res.Action)
assert.Equal(t, shared.FAILURE_UNKNOWN_NEXT_PEER, res.FailureCode) assert.Equal(t, common.FAILURE_UNKNOWN_NEXT_PEER, res.FailureCode)
assertEmpty(t, i) assertEmpty(t, i)
} }
@@ -388,7 +388,7 @@ func Test_Mpp_SinglePart_Happyflow(t *testing.T) {
i := setupInterceptor(ctx, &interceptP{store: mppStore()}) i := setupInterceptor(ctx, &interceptP{store: mppStore()})
res := i.Intercept(createPart(&part{amt: defaultPaymentSizeMsat})) res := i.Intercept(createPart(&part{amt: defaultPaymentSizeMsat}))
assert.Equal(t, shared.INTERCEPT_RESUME_WITH_ONION, res.Action) assert.Equal(t, common.INTERCEPT_RESUME_WITH_ONION, res.Action)
assert.Equal(t, defaultPaymentSizeMsat-defaultFee, res.AmountMsat) assert.Equal(t, defaultPaymentSizeMsat-defaultFee, res.AmountMsat)
assert.Equal(t, defaultFee, *res.FeeMsat) assert.Equal(t, defaultFee, *res.FeeMsat)
assert.Equal(t, defaultChannelScid, uint64(res.Scid)) assert.Equal(t, defaultChannelScid, uint64(res.Scid))
@@ -407,8 +407,8 @@ func Test_Mpp_SinglePart_AmtTooSmall(t *testing.T) {
start := time.Now() start := time.Now()
res := i.Intercept(createPart(&part{amt: defaultPaymentSizeMsat - 1})) res := i.Intercept(createPart(&part{amt: defaultPaymentSizeMsat - 1}))
end := time.Now() end := time.Now()
assert.Equal(t, shared.INTERCEPT_FAIL_HTLC_WITH_CODE, res.Action) assert.Equal(t, common.INTERCEPT_FAIL_HTLC_WITH_CODE, res.Action)
assert.Equal(t, shared.FAILURE_TEMPORARY_CHANNEL_FAILURE, res.FailureCode) assert.Equal(t, common.FAILURE_TEMPORARY_CHANNEL_FAILURE, res.FailureCode)
assert.GreaterOrEqual(t, end.Sub(start).Milliseconds(), config.MppTimeout.Milliseconds()) assert.GreaterOrEqual(t, end.Sub(start).Milliseconds(), config.MppTimeout.Milliseconds())
assertEmpty(t, i) assertEmpty(t, i)
} }
@@ -425,8 +425,8 @@ func Test_Mpp_TwoParts_FinalizedOnSecond(t *testing.T) {
var wg sync.WaitGroup var wg sync.WaitGroup
wg.Add(2) wg.Add(2)
var res1 shared.InterceptResult var res1 common.InterceptResult
var res2 shared.InterceptResult var res2 common.InterceptResult
var t1 time.Time var t1 time.Time
var t2 time.Time var t2 time.Time
start := time.Now() start := time.Now()
@@ -451,11 +451,11 @@ func Test_Mpp_TwoParts_FinalizedOnSecond(t *testing.T) {
}() }()
wg.Wait() wg.Wait()
assert.Equal(t, shared.INTERCEPT_RESUME_WITH_ONION, res1.Action) assert.Equal(t, common.INTERCEPT_RESUME_WITH_ONION, res1.Action)
assert.Equal(t, defaultPaymentSizeMsat-defaultConfig().HtlcMinimumMsat-defaultFee, res1.AmountMsat) assert.Equal(t, defaultPaymentSizeMsat-defaultConfig().HtlcMinimumMsat-defaultFee, res1.AmountMsat)
assert.Equal(t, defaultFee, *res1.FeeMsat) assert.Equal(t, defaultFee, *res1.FeeMsat)
assert.Equal(t, shared.INTERCEPT_RESUME_WITH_ONION, res2.Action) assert.Equal(t, common.INTERCEPT_RESUME_WITH_ONION, res2.Action)
assert.Equal(t, defaultConfig().HtlcMinimumMsat, res2.AmountMsat) assert.Equal(t, defaultConfig().HtlcMinimumMsat, res2.AmountMsat)
assert.Nil(t, res2.FeeMsat) assert.Nil(t, res2.FeeMsat)
@@ -480,9 +480,9 @@ func Test_Mpp_BadSecondPart_ThirdPartCompletes(t *testing.T) {
var wg sync.WaitGroup var wg sync.WaitGroup
wg.Add(2) wg.Add(2)
var res1 shared.InterceptResult var res1 common.InterceptResult
var res2 shared.InterceptResult var res2 common.InterceptResult
var res3 shared.InterceptResult var res3 common.InterceptResult
var t1 time.Time var t1 time.Time
var t2 time.Time var t2 time.Time
var t3 time.Time var t3 time.Time
@@ -514,14 +514,14 @@ func Test_Mpp_BadSecondPart_ThirdPartCompletes(t *testing.T) {
}() }()
wg.Wait() wg.Wait()
assert.Equal(t, shared.INTERCEPT_RESUME_WITH_ONION, res1.Action) assert.Equal(t, common.INTERCEPT_RESUME_WITH_ONION, res1.Action)
assert.Equal(t, defaultPaymentSizeMsat-defaultConfig().HtlcMinimumMsat-defaultFee, res1.AmountMsat) assert.Equal(t, defaultPaymentSizeMsat-defaultConfig().HtlcMinimumMsat-defaultFee, res1.AmountMsat)
assert.Equal(t, defaultFee, *res1.FeeMsat) assert.Equal(t, defaultFee, *res1.FeeMsat)
assert.Equal(t, shared.INTERCEPT_FAIL_HTLC_WITH_CODE, res2.Action) assert.Equal(t, common.INTERCEPT_FAIL_HTLC_WITH_CODE, res2.Action)
assert.Equal(t, shared.FAILURE_AMOUNT_BELOW_MINIMUM, res2.FailureCode) assert.Equal(t, common.FAILURE_AMOUNT_BELOW_MINIMUM, res2.FailureCode)
assert.Equal(t, shared.INTERCEPT_RESUME_WITH_ONION, res3.Action) assert.Equal(t, common.INTERCEPT_RESUME_WITH_ONION, res3.Action)
assert.Equal(t, defaultConfig().HtlcMinimumMsat, res3.AmountMsat) assert.Equal(t, defaultConfig().HtlcMinimumMsat, res3.AmountMsat)
assert.Nil(t, res3.FeeMsat) assert.Nil(t, res3.FeeMsat)
@@ -540,8 +540,8 @@ func Test_Mpp_CltvDeltaBelowMinimum(t *testing.T) {
i := setupInterceptor(ctx, &interceptP{store: mppStore()}) i := setupInterceptor(ctx, &interceptP{store: mppStore()})
res := i.Intercept(createPart(&part{cltvDelta: 145})) res := i.Intercept(createPart(&part{cltvDelta: 145}))
assert.Equal(t, shared.INTERCEPT_FAIL_HTLC_WITH_CODE, res.Action) assert.Equal(t, common.INTERCEPT_FAIL_HTLC_WITH_CODE, res.Action)
assert.Equal(t, shared.FAILURE_INCORRECT_CLTV_EXPIRY, res.FailureCode) assert.Equal(t, common.FAILURE_INCORRECT_CLTV_EXPIRY, res.FailureCode)
assertEmpty(t, i) assertEmpty(t, i)
} }
@@ -553,7 +553,7 @@ func Test_Mpp_HigherCltvDelta(t *testing.T) {
i := setupInterceptor(ctx, &interceptP{store: mppStore()}) i := setupInterceptor(ctx, &interceptP{store: mppStore()})
res := i.Intercept(createPart(&part{cltvDelta: 1000})) res := i.Intercept(createPart(&part{cltvDelta: 1000}))
assert.Equal(t, shared.INTERCEPT_RESUME_WITH_ONION, res.Action) assert.Equal(t, common.INTERCEPT_RESUME_WITH_ONION, res.Action)
assertEmpty(t, i) assertEmpty(t, i)
} }
@@ -568,8 +568,8 @@ func Test_Mpp_ParamsExpired(t *testing.T) {
i := setupInterceptor(ctx, &interceptP{store: store}) i := setupInterceptor(ctx, &interceptP{store: store})
res := i.Intercept(createPart(nil)) res := i.Intercept(createPart(nil))
assert.Equal(t, shared.INTERCEPT_FAIL_HTLC_WITH_CODE, res.Action) assert.Equal(t, common.INTERCEPT_FAIL_HTLC_WITH_CODE, res.Action)
assert.Equal(t, shared.FAILURE_UNKNOWN_NEXT_PEER, res.FailureCode) assert.Equal(t, common.FAILURE_UNKNOWN_NEXT_PEER, res.FailureCode)
assertEmpty(t, i) assertEmpty(t, i)
} }
@@ -585,8 +585,8 @@ func Test_Mpp_ParamsExpireInFlight(t *testing.T) {
store.registrations[defaultScid].OpeningFeeParams.ValidUntil = start. store.registrations[defaultScid].OpeningFeeParams.ValidUntil = start.
UTC().Add(time.Millisecond * 250).Format(lsps0.TIME_FORMAT) UTC().Add(time.Millisecond * 250).Format(lsps0.TIME_FORMAT)
var res1 shared.InterceptResult var res1 common.InterceptResult
var res2 shared.InterceptResult var res2 common.InterceptResult
var wg sync.WaitGroup var wg sync.WaitGroup
wg.Add(1) wg.Add(1)
go func() { go func() {
@@ -604,10 +604,10 @@ func Test_Mpp_ParamsExpireInFlight(t *testing.T) {
})) }))
wg.Wait() wg.Wait()
assert.Equal(t, shared.INTERCEPT_FAIL_HTLC_WITH_CODE, res1.Action) assert.Equal(t, common.INTERCEPT_FAIL_HTLC_WITH_CODE, res1.Action)
assert.Equal(t, shared.FAILURE_UNKNOWN_NEXT_PEER, res1.FailureCode) assert.Equal(t, common.FAILURE_UNKNOWN_NEXT_PEER, res1.FailureCode)
assert.Equal(t, shared.INTERCEPT_FAIL_HTLC_WITH_CODE, res2.Action) assert.Equal(t, common.INTERCEPT_FAIL_HTLC_WITH_CODE, res2.Action)
assert.Equal(t, shared.FAILURE_UNKNOWN_NEXT_PEER, res2.FailureCode) assert.Equal(t, common.FAILURE_UNKNOWN_NEXT_PEER, res2.FailureCode)
assertEmpty(t, i) assertEmpty(t, i)
} }
@@ -622,9 +622,9 @@ func Test_Mpp_PartReplacement(t *testing.T) {
var wg sync.WaitGroup var wg sync.WaitGroup
wg.Add(3) wg.Add(3)
var res1 shared.InterceptResult var res1 common.InterceptResult
var res2 shared.InterceptResult var res2 common.InterceptResult
var res3 shared.InterceptResult var res3 common.InterceptResult
var t1 time.Time var t1 time.Time
var t2 time.Time var t2 time.Time
var t3 time.Time var t3 time.Time
@@ -659,13 +659,13 @@ func Test_Mpp_PartReplacement(t *testing.T) {
}() }()
wg.Wait() wg.Wait()
assert.Equal(t, shared.INTERCEPT_IGNORE, res1.Action) assert.Equal(t, common.INTERCEPT_IGNORE, res1.Action)
assert.Equal(t, shared.INTERCEPT_RESUME_WITH_ONION, res2.Action) assert.Equal(t, common.INTERCEPT_RESUME_WITH_ONION, res2.Action)
assert.Equal(t, defaultPaymentSizeMsat-defaultConfig().HtlcMinimumMsat-defaultFee, res2.AmountMsat) assert.Equal(t, defaultPaymentSizeMsat-defaultConfig().HtlcMinimumMsat-defaultFee, res2.AmountMsat)
assert.Equal(t, defaultFee, *res2.FeeMsat) assert.Equal(t, defaultFee, *res2.FeeMsat)
assert.Equal(t, shared.INTERCEPT_RESUME_WITH_ONION, res3.Action) assert.Equal(t, common.INTERCEPT_RESUME_WITH_ONION, res3.Action)
assert.Equal(t, defaultConfig().HtlcMinimumMsat, res3.AmountMsat) assert.Equal(t, defaultConfig().HtlcMinimumMsat, res3.AmountMsat)
assert.Nil(t, res3.FeeMsat) assert.Nil(t, res3.FeeMsat)
@@ -684,7 +684,7 @@ func Test_Mpp_ChannelAlreadyOpened_NotComplete_Forwards(t *testing.T) {
i := setupInterceptor(ctx, &interceptP{store: store}) i := setupInterceptor(ctx, &interceptP{store: store})
res := i.Intercept(createPart(nil)) res := i.Intercept(createPart(nil))
assert.Equal(t, shared.INTERCEPT_RESUME_WITH_ONION, res.Action) assert.Equal(t, common.INTERCEPT_RESUME_WITH_ONION, res.Action)
assertEmpty(t, i) assertEmpty(t, i)
} }
@@ -697,8 +697,8 @@ func Test_Mpp_ChannelAlreadyOpened_Complete_Fails(t *testing.T) {
i := setupInterceptor(ctx, &interceptP{store: store}) i := setupInterceptor(ctx, &interceptP{store: store})
res := i.Intercept(createPart(nil)) res := i.Intercept(createPart(nil))
assert.Equal(t, shared.INTERCEPT_FAIL_HTLC_WITH_CODE, res.Action) assert.Equal(t, common.INTERCEPT_FAIL_HTLC_WITH_CODE, res.Action)
assert.Equal(t, shared.FAILURE_UNKNOWN_NEXT_PEER, res.FailureCode) assert.Equal(t, common.FAILURE_UNKNOWN_NEXT_PEER, res.FailureCode)
assertEmpty(t, i) assertEmpty(t, i)
} }
@@ -745,7 +745,7 @@ func Test_Mpp_Performance(t *testing.T) {
amt: defaultPaymentSizeMsat / uint64(partCount), amt: defaultPaymentSizeMsat / uint64(partCount),
})) }))
assert.Equal(t, shared.INTERCEPT_RESUME_WITH_ONION, res.Action) assert.Equal(t, common.INTERCEPT_RESUME_WITH_ONION, res.Action)
wg.Done() wg.Done()
}() }()
} }

View File

@@ -7,8 +7,8 @@ import (
"time" "time"
"github.com/breez/lspd/chain" "github.com/breez/lspd/chain"
"github.com/breez/lspd/common"
"github.com/breez/lspd/lightning" "github.com/breez/lspd/lightning"
"github.com/breez/lspd/shared"
"github.com/btcsuite/btcd/btcec/v2" "github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcd/wire"
) )
@@ -16,20 +16,20 @@ import (
var ErrNotImplemented = errors.New("not implemented") var ErrNotImplemented = errors.New("not implemented")
type mockNodesService struct { type mockNodesService struct {
node *shared.Node node *common.Node
err error err error
} }
func (m *mockNodesService) GetNode(token string) (*shared.Node, error) { func (m *mockNodesService) GetNode(token string) (*common.Node, error) {
return m.node, m.err return m.node, m.err
} }
func (m *mockNodesService) GetNodes() []*shared.Node { func (m *mockNodesService) GetNodes() []*common.Node {
return []*shared.Node{m.node} return []*common.Node{m.node}
} }
type mockOpeningService struct { type mockOpeningService struct {
menu []*shared.OpeningFeeParams menu []*common.OpeningFeeParams
err error err error
invalid bool invalid bool
isCurrentChainFeeCheaper bool isCurrentChainFeeCheaper bool
@@ -38,12 +38,12 @@ type mockOpeningService struct {
func (m *mockOpeningService) GetFeeParamsMenu( func (m *mockOpeningService) GetFeeParamsMenu(
token string, token string,
privateKey *btcec.PrivateKey, privateKey *btcec.PrivateKey,
) ([]*shared.OpeningFeeParams, error) { ) ([]*common.OpeningFeeParams, error) {
return m.menu, m.err return m.menu, m.err
} }
func (m *mockOpeningService) ValidateOpeningFeeParams( func (m *mockOpeningService) ValidateOpeningFeeParams(
params *shared.OpeningFeeParams, params *common.OpeningFeeParams,
publicKey *btcec.PublicKey, publicKey *btcec.PublicKey,
) bool { ) bool {
return !m.invalid return !m.invalid
@@ -51,7 +51,7 @@ func (m *mockOpeningService) ValidateOpeningFeeParams(
func (m *mockOpeningService) IsCurrentChainFeeCheaper( func (m *mockOpeningService) IsCurrentChainFeeCheaper(
token string, token string,
params *shared.OpeningFeeParams, params *common.OpeningFeeParams,
) bool { ) bool {
return m.isCurrentChainFeeCheaper return m.isCurrentChainFeeCheaper
} }

View File

@@ -4,10 +4,10 @@ import (
"context" "context"
"log" "log"
"github.com/breez/lspd/common"
"github.com/breez/lspd/lsps0" "github.com/breez/lspd/lsps0"
"github.com/breez/lspd/lsps0/codes" "github.com/breez/lspd/lsps0/codes"
"github.com/breez/lspd/lsps0/status" "github.com/breez/lspd/lsps0/status"
"github.com/breez/lspd/shared"
) )
var SupportedVersion uint32 = 1 var SupportedVersion uint32 = 1
@@ -57,9 +57,9 @@ type Lsps2Server interface {
Buy(ctx context.Context, request *BuyRequest) (*BuyResponse, error) Buy(ctx context.Context, request *BuyRequest) (*BuyResponse, error)
} }
type server struct { type server struct {
openingService shared.OpeningService openingService common.OpeningService
nodesService shared.NodesService nodesService common.NodesService
node *shared.Node node *common.Node
store Lsps2Store store Lsps2Store
} }
@@ -71,9 +71,9 @@ const (
) )
func NewLsps2Server( func NewLsps2Server(
openingService shared.OpeningService, openingService common.OpeningService,
nodesService shared.NodesService, nodesService common.NodesService,
node *shared.Node, node *common.Node,
store Lsps2Store, store Lsps2Store,
) Lsps2Server { ) Lsps2Server {
return &server{ return &server{
@@ -106,7 +106,7 @@ func (s *server) GetInfo(
} }
node, err := s.nodesService.GetNode(*request.Token) node, err := s.nodesService.GetNode(*request.Token)
if err == shared.ErrNodeNotFound { if err == common.ErrNodeNotFound {
return nil, status.New(codes.Code(2), "unrecognized_or_stale_token").Err() return nil, status.New(codes.Code(2), "unrecognized_or_stale_token").Err()
} }
if err != nil { if err != nil {
@@ -124,7 +124,7 @@ func (s *server) GetInfo(
} }
m, err := s.openingService.GetFeeParamsMenu(*request.Token, node.PrivateKey) m, err := s.openingService.GetFeeParamsMenu(*request.Token, node.PrivateKey)
if err == shared.ErrNodeNotFound { if err == common.ErrNodeNotFound {
return nil, status.New(codes.Code(2), "unrecognized_or_stale_token").Err() return nil, status.New(codes.Code(2), "unrecognized_or_stale_token").Err()
} }
if err != nil { if err != nil {
@@ -167,7 +167,7 @@ func (s *server) Buy(
return nil, status.New(codes.Code(1), "unsupported_version").Err() return nil, status.New(codes.Code(1), "unsupported_version").Err()
} }
params := &shared.OpeningFeeParams{ params := &common.OpeningFeeParams{
MinFeeMsat: request.OpeningFeeParams.MinFeeMsat, MinFeeMsat: request.OpeningFeeParams.MinFeeMsat,
Proportional: request.OpeningFeeParams.Proportional, Proportional: request.OpeningFeeParams.Proportional,
ValidUntil: request.OpeningFeeParams.ValidUntil, ValidUntil: request.OpeningFeeParams.ValidUntil,

View File

@@ -5,16 +5,16 @@ import (
"fmt" "fmt"
"testing" "testing"
"github.com/breez/lspd/common"
"github.com/breez/lspd/config" "github.com/breez/lspd/config"
"github.com/breez/lspd/lsps0" "github.com/breez/lspd/lsps0"
"github.com/breez/lspd/lsps0/status" "github.com/breez/lspd/lsps0/status"
"github.com/breez/lspd/shared"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
var token = "blah" var token = "blah"
var node = func() *shared.Node { var node = func() *common.Node {
return &shared.Node{ return &common.Node{
NodeConfig: &config.NodeConfig{ NodeConfig: &config.NodeConfig{
MinPaymentSizeMsat: 1000, MinPaymentSizeMsat: 1000,
MaxPaymentSizeMsat: 10000, MaxPaymentSizeMsat: 10000,
@@ -40,7 +40,7 @@ func Test_GetInfo_UnsupportedVersion(t *testing.T) {
func Test_GetInfo_InvalidToken(t *testing.T) { func Test_GetInfo_InvalidToken(t *testing.T) {
n := &mockNodesService{ n := &mockNodesService{
err: shared.ErrNodeNotFound, err: common.ErrNodeNotFound,
} }
o := &mockOpeningService{} o := &mockOpeningService{}
st := &mockLsps2Store{} st := &mockLsps2Store{}
@@ -58,7 +58,7 @@ func Test_GetInfo_InvalidToken(t *testing.T) {
func Test_GetInfo_EmptyMenu(t *testing.T) { func Test_GetInfo_EmptyMenu(t *testing.T) {
node := node() node := node()
n := &mockNodesService{node: node} n := &mockNodesService{node: node}
o := &mockOpeningService{menu: []*shared.OpeningFeeParams{}} o := &mockOpeningService{menu: []*common.OpeningFeeParams{}}
st := &mockLsps2Store{} st := &mockLsps2Store{}
s := NewLsps2Server(o, n, node, st) s := NewLsps2Server(o, n, node, st)
resp, err := s.GetInfo(context.Background(), &GetInfoRequest{ resp, err := s.GetInfo(context.Background(), &GetInfoRequest{
@@ -75,7 +75,7 @@ func Test_GetInfo_EmptyMenu(t *testing.T) {
func Test_GetInfo_PopulatedMenu_Ordered(t *testing.T) { func Test_GetInfo_PopulatedMenu_Ordered(t *testing.T) {
node := node() node := node()
n := &mockNodesService{node: node} n := &mockNodesService{node: node}
o := &mockOpeningService{menu: []*shared.OpeningFeeParams{ o := &mockOpeningService{menu: []*common.OpeningFeeParams{
{ {
MinFeeMsat: 1, MinFeeMsat: 1,
Proportional: 2, Proportional: 2,

View File

@@ -6,14 +6,14 @@ import (
"log" "log"
"time" "time"
"github.com/breez/lspd/common"
"github.com/breez/lspd/lightning" "github.com/breez/lspd/lightning"
"github.com/breez/lspd/lsps0" "github.com/breez/lspd/lsps0"
"github.com/breez/lspd/shared"
"github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcd/wire"
) )
type SavePromises struct { type SavePromises struct {
Menu []*shared.OpeningFeeParams Menu []*common.OpeningFeeParams
Token string Token string
} }
@@ -21,7 +21,7 @@ type RegisterBuy struct {
LspId string LspId string
PeerId string PeerId string
Scid lightning.ShortChannelID Scid lightning.ShortChannelID
OpeningFeeParams shared.OpeningFeeParams OpeningFeeParams common.OpeningFeeParams
PaymentSizeMsat *uint64 PaymentSizeMsat *uint64
Mode OpeningMode Mode OpeningMode
} }
@@ -32,7 +32,7 @@ type BuyRegistration struct {
PeerId string // TODO: Make peerId in the registration a byte array. PeerId string // TODO: Make peerId in the registration a byte array.
Token string Token string
Scid lightning.ShortChannelID Scid lightning.ShortChannelID
OpeningFeeParams shared.OpeningFeeParams OpeningFeeParams common.OpeningFeeParams
PaymentSizeMsat *uint64 PaymentSizeMsat *uint64
Mode OpeningMode Mode OpeningMode
ChannelPoint *wire.OutPoint ChannelPoint *wire.OutPoint

14
main.go
View File

@@ -15,6 +15,7 @@ import (
"github.com/breez/lspd/chain" "github.com/breez/lspd/chain"
"github.com/breez/lspd/cln" "github.com/breez/lspd/cln"
"github.com/breez/lspd/common"
"github.com/breez/lspd/config" "github.com/breez/lspd/config"
"github.com/breez/lspd/interceptor" "github.com/breez/lspd/interceptor"
"github.com/breez/lspd/lnd" "github.com/breez/lspd/lnd"
@@ -23,7 +24,6 @@ import (
"github.com/breez/lspd/mempool" "github.com/breez/lspd/mempool"
"github.com/breez/lspd/notifications" "github.com/breez/lspd/notifications"
"github.com/breez/lspd/postgresql" "github.com/breez/lspd/postgresql"
"github.com/breez/lspd/shared"
"github.com/btcsuite/btcd/btcec/v2" "github.com/btcsuite/btcd/btcec/v2"
ecies "github.com/ecies/go/v2" ecies "github.com/ecies/go/v2"
) )
@@ -54,7 +54,7 @@ func main() {
log.Fatalf("failed to initialize nodes: %v", err) log.Fatalf("failed to initialize nodes: %v", err)
} }
nodesService, err := shared.NewNodesService(nodes) nodesService, err := common.NewNodesService(nodes)
if err != nil { if err != nil {
log.Fatalf("failed to create nodes service: %v", err) log.Fatalf("failed to create nodes service: %v", err)
} }
@@ -101,7 +101,7 @@ func main() {
notificationService := notifications.NewNotificationService(notificationsStore) notificationService := notifications.NewNotificationService(notificationsStore)
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
openingService := shared.NewOpeningService(openingStore, nodesService) openingService := common.NewOpeningService(openingStore, nodesService)
cleanupService := lsps2.NewCleanupService(lsps2Store) cleanupService := lsps2.NewCleanupService(lsps2Store)
go cleanupService.Start(ctx) go cleanupService.Start(ctx)
var interceptors []interceptor.HtlcInterceptor var interceptors []interceptor.HtlcInterceptor
@@ -141,7 +141,7 @@ func main() {
MppTimeout: time.Second * 90, MppTimeout: time.Second * 90,
}) })
go lsps2Handler.Start(ctx) go lsps2Handler.Start(ctx)
combinedHandler := shared.NewCombinedHandler(lsps2Handler, legacyHandler) combinedHandler := common.NewCombinedHandler(lsps2Handler, legacyHandler)
htlcInterceptor, err = cln.NewClnHtlcInterceptor(node.NodeConfig, client, combinedHandler) htlcInterceptor, err = cln.NewClnHtlcInterceptor(node.NodeConfig, client, combinedHandler)
if err != nil { if err != nil {
log.Fatalf("failed to initialize CLN interceptor: %v", err) log.Fatalf("failed to initialize CLN interceptor: %v", err)
@@ -233,12 +233,12 @@ func main() {
log.Printf("lspd exited") log.Printf("lspd exited")
} }
func initializeNodes(configs []*config.NodeConfig) ([]*shared.Node, error) { func initializeNodes(configs []*config.NodeConfig) ([]*common.Node, error) {
if len(configs) == 0 { if len(configs) == 0 {
return nil, fmt.Errorf("no nodes supplied") return nil, fmt.Errorf("no nodes supplied")
} }
nodes := []*shared.Node{} nodes := []*common.Node{}
for _, config := range configs { for _, config := range configs {
pk, err := hex.DecodeString(config.LspdPrivateKey) pk, err := hex.DecodeString(config.LspdPrivateKey)
if err != nil { if err != nil {
@@ -248,7 +248,7 @@ func initializeNodes(configs []*config.NodeConfig) ([]*shared.Node, error) {
eciesPrivateKey := ecies.NewPrivateKeyFromBytes(pk) eciesPrivateKey := ecies.NewPrivateKeyFromBytes(pk)
eciesPublicKey := eciesPrivateKey.PublicKey eciesPublicKey := eciesPrivateKey.PublicKey
privateKey, publicKey := btcec.PrivKeyFromBytes(pk) privateKey, publicKey := btcec.PrivKeyFromBytes(pk)
node := &shared.Node{ node := &common.Node{
NodeConfig: config, NodeConfig: config,
PrivateKey: privateKey, PrivateKey: privateKey,
PublicKey: publicKey, PublicKey: publicKey,

View File

@@ -7,8 +7,8 @@ import (
"log" "log"
"time" "time"
"github.com/breez/lspd/common"
"github.com/breez/lspd/lightning" "github.com/breez/lspd/lightning"
"github.com/breez/lspd/shared"
"github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcd/wire"
"github.com/jackc/pgtype" "github.com/jackc/pgtype"
"github.com/jackc/pgx/v4" "github.com/jackc/pgx/v4"
@@ -23,7 +23,7 @@ func NewPostgresInterceptStore(pool *pgxpool.Pool) *PostgresInterceptStore {
return &PostgresInterceptStore{pool: pool} return &PostgresInterceptStore{pool: pool}
} }
func (s *PostgresInterceptStore) PaymentInfo(htlcPaymentHash []byte) (string, *shared.OpeningFeeParams, []byte, []byte, []byte, int64, int64, *wire.OutPoint, *string, error) { func (s *PostgresInterceptStore) PaymentInfo(htlcPaymentHash []byte) (string, *common.OpeningFeeParams, []byte, []byte, []byte, int64, int64, *wire.OutPoint, *string, error) {
var ( var (
p, tag *string p, tag *string
paymentHash, paymentSecret, destination []byte paymentHash, paymentSecret, destination []byte
@@ -72,7 +72,7 @@ func (s *PostgresInterceptStore) SetFundingTx(paymentHash []byte, channelPoint *
return err return err
} }
func (s *PostgresInterceptStore) RegisterPayment(token string, params *shared.OpeningFeeParams, destination, paymentHash, paymentSecret []byte, incomingAmountMsat, outgoingAmountMsat int64, tag string) error { func (s *PostgresInterceptStore) RegisterPayment(token string, params *common.OpeningFeeParams, destination, paymentHash, paymentSecret []byte, incomingAmountMsat, outgoingAmountMsat int64, tag string) error {
var t *string var t *string
if tag != "" { if tag != "" {
t = &tag t = &tag

View File

@@ -7,10 +7,10 @@ import (
"strings" "strings"
"time" "time"
"github.com/breez/lspd/common"
"github.com/breez/lspd/lightning" "github.com/breez/lspd/lightning"
"github.com/breez/lspd/lsps0" "github.com/breez/lspd/lsps0"
"github.com/breez/lspd/lsps2" "github.com/breez/lspd/lsps2"
"github.com/breez/lspd/shared"
"github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcd/wire"
"github.com/jackc/pgx/v4" "github.com/jackc/pgx/v4"
"github.com/jackc/pgx/v4/pgxpool" "github.com/jackc/pgx/v4/pgxpool"
@@ -171,7 +171,7 @@ func (s *Lsps2Store) GetBuyRegistration(ctx context.Context, scid lightning.Shor
LspId: db_lsp_id, LspId: db_lsp_id,
PeerId: db_peer_id, PeerId: db_peer_id,
Scid: lightning.ShortChannelID(uint64(db_scid)), Scid: lightning.ShortChannelID(uint64(db_scid)),
OpeningFeeParams: shared.OpeningFeeParams{ OpeningFeeParams: common.OpeningFeeParams{
MinFeeMsat: uint64(db_params_min_fee_msat), MinFeeMsat: uint64(db_params_min_fee_msat),
Proportional: db_params_proportional, Proportional: db_params_proportional,
ValidUntil: db_params_valid_until, ValidUntil: db_params_valid_until,

View File

@@ -6,13 +6,13 @@ import (
"log" "log"
"time" "time"
"github.com/breez/lspd/shared" "github.com/breez/lspd/common"
"github.com/jackc/pgx/v4/pgxpool" "github.com/jackc/pgx/v4/pgxpool"
) )
type extendedParams struct { type extendedParams struct {
Token string `json:"token"` Token string `json:"token"`
Params shared.OpeningFeeParams `json:"fees_params"` Params common.OpeningFeeParams `json:"fees_params"`
} }
type PostgresOpeningStore struct { type PostgresOpeningStore struct {
@@ -23,14 +23,14 @@ func NewPostgresOpeningStore(pool *pgxpool.Pool) *PostgresOpeningStore {
return &PostgresOpeningStore{pool: pool} return &PostgresOpeningStore{pool: pool}
} }
func (s *PostgresOpeningStore) GetFeeParamsSettings(token string) ([]*shared.OpeningFeeParamsSetting, error) { func (s *PostgresOpeningStore) GetFeeParamsSettings(token string) ([]*common.OpeningFeeParamsSetting, error) {
rows, err := s.pool.Query(context.Background(), `SELECT validity, params FROM new_channel_params WHERE token=$1`, token) rows, err := s.pool.Query(context.Background(), `SELECT validity, params FROM new_channel_params WHERE token=$1`, token)
if err != nil { if err != nil {
log.Printf("GetFeeParamsSettings(%v) error: %v", token, err) log.Printf("GetFeeParamsSettings(%v) error: %v", token, err)
return nil, err return nil, err
} }
var settings []*shared.OpeningFeeParamsSetting var settings []*common.OpeningFeeParamsSetting
for rows.Next() { for rows.Next() {
var validity int64 var validity int64
var param string var param string
@@ -39,7 +39,7 @@ func (s *PostgresOpeningStore) GetFeeParamsSettings(token string) ([]*shared.Ope
return nil, err return nil, err
} }
var params *shared.OpeningFeeParams var params *common.OpeningFeeParams
err := json.Unmarshal([]byte(param), &params) err := json.Unmarshal([]byte(param), &params)
if err != nil { if err != nil {
log.Printf("Failed to unmarshal fee param '%v': %v", param, err) log.Printf("Failed to unmarshal fee param '%v': %v", param, err)
@@ -47,7 +47,7 @@ func (s *PostgresOpeningStore) GetFeeParamsSettings(token string) ([]*shared.Ope
} }
duration := time.Second * time.Duration(validity) duration := time.Second * time.Duration(validity)
settings = append(settings, &shared.OpeningFeeParamsSetting{ settings = append(settings, &common.OpeningFeeParamsSetting{
Validity: duration, Validity: duration,
Params: params, Params: params,
}) })