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"
"github.com/breez/lspd/btceclegacy"
"github.com/breez/lspd/common"
"github.com/breez/lspd/interceptor"
"github.com/breez/lspd/lightning"
"github.com/breez/lspd/lsps0"
lspdrpc "github.com/breez/lspd/rpc"
"github.com/breez/lspd/shared"
ecies "github.com/ecies/go/v2"
"github.com/golang/protobuf/proto"
"google.golang.org/grpc/codes"
@@ -28,12 +28,12 @@ import (
type channelOpenerServer struct {
lspdrpc.ChannelOpenerServer
store interceptor.InterceptStore
openingService shared.OpeningService
openingService common.OpeningService
}
func NewChannelOpenerServer(
store interceptor.InterceptStore,
openingService shared.OpeningService,
openingService common.OpeningService,
) *channelOpenerServer {
return &channelOpenerServer{
store: store,
@@ -128,7 +128,7 @@ func (s *channelOpenerServer) RegisterPayment(
// clients to use opening_fee_params.
if pi.OpeningFeeParams != nil {
valid := s.openingService.ValidateOpeningFeeParams(
&shared.OpeningFeeParams{
&common.OpeningFeeParams{
MinFeeMsat: pi.OpeningFeeParams.MinMsat,
Proportional: pi.OpeningFeeParams.Proportional,
ValidUntil: pi.OpeningFeeParams.ValidUntil,
@@ -157,7 +157,7 @@ func (s *channelOpenerServer) RegisterPayment(
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)
}
params := &shared.OpeningFeeParams{
params := &common.OpeningFeeParams{
MinFeeMsat: pi.OpeningFeeParams.MinMsat,
Proportional: pi.OpeningFeeParams.Proportional,
ValidUntil: pi.OpeningFeeParams.ValidUntil,
@@ -217,7 +217,7 @@ func (s *channelOpenerServer) OpenChannel(ctx context.Context, in *lspdrpc.OpenC
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
signedBlob, err := ecies.Decrypt(n.EciesPrivateKey, in.Data)
if err != nil {
@@ -312,7 +312,7 @@ func (s *channelOpenerServer) CheckChannels(ctx context.Context, in *lspdrpc.Enc
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"))
if nd == nil {
return nil, "", status.Errorf(codes.PermissionDenied, "Not authorized")

View File

@@ -11,9 +11,9 @@ import (
"time"
"github.com/breez/lspd/cln_plugin/proto"
"github.com/breez/lspd/common"
"github.com/breez/lspd/config"
"github.com/breez/lspd/lightning"
"github.com/breez/lspd/shared"
sphinx "github.com/lightningnetwork/lightning-onion"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/record"
@@ -26,7 +26,7 @@ import (
)
type ClnHtlcInterceptor struct {
interceptor shared.InterceptHandler
interceptor common.InterceptHandler
config *config.NodeConfig
pluginAddress string
client *ClnClient
@@ -38,7 +38,7 @@ type ClnHtlcInterceptor struct {
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{
config: conf,
pluginAddress: conf.Cln.PluginAddress,
@@ -147,7 +147,7 @@ func (i *ClnHtlcInterceptor) intercept() error {
return
}
interceptResult := i.interceptor.Intercept(shared.InterceptRequest{
interceptResult := i.interceptor.Intercept(common.InterceptRequest{
Identifier: request.Onion.SharedSecret,
Scid: *scid,
PaymentHash: paymentHash,
@@ -157,15 +157,15 @@ func (i *ClnHtlcInterceptor) intercept() error {
OutgoingExpiry: request.Onion.OutgoingCltvValue,
})
switch interceptResult.Action {
case shared.INTERCEPT_RESUME_WITH_ONION:
case common.INTERCEPT_RESUME_WITH_ONION:
interceptorClient.Send(i.resumeWithOnion(request, interceptResult))
case shared.INTERCEPT_FAIL_HTLC_WITH_CODE:
case common.INTERCEPT_FAIL_HTLC_WITH_CODE:
interceptorClient.Send(
i.failWithCode(request, interceptResult.FailureCode),
)
case shared.INTERCEPT_IGNORE:
case common.INTERCEPT_IGNORE:
// Do nothing
case shared.INTERCEPT_RESUME:
case common.INTERCEPT_RESUME:
fallthrough
default:
interceptorClient.Send(
@@ -197,17 +197,17 @@ func (i *ClnHtlcInterceptor) WaitStarted() {
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.
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, shared.FAILURE_TEMPORARY_CHANNEL_FAILURE)
return i.failWithCode(request, common.FAILURE_TEMPORARY_CHANNEL_FAILURE)
}
newPayload, err := encodePayloadWithNextHop(payload, interceptResult.Scid, interceptResult.AmountMsat, interceptResult.FeeMsat)
if err != nil {
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)
@@ -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{
Correlationid: request.Correlationid,
Outcome: &proto.HtlcResolution_Fail{
@@ -305,19 +305,19 @@ func encodePayloadWithNextHop(payload []byte, scid lightning.ShortChannelID, amo
return newPayloadBuf.Bytes(), nil
}
func (i *ClnHtlcInterceptor) mapFailureCode(original shared.InterceptFailureCode) string {
func (i *ClnHtlcInterceptor) mapFailureCode(original common.InterceptFailureCode) string {
switch original {
case shared.FAILURE_TEMPORARY_CHANNEL_FAILURE:
case common.FAILURE_TEMPORARY_CHANNEL_FAILURE:
return "1007"
case shared.FAILURE_AMOUNT_BELOW_MINIMUM:
case common.FAILURE_AMOUNT_BELOW_MINIMUM:
return "100B"
case shared.FAILURE_INCORRECT_CLTV_EXPIRY:
case common.FAILURE_INCORRECT_CLTV_EXPIRY:
return "100D"
case shared.FAILURE_TEMPORARY_NODE_FAILURE:
case common.FAILURE_TEMPORARY_NODE_FAILURE:
return "2002"
case shared.FAILURE_UNKNOWN_NEXT_PEER:
case common.FAILURE_UNKNOWN_NEXT_PEER:
return "400A"
case shared.FAILURE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS:
case common.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 shared
package common
import "log"

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -10,11 +10,11 @@ import (
"time"
"github.com/breez/lspd/chain"
"github.com/breez/lspd/common"
"github.com/breez/lspd/config"
"github.com/breez/lspd/lightning"
"github.com/breez/lspd/lsps0"
"github.com/breez/lspd/notifications"
"github.com/breez/lspd/shared"
"github.com/btcsuite/btcd/wire"
"golang.org/x/exp/slices"
"golang.org/x/sync/singleflight"
@@ -24,7 +24,7 @@ type Interceptor struct {
client lightning.Client
config *config.NodeConfig
store InterceptStore
openingService shared.OpeningService
openingService common.OpeningService
feeEstimator chain.FeeEstimator
feeStrategy chain.FeeStrategy
payHashGroup singleflight.Group
@@ -35,7 +35,7 @@ func NewInterceptHandler(
client lightning.Client,
config *config.NodeConfig,
store InterceptStore,
openingService shared.OpeningService,
openingService common.OpeningService,
feeEstimator chain.FeeEstimator,
feeStrategy chain.FeeStrategy,
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)
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) {
token, params, paymentHash, paymentSecret, destination, incomingAmountMsat, outgoingAmountMsat, channelPoint, tag, err := i.store.PaymentInfo(req.PaymentHash)
if err != nil {
log.Printf("paymentInfo(%x) error: %v", req.PaymentHash, err)
return shared.InterceptResult{
Action: shared.INTERCEPT_FAIL_HTLC_WITH_CODE,
FailureCode: shared.FAILURE_TEMPORARY_NODE_FAILURE,
return common.InterceptResult{
Action: common.INTERCEPT_FAIL_HTLC_WITH_CODE,
FailureCode: common.FAILURE_TEMPORARY_NODE_FAILURE,
}, nil
}
@@ -74,8 +74,8 @@ func (i *Interceptor) Intercept(req shared.InterceptRequest) shared.InterceptRes
nextHop, _ := i.client.GetPeerId(&req.Scid)
if err != nil {
log.Printf("GetPeerId(%s) error: %v", req.Scid.ToString(), err)
return shared.InterceptResult{
Action: shared.INTERCEPT_RESUME,
return common.InterceptResult{
Action: common.INTERCEPT_RESUME,
}, 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.
if isRegistered && nextHop != nil && !bytes.Equal(nextHop, destination) {
log.Printf("paymentHash: %s, nextHop (%s) != destination (%s)", reqPaymentHashStr, hex.EncodeToString(nextHop), hex.EncodeToString(destination))
return shared.InterceptResult{
Action: shared.INTERCEPT_RESUME,
return common.InterceptResult{
Action: common.INTERCEPT_RESUME,
}, 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.
if !isRegistered {
log.Printf("paymentHash: %s, nextHop == nil and not registered", reqPaymentHashStr)
return shared.InterceptResult{
Action: shared.INTERCEPT_RESUME,
return common.InterceptResult{
Action: common.INTERCEPT_RESUME,
}, nil
}
@@ -110,9 +110,9 @@ func (i *Interceptor) Intercept(req shared.InterceptRequest) shared.InterceptRes
isConnected, err := i.client.IsConnected(nextHop)
if err != nil {
log.Printf("IsConnected(%x) error: %v", nextHop, err)
return &shared.InterceptResult{
Action: shared.INTERCEPT_FAIL_HTLC_WITH_CODE,
FailureCode: shared.FAILURE_TEMPORARY_CHANNEL_FAILURE,
return &common.InterceptResult{
Action: common.INTERCEPT_FAIL_HTLC_WITH_CODE,
FailureCode: common.FAILURE_TEMPORARY_CHANNEL_FAILURE,
}, 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 !isConnected {
log.Printf("paymentHash: %s, probe and not connected", reqPaymentHashStr)
return shared.InterceptResult{
Action: shared.INTERCEPT_RESUME,
return common.InterceptResult{
Action: common.INTERCEPT_RESUME,
}, nil
}
@@ -132,9 +132,9 @@ func (i *Interceptor) Intercept(req shared.InterceptRequest) shared.InterceptRes
// know that the actual payment would probably succeed.
if channelPoint == nil {
log.Printf("paymentHash: %s, probe and channelPoint == nil", reqPaymentHashStr)
return shared.InterceptResult{
Action: shared.INTERCEPT_FAIL_HTLC_WITH_CODE,
FailureCode: shared.FAILURE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS,
return common.InterceptResult{
Action: common.INTERCEPT_FAIL_HTLC_WITH_CODE,
FailureCode: common.FAILURE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS,
}, 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.
if !isRegistered {
return shared.InterceptResult{
Action: shared.INTERCEPT_RESUME,
return common.InterceptResult{
Action: common.INTERCEPT_RESUME,
}, 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.
if params == nil {
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),
Proportional: uint32(i.config.ChannelFeePermyriad * 100),
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.
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)
return shared.InterceptResult{
Action: shared.INTERCEPT_FAIL_HTLC_WITH_CODE,
FailureCode: shared.FAILURE_TEMPORARY_CHANNEL_FAILURE,
return common.InterceptResult{
Action: common.INTERCEPT_FAIL_HTLC_WITH_CODE,
FailureCode: common.FAILURE_TEMPORARY_CHANNEL_FAILURE,
}, nil
}
validUntil, err := time.Parse(lsps0.TIME_FORMAT, params.ValidUntil)
if err != nil {
log.Printf("time.Parse(%s, %s) failed. Failing channel open: %v", lsps0.TIME_FORMAT, params.ValidUntil, err)
return shared.InterceptResult{
Action: shared.INTERCEPT_FAIL_HTLC_WITH_CODE,
FailureCode: shared.FAILURE_TEMPORARY_CHANNEL_FAILURE,
return common.InterceptResult{
Action: common.INTERCEPT_FAIL_HTLC_WITH_CODE,
FailureCode: common.FAILURE_TEMPORARY_CHANNEL_FAILURE,
}, nil
}
@@ -192,9 +192,9 @@ func (i *Interceptor) Intercept(req shared.InterceptRequest) shared.InterceptRes
if time.Now().UTC().After(validUntil) {
if !i.openingService.IsCurrentChainFeeCheaper(token, params) {
log.Printf("Intercepted expired payment registration. Failing payment. payment hash: %x, valid until: %s", paymentHash, params.ValidUntil)
return shared.InterceptResult{
Action: shared.INTERCEPT_FAIL_HTLC_WITH_CODE,
FailureCode: shared.FAILURE_TEMPORARY_CHANNEL_FAILURE,
return common.InterceptResult{
Action: common.INTERCEPT_FAIL_HTLC_WITH_CODE,
FailureCode: common.FAILURE_TEMPORARY_CHANNEL_FAILURE,
}, nil
}
@@ -204,9 +204,9 @@ func (i *Interceptor) Intercept(req shared.InterceptRequest) shared.InterceptRes
channelPoint, err = i.openChannel(req.PaymentHash, destination, incomingAmountMsat, tag)
if err != nil {
log.Printf("openChannel(%x, %v) err: %v", destination, incomingAmountMsat, err)
return shared.InterceptResult{
Action: shared.INTERCEPT_FAIL_HTLC_WITH_CODE,
FailureCode: shared.FAILURE_TEMPORARY_CHANNEL_FAILURE,
return common.InterceptResult{
Action: common.INTERCEPT_FAIL_HTLC_WITH_CODE,
FailureCode: common.FAILURE_TEMPORARY_CHANNEL_FAILURE,
}, nil
}
}
@@ -231,9 +231,9 @@ func (i *Interceptor) Intercept(req shared.InterceptRequest) shared.InterceptRes
if err != nil {
log.Printf("insertChannel error: %v", err)
return shared.InterceptResult{
Action: shared.INTERCEPT_FAIL_HTLC_WITH_CODE,
FailureCode: shared.FAILURE_TEMPORARY_CHANNEL_FAILURE,
return common.InterceptResult{
Action: common.INTERCEPT_FAIL_HTLC_WITH_CODE,
FailureCode: common.FAILURE_TEMPORARY_CHANNEL_FAILURE,
}, nil
}
@@ -243,8 +243,8 @@ func (i *Interceptor) Intercept(req shared.InterceptRequest) shared.InterceptRes
}
useLegacyOnionBlob := slices.Contains(i.config.LegacyOnionTokens, token)
return shared.InterceptResult{
Action: shared.INTERCEPT_RESUME_WITH_ONION,
return common.InterceptResult{
Action: common.INTERCEPT_RESUME_WITH_ONION,
Destination: destination,
ChannelPoint: channelPoint,
Scid: channelID,
@@ -264,16 +264,16 @@ func (i *Interceptor) Intercept(req shared.InterceptRequest) shared.InterceptRes
}
log.Printf("Error: Channel failed to open... timed out. ")
return shared.InterceptResult{
Action: shared.INTERCEPT_FAIL_HTLC_WITH_CODE,
FailureCode: shared.FAILURE_TEMPORARY_CHANNEL_FAILURE,
return common.InterceptResult{
Action: common.INTERCEPT_FAIL_HTLC_WITH_CODE,
FailureCode: common.FAILURE_TEMPORARY_CHANNEL_FAILURE,
}, 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
// notification service for this client if available.
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
// result in UNKOWN_NEXT_PEER)
if err != nil || !notified {
return &shared.InterceptResult{
Action: shared.INTERCEPT_RESUME,
return &common.InterceptResult{
Action: common.INTERCEPT_RESUME,
}
}
@@ -309,8 +309,8 @@ func (i *Interceptor) notify(reqPaymentHashStr string, nextHop []byte, isRegiste
nextHop,
err,
)
return &shared.InterceptResult{
Action: shared.INTERCEPT_RESUME,
return &common.InterceptResult{
Action: common.INTERCEPT_RESUME,
}
}
@@ -331,8 +331,8 @@ func (i *Interceptor) notify(reqPaymentHashStr string, nextHop []byte, isRegiste
nextHop,
err,
)
return &shared.InterceptResult{
Action: shared.INTERCEPT_RESUME,
return &common.InterceptResult{
Action: common.INTERCEPT_RESUME,
}
}
}

View File

@@ -3,13 +3,13 @@ package interceptor
import (
"time"
"github.com/breez/lspd/shared"
"github.com/breez/lspd/common"
"github.com/btcsuite/btcd/wire"
)
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
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
}

View File

@@ -7,10 +7,10 @@ import (
"sync"
"time"
"github.com/breez/lspd/common"
"github.com/breez/lspd/config"
"github.com/breez/lspd/interceptor"
"github.com/breez/lspd/lightning"
"github.com/breez/lspd/shared"
"github.com/btcsuite/btcd/btcec/v2"
sphinx "github.com/lightningnetwork/lightning-onion"
"github.com/lightningnetwork/lnd/lnrpc"
@@ -137,7 +137,7 @@ func (i *LndHtlcInterceptor) intercept() error {
i.doneWg.Add(1)
go func() {
scid := lightning.ShortChannelID(request.OutgoingRequestedChanId)
interceptResult := i.interceptor.Intercept(shared.InterceptRequest{
interceptResult := i.interceptor.Intercept(common.InterceptRequest{
Identifier: request.IncomingCircuitKey.String(),
Scid: scid,
PaymentHash: request.PaymentHash,
@@ -147,15 +147,15 @@ func (i *LndHtlcInterceptor) intercept() error {
OutgoingExpiry: request.OutgoingExpiry,
})
switch interceptResult.Action {
case shared.INTERCEPT_RESUME_WITH_ONION:
case common.INTERCEPT_RESUME_WITH_ONION:
interceptorClient.Send(i.createOnionResponse(interceptResult, request))
case shared.INTERCEPT_FAIL_HTLC_WITH_CODE:
case common.INTERCEPT_FAIL_HTLC_WITH_CODE:
interceptorClient.Send(&routerrpc.ForwardHtlcInterceptResponse{
IncomingCircuitKey: request.IncomingCircuitKey,
Action: routerrpc.ResolveHoldForwardAction_FAIL,
FailureCode: i.mapFailureCode(interceptResult.FailureCode),
})
case shared.INTERCEPT_RESUME:
case common.INTERCEPT_RESUME:
fallthrough
default:
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 {
case shared.FAILURE_TEMPORARY_CHANNEL_FAILURE:
case common.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
case shared.FAILURE_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS:
case common.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)
@@ -190,7 +190,7 @@ func (i *LndHtlcInterceptor) mapFailureCode(original shared.InterceptFailureCode
}
func (i *LndHtlcInterceptor) constructOnion(
interceptResult shared.InterceptResult,
interceptResult common.InterceptResult,
reqOutgoingExpiry uint32,
reqPaymentHash []byte,
) ([]byte, error) {
@@ -251,7 +251,7 @@ func (i *LndHtlcInterceptor) constructOnion(
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
if interceptResult.UseLegacyOnionBlob {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

14
main.go
View File

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

View File

@@ -7,8 +7,8 @@ import (
"log"
"time"
"github.com/breez/lspd/common"
"github.com/breez/lspd/lightning"
"github.com/breez/lspd/shared"
"github.com/btcsuite/btcd/wire"
"github.com/jackc/pgtype"
"github.com/jackc/pgx/v4"
@@ -23,7 +23,7 @@ func NewPostgresInterceptStore(pool *pgxpool.Pool) *PostgresInterceptStore {
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 (
p, tag *string
paymentHash, paymentSecret, destination []byte
@@ -72,7 +72,7 @@ func (s *PostgresInterceptStore) SetFundingTx(paymentHash []byte, channelPoint *
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
if tag != "" {
t = &tag

View File

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

View File

@@ -6,13 +6,13 @@ import (
"log"
"time"
"github.com/breez/lspd/shared"
"github.com/breez/lspd/common"
"github.com/jackc/pgx/v4/pgxpool"
)
type extendedParams struct {
Token string `json:"token"`
Params shared.OpeningFeeParams `json:"fees_params"`
Params common.OpeningFeeParams `json:"fees_params"`
}
type PostgresOpeningStore struct {
@@ -23,14 +23,14 @@ func NewPostgresOpeningStore(pool *pgxpool.Pool) *PostgresOpeningStore {
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)
if err != nil {
log.Printf("GetFeeParamsSettings(%v) error: %v", token, err)
return nil, err
}
var settings []*shared.OpeningFeeParamsSetting
var settings []*common.OpeningFeeParamsSetting
for rows.Next() {
var validity int64
var param string
@@ -39,7 +39,7 @@ func (s *PostgresOpeningStore) GetFeeParamsSettings(token string) ([]*shared.Ope
return nil, err
}
var params *shared.OpeningFeeParams
var params *common.OpeningFeeParams
err := json.Unmarshal([]byte(param), &params)
if err != nil {
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)
settings = append(settings, &shared.OpeningFeeParamsSetting{
settings = append(settings, &common.OpeningFeeParamsSetting{
Validity: duration,
Params: params,
})