From 995da762e9219b976efe6070543e47d109f09d6d Mon Sep 17 00:00:00 2001 From: asolovov Date: Thu, 9 May 2024 11:43:58 +0300 Subject: [PATCH] debug: new reveal implementation and debug logs --- internal/service/sender.go | 36 ++++++++++++------- .../flareChain/priceSubmitterFlare.go | 6 ++-- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/internal/service/sender.go b/internal/service/sender.go index e101d9f..a39ad7e 100644 --- a/internal/service/sender.go +++ b/internal/service/sender.go @@ -3,9 +3,8 @@ package service import ( "fmt" "math/big" - "time" - "oracle-flare/pkg/flare/contracts" + "time" ) func (s *coinAVGPriceSender) runSender() { @@ -23,26 +22,39 @@ func (s *coinAVGPriceSender) runSender() { continue } - sleep, _ := time.ParseDuration(fmt.Sprintf("%vs", epoch.RevealEndTimestamp.Uint64()-epoch.CurrentTimestamp.Uint64()-60)) + logInfo(fmt.Sprintf("epochID: %v current: %v reveal end: %v", epoch.EpochID, epoch.CurrentTimestamp, epoch.RevealEndTimestamp), "Sender") + + //sleep, _ := time.ParseDuration(fmt.Sprintf("%vs", epoch.RevealEndTimestamp.Uint64()-epoch.CurrentTimestamp.Uint64()-60)) random := s.getRandom() if err := s.flare.CommitPrices(epoch.EpochID, s.tokens, s.parsePrices(), random); err != nil { continue } - timer := time.NewTimer(sleep) - logInfo(fmt.Sprintf("time for reverl: %v", sleep), "Sender") - go s.reveal(timer, epoch.EpochID, s.tokens, s.parsePrices(), random) + //timer := time.NewTimer(sleep) + //logInfo(fmt.Sprintf("time for reverl: %v", sleep), "Sender") + + timer := time.NewTimer(time.Second * 300) + ticker := time.NewTicker(time.Second * 30) + go s.reveal(ticker, timer, epoch.EpochID, s.tokens, s.parsePrices(), random) } } } // reveal will wait the sleep time and then call the reveal smart-contract method -func (s *coinAVGPriceSender) reveal(timer *time.Timer, epochID *big.Int, indices []contracts.TokenID, prices []*big.Int, random *big.Int) { - logInfo(fmt.Sprintf("received for reveal: epochID %v, indices %v, prices %v, random %v", epochID, indices, prices, random), "Sender") - <-timer.C - logInfo(fmt.Sprintf("revealing price for the %v epoch", epochID.Int64()), "Sender") - if err := s.flare.RevealPrices(epochID, indices, prices, random); err != nil { - logErr("err reveal", "Sender") +func (s *coinAVGPriceSender) reveal(ticker *time.Ticker, timer *time.Timer, epochID *big.Int, indices []contracts.TokenID, prices []*big.Int, random *big.Int) { + for { + select { + case <-timer.C: + ticker.Stop() + logErr(fmt.Sprintf("epochID: %v never success", epochID), "Sender") + return + case <-ticker.C: + if err := s.flare.RevealPrices(epochID, indices, prices, random); err == nil { + ticker.Stop() + timer.Stop() + return + } + } } } diff --git a/pkg/flare/contracts/flareChain/priceSubmitterFlare.go b/pkg/flare/contracts/flareChain/priceSubmitterFlare.go index 859bc5e..9e8f870 100644 --- a/pkg/flare/contracts/flareChain/priceSubmitterFlare.go +++ b/pkg/flare/contracts/flareChain/priceSubmitterFlare.go @@ -81,7 +81,7 @@ func (c *priceSubmitter) CommitPrices(epochID *big.Int, indices []contracts.Toke return err } - logger.Log().WithField("layer", "PriceSubmitter-CommitPrices").Infof("submitHash tx hash: %v time: %v", tx.Hash(), tx.Time()) + logger.Log().WithField("layer", "PriceSubmitter-CommitPrices").Infof("submitHash epochID: %v tx hash: %v time: %v", epochID, tx.Hash(), tx.Time()) return nil } @@ -102,11 +102,11 @@ func (c *priceSubmitter) RevealPrices(epochID *big.Int, indices []contracts.Toke tx, err := c.contract.Transact(c.signer, "revealPrices", epochID, sortStruct.Indices, sortStruct.Prices, random) if err != nil { - logger.Log().WithField("layer", "PriceSubmitter-RevealPrices").Errorln("err tx:", err.Error()) + logger.Log().WithField("layer", "PriceSubmitter-RevealPrices").Errorf("epochID: %v err tx: %s", epochID, err.Error()) return err } - logger.Log().WithField("layer", "PriceSubmitter-RevealPrices").Infof("revealPrices tx hash: %v time: %v", tx.Hash(), tx.Time()) + logger.Log().WithField("layer", "PriceSubmitter-RevealPrices").Infof("revealPrices epochID: %v tx hash: %v time: %v", epochID, tx.Hash(), tx.Time()) return nil }