Skip to content

Commit

Permalink
fix: attempt to fix LDK deadlock on bump transaction on double-spent …
Browse files Browse the repository at this point in the history
…utxo

- update ldk-node-go dependency (decreased esplora timeout, use separate esplora clients)
- do not do unnecessary fee estimates sync before full sync
- only update fee estimates every 5 minutes instead of once per minute
  • Loading branch information
rolznz committed Aug 15, 2024
1 parent f232eba commit 0a9197e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 24 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
54 changes: 33 additions & 21 deletions lnclient/ldk/ldk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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()

Expand All @@ -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,
Expand Down

0 comments on commit 0a9197e

Please sign in to comment.