From f2984149cff7928007148a4fe6a6974ca4171dcb Mon Sep 17 00:00:00 2001 From: Roland Bewick Date: Fri, 5 Jan 2024 12:41:31 +0700 Subject: [PATCH 01/16] fix: make timestamps numbers to follow NIP-47 --- alby.go | 18 +++++++++++++++--- lnd.go | 31 +++++++++++++++---------------- models.go | 6 +++--- service_test.go | 7 ++++--- 4 files changed, 37 insertions(+), 25 deletions(-) diff --git a/alby.go b/alby.go index 7a0e0f9d..65205486 100644 --- a/alby.go +++ b/alby.go @@ -709,6 +709,18 @@ func albyInvoiceToTransaction(invoice *AlbyInvoice) *Nip47Transaction { preimage = invoice.Preimage } + var expiresAt *int64 + if invoice.ExpiresAt != nil { + expiresAtUnix := invoice.ExpiresAt.Unix() + expiresAt = &expiresAtUnix + } + + var settledAt *int64 + if invoice.SettledAt != nil { + settledAtUnix := invoice.SettledAt.Unix() + settledAt = &settledAtUnix + } + return &Nip47Transaction{ Type: invoice.Type, Invoice: invoice.PaymentRequest, @@ -718,9 +730,9 @@ func albyInvoiceToTransaction(invoice *AlbyInvoice) *Nip47Transaction { PaymentHash: invoice.PaymentHash, Amount: invoice.Amount * 1000, FeesPaid: 0, // TODO: support fees - CreatedAt: invoice.CreatedAt, - ExpiresAt: invoice.ExpiresAt, - SettledAt: invoice.SettledAt, + CreatedAt: invoice.CreatedAt.Unix(), + ExpiresAt: expiresAt, + SettledAt: settledAt, Metadata: invoice.Metadata, } } diff --git a/lnd.go b/lnd.go index 82342c1c..06ab998d 100644 --- a/lnd.go +++ b/lnd.go @@ -7,8 +7,8 @@ import ( "encoding/hex" "errors" "sort" - "time" "strings" + "time" "github.com/getAlby/nostr-wallet-connect/lnd" decodepay "github.com/nbd-wtf/ln-decodepay" @@ -96,7 +96,7 @@ func (svc *LNDService) ListTransactions(ctx context.Context, senderPubkey string continue } var paymentRequest decodepay.Bolt11 - var expiresAt *time.Time + var expiresAt *int64 var description string var descriptionHash string if payment.PaymentRequest != "" { @@ -108,17 +108,17 @@ func (svc *LNDService) ListTransactions(ctx context.Context, senderPubkey string return nil, err } - expiresAt = &time.Time{} - *expiresAt = time.UnixMilli(int64(paymentRequest.CreatedAt) * 1000).Add(time.Duration(paymentRequest.Expiry) * time.Second) + expiresAtUnix := time.UnixMilli(int64(paymentRequest.CreatedAt) * 1000).Add(time.Duration(paymentRequest.Expiry) * time.Second).Unix() + expiresAt = &expiresAtUnix description = paymentRequest.Description descriptionHash = paymentRequest.DescriptionHash } - var settledAt *time.Time + var settledAt *int64 if payment.Status == lnrpc.Payment_SUCCEEDED { // FIXME: how to get the actual settled at time? - settledAt = &time.Time{} - *settledAt = time.Unix(0, payment.CreationTimeNs) + settledAtUnix := time.Unix(0, payment.CreationTimeNs).Unix() + settledAt = &settledAtUnix } transaction := Nip47Transaction{ @@ -128,7 +128,7 @@ func (svc *LNDService) ListTransactions(ctx context.Context, senderPubkey string PaymentHash: payment.PaymentHash, Amount: payment.ValueMsat, FeesPaid: payment.FeeMsat, - CreatedAt: time.Unix(0, payment.CreationTimeNs), + CreatedAt: time.Unix(0, payment.CreationTimeNs).Unix(), Description: description, DescriptionHash: descriptionHash, ExpiresAt: expiresAt, @@ -140,7 +140,7 @@ func (svc *LNDService) ListTransactions(ctx context.Context, senderPubkey string // sort by created date descending sort.SliceStable(transactions, func(i, j int) bool { - return transactions[i].CreatedAt.After(transactions[j].CreatedAt) + return transactions[i].CreatedAt > transactions[j].CreatedAt }) return transactions, nil @@ -357,18 +357,17 @@ func NewLNDService(ctx context.Context, svc *Service, e *echo.Echo) (result *LND } func lndInvoiceToTransaction(invoice *lnrpc.Invoice) *Nip47Transaction { - var settledAt *time.Time + var settledAt *int64 var preimage string if invoice.State == lnrpc.Invoice_SETTLED { - settledAt = &time.Time{} - *settledAt = time.Unix(invoice.SettleDate, 0) + settledAt = &invoice.SettleDate // only set preimage if invoice is settled preimage = hex.EncodeToString(invoice.RPreimage) } - var expiresAt *time.Time + var expiresAt *int64 if invoice.Expiry > 0 { - expiresAt = &time.Time{} - *expiresAt = time.Unix(invoice.SettleDate, 0) + expiresAtUnix := invoice.CreationDate + invoice.Expiry + expiresAt = &expiresAtUnix } return &Nip47Transaction{ @@ -380,7 +379,7 @@ func lndInvoiceToTransaction(invoice *lnrpc.Invoice) *Nip47Transaction { PaymentHash: hex.EncodeToString(invoice.RHash), Amount: invoice.ValueMsat, FeesPaid: invoice.AmtPaidMsat, - CreatedAt: time.Unix(invoice.CreationDate, 0), + CreatedAt: invoice.CreationDate, SettledAt: settledAt, ExpiresAt: expiresAt, // TODO: Metadata (e.g. keysend) diff --git a/models.go b/models.go index 4f56a251..f7ad3c42 100644 --- a/models.go +++ b/models.go @@ -135,9 +135,9 @@ type Nip47Transaction struct { PaymentHash string `json:"payment_hash"` Amount int64 `json:"amount"` FeesPaid int64 `json:"fees_paid"` - CreatedAt time.Time `json:"created_at"` - ExpiresAt *time.Time `json:"expires_at"` - SettledAt *time.Time `json:"settled_at"` + CreatedAt int64 `json:"created_at"` + ExpiresAt *int64 `json:"expires_at"` + SettledAt *int64 `json:"settled_at"` Metadata interface{} `json:"metadata,omitempty"` } diff --git a/service_test.go b/service_test.go index fecefee3..8cc49e45 100644 --- a/service_test.go +++ b/service_test.go @@ -111,6 +111,7 @@ var mockNodeInfo = NodeInfo{ } var mockTime = time.Unix(1693876963, 0) +var mockTimeUnix = mockTime.Unix() var mockTransactions = []Nip47Transaction{ { @@ -122,7 +123,7 @@ var mockTransactions = []Nip47Transaction{ PaymentHash: "payment_hash_1", Amount: 1000, FeesPaid: 50, - SettledAt: &mockTime, + SettledAt: &mockTimeUnix, Metadata: map[string]interface{}{ "key1": "value1", "key2": 42, @@ -137,7 +138,7 @@ var mockTransactions = []Nip47Transaction{ PaymentHash: "payment_hash_2", Amount: 2000, FeesPaid: 75, - SettledAt: &mockTime, + SettledAt: &mockTimeUnix, }, } var mockTransaction = &mockTransactions[0] @@ -571,7 +572,7 @@ func TestHandleEvent(t *testing.T) { assert.Equal(t, mockTransactions[0].PaymentHash, transaction.PaymentHash) assert.Equal(t, mockTransactions[0].Amount, transaction.Amount) assert.Equal(t, mockTransactions[0].FeesPaid, transaction.FeesPaid) - assert.Equal(t, mockTransactions[0].SettledAt.Unix(), transaction.SettledAt.Unix()) + assert.Equal(t, mockTransactions[0].SettledAt, transaction.SettledAt) // get_info: without permission newPayload, err = nip04.Encrypt(nip47GetInfoJson, ss) From d0b270d8783e44411c06d87bd4bc257f02e4006e Mon Sep 17 00:00:00 2001 From: Roland Bewick Date: Fri, 5 Jan 2024 15:25:19 +0700 Subject: [PATCH 02/16] fix: remove infinite loop in subscription causing high cpu --- service.go | 144 ++++++++++++++++++++++++++--------------------------- 1 file changed, 72 insertions(+), 72 deletions(-) diff --git a/service.go b/service.go index f6def421..871d9966 100644 --- a/service.go +++ b/service.go @@ -54,87 +54,87 @@ func (svc *Service) GetUser(c echo.Context) (user *User, err error) { } func (svc *Service) StartSubscription(ctx context.Context, sub *nostr.Subscription) error { - for { - if sub.Relay.ConnectionError != nil { - return sub.Relay.ConnectionError - } - select { - case <-ctx.Done(): - svc.Logger.Info("Exiting subscription.") - return nil - case <-sub.EndOfStoredEvents: - if !svc.ReceivedEOS { - svc.Logger.Info("Received EOS") + go func() { + <-sub.EndOfStoredEvents + svc.ReceivedEOS = true + svc.Logger.Info("Received EOS") + }() + + go func() { + for event := range sub.Events { + resp, err := svc.HandleEvent(ctx, event) + if err != nil { + svc.Logger.WithFields(logrus.Fields{ + "eventId": event.ID, + "eventKind": event.Kind, + }).Errorf("Failed to process event: %v", err) } - svc.ReceivedEOS = true - case event := <-sub.Events: - go func() { - resp, err := svc.HandleEvent(ctx, event) + if resp != nil { + status, err := sub.Relay.Publish(ctx, *resp) if err != nil { svc.Logger.WithFields(logrus.Fields{ - "eventId": event.ID, - "eventKind": event.Kind, - }).Errorf("Failed to process event: %v", err) + "eventId": event.ID, + "status": status, + "replyEventId": resp.ID, + }).Errorf("Failed to publish reply: %v", err) + return } - if resp != nil { - status, err := sub.Relay.Publish(ctx, *resp) - if err != nil { - svc.Logger.WithFields(logrus.Fields{ - "eventId": event.ID, - "status": status, - "replyEventId": resp.ID, - }).Errorf("Failed to publish reply: %v", err) - return - } - nostrEvent := NostrEvent{} - result := svc.db.Where("nostr_id = ?", event.ID).First(&nostrEvent) - if result.Error != nil { - svc.Logger.WithFields(logrus.Fields{ - "eventId": event.ID, - "status": status, - "replyEventId": resp.ID, - }).Error(result.Error) - return - } - nostrEvent.ReplyId = resp.ID + nostrEvent := NostrEvent{} + result := svc.db.Where("nostr_id = ?", event.ID).First(&nostrEvent) + if result.Error != nil { + svc.Logger.WithFields(logrus.Fields{ + "eventId": event.ID, + "status": status, + "replyEventId": resp.ID, + }).Error(result.Error) + return + } + nostrEvent.ReplyId = resp.ID - if status == nostr.PublishStatusSucceeded { - nostrEvent.State = NOSTR_EVENT_STATE_PUBLISH_CONFIRMED - nostrEvent.RepliedAt = time.Now() - svc.db.Save(&nostrEvent) - svc.Logger.WithFields(logrus.Fields{ - "nostrEventId": nostrEvent.ID, - "eventId": event.ID, - "status": status, - "replyEventId": resp.ID, - "appId": nostrEvent.AppId, - }).Info("Published reply") - } else if status == nostr.PublishStatusFailed { - nostrEvent.State = NOSTR_EVENT_STATE_PUBLISH_FAILED - svc.db.Save(&nostrEvent) - svc.Logger.WithFields(logrus.Fields{ - "nostrEventId": nostrEvent.ID, - "eventId": event.ID, - "status": status, - "replyEventId": resp.ID, - "appId": nostrEvent.AppId, - }).Info("Failed to publish reply") - } else { - nostrEvent.State = NOSTR_EVENT_STATE_PUBLISH_UNCONFIRMED - svc.db.Save(&nostrEvent) - svc.Logger.WithFields(logrus.Fields{ - "nostrEventId": nostrEvent.ID, - "eventId": event.ID, - "status": status, - "replyEventId": resp.ID, - "appId": nostrEvent.AppId, - }).Info("Reply sent but no response from relay (timeout)") - } + if status == nostr.PublishStatusSucceeded { + nostrEvent.State = NOSTR_EVENT_STATE_PUBLISH_CONFIRMED + nostrEvent.RepliedAt = time.Now() + svc.db.Save(&nostrEvent) + svc.Logger.WithFields(logrus.Fields{ + "nostrEventId": nostrEvent.ID, + "eventId": event.ID, + "status": status, + "replyEventId": resp.ID, + "appId": nostrEvent.AppId, + }).Info("Published reply") + } else if status == nostr.PublishStatusFailed { + nostrEvent.State = NOSTR_EVENT_STATE_PUBLISH_FAILED + svc.db.Save(&nostrEvent) + svc.Logger.WithFields(logrus.Fields{ + "nostrEventId": nostrEvent.ID, + "eventId": event.ID, + "status": status, + "replyEventId": resp.ID, + "appId": nostrEvent.AppId, + }).Info("Failed to publish reply") + } else { + nostrEvent.State = NOSTR_EVENT_STATE_PUBLISH_UNCONFIRMED + svc.db.Save(&nostrEvent) + svc.Logger.WithFields(logrus.Fields{ + "nostrEventId": nostrEvent.ID, + "eventId": event.ID, + "status": status, + "replyEventId": resp.ID, + "appId": nostrEvent.AppId, + }).Info("Reply sent but no response from relay (timeout)") } - }() + } } + }() + + <-ctx.Done() + if ctx.Err() != context.Canceled { + svc.Logger.Errorf("Subscription error %v", ctx.Err()) + return ctx.Err() } + svc.Logger.Info("Exiting subscription.") + return nil } func (svc *Service) HandleEvent(ctx context.Context, event *nostr.Event) (result *nostr.Event, err error) { From dc6a62c0555d67dd71a0e1a946f5809110b3f0f2 Mon Sep 17 00:00:00 2001 From: Roland Bewick Date: Fri, 5 Jan 2024 15:43:32 +0700 Subject: [PATCH 03/16] fix: add check for relay connection error --- service.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/service.go b/service.go index 871d9966..5efa4b1f 100644 --- a/service.go +++ b/service.go @@ -129,6 +129,10 @@ func (svc *Service) StartSubscription(ctx context.Context, sub *nostr.Subscripti }() <-ctx.Done() + if sub.Relay.ConnectionError != nil { + svc.Logger.Errorf("Relay error %v", ctx.Err()) + return sub.Relay.ConnectionError + } if ctx.Err() != context.Canceled { svc.Logger.Errorf("Subscription error %v", ctx.Err()) return ctx.Err() From dd59887a3d8aaf178e4df05c4f68e9716fec7b97 Mon Sep 17 00:00:00 2001 From: Roland Bewick Date: Fri, 5 Jan 2024 19:52:05 +0700 Subject: [PATCH 04/16] fix: listen to relay context done message --- .env.example | 1 + service.go | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.env.example b/.env.example index e0e7c094..5aa2ed4f 100644 --- a/.env.example +++ b/.env.example @@ -2,6 +2,7 @@ DATABASE_URI=file:nwc.db NOSTR_PRIVKEY= COOKIE_SECRET=secretsecret RELAY=wss://relay.getalby.com/v1 +#RELAY=ws://localhost:7447/v1 PUBLIC_RELAY= PORT=8080 diff --git a/service.go b/service.go index 5efa4b1f..8707bdf4 100644 --- a/service.go +++ b/service.go @@ -128,17 +128,18 @@ func (svc *Service) StartSubscription(ctx context.Context, sub *nostr.Subscripti } }() - <-ctx.Done() - if sub.Relay.ConnectionError != nil { - svc.Logger.Errorf("Relay error %v", ctx.Err()) + select { + case <-sub.Relay.Context().Done(): + svc.Logger.Errorf("Relay error %v", sub.Relay.ConnectionError) return sub.Relay.ConnectionError + case <-ctx.Done(): + if ctx.Err() != context.Canceled { + svc.Logger.Errorf("Subscription error %v", ctx.Err()) + return ctx.Err() + } + svc.Logger.Info("Exiting subscription.") + return nil } - if ctx.Err() != context.Canceled { - svc.Logger.Errorf("Subscription error %v", ctx.Err()) - return ctx.Err() - } - svc.Logger.Info("Exiting subscription.") - return nil } func (svc *Service) HandleEvent(ctx context.Context, event *nostr.Event) (result *nostr.Event, err error) { From 5e95d1ea0b0a0377dabb588f084ff6cc8291553b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Aaron?= Date: Tue, 9 Jan 2024 22:31:36 +0000 Subject: [PATCH 05/16] fix: create index on events --- .../202401092201_add_events_id_index.go | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 migrations/202401092201_add_events_id_index.go diff --git a/migrations/202401092201_add_events_id_index.go b/migrations/202401092201_add_events_id_index.go new file mode 100644 index 00000000..21a8842d --- /dev/null +++ b/migrations/202401092201_add_events_id_index.go @@ -0,0 +1,21 @@ +package migrations + +import ( + "github.com/go-gormigrate/gormigrate/v2" + "gorm.io/gorm" +) + +// Create a composite index to improve performance of summing payments in the current budget period +var _202401092201_add_events_id_index = &gormigrate.Migration{ + ID: "202401092201_add_events_id_index", + Migrate: func(tx *gorm.DB) error { + + var sql string + sql = "CREATE INDEX idx_nostr_events_app_id_and_id ON nostr_events(app_id, id)" + + return tx.Exec(sql).Error + }, + Rollback: func(tx *gorm.DB) error { + return nil + }, +} From 6626a480ba71eeb5d855c8ef6e88364d5dd2d65c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Aaron?= Date: Tue, 9 Jan 2024 23:28:13 +0000 Subject: [PATCH 06/16] fix: add migration to migration list --- migrations/migrate.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/migrations/migrate.go b/migrations/migrate.go index a3281a89..771b10ff 100644 --- a/migrations/migrate.go +++ b/migrations/migrate.go @@ -11,7 +11,8 @@ func Migrate(db *gorm.DB) error { _202309271616_initial_migration, _202309271617_fix_preimage_null, _202309271618_add_payment_sum_index, + _202401092201_add_events_id_index, }) return m.Migrate() -} \ No newline at end of file +} From 20e10f5ee6910eaffd9b35d83de7a760898106a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Aaron?= Date: Tue, 9 Jan 2024 23:30:32 +0000 Subject: [PATCH 07/16] fix: sql --- migrations/202401092201_add_events_id_index.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/migrations/202401092201_add_events_id_index.go b/migrations/202401092201_add_events_id_index.go index 21a8842d..8458e107 100644 --- a/migrations/202401092201_add_events_id_index.go +++ b/migrations/202401092201_add_events_id_index.go @@ -9,11 +9,7 @@ import ( var _202401092201_add_events_id_index = &gormigrate.Migration{ ID: "202401092201_add_events_id_index", Migrate: func(tx *gorm.DB) error { - - var sql string - sql = "CREATE INDEX idx_nostr_events_app_id_and_id ON nostr_events(app_id, id)" - - return tx.Exec(sql).Error + return tx.Exec("CREATE INDEX idx_nostr_events_app_id_and_id ON nostr_events(app_id, id)").Error }, Rollback: func(tx *gorm.DB) error { return nil From 11bbaf9ba9a8e2748c3ecc3adc386a74516c734c Mon Sep 17 00:00:00 2001 From: Roland <33993199+rolznz@users.noreply.github.com> Date: Wed, 10 Jan 2024 10:48:40 +0700 Subject: [PATCH 08/16] Update migrations/202401092201_add_events_id_index.go --- migrations/202401092201_add_events_id_index.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrations/202401092201_add_events_id_index.go b/migrations/202401092201_add_events_id_index.go index 8458e107..7b2ef48e 100644 --- a/migrations/202401092201_add_events_id_index.go +++ b/migrations/202401092201_add_events_id_index.go @@ -5,7 +5,7 @@ import ( "gorm.io/gorm" ) -// Create a composite index to improve performance of summing payments in the current budget period +// Create a composite index to improve performance of finding the latest nostr event for an app var _202401092201_add_events_id_index = &gormigrate.Migration{ ID: "202401092201_add_events_id_index", Migrate: func(tx *gorm.DB) error { From 9f0585676bccd6f991f68cf73be9d42e5fbd233c Mon Sep 17 00:00:00 2001 From: Michael Bumann Date: Wed, 10 Jan 2024 10:22:28 +0200 Subject: [PATCH 09/16] Create index only if it does not exist otherwise the migration fails --- migrations/202401092201_add_events_id_index.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrations/202401092201_add_events_id_index.go b/migrations/202401092201_add_events_id_index.go index 7b2ef48e..babb014f 100644 --- a/migrations/202401092201_add_events_id_index.go +++ b/migrations/202401092201_add_events_id_index.go @@ -9,7 +9,7 @@ import ( var _202401092201_add_events_id_index = &gormigrate.Migration{ ID: "202401092201_add_events_id_index", Migrate: func(tx *gorm.DB) error { - return tx.Exec("CREATE INDEX idx_nostr_events_app_id_and_id ON nostr_events(app_id, id)").Error + return tx.Exec("CREATE INDEX IF NOT EXISTS idx_nostr_events_app_id_and_id ON nostr_events(app_id, id)").Error }, Rollback: func(tx *gorm.DB) error { return nil From 2710de942413ae6877be759459b3537a1516789c Mon Sep 17 00:00:00 2001 From: Roland Bewick Date: Wed, 10 Jan 2024 23:27:24 +0700 Subject: [PATCH 10/16] fix: wrap event handling in function --- service.go | 117 +++++++++++++++++++++++++++-------------------------- 1 file changed, 60 insertions(+), 57 deletions(-) diff --git a/service.go b/service.go index 8707bdf4..88ab3441 100644 --- a/service.go +++ b/service.go @@ -62,70 +62,73 @@ func (svc *Service) StartSubscription(ctx context.Context, sub *nostr.Subscripti go func() { for event := range sub.Events { - resp, err := svc.HandleEvent(ctx, event) - if err != nil { - svc.Logger.WithFields(logrus.Fields{ - "eventId": event.ID, - "eventKind": event.Kind, - }).Errorf("Failed to process event: %v", err) - } - if resp != nil { - status, err := sub.Relay.Publish(ctx, *resp) + go func(event *nostr.Event) { + resp, err := svc.HandleEvent(ctx, event) if err != nil { svc.Logger.WithFields(logrus.Fields{ - "eventId": event.ID, - "status": status, - "replyEventId": resp.ID, - }).Errorf("Failed to publish reply: %v", err) - return + "eventId": event.ID, + "eventKind": event.Kind, + }).Errorf("Failed to process event: %v", err) } + if resp != nil { + status, err := sub.Relay.Publish(ctx, *resp) + if err != nil { + svc.Logger.WithFields(logrus.Fields{ + "eventId": event.ID, + "status": status, + "replyEventId": resp.ID, + }).Errorf("Failed to publish reply: %v", err) + return + } - nostrEvent := NostrEvent{} - result := svc.db.Where("nostr_id = ?", event.ID).First(&nostrEvent) - if result.Error != nil { - svc.Logger.WithFields(logrus.Fields{ - "eventId": event.ID, - "status": status, - "replyEventId": resp.ID, - }).Error(result.Error) - return - } - nostrEvent.ReplyId = resp.ID + nostrEvent := NostrEvent{} + result := svc.db.Where("nostr_id = ?", event.ID).First(&nostrEvent) + if result.Error != nil { + svc.Logger.WithFields(logrus.Fields{ + "eventId": event.ID, + "status": status, + "replyEventId": resp.ID, + }).Error(result.Error) + return + } + nostrEvent.ReplyId = resp.ID - if status == nostr.PublishStatusSucceeded { - nostrEvent.State = NOSTR_EVENT_STATE_PUBLISH_CONFIRMED - nostrEvent.RepliedAt = time.Now() - svc.db.Save(&nostrEvent) - svc.Logger.WithFields(logrus.Fields{ - "nostrEventId": nostrEvent.ID, - "eventId": event.ID, - "status": status, - "replyEventId": resp.ID, - "appId": nostrEvent.AppId, - }).Info("Published reply") - } else if status == nostr.PublishStatusFailed { - nostrEvent.State = NOSTR_EVENT_STATE_PUBLISH_FAILED - svc.db.Save(&nostrEvent) - svc.Logger.WithFields(logrus.Fields{ - "nostrEventId": nostrEvent.ID, - "eventId": event.ID, - "status": status, - "replyEventId": resp.ID, - "appId": nostrEvent.AppId, - }).Info("Failed to publish reply") - } else { - nostrEvent.State = NOSTR_EVENT_STATE_PUBLISH_UNCONFIRMED - svc.db.Save(&nostrEvent) - svc.Logger.WithFields(logrus.Fields{ - "nostrEventId": nostrEvent.ID, - "eventId": event.ID, - "status": status, - "replyEventId": resp.ID, - "appId": nostrEvent.AppId, - }).Info("Reply sent but no response from relay (timeout)") + if status == nostr.PublishStatusSucceeded { + nostrEvent.State = NOSTR_EVENT_STATE_PUBLISH_CONFIRMED + nostrEvent.RepliedAt = time.Now() + svc.db.Save(&nostrEvent) + svc.Logger.WithFields(logrus.Fields{ + "nostrEventId": nostrEvent.ID, + "eventId": event.ID, + "status": status, + "replyEventId": resp.ID, + "appId": nostrEvent.AppId, + }).Info("Published reply") + } else if status == nostr.PublishStatusFailed { + nostrEvent.State = NOSTR_EVENT_STATE_PUBLISH_FAILED + svc.db.Save(&nostrEvent) + svc.Logger.WithFields(logrus.Fields{ + "nostrEventId": nostrEvent.ID, + "eventId": event.ID, + "status": status, + "replyEventId": resp.ID, + "appId": nostrEvent.AppId, + }).Info("Failed to publish reply") + } else { + nostrEvent.State = NOSTR_EVENT_STATE_PUBLISH_UNCONFIRMED + svc.db.Save(&nostrEvent) + svc.Logger.WithFields(logrus.Fields{ + "nostrEventId": nostrEvent.ID, + "eventId": event.ID, + "status": status, + "replyEventId": resp.ID, + "appId": nostrEvent.AppId, + }).Info("Reply sent but no response from relay (timeout)") + } } - } + }(event) } + svc.Logger.Info("Subscription ended") }() select { From 99a2184971b3e414af76d9dcd97170b66ec4eaa0 Mon Sep 17 00:00:00 2001 From: Fmar Date: Wed, 10 Jan 2024 17:41:41 +0100 Subject: [PATCH 11/16] update simnet yaml files inside values --- .github/workflows/workflow.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yaml b/.github/workflows/workflow.yaml index 32eece37..d1a2620c 100644 --- a/.github/workflows/workflow.yaml +++ b/.github/workflows/workflow.yaml @@ -39,7 +39,7 @@ jobs: if: ${{ github.ref == 'refs/heads/main' }} uses: fjogeleit/yaml-update-action@v0.7.0 with: - valueFile: 'alby-simnet-deployment/values.yaml' + valueFile: 'alby-simnet-deployment/values/nwc.yaml' propertyPath: 'nwc.image.tag' value: ${{ steps.build.outputs.tags }} repository: getalby/alby-deployment From 679c382624060f3888d8fb4060c95bcd967cc2dc Mon Sep 17 00:00:00 2001 From: Fmar Date: Wed, 17 Jan 2024 15:50:21 +0100 Subject: [PATCH 12/16] Update workflow.yaml --- .github/workflows/workflow.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/workflow.yaml b/.github/workflows/workflow.yaml index d1a2620c..8add4357 100644 --- a/.github/workflows/workflow.yaml +++ b/.github/workflows/workflow.yaml @@ -47,6 +47,7 @@ jobs: createPR: false message: 'CD: Update nwc tag to ${{ steps.build.outputs.tags }}' token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} + # needs to be updated workDir: infrastructure # Only update prod environment if this action was triggered by a new tag - name: Update production environment From 6a85e836310a881826a0204adb50b7416c468b76 Mon Sep 17 00:00:00 2001 From: Fmar Date: Wed, 17 Jan 2024 15:51:47 +0100 Subject: [PATCH 13/16] Update workflow.yaml --- .github/workflows/workflow.yaml | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/workflow.yaml b/.github/workflows/workflow.yaml index 8add4357..0684106d 100644 --- a/.github/workflows/workflow.yaml +++ b/.github/workflows/workflow.yaml @@ -50,16 +50,16 @@ jobs: # needs to be updated workDir: infrastructure # Only update prod environment if this action was triggered by a new tag - - name: Update production environment - if: startsWith(github.ref, 'refs/tags') - uses: fjogeleit/yaml-update-action@v0.7.0 - with: - valueFile: 'alby-mainnet-deployment/values.yaml' - propertyPath: 'nwc.image.tag' - value: ${{ steps.build.outputs.tags }} - repository: getalby/alby-deployment - branch: main - createPR: false - message: 'CD: Update nwc tag to ${{ steps.build.outputs.tags }}' - token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} - workDir: infrastructure + # - name: Update production environment + # if: startsWith(github.ref, 'refs/tags') + # uses: fjogeleit/yaml-update-action@v0.7.0 + # with: + # valueFile: 'alby-mainnet-deployment/values.yaml' + # propertyPath: 'nwc.image.tag' + # value: ${{ steps.build.outputs.tags }} + # repository: getalby/alby-deployment + # branch: main + # createPR: false + # message: 'CD: Update nwc tag to ${{ steps.build.outputs.tags }}' + # token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} + # workDir: infrastructure From 7819a48ad2c77217ec6d931f568297bea9923cff Mon Sep 17 00:00:00 2001 From: Fmar Date: Wed, 17 Jan 2024 16:47:48 +0100 Subject: [PATCH 14/16] add workflow_dispatch for manual build possibility --- .github/workflows/multiplatform.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/multiplatform.yaml b/.github/workflows/multiplatform.yaml index a3da7195..602fc5e8 100644 --- a/.github/workflows/multiplatform.yaml +++ b/.github/workflows/multiplatform.yaml @@ -1,5 +1,6 @@ name: Multiplatform Docker build & push on: + workflow_dispatch: push: release: types: [published] @@ -29,4 +30,4 @@ jobs: multiPlatform: true platform: linux/amd64,linux/arm64,linux/386 username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + password: ${{ secrets.GITHUB_TOKEN }} From 58d3c92b54a6b06a86e5c951968642147b4e5ac4 Mon Sep 17 00:00:00 2001 From: Fmar Date: Wed, 17 Jan 2024 17:16:30 +0100 Subject: [PATCH 15/16] uncomment production deployment --- .github/workflows/workflow.yaml | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/workflow.yaml b/.github/workflows/workflow.yaml index 0684106d..8add4357 100644 --- a/.github/workflows/workflow.yaml +++ b/.github/workflows/workflow.yaml @@ -50,16 +50,16 @@ jobs: # needs to be updated workDir: infrastructure # Only update prod environment if this action was triggered by a new tag - # - name: Update production environment - # if: startsWith(github.ref, 'refs/tags') - # uses: fjogeleit/yaml-update-action@v0.7.0 - # with: - # valueFile: 'alby-mainnet-deployment/values.yaml' - # propertyPath: 'nwc.image.tag' - # value: ${{ steps.build.outputs.tags }} - # repository: getalby/alby-deployment - # branch: main - # createPR: false - # message: 'CD: Update nwc tag to ${{ steps.build.outputs.tags }}' - # token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} - # workDir: infrastructure + - name: Update production environment + if: startsWith(github.ref, 'refs/tags') + uses: fjogeleit/yaml-update-action@v0.7.0 + with: + valueFile: 'alby-mainnet-deployment/values.yaml' + propertyPath: 'nwc.image.tag' + value: ${{ steps.build.outputs.tags }} + repository: getalby/alby-deployment + branch: main + createPR: false + message: 'CD: Update nwc tag to ${{ steps.build.outputs.tags }}' + token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} + workDir: infrastructure From af7ecd8e8eecd65b32f6ff1e3e6adaba1f69d26c Mon Sep 17 00:00:00 2001 From: Fmar Date: Wed, 17 Jan 2024 18:48:04 +0100 Subject: [PATCH 16/16] Update workflow.yaml --- .github/workflows/workflow.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/workflow.yaml b/.github/workflows/workflow.yaml index 8add4357..d1a2620c 100644 --- a/.github/workflows/workflow.yaml +++ b/.github/workflows/workflow.yaml @@ -47,7 +47,6 @@ jobs: createPR: false message: 'CD: Update nwc tag to ${{ steps.build.outputs.tags }}' token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} - # needs to be updated workDir: infrastructure # Only update prod environment if this action was triggered by a new tag - name: Update production environment