From dd8c2ca89851001f4f5d26adf2611da784256f3e Mon Sep 17 00:00:00 2001 From: asolovov Date: Wed, 28 Feb 2024 14:21:45 +0200 Subject: [PATCH] update: change send logic --- internal/service/sender.go | 47 +++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/internal/service/sender.go b/internal/service/sender.go index 0444fd9..66a4fe2 100644 --- a/internal/service/sender.go +++ b/internal/service/sender.go @@ -31,34 +31,35 @@ func (s *coinAveragePriceSender) sendARGPrice(stop chan struct{}) { logTrace("stop...", "sendARGPrice") return default: - logTrace("sending prices...", "sendARGPrice") - epoch, err := s.flare.GetCurrentPriceEpochData() - if err != nil { - logErr(fmt.Sprintln("err get epoch:", err.Error()), "sendARGPrice") - time.Sleep(time.Second * 1) - continue - } - - sleep, _ := time.ParseDuration(fmt.Sprintf("%vs", epoch.RevealEndTimestamp.Uint64()-epoch.CurrentTimestamp.Uint64()-60)) - random := s.getRandom() + go s.send() + time.Sleep(time.Minute * 3) + } + } +} - s.mu.Lock() - prices := s.currentPrices() - s.mu.Unlock() +func (s *coinAveragePriceSender) send() { + logTrace("sending prices...", "send") + epoch, err := s.flare.GetCurrentPriceEpochData() + if err != nil { + logErr(fmt.Sprintln("err get epoch:", err.Error()), "send") + time.Sleep(time.Second * 1) + return + } - logTrace(fmt.Sprintf("commiting prices"), "sendARGPrice") - if err := s.flare.CommitPrices(epoch.EpochID, s.tokens, prices, random); err != nil { - time.Sleep(time.Second * 1) - continue - } + sleep, _ := time.ParseDuration(fmt.Sprintf("%vs", epoch.RevealEndTimestamp.Uint64()-epoch.CurrentTimestamp.Uint64()-60)) + random := s.getRandom() - go s.reveal(sleep, epoch.EpochID, s.tokens, prices, random) + s.mu.Lock() + prices := s.currentPrices() + s.mu.Unlock() - wait, _ := time.ParseDuration(fmt.Sprintf("%vs", epoch.EndTimestamp.Uint64()-epoch.CurrentTimestamp.Uint64()+60)) - logTrace(fmt.Sprintf("sleep send prices for %v", wait), "sendARGPrice") - time.Sleep(wait) - } + logTrace(fmt.Sprintf("commiting prices"), "send") + if err := s.flare.CommitPrices(epoch.EpochID, s.tokens, prices, random); err != nil { + time.Sleep(time.Second * 1) + return } + + go s.reveal(sleep, epoch.EpochID, s.tokens, prices, random) } // reveal will wait the sleep time and then call the reveal smart-contract method