mirror of
https://github.com/getAlby/hub.git
synced 2026-08-13 12:33:39 +02:00
fix: slow app deletion due to unnecessary key derivation (#2342)
* fix: slow app deletion due to unnecessary key derivation * chore: fix comment grammar Co-authored-by: Adithya Vardhan <imadithyavardhan@gmail.com> --------- Co-authored-by: Adithya Vardhan <imadithyavardhan@gmail.com>
This commit is contained in:
parent
55d665db74
commit
a0d3da2803
4 changed files with 32 additions and 27 deletions
|
|
@ -184,11 +184,17 @@ func (svc *appsService) DeleteApp(app *db.App) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
walletPubkey := ""
|
||||
if app.WalletPubkey != nil {
|
||||
// only exists for non-legacy apps
|
||||
walletPubkey = *app.WalletPubkey
|
||||
}
|
||||
svc.eventPublisher.Publish(&events.Event{
|
||||
Event: "nwc_app_deleted",
|
||||
Properties: map[string]interface{}{
|
||||
"name": app.Name,
|
||||
"id": app.ID,
|
||||
"name": app.Name,
|
||||
"id": app.ID,
|
||||
"walletPubkey": walletPubkey,
|
||||
},
|
||||
})
|
||||
return nil
|
||||
|
|
|
|||
2
go.mod
2
go.mod
|
|
@ -7,7 +7,7 @@ require (
|
|||
github.com/btcsuite/btcd v0.24.3-0.20250318170759-4f4ea81776d6
|
||||
github.com/btcsuite/btcd/btcutil v1.1.6
|
||||
github.com/elnosh/gonuts v0.4.2
|
||||
github.com/getAlby/go-nostr v0.0.0-20260509070347-31e205cac904
|
||||
github.com/getAlby/go-nostr v0.0.0-20260513161014-22fb7840c7a4
|
||||
github.com/getAlby/ldk-node-go v0.0.0-20260424111754-3690cdb3031c
|
||||
github.com/go-gormigrate/gormigrate/v2 v2.1.5
|
||||
github.com/google/uuid v1.6.0
|
||||
|
|
|
|||
4
go.sum
4
go.sum
|
|
@ -189,8 +189,8 @@ github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S
|
|||
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
|
||||
github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E=
|
||||
github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ=
|
||||
github.com/getAlby/go-nostr v0.0.0-20260509070347-31e205cac904 h1:UvdEf2rj3EXGR/HkMz3eZI9x1hBdSSlTLutyIHLYy8o=
|
||||
github.com/getAlby/go-nostr v0.0.0-20260509070347-31e205cac904/go.mod h1:BtlkV9evCTjpY0YeFhoNgycp7XNFbnfVXJPoykp+NtM=
|
||||
github.com/getAlby/go-nostr v0.0.0-20260513161014-22fb7840c7a4 h1:Z93wPXKIMY4Emr+zDz0R0NrSg1FEVGrzcqqomuSrmko=
|
||||
github.com/getAlby/go-nostr v0.0.0-20260513161014-22fb7840c7a4/go.mod h1:BtlkV9evCTjpY0YeFhoNgycp7XNFbnfVXJPoykp+NtM=
|
||||
github.com/getAlby/ldk-node-go v0.0.0-20260424111754-3690cdb3031c h1:ikai5+taiPSgbaocdVMdxPkmOhnXs5V/gCX+J/P8iRw=
|
||||
github.com/getAlby/ldk-node-go v0.0.0-20260424111754-3690cdb3031c/go.mod h1:8BRjtKcz8E0RyYTPEbMS8VIdgredcGSLne8vHDtcRLg=
|
||||
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
||||
|
|
|
|||
|
|
@ -27,43 +27,42 @@ func (s *deleteAppConsumer) ConsumeEvent(ctx context.Context, event *events.Even
|
|||
logger.Logger.WithField("event", event).Error("Failed to cast event.Properties to map")
|
||||
return
|
||||
}
|
||||
// Note: for legacy apps the deleted app's WalletPubkey is empty and will
|
||||
// not match the master key used for the legacy app subscription, so the
|
||||
// subscription is preserved for any remaining legacy apps.
|
||||
walletPubKey, _ := properties["walletPubkey"].(string)
|
||||
if walletPubKey == "" || walletPubKey != s.walletPubkey {
|
||||
return
|
||||
}
|
||||
id, ok := properties["id"].(uint)
|
||||
if !ok {
|
||||
logger.Logger.WithField("event", event).Error("missing id in properties event")
|
||||
return
|
||||
}
|
||||
|
||||
// no longer need to listen to events for this wallet
|
||||
s.cancelSubscription()
|
||||
|
||||
// remove this consumer as subscriber in eventPublisher
|
||||
s.svc.eventPublisher.RemoveSubscriber(s)
|
||||
|
||||
walletPrivKey, err := s.svc.keys.GetAppWalletKey(id)
|
||||
if err != nil {
|
||||
logger.Logger.WithError(err).WithField("id", id).Error("Failed to calculate app wallet priv key")
|
||||
return
|
||||
}
|
||||
walletPubKey, err := nostr.GetPublicKey(walletPrivKey)
|
||||
|
||||
// try to delete info event from relays (non-critical if it fails)
|
||||
// get nip47 event info for this app wallet key
|
||||
nip47InfoEvent, err := s.svc.GetNip47Service().GetNip47Info(ctx, s.pool, s.walletPubkey)
|
||||
if err != nil {
|
||||
logger.Logger.WithError(err).WithField("id", id).Error("Failed to calculate app wallet pub key")
|
||||
logger.Logger.WithError(err).Error("Could not get nip47 info event")
|
||||
return
|
||||
}
|
||||
// Note: for legacy apps this check will always return false as the wallet pubkey
|
||||
// generated by the id will not match the master key which is used for all legacy apps
|
||||
if s.walletPubkey == walletPubKey {
|
||||
// no longer need to listen to events for this wallet
|
||||
s.cancelSubscription()
|
||||
|
||||
// remove this consumer as subscriber in eventPublisher
|
||||
s.svc.eventPublisher.RemoveSubscriber(s)
|
||||
|
||||
// try to delete info event from relays (non-critical if it fails)
|
||||
// get nip47 event info for this app wallet key
|
||||
nip47InfoEvent, err := s.svc.GetNip47Service().GetNip47Info(ctx, s.pool, s.walletPubkey)
|
||||
if nip47InfoEvent != nil {
|
||||
err = s.svc.nip47Service.PublishNip47InfoDeletion(ctx, s.pool, walletPubKey, walletPrivKey, nip47InfoEvent.ID)
|
||||
if err != nil {
|
||||
logger.Logger.WithError(err).Error("Could not get nip47 info event")
|
||||
return
|
||||
}
|
||||
if nip47InfoEvent != nil {
|
||||
err = s.svc.nip47Service.PublishNip47InfoDeletion(ctx, s.pool, walletPubKey, walletPrivKey, nip47InfoEvent.ID)
|
||||
if err != nil {
|
||||
logger.Logger.WithError(err).WithField("event", event).Error("Failed to publish nip47 info deletion")
|
||||
}
|
||||
logger.Logger.WithError(err).WithField("event", event).Error("Failed to publish nip47 info deletion")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue