Skip to content

Commit

Permalink
fix(oracle):bigint set, slice initialize
Browse files Browse the repository at this point in the history
  • Loading branch information
leonz789 committed May 12, 2024
1 parent aa0fb96 commit dc3621d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions x/oracle/keeper/aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions x/oracle/keeper/aggregator/calculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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()
}

Check warning

Code scanning / CodeQL

Iteration over map Warning

Iteration over map may be a possible source of non-determinism

return ret
Expand Down
2 changes: 1 addition & 1 deletion x/oracle/keeper/aggregator/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dc3621d

Please sign in to comment.