diff --git a/Makefile b/Makefile index 1de773f..b61bfa4 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ endif ldflags= \ -X "github.com/mike76-dev/hostscore/internal/build.NodeBinaryName=hsd" \ --X "github.com/mike76-dev/hostscore/internal/build.NodeVersion=1.1.2" \ +-X "github.com/mike76-dev/hostscore/internal/build.NodeVersion=1.1.3" \ -X "github.com/mike76-dev/hostscore/internal/build.ClientBinaryName=hsc" \ -X "github.com/mike76-dev/hostscore/internal/build.ClientVersion=1.4.1" \ -X "github.com/mike76-dev/hostscore/internal/build.GitRevision=${GIT_DIRTY}${GIT_REVISION}" \ diff --git a/hostdb/hostdb.go b/hostdb/hostdb.go index 94898db..4b7ed97 100644 --- a/hostdb/hostdb.go +++ b/hostdb/hostdb.go @@ -256,8 +256,14 @@ func NewHostDB(db *sql.DB, dir string, cm *chain.Manager, cmZen *chain.Manager, // Subscribe in a goroutine to prevent blocking. go func() { + for hdb.cm.Tip().Height <= tip.Height { + time.Sleep(5 * time.Second) + } if err := syncStore(hdb.s, hdb.cm, tip); err != nil { - l.Fatal("failed to subscribe to chain manager", zap.String("network", "mainnet"), zap.Error(err)) + index, _ := hdb.cm.BestIndex(tip.Height - 1) + if err := syncStore(hdb.s, hdb.cm, index); err != nil { + l.Fatal("failed to subscribe to chain manager", zap.String("network", "mainnet"), zap.Error(err)) + } } reorgChan := make(chan types.ChainIndex, 1) @@ -277,8 +283,14 @@ func NewHostDB(db *sql.DB, dir string, cm *chain.Manager, cmZen *chain.Manager, }() go func() { + for hdb.cmZen.Tip().Height <= tipZen.Height { + time.Sleep(5 * time.Second) + } if err := syncStore(hdb.sZen, hdb.cmZen, tipZen); err != nil { - l.Fatal("failed to subscribe to chain manager", zap.String("network", "zen"), zap.Error(err)) + index, _ := hdb.cmZen.BestIndex(tipZen.Height - 1) + if err := syncStore(hdb.sZen, hdb.cmZen, index); err != nil { + l.Fatal("failed to subscribe to chain manager", zap.String("network", "zen"), zap.Error(err)) + } } reorgChan := make(chan types.ChainIndex, 1) diff --git a/internal/walletutil/store.go b/internal/walletutil/store.go index a89e4a8..449655d 100644 --- a/internal/walletutil/store.go +++ b/internal/walletutil/store.go @@ -146,7 +146,9 @@ func (s *DBStore) addSiacoinElements(sces []types.SiacoinElement) error { e.Flush() _, err := s.tx.Exec(` INSERT INTO wt_sces (scoid, network, bytes) - VALUES (?, ?, ?) + VALUES (?, ?, ?) AS new + ON DUPLICATE KEY UPDATE + bytes = new.bytes `, sce.ID[:], s.network, buf.Bytes()) if err != nil { s.log.Error("couldn't add SC output", zap.String("network", s.network), zap.Error(err)) @@ -182,7 +184,9 @@ func (s *DBStore) addSiafundElements(sfes []types.SiafundElement) error { e.Flush() _, err := s.tx.Exec(` INSERT INTO wt_sfes (sfoid, network, bytes) - VALUES (?, ?, ?) + VALUES (?, ?, ?) AS new + ON DUPLICATE KEY UPDATE + bytes = new.bytes `, sfe.ID[:], s.network, buf.Bytes()) if err != nil { s.log.Error("couldn't add SF output", zap.String("network", s.network), zap.Error(err)) diff --git a/internal/walletutil/wallet.go b/internal/walletutil/wallet.go index 1854467..410ddaf 100644 --- a/internal/walletutil/wallet.go +++ b/internal/walletutil/wallet.go @@ -169,8 +169,14 @@ func NewWallet(db *sql.DB, seed, seedZen, dir string, cm *chain.Manager, cmZen * } go func() { + for w.cm.Tip().Height <= tip.Height { + time.Sleep(5 * time.Second) + } if err := syncStore(w.s, w.cm, tip); err != nil { - l.Fatal("failed to subscribe to chain manager", zap.String("network", "mainnet"), zap.Error(err)) + index, _ := w.cm.BestIndex(tip.Height - 1) + if err := syncStore(w.s, w.cm, index); err != nil { + l.Fatal("failed to subscribe to chain manager", zap.String("network", "mainnet"), zap.Error(err)) + } } reorgChan := make(chan types.ChainIndex, 1) @@ -190,8 +196,14 @@ func NewWallet(db *sql.DB, seed, seedZen, dir string, cm *chain.Manager, cmZen * }() go func() { + for w.cmZen.Tip().Height <= tipZen.Height { + time.Sleep(5 * time.Second) + } if err := syncStore(w.sZen, w.cmZen, tipZen); err != nil { - l.Fatal("failed to subscribe to chain manager", zap.String("network", "zen"), zap.Error(err)) + index, _ := w.cmZen.BestIndex(tipZen.Height - 1) + if err := syncStore(w.sZen, w.cmZen, index); err != nil { + l.Fatal("failed to subscribe to chain manager", zap.String("network", "zen"), zap.Error(err)) + } } reorgChan := make(chan types.ChainIndex, 1)