mirror of
https://github.com/aljazceru/lspd.git
synced 2025-12-19 06:44:23 +01:00
rename shared package to common
This commit is contained in:
@@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user