Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: query blocks before enable feemarket module get nil pointer … #485

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (rpc) [#473](https://github.com/crypto-org-chain/ethermint/pull/473) Avoid panic on invalid elasticity_multiplier.
* (rpc) [#474](https://github.com/crypto-org-chain/ethermint/pull/474), [#476](https://github.com/crypto-org-chain/ethermint/pull/441) Align genesis related cmd.
* (rpc) [#480](https://github.com/crypto-org-chain/ethermint/pull/480), [#482](https://github.com/crypto-org-chain/ethermint/pull/482) Fix parsed logs from old events.
* (rpc) [#485](https://github.com/crypto-org-chain/ethermint/pull/485) Avoid nil pointer error when query blocks before enable feemarket module.

### Improvements

Expand Down
5 changes: 3 additions & 2 deletions x/feemarket/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ import (
)

// GetParams returns the total set of fee market parameters.
func (k Keeper) GetParams(ctx sdk.Context) types.Params {
var params types.Params
func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
bz := ctx.KVStore(k.storeKey).Get(types.ParamsKey)
if len(bz) == 0 {
k.ss.GetParamSetIfExists(ctx, &params)
// avoid nil pointers when params are not set
params.FillDefaults()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually it's panic from store.parent.Get before get from subspace

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why parent get will have panic?

Copy link
Collaborator Author

@mmsqe mmsqe May 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since store is nil when query on old block, the passed parent is nil

Copy link
Collaborator

@yihuang yihuang May 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the store won't be nil if it's registered in the binary, just the data could be missing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when query old version, cacheStore will be nil right?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, that makes sense.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess if we have this: crypto-org-chain/cosmos-sdk#435, we don't need this?

} else {
k.cdc.MustUnmarshal(bz, &params)
}
Expand Down
22 changes: 22 additions & 0 deletions x/feemarket/keeper/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import (
"reflect"
"testing"

"cosmossdk.io/store/cachemulti"
"cosmossdk.io/store/dbadapter"
storetypes "cosmossdk.io/store/types"
dbm "github.com/cosmos/cosmos-db"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/evmos/ethermint/testutil"
"github.com/evmos/ethermint/x/feemarket/types"
"github.com/stretchr/testify/suite"
Expand Down Expand Up @@ -72,6 +77,23 @@ func (suite *ParamsTestSuite) TestSetGetParams() {
},
false,
},
{
"success - get default params if not exists",
func() interface{} {
var params types.Params
params.FillDefaults()
return params
},
func() interface{} {
stores := map[storetypes.StoreKey]storetypes.CacheWrapper{
suite.App.GetKey(types.StoreKey): dbadapter.Store{DB: dbm.NewMemDB()},
suite.App.GetKey(paramstypes.StoreKey): dbadapter.Store{DB: dbm.NewMemDB()},
}
ctx := suite.Ctx.WithMultiStore(cachemulti.NewFromKVStore(stores, nil, nil))
return suite.App.FeeMarketKeeper.GetParams(ctx)
},
true,
},
}
for _, tc := range testCases {
suite.Run(tc.name, func() {
Expand Down
12 changes: 12 additions & 0 deletions x/feemarket/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,18 @@
return p.BaseFee.BigInt()
}

func (p *Params) FillDefaults() {
if p.BaseFee.IsNil() {
p.BaseFee = sdkmath.NewIntFromUint64(params.InitialBaseFee)

Check warning on line 149 in x/feemarket/types/params.go

View check run for this annotation

Codecov / codecov/patch

x/feemarket/types/params.go#L147-L149

Added lines #L147 - L149 were not covered by tests
}
if p.MinGasPrice.IsNil() {
p.MinGasPrice = DefaultMinGasPrice

Check warning on line 152 in x/feemarket/types/params.go

View check run for this annotation

Codecov / codecov/patch

x/feemarket/types/params.go#L151-L152

Added lines #L151 - L152 were not covered by tests
}
if p.MinGasMultiplier.IsNil() {
p.MinGasMultiplier = DefaultMinGasMultiplier

Check warning on line 155 in x/feemarket/types/params.go

View check run for this annotation

Codecov / codecov/patch

x/feemarket/types/params.go#L154-L155

Added lines #L154 - L155 were not covered by tests
}
}

func validateMinGasPrice(i interface{}) error {
v, ok := i.(sdkmath.LegacyDec)

Expand Down
Loading