diff --git a/x/oracle/keeper/common/types.go b/x/oracle/keeper/common/types.go index e4df3eaf4..993c20674 100644 --- a/x/oracle/keeper/common/types.go +++ b/x/oracle/keeper/common/types.go @@ -19,6 +19,9 @@ var ( // maxDetId each validator can submit, so the calculator can cache maximum of maxDetId*count(validators) values, this is for resistance of malicious validator submmiting invalid detId MaxDetID int32 = 5 + // for each token at most MaxSizePrices round of prices will be keep in store + MaxSizePrices = 100 + // consensus mode: v1: as soon as possbile Mode types.ConsensusMode = types.ConsensusModeASAP ) diff --git a/x/oracle/keeper/prices.go b/x/oracle/keeper/prices.go index 309054245..fefd74e17 100644 --- a/x/oracle/keeper/prices.go +++ b/x/oracle/keeper/prices.go @@ -5,6 +5,7 @@ import ( sdkmath "cosmossdk.io/math" assetstypes "github.com/ExocoreNetwork/exocore/x/assets/types" + "github.com/ExocoreNetwork/exocore/x/oracle/keeper/common" "github.com/ExocoreNetwork/exocore/x/oracle/types" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" @@ -30,14 +31,20 @@ func (k Keeper) GetPrices( val.TokenID = tokenID val.NextRoundID = nextRoundID - val.PriceList = make([]*types.PriceTimeRound, nextRoundID) + var i uint64 + // i := max(1, nextRoundID-uint64(common.MaxSizePrices)) + if i = nextRoundID - uint64(common.MaxSizePrices); i < 1 { + i = 1 + val.PriceList = make([]*types.PriceTimeRound, nextRoundID) + } else { + val.PriceList = make([]*types.PriceTimeRound, common.MaxSizePrices) + } // 0 roundId is reserved, expect the roundid corresponds to the slice index val.PriceList[0] = &types.PriceTimeRound{} - for i := uint64(1); i < nextRoundID; i++ { + for ; i < nextRoundID; i++ { b := store.Get(types.PricesRoundKey(i)) val.PriceList[i] = &types.PriceTimeRound{} if b != nil { - // should always be true since we don't delete prices from history round k.cdc.MustUnmarshal(b, val.PriceList[i]) found = true } diff --git a/x/oracle/keeper/single.go b/x/oracle/keeper/single.go index c1f60e652..1bdec9d4b 100644 --- a/x/oracle/keeper/single.go +++ b/x/oracle/keeper/single.go @@ -199,12 +199,15 @@ func ResetAggregatorContextCheckTx() { agcCheckTx = nil } +// setCommonParams save static fields in params in memory cache since these fields will not change during node running +// TODO: further when params is abled to be updated through tx/gov, this cache should be taken care if any is available to be changed func setCommonParams(p *types.Params) { common.MaxNonce = p.MaxNonce common.ThresholdA = p.ThresholdA common.ThresholdB = p.ThresholdB common.MaxDetID = p.MaxDetId common.Mode = p.Mode + common.MaxSizePrices = int(p.MaxSizePrices) } func ResetUpdatedFeederIDs() {