mirror of
https://github.com/aljazceru/lspd.git
synced 2025-12-18 22:34:22 +01:00
insert channel directly after opening
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/breez/lspd/chain"
|
"github.com/breez/lspd/chain"
|
||||||
"github.com/breez/lspd/common"
|
"github.com/breez/lspd/common"
|
||||||
"github.com/breez/lspd/config"
|
"github.com/breez/lspd/config"
|
||||||
|
"github.com/breez/lspd/history"
|
||||||
"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"
|
||||||
@@ -20,9 +21,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Interceptor struct {
|
type Interceptor struct {
|
||||||
|
nodeid []byte
|
||||||
client lightning.Client
|
client lightning.Client
|
||||||
config *config.NodeConfig
|
config *config.NodeConfig
|
||||||
store InterceptStore
|
store InterceptStore
|
||||||
|
historyStore history.Store
|
||||||
openingService common.OpeningService
|
openingService common.OpeningService
|
||||||
feeEstimator chain.FeeEstimator
|
feeEstimator chain.FeeEstimator
|
||||||
feeStrategy chain.FeeStrategy
|
feeStrategy chain.FeeStrategy
|
||||||
@@ -34,15 +37,19 @@ func NewInterceptHandler(
|
|||||||
client lightning.Client,
|
client lightning.Client,
|
||||||
config *config.NodeConfig,
|
config *config.NodeConfig,
|
||||||
store InterceptStore,
|
store InterceptStore,
|
||||||
|
historyStore history.Store,
|
||||||
openingService common.OpeningService,
|
openingService common.OpeningService,
|
||||||
feeEstimator chain.FeeEstimator,
|
feeEstimator chain.FeeEstimator,
|
||||||
feeStrategy chain.FeeStrategy,
|
feeStrategy chain.FeeStrategy,
|
||||||
notificationService *notifications.NotificationService,
|
notificationService *notifications.NotificationService,
|
||||||
) *Interceptor {
|
) *Interceptor {
|
||||||
|
nodeid, _ := hex.DecodeString(config.NodePubkey)
|
||||||
return &Interceptor{
|
return &Interceptor{
|
||||||
|
nodeid: nodeid,
|
||||||
client: client,
|
client: client,
|
||||||
config: config,
|
config: config,
|
||||||
store: store,
|
store: store,
|
||||||
|
historyStore: historyStore,
|
||||||
openingService: openingService,
|
openingService: openingService,
|
||||||
feeEstimator: feeEstimator,
|
feeEstimator: feeEstimator,
|
||||||
feeStrategy: feeStrategy,
|
feeStrategy: feeStrategy,
|
||||||
@@ -238,6 +245,19 @@ func (i *Interceptor) Intercept(req common.InterceptRequest) common.InterceptRes
|
|||||||
scid = chanResult.ConfirmedScid
|
scid = chanResult.ConfirmedScid
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = i.historyStore.UpdateChannels(context.TODO(), []*history.ChannelUpdate{{
|
||||||
|
NodeID: i.nodeid,
|
||||||
|
PeerId: destination,
|
||||||
|
AliasScid: chanResult.AliasScid,
|
||||||
|
ConfirmedScid: chanResult.ConfirmedScid,
|
||||||
|
ChannelPoint: channelPoint,
|
||||||
|
LastUpdate: time.Now(),
|
||||||
|
}})
|
||||||
|
if err != nil {
|
||||||
|
// Don't break here, this is not critical.
|
||||||
|
log.Printf("paymentHash: %s, failed to insert newly opened channel in history store. %v", reqPaymentHashStr, channelPoint.String())
|
||||||
|
}
|
||||||
|
|
||||||
useLegacyOnionBlob := slices.Contains(i.config.LegacyOnionTokens, token)
|
useLegacyOnionBlob := slices.Contains(i.config.LegacyOnionTokens, token)
|
||||||
return common.InterceptResult{
|
return common.InterceptResult{
|
||||||
Action: common.INTERCEPT_RESUME_WITH_ONION,
|
Action: common.INTERCEPT_RESUME_WITH_ONION,
|
||||||
|
|||||||
@@ -10,12 +10,14 @@ import (
|
|||||||
|
|
||||||
"github.com/breez/lspd/chain"
|
"github.com/breez/lspd/chain"
|
||||||
"github.com/breez/lspd/common"
|
"github.com/breez/lspd/common"
|
||||||
|
"github.com/breez/lspd/history"
|
||||||
"github.com/breez/lspd/lightning"
|
"github.com/breez/lspd/lightning"
|
||||||
"github.com/breez/lspd/lsps0"
|
"github.com/breez/lspd/lsps0"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
type InterceptorConfig struct {
|
type InterceptorConfig struct {
|
||||||
|
NodeId []byte
|
||||||
AdditionalChannelCapacitySat uint64
|
AdditionalChannelCapacitySat uint64
|
||||||
MinConfs *uint32
|
MinConfs *uint32
|
||||||
TargetConf uint32
|
TargetConf uint32
|
||||||
@@ -29,6 +31,7 @@ type InterceptorConfig struct {
|
|||||||
|
|
||||||
type Interceptor struct {
|
type Interceptor struct {
|
||||||
store Lsps2Store
|
store Lsps2Store
|
||||||
|
historyStore history.Store
|
||||||
openingService common.OpeningService
|
openingService common.OpeningService
|
||||||
client lightning.Client
|
client lightning.Client
|
||||||
feeEstimator chain.FeeEstimator
|
feeEstimator chain.FeeEstimator
|
||||||
@@ -43,6 +46,7 @@ type Interceptor struct {
|
|||||||
|
|
||||||
func NewInterceptHandler(
|
func NewInterceptHandler(
|
||||||
store Lsps2Store,
|
store Lsps2Store,
|
||||||
|
historyStore history.Store,
|
||||||
openingService common.OpeningService,
|
openingService common.OpeningService,
|
||||||
client lightning.Client,
|
client lightning.Client,
|
||||||
feeEstimator chain.FeeEstimator,
|
feeEstimator chain.FeeEstimator,
|
||||||
@@ -54,6 +58,7 @@ func NewInterceptHandler(
|
|||||||
|
|
||||||
return &Interceptor{
|
return &Interceptor{
|
||||||
store: store,
|
store: store,
|
||||||
|
historyStore: historyStore,
|
||||||
openingService: openingService,
|
openingService: openingService,
|
||||||
client: client,
|
client: client,
|
||||||
feeEstimator: feeEstimator,
|
feeEstimator: feeEstimator,
|
||||||
@@ -532,6 +537,19 @@ func (i *Interceptor) ensureChannelOpen(payment *paymentState) {
|
|||||||
scid = chanResult.ConfirmedScid
|
scid = chanResult.ConfirmedScid
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err := i.historyStore.UpdateChannels(context.TODO(), []*history.ChannelUpdate{{
|
||||||
|
NodeID: i.config.NodeId,
|
||||||
|
PeerId: destination,
|
||||||
|
AliasScid: chanResult.AliasScid,
|
||||||
|
ConfirmedScid: chanResult.ConfirmedScid,
|
||||||
|
ChannelPoint: payment.registration.ChannelPoint,
|
||||||
|
LastUpdate: time.Now(),
|
||||||
|
}})
|
||||||
|
if err != nil {
|
||||||
|
// Don't break here, this is not critical.
|
||||||
|
log.Printf("failed to insert newly opened channel in history store. %v", payment.registration.ChannelPoint.String())
|
||||||
|
}
|
||||||
|
|
||||||
i.paymentChanOpened <- &paymentChanOpenedEvent{
|
i.paymentChanOpened <- &paymentChanOpenedEvent{
|
||||||
paymentId: payment.id,
|
paymentId: payment.id,
|
||||||
scid: *scid,
|
scid: *scid,
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ func setupInterceptor(
|
|||||||
openingService = defaultopeningService()
|
openingService = defaultopeningService()
|
||||||
}
|
}
|
||||||
|
|
||||||
i := NewInterceptHandler(store, openingService, client, f, config)
|
i := NewInterceptHandler(store, &mockHistoryStore{}, openingService, client, f, config)
|
||||||
go i.Start(ctx)
|
go i.Start(ctx)
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/GoWebProd/uuid7"
|
"github.com/GoWebProd/uuid7"
|
||||||
"github.com/breez/lspd/chain"
|
"github.com/breez/lspd/chain"
|
||||||
"github.com/breez/lspd/common"
|
"github.com/breez/lspd/common"
|
||||||
|
"github.com/breez/lspd/history"
|
||||||
"github.com/breez/lspd/lightning"
|
"github.com/breez/lspd/lightning"
|
||||||
"github.com/btcsuite/btcd/btcec/v2"
|
"github.com/btcsuite/btcd/btcec/v2"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
@@ -96,6 +97,12 @@ func (s *mockLsps2Store) RemoveUnusedExpired(ctx context.Context, before time.Ti
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type mockHistoryStore struct{}
|
||||||
|
|
||||||
|
func (s *mockHistoryStore) UpdateChannels(ctx context.Context, updates []*history.ChannelUpdate) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
type mockLightningClient struct {
|
type mockLightningClient struct {
|
||||||
openResponses []*wire.OutPoint
|
openResponses []*wire.OutPoint
|
||||||
openRequests []*lightning.OpenChannelRequest
|
openRequests []*lightning.OpenChannelRequest
|
||||||
|
|||||||
7
main.go
7
main.go
@@ -130,7 +130,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
client.StartListeners()
|
client.StartListeners()
|
||||||
interceptor := interceptor.NewInterceptHandler(client, node.NodeConfig, interceptStore, openingService, feeEstimator, feeStrategy, notificationService)
|
interceptor := interceptor.NewInterceptHandler(client, node.NodeConfig, interceptStore, historyStore, openingService, feeEstimator, feeStrategy, notificationService)
|
||||||
htlcInterceptor, err = lnd.NewLndHtlcInterceptor(node.NodeConfig, client, interceptor)
|
htlcInterceptor, err = lnd.NewLndHtlcInterceptor(node.NodeConfig, client, interceptor)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("failed to initialize LND interceptor: %v", err)
|
log.Fatalf("failed to initialize LND interceptor: %v", err)
|
||||||
@@ -143,8 +143,9 @@ func main() {
|
|||||||
log.Fatalf("failed to initialize CLN client: %v", err)
|
log.Fatalf("failed to initialize CLN client: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
legacyHandler := interceptor.NewInterceptHandler(client, node.NodeConfig, interceptStore, openingService, feeEstimator, feeStrategy, notificationService)
|
legacyHandler := interceptor.NewInterceptHandler(client, node.NodeConfig, interceptStore, historyStore, openingService, feeEstimator, feeStrategy, notificationService)
|
||||||
lsps2Handler := lsps2.NewInterceptHandler(lsps2Store, openingService, client, feeEstimator, &lsps2.InterceptorConfig{
|
lsps2Handler := lsps2.NewInterceptHandler(lsps2Store, historyStore, openingService, client, feeEstimator, &lsps2.InterceptorConfig{
|
||||||
|
NodeId: node.NodeId,
|
||||||
AdditionalChannelCapacitySat: uint64(node.NodeConfig.AdditionalChannelCapacity),
|
AdditionalChannelCapacitySat: uint64(node.NodeConfig.AdditionalChannelCapacity),
|
||||||
MinConfs: node.NodeConfig.MinConfs,
|
MinConfs: node.NodeConfig.MinConfs,
|
||||||
TargetConf: node.NodeConfig.TargetConf,
|
TargetConf: node.NodeConfig.TargetConf,
|
||||||
|
|||||||
Reference in New Issue
Block a user