Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
### BUG FIXES

- [\#769](https://github.com/cosmos/evm/pull/769) Fix erc20 ibc middleware to not to validate sender address format.
- [\#790](https://github.com/cosmos/evm/pull/790) fix panic in historical query due to missing EvmCoinInfo.
- [\#816](https://github.com/cosmos/evm/pull/816) Avoid nil pointer when RPC requests execute before evmCoinInfo initialization in PreBlock with defaultEvmCoinInfo fallback.

## v0.5.0

Expand Down
2 changes: 1 addition & 1 deletion x/vm/keeper/coin_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (k Keeper) GetEvmCoinInfo(ctx sdk.Context) (coinInfo types.EvmCoinInfo) {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.KeyPrefixEvmCoinInfo)
if bz == nil {
return coinInfo
return k.defaultEvmCoinInfo
}
k.cdc.MustUnmarshal(bz, &coinInfo)
return
Expand Down
11 changes: 11 additions & 0 deletions x/vm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ type Keeper struct {
// evmMempool is the custom EVM appside mempool
// if it is nil, the default comet mempool will be used
evmMempool *evmmempool.ExperimentalEVMMempool

// defaultEvmCoinInfo is the default EVM coin info used when evmCoinInfo is not initialized in the state,
// mainly for historical queries.
defaultEvmCoinInfo types.EvmCoinInfo
}

// NewKeeper generates new evm module keeper
Expand Down Expand Up @@ -139,6 +143,13 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", types.ModuleName)
}

// WithDefaultEvmCoinInfo set default EvmCoinInfo
func (k *Keeper) WithDefaultEvmCoinInfo(coinInfo types.EvmCoinInfo) *Keeper {
k.defaultEvmCoinInfo = coinInfo
types.SetDefaultEvmCoinInfo(coinInfo)
return k
}

// ----------------------------------------------------------------------------
// Block Bloom
// Required by Web3 API.
Expand Down
27 changes: 23 additions & 4 deletions x/vm/types/denom_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,29 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

// defaultEvmCoinInfo provides a default configuration to prevent nil pointer dereferences
// when RPC requests execute before evmCoinInfo is initialized in PreBlock.
// This is set via SetDefaultEvmCoinInfo from the keeper's defaultEvmCoinInfo field.
var defaultEvmCoinInfo *EvmCoinInfo

// SetDefaultEvmCoinInfo sets the default EVM coin info to be used as fallback.
// This should be called during keeper initialization.
func SetDefaultEvmCoinInfo(coinInfo EvmCoinInfo) {
defaultEvmCoinInfo = &coinInfo
}

// evmCoinInfo hold the information of the coin used in the EVM as gas token. It
// can only be set via `EVMConfigurator` before starting the app.
var evmCoinInfo *EvmCoinInfo

// getEvmCoinInfo returns the evmCoinInfo if set, otherwise returns defaultEvmCoinInfo.
func getEvmCoinInfo() *EvmCoinInfo {
if evmCoinInfo == nil {
return defaultEvmCoinInfo
}
return evmCoinInfo
}

// setEVMCoinDecimals allows to define the decimals used in the representation
// of the EVM coin.
func setEVMCoinDecimals(d Decimals) error {
Expand Down Expand Up @@ -58,22 +77,22 @@ func setDisplayDenom(displayDenom string) error {
// GetEVMCoinDecimals returns the decimals used in the representation of the EVM
// coin.
func GetEVMCoinDecimals() Decimals {
return Decimals(evmCoinInfo.Decimals)
return Decimals(getEvmCoinInfo().Decimals)
}

// GetEVMCoinDenom returns the denom used for the EVM coin.
func GetEVMCoinDenom() string {
return evmCoinInfo.Denom
return getEvmCoinInfo().Denom
}

// GetEVMCoinExtendedDenom returns the extended denom used for the EVM coin.
func GetEVMCoinExtendedDenom() string {
return evmCoinInfo.ExtendedDenom
return getEvmCoinInfo().ExtendedDenom
}

// GetEVMCoinDisplayDenom returns the display denom used for the EVM coin.
func GetEVMCoinDisplayDenom() string {
return evmCoinInfo.DisplayDenom
return getEvmCoinInfo().DisplayDenom
}

// setEVMCoinInfo allows to define denom and decimals of the coin used in the EVM.
Expand Down
6 changes: 6 additions & 0 deletions x/vm/types/denom_config_testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ import (
// can only be set via `EVMConfigurator` before starting the app.
var testingEvmCoinInfo *EvmCoinInfo

// SetDefaultEvmCoinInfo sets the default EVM coin info to be used as fallback.
// This should be called during keeper initialization.
func SetDefaultEvmCoinInfo(coinInfo EvmCoinInfo) {
testingEvmCoinInfo = &coinInfo
}

// setEVMCoinDecimals allows to define the decimals used in the representation
// of the EVM coin.
func setEVMCoinDecimals(d Decimals) error {
Expand Down
Loading