From eaf4edc27d5eff9bd4f6506ff8112ac87b40e894 Mon Sep 17 00:00:00 2001 From: mike76-dev Date: Mon, 13 May 2024 16:00:05 +0200 Subject: [PATCH] Fix syncing bug --- Makefile | 2 +- modules/manager/persist.go | 5 +++++ modules/portal/database.go | 3 +-- modules/portal/portal.go | 6 ++++++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 71a7531..66b7a2b 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ endif ldflags= \ -X "github.com/mike76-dev/sia-satellite/internal/build.BinaryName=satd" \ --X "github.com/mike76-dev/sia-satellite/internal/build.NodeVersion=0.11.4" \ +-X "github.com/mike76-dev/sia-satellite/internal/build.NodeVersion=0.11.5" \ -X "github.com/mike76-dev/sia-satellite/internal/build.GitRevision=${GIT_DIRTY}${GIT_REVISION}" \ -X "github.com/mike76-dev/sia-satellite/internal/build.BuildTime=${BUILD_TIME}" diff --git a/modules/manager/persist.go b/modules/manager/persist.go index 11f14a5..e710bbb 100644 --- a/modules/manager/persist.go +++ b/modules/manager/persist.go @@ -161,6 +161,11 @@ func (m *Manager) initPersist(dir string) error { } defer m.tg.Done() + err := m.sync(m.tip) + if err != nil { + m.log.Error("failed to sync manager", zap.Error(err)) + } + for { select { case <-m.tg.StopChan(): diff --git a/modules/portal/database.go b/modules/portal/database.go index 82e22f9..34cb1ff 100644 --- a/modules/portal/database.go +++ b/modules/portal/database.go @@ -336,6 +336,7 @@ func (p *Portal) addSiacoinPayment(email string, amount types.Currency, txid typ // confirmSiacoinPayment decrements the number of remaining payment // confirmations. +// A lock must be acquired before calling this function. func (p *Portal) confirmSiacoinPayment(txid types.TransactionID) error { tx, err := p.db.Begin() if err != nil { @@ -372,9 +373,7 @@ func (p *Portal) confirmSiacoinPayment(txid types.TransactionID) error { // If the tx is confirmed, increase the account balance. if left == 0 { // Delete from the map. - p.mu.Lock() delete(p.transactions, txid) - p.mu.Unlock() // Fetch the account. var c, id, in string diff --git a/modules/portal/portal.go b/modules/portal/portal.go index 24c0ed2..8b156c4 100644 --- a/modules/portal/portal.go +++ b/modules/portal/portal.go @@ -150,6 +150,12 @@ func New(config *persist.SatdConfig, db *sql.DB, ms mail.MailSender, cm *chain.M } defer pt.tg.Done() + err := pt.sync(pt.tip) + if err != nil { + pt.log.Error("couldn't sync portal", zap.Error(err)) + return + } + for { select { case <-pt.tg.StopChan():