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

feat(evm): keeper collections and grpc query impls for EthAccount, NibiruAccount #1873

Merged
merged 15 commits into from
May 15, 2024
Merged
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#1855](https://github.com/NibiruChain/nibiru/pull/1855) - feat(eth-pubsub): Implement in-memory EventBus for real-time topic management and event distribution
- [#1856](https://github.com/NibiruChain/nibiru/pull/1856) - feat(eth-rpc): Conversion types and functions between Ethereum txs and blocks and Tendermint ones.
- [#1861](https://github.com/NibiruChain/nibiru/pull/1861) - feat(eth-rpc): RPC backend, Ethereum tracer, KV indexer, and RPC APIs
- [#1869](https://github.com/NibiruChain/nibiru/pull/1869) - feat(eth): Module and start of keeper tests
- [#1869](https://github.com/NibiruChain/nibiru/pull/1869) - feat(eth): Module and start of keeper tests
- [#1873](https://github.com/NibiruChain/nibiru/pull/1873) - feat(evm): keeper collections and grpc query impls for EthAccount, NibiruAccount
Comment on lines +61 to +62
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove trailing space.

- - [#1869](https://github.com/NibiruChain/nibiru/pull/1869) - feat(eth): Module and start of keeper tests 
+ - [#1869](https://github.com/NibiruChain/nibiru/pull/1869) - feat(eth): Module and start of keeper tests

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
- [#1869](https://github.com/NibiruChain/nibiru/pull/1869) - feat(eth): Module and start of keeper tests
- [#1873](https://github.com/NibiruChain/nibiru/pull/1873) - feat(evm): keeper collections and grpc query impls for EthAccount, NibiruAccount
- [#1869](https://github.com/NibiruChain/nibiru/pull/1869) - feat(eth): Module and start of keeper tests
- [#1873](https://github.com/NibiruChain/nibiru/pull/1873) - feat(evm): keeper collections and grpc query impls for EthAccount, NibiruAccount

Copy link
Contributor

Choose a reason for hiding this comment

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

Add a period at the end of the entry for consistency.

- - [#1873](https://github.com/NibiruChain/nibiru/pull/1873) - feat(evm): keeper collections and grpc query impls for EthAccount, NibiruAccount
+ - [#1873](https://github.com/NibiruChain/nibiru/pull/1873) - feat(evm): keeper collections and grpc query impls for EthAccount, NibiruAccount.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
- [#1873](https://github.com/NibiruChain/nibiru/pull/1873) - feat(evm): keeper collections and grpc query impls for EthAccount, NibiruAccount
- [#1873](https://github.com/NibiruChain/nibiru/pull/1873) - feat(evm): keeper collections and grpc query impls for EthAccount, NibiruAccount.


#### Dapp modules: perp, spot, oracle, etc

Expand Down
47 changes: 27 additions & 20 deletions app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,8 @@ type AnteHandlerOptions struct {
// numbers, checks signatures and account numbers, and deducts fees from the
// first signer.
func NewAnteHandler(options AnteHandlerOptions) (sdk.AnteHandler, error) {
if options.AccountKeeper == nil {
return nil, AnteHandlerError("account keeper")
}
if options.BankKeeper == nil {
return nil, AnteHandlerError("bank keeper")
}
if options.SignModeHandler == nil {
return nil, AnteHandlerError("sign mode handler")
}
if options.SigGasConsumer == nil {
options.SigGasConsumer = sdkante.DefaultSigVerificationGasConsumer
}
if options.WasmConfig == nil {
return nil, AnteHandlerError("wasm config")
}
if options.DevGasKeeper == nil {
return nil, AnteHandlerError("devgas keeper")
}
if options.IBCKeeper == nil {
return nil, AnteHandlerError("ibc keeper")
if err := options.ValidateAndClean(); err != nil {
return nil, err
}

anteDecorators := []sdk.AnteDecorator{
Expand Down Expand Up @@ -80,6 +62,31 @@ func NewAnteHandler(options AnteHandlerOptions) (sdk.AnteHandler, error) {
return sdk.ChainAnteDecorators(anteDecorators...), nil
}

func (opts *AnteHandlerOptions) ValidateAndClean() error {
if opts.AccountKeeper == nil {
return AnteHandlerError("account keeper")
}
if opts.BankKeeper == nil {
return AnteHandlerError("bank keeper")
}
if opts.SignModeHandler == nil {
return AnteHandlerError("sign mode handler")
}
if opts.SigGasConsumer == nil {
opts.SigGasConsumer = sdkante.DefaultSigVerificationGasConsumer
}
if opts.WasmConfig == nil {
return AnteHandlerError("wasm config")
}
if opts.DevGasKeeper == nil {
return AnteHandlerError("devgas keeper")
}
if opts.IBCKeeper == nil {
return AnteHandlerError("ibc keeper")
}
return nil
}

func AnteHandlerError(shortDesc string) error {
return sdkerrors.Wrapf(errors.ErrLogic, "%s is required for AnteHandler", shortDesc)
}
2 changes: 1 addition & 1 deletion app/ante/fixed_gas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (suite *AnteTestSuite) TestOraclePostPriceTransactionsHaveFixedPrice() {
Amount: sdk.NewCoins(sdk.NewInt64Coin(appconst.BondDenom, 200)),
},
},
expectedGas: 62288,
expectedGas: 67193,
expectedErr: nil,
},
}
Expand Down
2 changes: 1 addition & 1 deletion app/ante/testutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (suite *AnteTestSuite) SetupTest() {
// Set up base app and ctx
testapp.EnsureNibiruPrefix()
encodingConfig := app.MakeEncodingConfig()
suite.app = testapp.NewNibiruTestApp(app.NewDefaultGenesisState(encodingConfig.Marshaler))
suite.app = testapp.NewNibiruTestApp(app.NewDefaultGenesisState(encodingConfig.Codec))
chainId := "test-chain-id"
ctx := suite.app.NewContext(true, tmproto.Header{
Height: 1,
Expand Down
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func NewNibiruApp(
appOpts servertypes.AppOptions,
baseAppOptions ...func(*baseapp.BaseApp),
) *NibiruApp {
appCodec := encodingConfig.Marshaler
appCodec := encodingConfig.Codec
legacyAmino := encodingConfig.Amino
interfaceRegistry := encodingConfig.InterfaceRegistry
txConfig := encodingConfig.TxConfig
Expand Down
2 changes: 1 addition & 1 deletion app/appconst/appconst.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func init() {
GoArch = runtime.GOARCH
}

func Version() string {
func RuntimeVersion() string {
return fmt.Sprintf(
"Version %s (%s)\nCompiled at %s using Go %s (%s)",
AppVersion,
Expand Down
4 changes: 2 additions & 2 deletions app/codec/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
// This is provided for compatibility between protobuf and amino implementations.
type EncodingConfig struct {
InterfaceRegistry types.InterfaceRegistry
Marshaler codec.Codec
Codec codec.Codec
TxConfig client.TxConfig
Amino *codec.LegacyAmino
}
Expand All @@ -25,7 +25,7 @@ func MakeEncodingConfig() EncodingConfig {

return EncodingConfig{
InterfaceRegistry: interfaceRegistry,
Marshaler: marshaler,
Codec: marshaler,
TxConfig: txCfg,
Amino: amino,
}
Expand Down
2 changes: 1 addition & 1 deletion app/ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func SetupNibiruTestingApp() (

// Create genesis state
encCdc := app.MakeEncodingConfig()
genesisState := app.NewDefaultGenesisState(encCdc.Marshaler)
genesisState := app.NewDefaultGenesisState(encCdc.Codec)
testapp.SetDefaultSudoGenesis(genesisState)

return nibiruApp, genesisState
Expand Down
8 changes: 6 additions & 2 deletions app/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ import (
// ---------------------------------------------------------------
// Nibiru Custom Modules

"github.com/NibiruChain/nibiru/eth"
"github.com/NibiruChain/nibiru/x/common"
"github.com/NibiruChain/nibiru/x/devgas/v1"
devgaskeeper "github.com/NibiruChain/nibiru/x/devgas/v1/keeper"
Expand Down Expand Up @@ -280,11 +281,12 @@ func (app *NibiruApp) InitKeepers(
// seal capability keeper after scoping modules
// app.capabilityKeeper.Seal()

// add keepers
// TODO: chore(upgrade): Potential breaking change on AccountKeeper dur
// to ProtoBaseAccount replacement.
app.AccountKeeper = authkeeper.NewAccountKeeper(
appCodec,
keys[authtypes.StoreKey],
authtypes.ProtoBaseAccount,
eth.ProtoBaseAccount,
Comment on lines +284 to +289
Copy link
Contributor

Choose a reason for hiding this comment

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

Clarify the TODO comment and ensure the initialization of AccountKeeper with eth.ProtoBaseAccount is correct.

The TODO comment should be more specific about the potential breaking change and what needs to be done to address it. Additionally, verify that eth.ProtoBaseAccount is the correct type to use here.

- // TODO: chore(upgrade): Potential breaking change on AccountKeeper dur
- // to ProtoBaseAccount replacement.
+ // TODO: chore(upgrade): Investigate potential breaking change on AccountKeeper due to ProtoBaseAccount replacement and ensure compatibility.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
// TODO: chore(upgrade): Potential breaking change on AccountKeeper dur
// to ProtoBaseAccount replacement.
app.AccountKeeper = authkeeper.NewAccountKeeper(
appCodec,
keys[authtypes.StoreKey],
authtypes.ProtoBaseAccount,
eth.ProtoBaseAccount,
// TODO: chore(upgrade): Investigate potential breaking change on AccountKeeper due to ProtoBaseAccount replacement and ensure compatibility.
app.AccountKeeper = authkeeper.NewAccountKeeper(
appCodec,
keys[authtypes.StoreKey],
eth.ProtoBaseAccount,

maccPerms,
sdk.GetConfig().GetBech32AccountAddrPrefix(),
govModuleAddr,
Expand Down Expand Up @@ -396,6 +398,8 @@ func (app *NibiruApp) InitKeepers(
keys[evm.StoreKey],
tkeys[evm.TransientKey],
authtypes.NewModuleAddress(govtypes.ModuleName),
app.AccountKeeper,
app.BankKeeper,
)

// ---------------------------------- IBC keepers
Expand Down
10 changes: 5 additions & 5 deletions app/modules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ func (s *TestSuite) SetupSuite() {
}

func (s *TestSuite) DefaultGenesisCopy() app.GenesisState {
return app.NewDefaultGenesisState(s.encCfg.Marshaler)
return app.NewDefaultGenesisState(s.encCfg.Codec)
}

func (s *TestSuite) TestGenesis() {
getDefaultStakingGenesis := func() *stakingtypes.GenesisState {
genStaking := new(stakingtypes.GenesisState)
s.encCfg.Marshaler.MustUnmarshalJSON(
app.StakingModule{}.DefaultGenesis(s.encCfg.Marshaler),
s.encCfg.Codec.MustUnmarshalJSON(
app.StakingModule{}.DefaultGenesis(s.encCfg.Codec),
genStaking,
)
return genStaking
Expand Down Expand Up @@ -61,9 +61,9 @@ func (s *TestSuite) TestGenesis() {
},
} {
s.T().Run(tc.name, func(t *testing.T) {
genStakingJson := s.encCfg.Marshaler.MustMarshalJSON(tc.gen)
genStakingJson := s.encCfg.Codec.MustMarshalJSON(tc.gen)
err := app.StakingModule{}.ValidateGenesis(
s.encCfg.Marshaler,
s.encCfg.Codec,
s.encCfg.TxConfig,
genStakingJson,
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/nibid/cmd/decode_base64_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestBase64Decode(t *testing.T) {
cfg, err := genutiltest.CreateDefaultTendermintConfig(home)
require.NoError(t, err)

appCodec := app.MakeEncodingConfig().Marshaler
appCodec := app.MakeEncodingConfig().Codec
err = genutiltest.ExecInitCmd(
testModuleBasicManager, home, appCodec)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/nibid/cmd/genaccounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestAddGenesisAccountCmd(t *testing.T) {
cfg, err := genutiltest.CreateDefaultTendermintConfig(home)
require.NoError(t, err)

appCodec := app.MakeEncodingConfig().Marshaler
appCodec := app.MakeEncodingConfig().Codec
Copy link
Contributor

Choose a reason for hiding this comment

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

Update test description.

Update the test description to reflect the change from Marshaler to Codec.

- appCodec := app.MakeEncodingConfig().Codec
+ // Use Codec instead of Marshaler for encoding configuration
+ appCodec := app.MakeEncodingConfig().Codec

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
appCodec := app.MakeEncodingConfig().Codec
// Use Codec instead of Marshaler for encoding configuration
appCodec := app.MakeEncodingConfig().Codec

err = genutiltest.ExecInitCmd(
testModuleBasicManager, home, appCodec)
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/nibid/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func NewRootCmd() (*cobra.Command, app.EncodingConfig) {
app.SetPrefixes(appconst.AccountAddressPrefix)

initClientCtx := client.Context{}.
WithCodec(encodingConfig.Marshaler).
WithCodec(encodingConfig.Codec).
WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
WithTxConfig(encodingConfig.TxConfig).
WithLegacyAmino(encodingConfig.Amino).
Expand Down
6 changes: 3 additions & 3 deletions cmd/nibid/cmd/testnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ func Test_TestnetCmd(t *testing.T) {
cfg, err := genutiltest.CreateDefaultTendermintConfig(home)
require.NoError(t, err)

err = genutiltest.ExecInitCmd(app.ModuleBasics, home, encodingConfig.Marshaler)
err = genutiltest.ExecInitCmd(app.ModuleBasics, home, encodingConfig.Codec)
require.NoError(t, err)

serverCtx := server.NewContext(viper.New(), cfg, logger)
clientCtx := client.Context{}.
WithCodec(encodingConfig.Marshaler).
WithCodec(encodingConfig.Codec).
WithHomeDir(home).
WithTxConfig(encodingConfig.TxConfig)

Expand All @@ -49,6 +49,6 @@ func Test_TestnetCmd(t *testing.T) {
appState, _, err := genutiltypes.GenesisStateFromGenFile(genFile)
require.NoError(t, err)

bankGenState := banktypes.GetGenesisStateFromAppState(encodingConfig.Marshaler, appState)
bankGenState := banktypes.GetGenesisStateFromAppState(encodingConfig.Codec, appState)
require.NotEmpty(t, bankGenState.Supply.String())
}
14 changes: 8 additions & 6 deletions eth/chain_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"math/big"
"regexp"
"strings"

errorsmod "cosmossdk.io/errors"
)

var (
Expand All @@ -24,7 +22,8 @@ var (
regexEpoch))
)

// IsValidChainID returns false if the given chain identifier is incorrectly formatted.
// IsValidChainID returns false if the given chain identifier is incorrectly
// formatted.
func IsValidChainID(chainID string) bool {
if len(chainID) > 48 {
return false
Expand All @@ -39,18 +38,21 @@ func IsValidChainID(chainID string) bool {
func ParseChainID(chainID string) (*big.Int, error) {
chainID = strings.TrimSpace(chainID)
if len(chainID) > 48 {
return nil, errorsmod.Wrapf(ErrInvalidChainID, "chain-id '%s' cannot exceed 48 chars", chainID)
return nil, ErrInvalidChainID.Wrapf(
`chain-id input "%s" cannot exceed 48 chars`, chainID)
}

matches := nibiruEvmChainId.FindStringSubmatch(chainID)
if matches == nil || len(matches) != 4 || matches[1] == "" {
return nil, errorsmod.Wrapf(ErrInvalidChainID, "%s: %v", chainID, matches)
return nil, ErrInvalidChainID.Wrapf(
`chain-id input "%s", matches "%v"`, chainID, matches)
}

// verify that the chain-id entered is a base 10 integer
chainIDInt, ok := new(big.Int).SetString(matches[2], 10)
if !ok {
return nil, errorsmod.Wrapf(ErrInvalidChainID, "epoch %s must be base-10 integer format", matches[2])
return nil, ErrInvalidChainID.Wrapf(
`epoch "%s" must be base-10 integer format`, matches[2])
}

return chainIDInt, nil
Expand Down
Loading
Loading