Skip to content

Commit

Permalink
Merge branch 'uddugteam:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
andskur authored May 9, 2024
2 parents 1bb01f2 + c032900 commit bca1c7f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
36 changes: 24 additions & 12 deletions internal/service/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ package service
import (
"fmt"
"math/big"
"time"

"oracle-flare/pkg/flare/contracts"
"time"
)

func (s *coinAVGPriceSender) runSender() {
Expand All @@ -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
}
}
}
}
6 changes: 3 additions & 3 deletions pkg/flare/contracts/flareChain/priceSubmitterFlare.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}

0 comments on commit bca1c7f

Please sign in to comment.