diff --git a/go.mod b/go.mod index ebd16acc..c8dcdd62 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/breez/breez-sdk-go v0.3.4 github.com/elnosh/gonuts v0.1.1-0.20240602162005-49da741613e4 github.com/getAlby/glalby-go v0.0.0-20240621192717-95673c864d59 - github.com/getAlby/ldk-node-go v0.0.0-20240809074758-18af265ac44a + github.com/getAlby/ldk-node-go v0.0.0-20240814182444-37f58362f832 github.com/go-gormigrate/gormigrate/v2 v2.1.2 github.com/labstack/echo/v4 v4.12.0 github.com/nbd-wtf/go-nostr v0.34.5 diff --git a/go.sum b/go.sum index 5ea9b44c..d05c4f01 100644 --- a/go.sum +++ b/go.sum @@ -187,8 +187,8 @@ github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwV github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= github.com/getAlby/glalby-go v0.0.0-20240621192717-95673c864d59 h1:fSqdXE9uKhLcOOQaLtzN+D8RN3oEcZQkGX5E8PyiKy0= github.com/getAlby/glalby-go v0.0.0-20240621192717-95673c864d59/go.mod h1:ViyJvjlvv0GCesTJ7mb3fBo4G+/qsujDAFN90xZ7a9U= -github.com/getAlby/ldk-node-go v0.0.0-20240809074758-18af265ac44a h1:wmBI8Rak++XGKSKYJZEnhJpQV/pMu+FlUaEWoUI9XpU= -github.com/getAlby/ldk-node-go v0.0.0-20240809074758-18af265ac44a/go.mod h1:8BRjtKcz8E0RyYTPEbMS8VIdgredcGSLne8vHDtcRLg= +github.com/getAlby/ldk-node-go v0.0.0-20240814182444-37f58362f832 h1:9rGL1k3aeEs8QIyviZ1K5WoAqzoFCZNA8Ad1g9ZAWmg= +github.com/getAlby/ldk-node-go v0.0.0-20240814182444-37f58362f832/go.mod h1:8BRjtKcz8E0RyYTPEbMS8VIdgredcGSLne8vHDtcRLg= github.com/getsentry/raven-go v0.2.0 h1:no+xWJRb5ZI7eE8TWgIq1jLulQiIoLG0IfYxv5JYMGs= github.com/getsentry/raven-go v0.2.0/go.mod h1:KungGk8q33+aIAZUIVWZDr2OfAEBsO49PX4NzFV5kcQ= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= diff --git a/lnclient/ldk/ldk.go b/lnclient/ldk/ldk.go index a08d5127..6f94773d 100644 --- a/lnclient/ldk/ldk.go +++ b/lnclient/ldk/ldk.go @@ -39,7 +39,8 @@ type LDKService struct { network string eventPublisher events.EventPublisher syncing bool - lastSync time.Time + lastFullSync time.Time + lastFeeEstimatesSync time.Time cfg config.Config lastWalletSyncRequest time.Time pubkey string @@ -213,7 +214,8 @@ func NewLDKService(ctx context.Context, cfg config.Config, eventPublisher events return nil, err } - ls.lastSync = time.Now() + ls.lastFullSync = time.Now() + ls.lastFeeEstimatesSync = time.Now() logger.Logger.WithFields(logrus.Fields{ "nodeId": nodeId, @@ -254,6 +256,7 @@ func NewLDKService(ctx context.Context, cfg config.Config, eventPublisher events // setup background sync go func() { MIN_SYNC_INTERVAL := 1 * time.Minute + MIN_FEE_ESTIMATES_SYNC_INTERVAL := 5 * time.Minute MAX_SYNC_INTERVAL := 1 * time.Hour // NOTE: this could be increased further (possibly to 6 hours) for { ls.syncing = false @@ -262,28 +265,35 @@ func NewLDKService(ctx context.Context, cfg config.Config, eventPublisher events return case <-time.After(MIN_SYNC_INTERVAL): ls.syncing = true - // always update fee rates to avoid differences in fee rates with channel partners - logger.Logger.Debug("Updating fee estimates") - err = node.UpdateFeeEstimates() - if err != nil { - logger.Logger.WithError(err).Error("Failed to update fee estimates") - ls.eventPublisher.Publish(&events.Event{ - Event: "nwc_node_sync_failed", - Properties: map[string]interface{}{ - "error": err.Error(), - "sync_type": "fee_estimates", - "node_type": config.LDKBackendType, - "esplora_url": ls.cfg.GetEnv().LDKEsploraServer, - }, - }) - } - if time.Since(ls.lastWalletSyncRequest) > MIN_SYNC_INTERVAL && time.Since(ls.lastSync) < MAX_SYNC_INTERVAL { - // logger.Debug("skipping background wallet sync") + if time.Since(ls.lastWalletSyncRequest) > MIN_SYNC_INTERVAL && time.Since(ls.lastFullSync) < MAX_SYNC_INTERVAL { + + if time.Since(ls.lastFeeEstimatesSync) < MIN_FEE_ESTIMATES_SYNC_INTERVAL { + logger.Logger.Debug("Skipping updating fee estimates") + continue + } + + // only update fee estimates + logger.Logger.Debug("Updating fee estimates") + err = node.UpdateFeeEstimates() + if err != nil { + logger.Logger.WithError(err).Error("Failed to update fee estimates") + ls.eventPublisher.Publish(&events.Event{ + Event: "nwc_node_sync_failed", + Properties: map[string]interface{}{ + "error": err.Error(), + "sync_type": "fee_estimates", + "node_type": config.LDKBackendType, + "esplora_url": ls.cfg.GetEnv().LDKEsploraServer, + }, + }) + continue + } + ls.lastFeeEstimatesSync = time.Now() continue } - logger.Logger.Debug("Starting background wallet sync") + logger.Logger.Debug("Starting full background wallet sync") syncStartTime := time.Now() err = node.SyncWallets() @@ -303,7 +313,9 @@ func NewLDKService(ctx context.Context, cfg config.Config, eventPublisher events continue } - ls.lastSync = time.Now() + ls.lastFullSync = time.Now() + // fee estimates happens as part of full sync + ls.lastFeeEstimatesSync = time.Now() logger.Logger.WithFields(logrus.Fields{ "nodeId": nodeId,