insert channel directly after opening

This commit is contained in:
Jesse de Wit
2023-12-29 11:40:24 +01:00
parent 03a1708a1e
commit 9cd61585c2
5 changed files with 50 additions and 4 deletions

View File

@@ -11,6 +11,7 @@ import (
"github.com/breez/lspd/chain"
"github.com/breez/lspd/common"
"github.com/breez/lspd/config"
"github.com/breez/lspd/history"
"github.com/breez/lspd/lightning"
"github.com/breez/lspd/lsps0"
"github.com/breez/lspd/notifications"
@@ -20,9 +21,11 @@ import (
)
type Interceptor struct {
nodeid []byte
client lightning.Client
config *config.NodeConfig
store InterceptStore
historyStore history.Store
openingService common.OpeningService
feeEstimator chain.FeeEstimator
feeStrategy chain.FeeStrategy
@@ -34,15 +37,19 @@ func NewInterceptHandler(
client lightning.Client,
config *config.NodeConfig,
store InterceptStore,
historyStore history.Store,
openingService common.OpeningService,
feeEstimator chain.FeeEstimator,
feeStrategy chain.FeeStrategy,
notificationService *notifications.NotificationService,
) *Interceptor {
nodeid, _ := hex.DecodeString(config.NodePubkey)
return &Interceptor{
nodeid: nodeid,
client: client,
config: config,
store: store,
historyStore: historyStore,
openingService: openingService,
feeEstimator: feeEstimator,
feeStrategy: feeStrategy,
@@ -238,6 +245,19 @@ func (i *Interceptor) Intercept(req common.InterceptRequest) common.InterceptRes
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)
return common.InterceptResult{
Action: common.INTERCEPT_RESUME_WITH_ONION,