From 9f48edafcea8f66bc435b28f5432019d7a4b332a Mon Sep 17 00:00:00 2001 From: leonz789 Date: Sun, 12 May 2024 13:50:52 +0800 Subject: [PATCH] fix(oracle):bigint set, slice initialize --- x/oracle/keeper/aggregator/aggregator.go | 4 ++-- x/oracle/keeper/aggregator/calculator.go | 10 +++++----- x/oracle/keeper/aggregator/context.go | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/x/oracle/keeper/aggregator/aggregator.go b/x/oracle/keeper/aggregator/aggregator.go index 452377ab4..5da005a60 100644 --- a/x/oracle/keeper/aggregator/aggregator.go +++ b/x/oracle/keeper/aggregator/aggregator.go @@ -55,7 +55,7 @@ func (agg *aggregator) copy4CheckTx() *aggregator { totalPower: big.NewInt(0).Set(agg.totalPower), reports: make([]*reportPrice, 0, len(agg.reports)), - dsPrices: agg.dsPrices, + dsPrices: make(map[uint64]string), } for k, v := range agg.dsPrices { ret.dsPrices[k] = v @@ -66,7 +66,7 @@ func (agg *aggregator) copy4CheckTx() *aggregator { rTmp.power = big.NewInt(0).Set(report.power) for k, v := range report.prices { - // prices are just record, will not be modified during execution + // prices are information submitted by validators, these data will not change under deterministic sources, but with non-deterministic sources they might be overwrite by later prices tmpV := *v tmpV.price = big.NewInt(0).Set(v.price) rTmp.prices[k] = &tmpV diff --git a/x/oracle/keeper/aggregator/calculator.go b/x/oracle/keeper/aggregator/calculator.go index 549dc2028..8e5c8d264 100644 --- a/x/oracle/keeper/aggregator/calculator.go +++ b/x/oracle/keeper/aggregator/calculator.go @@ -68,21 +68,21 @@ type roundPricesList struct { func (r *roundPricesList) copy4CheckTx() *roundPricesList { ret := &roundPricesList{ - roundPricesList: make([]*roundPrices, len(r.roundPricesList)), + roundPricesList: make([]*roundPrices, 0, len(r.roundPricesList)), roundPricesCount: r.roundPricesCount, } for _, v := range r.roundPricesList { tmpRP := &roundPrices{ detID: v.detID, - price: big.NewInt(v.price.Int64()), - prices: make([]*priceAndPower, len(v.prices)), + price: big.NewInt(0).Set(v.price), + prices: make([]*priceAndPower, 0, len(v.prices)), timestamp: v.timestamp, } for _, pNP := range v.prices { tmpPNP := *pNP // power will be modified during execution - tmpPNP.power = big.NewInt(pNP.power.Int64()) + tmpPNP.power = big.NewInt(0).Set(pNP.power) tmpRP.prices = append(tmpRP.prices, &tmpPNP) } @@ -138,7 +138,7 @@ func (c *calculator) copy4CheckTx() *calculator { // copy deterministicSource for k, v := range c.deterministicSource { - c.deterministicSource[k] = v.copy4CheckTx() + ret.deterministicSource[k] = v.copy4CheckTx() } return ret diff --git a/x/oracle/keeper/aggregator/context.go b/x/oracle/keeper/aggregator/context.go index b5586d187..73cd3d6eb 100644 --- a/x/oracle/keeper/aggregator/context.go +++ b/x/oracle/keeper/aggregator/context.go @@ -260,7 +260,7 @@ func (agc *AggregatorContext) PrepareRound(ctx sdk.Context, block uint64) { round.nextRoundID = latestNextRoundID round.status = 1 // drop previous worker - agc.aggregators[feederIDUint64] = nil + delete(agc.aggregators, feederIDUint64) } else if round.status == 1 && left >= common.MaxNonce { // this shouldn't happen, if do sealround properly before prepareRound, basically for test only round.status = 2