Skip to content

Commit 7e05c8a

Browse files
committed
Merge remote-tracking branch 'origin/main' into multi_grpc
2 parents 744a04d + 6de21f7 commit 7e05c8a

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
- [\#774](https://github.com/cosmos/evm/pull/774) Emit proper allowance amount in erc20 event.
2929
- [\#790](https://github.com/cosmos/evm/pull/790) fix panic in historical query due to missing EvmCoinInfo.
3030
- [\#800](https://github.com/cosmos/evm/pull/800) Fix denom exponent validation in virtual fee deduct in vm module.
31+
- [\#816](https://github.com/cosmos/evm/pull/816) Avoid nil pointer when RPC requests execute before evmCoinInfo initialization in PreBlock with defaultEvmCoinInfo fallback.
3132

3233
## v0.5.0
3334

x/vm/keeper/keeper.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger {
161161
// WithDefaultEvmCoinInfo set default EvmCoinInfo
162162
func (k *Keeper) WithDefaultEvmCoinInfo(coinInfo types.EvmCoinInfo) *Keeper {
163163
k.defaultEvmCoinInfo = coinInfo
164+
types.SetDefaultEvmCoinInfo(coinInfo)
164165
return k
165166
}
166167

x/vm/types/denom_config.go

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,29 @@ import (
1414
sdk "github.com/cosmos/cosmos-sdk/types"
1515
)
1616

17+
// defaultEvmCoinInfo provides a default configuration to prevent nil pointer dereferences
18+
// when RPC requests execute before evmCoinInfo is initialized in PreBlock.
19+
// This is set via SetDefaultEvmCoinInfo from the keeper's defaultEvmCoinInfo field.
20+
var defaultEvmCoinInfo *EvmCoinInfo
21+
22+
// SetDefaultEvmCoinInfo sets the default EVM coin info to be used as fallback.
23+
// This should be called during keeper initialization.
24+
func SetDefaultEvmCoinInfo(coinInfo EvmCoinInfo) {
25+
defaultEvmCoinInfo = &coinInfo
26+
}
27+
1728
// evmCoinInfo hold the information of the coin used in the EVM as gas token. It
1829
// can only be set via `EVMConfigurator` before starting the app.
1930
var evmCoinInfo *EvmCoinInfo
2031

32+
// getEvmCoinInfo returns the evmCoinInfo if set, otherwise returns defaultEvmCoinInfo.
33+
func getEvmCoinInfo() *EvmCoinInfo {
34+
if evmCoinInfo == nil {
35+
return defaultEvmCoinInfo
36+
}
37+
return evmCoinInfo
38+
}
39+
2140
// setEVMCoinDecimals allows to define the decimals used in the representation
2241
// of the EVM coin.
2342
func setEVMCoinDecimals(d Decimals) error {
@@ -58,22 +77,22 @@ func setDisplayDenom(displayDenom string) error {
5877
// GetEVMCoinDecimals returns the decimals used in the representation of the EVM
5978
// coin.
6079
func GetEVMCoinDecimals() Decimals {
61-
return Decimals(evmCoinInfo.Decimals)
80+
return Decimals(getEvmCoinInfo().Decimals)
6281
}
6382

6483
// GetEVMCoinDenom returns the denom used for the EVM coin.
6584
func GetEVMCoinDenom() string {
66-
return evmCoinInfo.Denom
85+
return getEvmCoinInfo().Denom
6786
}
6887

6988
// GetEVMCoinExtendedDenom returns the extended denom used for the EVM coin.
7089
func GetEVMCoinExtendedDenom() string {
71-
return evmCoinInfo.ExtendedDenom
90+
return getEvmCoinInfo().ExtendedDenom
7291
}
7392

7493
// GetEVMCoinDisplayDenom returns the display denom used for the EVM coin.
7594
func GetEVMCoinDisplayDenom() string {
76-
return evmCoinInfo.DisplayDenom
95+
return getEvmCoinInfo().DisplayDenom
7796
}
7897

7998
// setEVMCoinInfo allows to define denom and decimals of the coin used in the EVM.

x/vm/types/denom_config_testing.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ import (
1818
// can only be set via `EVMConfigurator` before starting the app.
1919
var testingEvmCoinInfo *EvmCoinInfo
2020

21+
// SetDefaultEvmCoinInfo sets the default EVM coin info to be used as fallback.
22+
// This should be called during keeper initialization.
23+
func SetDefaultEvmCoinInfo(coinInfo EvmCoinInfo) {
24+
testingEvmCoinInfo = &coinInfo
25+
}
26+
2127
// setEVMCoinDecimals allows to define the decimals used in the representation
2228
// of the EVM coin.
2329
func setEVMCoinDecimals(d Decimals) error {

0 commit comments

Comments
 (0)