Skip to content

Commit

Permalink
gofumt, nolint to skip duplicate lines, replace sdkerrors
Browse files Browse the repository at this point in the history
  • Loading branch information
leonz789 committed Apr 16, 2024
1 parent 043c09d commit 8338b6a
Show file tree
Hide file tree
Showing 18 changed files with 48 additions and 41 deletions.
1 change: 1 addition & 0 deletions x/oracle/client/cli/query_recent_params.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// nolint
package cli

import (
Expand Down
8 changes: 4 additions & 4 deletions x/oracle/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import (

var DefaultRelativePacketTimeoutTimestamp = uint64((time.Duration(10) * time.Minute).Nanoseconds())

Check failure

Code scanning / gosec

Potential integer overflow by integer type conversion Error

Potential integer overflow by integer type conversion

const (
flagPacketTimeoutTimestamp = "packet-timeout-timestamp"
listSeparator = ","
)
//const (

Check failure on line 16 in x/oracle/client/cli/tx.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

commentFormatting: put a space between `//` and comment text (gocritic)
// flagPacketTimeoutTimestamp = "packet-timeout-timestamp"
// listSeparator = ","
//)

// GetTxCmd returns the transaction commands for this module
func GetTxCmd() *cobra.Command {
Expand Down
20 changes: 10 additions & 10 deletions x/oracle/keeper/aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (agc *AggregatorContext) SealRound(ctx sdk.Context, force bool) (success []
agc.aggregators[feederId] = nil
}
}

Check warning

Code scanning / CodeQL

Iteration over map Warning

Iteration over map may be a possible source of non-determinism
return
return success, failed
}

//func (agc *AggregatorContext) ForceSeal(ctx sdk.Context) (success []*priceItemKV, failed []int32) {

Check failure on line 188 in x/oracle/keeper/aggregator/aggregator.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

commentFormatting: put a space between `//` and comment text (gocritic)
Expand All @@ -208,29 +208,29 @@ func (agc *AggregatorContext) PrepareRound(ctx sdk.Context, block uint64) {
left := delta % feeder.Interval
count := delta / feeder.Interval
latestBasedblock := block - left
latestNextRoundId := feeder.StartRoundId + count
latestNextRoundID := feeder.StartRoundId + count

feederIdUint64 := uint64(feederId)
round := agc.rounds[feederIdUint64]
feederIDUint64 := uint64(feederId)

Check failure

Code scanning / gosec

Potential integer overflow by integer type conversion Error

Potential integer overflow by integer type conversion
round := agc.rounds[feederIDUint64]
if round == nil {
round = &roundInfo{
basedBlock: uint64(latestBasedblock),
nextRoundId: uint64(latestNextRoundId),
basedBlock: latestBasedblock,
nextRoundId: latestNextRoundID,
}
if left >= common.MaxNonce {
round.status = 2
} else {
round.status = 1
}
agc.rounds[feederIdUint64] = round
agc.rounds[feederIDUint64] = round
} else {
// prepare a new round for exist roundInfo
if left == 0 {
round.basedBlock = uint64(latestBasedblock)
round.nextRoundId = uint64(latestNextRoundId)
round.basedBlock = latestBasedblock
round.nextRoundId = latestNextRoundID
round.status = 1
// drop previous worker
agc.aggregators[feederIdUint64] = nil
agc.aggregators[feederIDUint64] = nil
} 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
20 changes: 10 additions & 10 deletions x/oracle/keeper/aggregator/aggregator_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ type filter struct {
validatorSource map[string]*common.Set[string]
}

func newFilter(maxNonce, maxDetId int) *filter {
func newFilter(maxNonce, maxDetID int) *filter {
return &filter{
maxNonce: maxNonce,
maxDetId: maxDetId,
maxDetId: maxDetID,
validatorNonce: make(map[string]*common.Set[int32]),
validatorSource: make(map[string]*common.Set[string]),
}
Expand All @@ -39,10 +39,10 @@ func (f *filter) addPSource(pSources []*types.PriceWithSource, validator string)
// check conflicts or duplicate data for the same roundId within the same source
if len(pSource.Prices[0].DetId) > 0 {
k := validator + strconv.Itoa(int(pSource.SourceId))
detIds := f.validatorSource[k]
if detIds == nil {
detIds = f.newVSSet()
f.validatorSource[k] = detIds
detIDs := f.validatorSource[k]
if detIDs == nil {
detIDs = f.newVSSet()
f.validatorSource[k] = detIDs
}

pSourceTmp := &types.PriceWithSource{
Expand All @@ -51,10 +51,10 @@ func (f *filter) addPSource(pSources []*types.PriceWithSource, validator string)
Desc: pSource.Desc,
}

for _, pDetId := range pSource.Prices {
if ok := detIds.Add(pDetId.DetId); ok {
for _, pDetID := range pSource.Prices {
if ok := detIDs.Add(pDetID.DetId); ok {
// deterministic id has not seen in filter and limitation of ids this souce has not reached
pSourceTmp.Prices = append(pSourceTmp.Prices, pDetId)
pSourceTmp.Prices = append(pSourceTmp.Prices, pDetID)
}
}
if len(pSourceTmp.Prices) > 0 {
Expand All @@ -66,7 +66,7 @@ func (f *filter) addPSource(pSources []*types.PriceWithSource, validator string)
list4Aggregator = append(list4Aggregator, pSource)
}
}
return
return list4Calculator, list4Aggregator
}

// filtrate checks data from MsgCreatePrice, and will drop the conflict or duplicate data, it will then fill data into calculator(for deterministic source data to get to consensus) and aggregator (for both deterministic and non0-deterministic source data run 2-layers aggregation to get the final price)
Expand Down
12 changes: 6 additions & 6 deletions x/oracle/keeper/aggregator/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ func (w *worker) seal() {
w.a = nil
}

func (w *worker) getPrice() (string, int32) {
if w.sealed {
return w.price, w.decimal
}
return "", 0
}
//func (w *worker) getPrice() (string, int32) {
// if w.sealed {
// return w.price, w.decimal
// }
// return "", 0
//}

// newWorker new a instance for a tokenFeeder's specific round
func newWorker(feederId uint64, agc *AggregatorContext) *worker {
Expand Down
4 changes: 1 addition & 3 deletions x/oracle/keeper/cache/caches.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,8 @@ func (c *Cache) AddCache(i any) {

// func (c *Cache) RemoveCache(i any, k common.KeeperOracle) {
func (c *Cache) RemoveCache(i any) {
switch item := i.(type) {
case *CacheItemM:
if item, isItemM := i.(*CacheItemM); isItemM {
c.msg.remove(item)
default:
}
}

Expand Down
1 change: 1 addition & 0 deletions x/oracle/keeper/index_recent_msg.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// nolint
package keeper

import (
Expand Down
1 change: 1 addition & 0 deletions x/oracle/keeper/index_recent_params.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// nolint
package keeper

import (
Expand Down
2 changes: 1 addition & 1 deletion x/oracle/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"context"
"testing"

sdkerrors "cosmossdk.io/errors"
keepertest "github.com/ExocoreNetwork/exocore/testutil/keeper"
"github.com/ExocoreNetwork/exocore/x/oracle/keeper"
"github.com/ExocoreNetwork/exocore/x/oracle/keeper/testdata"
"github.com/ExocoreNetwork/exocore/x/oracle/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

// "github.com/cosmos/ibc-go/testing/mock"

Expand Down
3 changes: 1 addition & 2 deletions x/oracle/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
}

// SetParams set the params
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error {
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
store := ctx.KVStore(k.storeKey)
// TODO: validation check
bz := k.cdc.MustMarshal(&params)
store.Set(types.ParamsKey, bz)
return nil
}
2 changes: 1 addition & 1 deletion x/oracle/keeper/prices.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (k Keeper) GetAllPrices(ctx sdk.Context) (list []types.Prices) {
if price.TokenId > 0 {
list = append(list, price)
}
return
return list
}

func (k Keeper) AppendPriceTR(ctx sdk.Context, tokenId uint64, priceTR types.PriceWithTimeAndRound) {
Expand Down
1 change: 1 addition & 0 deletions x/oracle/keeper/query_recent_params.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// nolint
package keeper

import (
Expand Down
1 change: 1 addition & 0 deletions x/oracle/keeper/single.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func recacheAggregatorContext(ctx sdk.Context, agc *aggregator.AggregatorContext
if msgs := recentMsgs[from+1]; msgs != nil {
for _, msg := range msgs {
// these messages are retreived for recache, just skip the validation check and fill the memory cache
//nolint
agc.FillPrice(&types.MsgCreatePrice{
Creator: msg.Validator,
FeederId: msg.FeederId,
Expand Down
4 changes: 3 additions & 1 deletion x/oracle/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncod

// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil {
panic(err)
}
}

// GetTxCmd returns the root Tx command for the module. The subcommands of this root command are used by end-users to generate new transactions containing messages defined in the module
Expand Down
2 changes: 1 addition & 1 deletion x/oracle/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package types
// DONTCOVER

import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
sdkerrors "cosmossdk.io/errors"
)

// x/oracle module sentinel errors
Expand Down
3 changes: 2 additions & 1 deletion x/oracle/types/message_create_price.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package types

import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

sdk "github.com/cosmos/cosmos-sdk/types"
)

const TypeMsgCreatePrice = "create_price"
Expand Down
2 changes: 2 additions & 0 deletions x/oracle/types/message_create_price_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (

"github.com/ExocoreNetwork/exocore/testutil/sample"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

//sdkerrors "cosmossdk.io/errors""
"github.com/stretchr/testify/require"
)

Expand Down
2 changes: 1 addition & 1 deletion x/oracle/types/message_update_params.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package types

import (
sdkerrors "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

const TypeMsgUpdateParams = "update_params"
Expand Down

0 comments on commit 8338b6a

Please sign in to comment.