-
Notifications
You must be signed in to change notification settings - Fork 193
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
Conversation
WalkthroughThe changes in the Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1873 +/- ##
==========================================
- Coverage 67.79% 67.13% -0.67%
==========================================
Files 208 212 +4
Lines 13228 13467 +239
==========================================
+ Hits 8968 9041 +73
- Misses 3619 3780 +161
- Partials 641 646 +5
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 24
Review Details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files ignored due to path filters (4)
go.mod
is excluded by!**/*.mod
,!**/*.mod
go.sum
is excluded by!**/*.sum
,!**/*.sum
x/evm/query.pb.go
is excluded by!**/*.pb.go
,!**/*.pb.go
x/evm/query.pb.gw.go
is excluded by!**/*.pb.gw.go
,!**/*.pb.gw.go
Files selected for processing (55)
- CHANGELOG.md (1 hunks)
- app/ante.go (2 hunks)
- app/ante/fixed_gas_test.go (1 hunks)
- app/ante/testutil_test.go (1 hunks)
- app/app.go (1 hunks)
- app/appconst/appconst.go (1 hunks)
- app/codec/codec.go (2 hunks)
- app/ibc_test.go (1 hunks)
- app/keepers.go (3 hunks)
- app/modules_test.go (2 hunks)
- cmd/nibid/cmd/decode_base64_test.go (1 hunks)
- cmd/nibid/cmd/genaccounts_test.go (1 hunks)
- cmd/nibid/cmd/root.go (1 hunks)
- cmd/nibid/cmd/testnet_test.go (2 hunks)
- eth/chain_id.go (3 hunks)
- eth/chain_id_test.go (1 hunks)
- eth/codec.go (1 hunks)
- eth/codec_test.go (1 hunks)
- eth/encoding/config.go (1 hunks)
- eth/eth_account.go (1 hunks)
- eth/indexer/kv_indexer_test.go (1 hunks)
- eth/rpc/backend/account_info.go (1 hunks)
- eth/rpc/backend/evm_query_client_test.go (1 hunks)
- eth/rpc/backend/mocks/evm_query_client.go (4 hunks)
- eth/rpc/rpcapi/web3_api.go (1 hunks)
- proto/eth/evm/v1/query.proto (4 hunks)
- x/common/error.go (1 hunks)
- x/common/testutil/cli/network.go (1 hunks)
- x/common/testutil/cli/network_test.go (1 hunks)
- x/common/testutil/cli/util.go (1 hunks)
- x/common/testutil/genesis/genesis.go (1 hunks)
- x/common/testutil/genesis/oracle_genesis.go (1 hunks)
- x/common/testutil/genesis/sudo_genesis.go (1 hunks)
- x/common/testutil/testapp/testapp.go (3 hunks)
- x/epochs/genesis_test.go (1 hunks)
- x/evm/codec.go (1 hunks)
- x/evm/const.go (2 hunks)
- x/evm/evmmodule/genesis.go (2 hunks)
- x/evm/evmmodule/module.go (2 hunks)
- x/evm/evmtest/eth.go (3 hunks)
- x/evm/keeper/evm_state.go (1 hunks)
- x/evm/keeper/grpc_query.go (5 hunks)
- x/evm/keeper/grpc_query_test.go (1 hunks)
- x/evm/keeper/keeper.go (2 hunks)
- x/evm/keeper/keeper_test.go (1 hunks)
- x/evm/keeper/statedb.go (1 hunks)
- x/evm/msg.go (2 hunks)
- x/evm/query.go (1 hunks)
- x/evm/query_test.go (1 hunks)
- x/evm/statedb/interfaces.go (1 hunks)
- x/genmsg/integration_test.go (2 hunks)
- x/oracle/types/genesis_test.go (1 hunks)
- x/oracle/types/test_utils.go (1 hunks)
- x/sudo/cli/cli_test.go (1 hunks)
- x/tokenfactory/keeper/msg_server.go (1 hunks)
Files not processed due to max files limit (1)
- x/tokenfactory/keeper/wasm_test.go
Files skipped from review due to trivial changes (7)
- app/appconst/appconst.go
- x/common/error.go
- x/common/testutil/cli/util.go
- x/common/testutil/genesis/genesis.go
- x/evm/codec.go
- x/evm/keeper/keeper_test.go
- x/evm/query.go
Additional comments not posted (77)
eth/rpc/rpcapi/web3_api.go (1)
21-21
: Update method to returnRuntimeVersion
.The change to return
appconst.RuntimeVersion()
is correct and aligns with the renaming inappconst.go
.x/oracle/types/genesis_test.go (1)
22-22
: Update codec usage in test.The change to use
app.MakeEncodingConfig().Codec
is correct and aligns with the shift fromMarshaler
toCodec
.x/common/testutil/genesis/oracle_genesis.go (1)
13-13
: Update codec usage inAddOracleGenesis
.The change to use
app.MakeEncodingConfig().Codec
is correct and aligns with the shift fromMarshaler
toCodec
.x/common/testutil/genesis/sudo_genesis.go (1)
22-23
: Update codec usage inAddSudoGenesis
.The change to use
app.MakeEncodingConfig().Codec
is correct and aligns with the shift fromMarshaler
toCodec
.app/codec/codec.go (2)
14-14
: UpdateEncodingConfig
struct to useCodec
.The change to use
codec.Codec
in theEncodingConfig
struct is correct and aligns with the shift fromMarshaler
toCodec
.
28-28
: UpdateMakeEncodingConfig
function to useCodec
.The change to use
codec.Codec
in theMakeEncodingConfig
function is correct and aligns with the shift fromMarshaler
toCodec
.eth/encoding/config.go (1)
29-29
: Update codec usage inMakeConfig
.The change to use
amino.NewProtoCodec
in theMakeConfig
function is correct and aligns with the shift fromMarshaler
toCodec
.x/evm/query_test.go (1)
14-57
: The test cases for nil queries are well-structured and ensure that nil requests return the appropriate error. Consider adding more test cases for other potential edge cases if necessary.eth/chain_id.go (2)
25-28
: TheIsValidChainID
function correctly validates the chain ID format using a regular expression. The implementation looks good.
41-55
: TheParseChainID
function correctly handles trimming, length checking, and parsing of the chain ID. Error handling is appropriately implemented. The implementation looks good.x/evm/statedb/interfaces.go (2)
Line range hint
12-15
: TheExtStateDB
interface is well-defined and extends the existingvm.StateDB
interface appropriately with theAppendJournalEntry
method.
22-39
: TheKeeper
interface is well-structured and covers essential functionalities for managing Ethereum accounts and contract storage. The implementation looks good.x/genmsg/integration_test.go (1)
Line range hint
23-52
: TheTestIntegration
test case is well-structured and verifies the integration of thegenmsg
module with the bank module. The implementation looks good.app/modules_test.go (1)
Line range hint
34-71
: TheTestGenesis
test case is well-structured and covers both default and custom genesis states for the staking module. Error handling is appropriately implemented. The implementation looks good.cmd/nibid/cmd/testnet_test.go (1)
Line range hint
28-52
: TheTest_TestnetCmd
test case is well-structured and verifies the correct execution of thetestnet
command. The changes fromMarshaler
toCodec
are correctly implemented. The implementation looks good.x/evm/const.go (1)
36-39
: Ensure unique namespace values.Verify that the namespace values are unique across the entire codebase to avoid conflicts.
eth/codec.go (1)
34-38
: Ensure proper usage of constants.Verify that the new constants
TYPE_URL_WEB3_TX
andTYPE_URL_DYNAMIC_FEE_TX
are used correctly throughout the codebase.Verification successful
The new constants
TYPE_URL_WEB3_TX
andTYPE_URL_DYNAMIC_FEE_TX
are correctly used in the test fileeth/codec_test.go
to verify their presence and correctness in the implementation ofTxExtensionOptionI
.
Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the usage of new constants `TYPE_URL_WEB3_TX` and `TYPE_URL_DYNAMIC_FEE_TX`. # Test: Search for the usage of the new constants. Expect: Proper usage in relevant files. rg --type go 'TYPE_URL_WEB3_TX' rg --type go 'TYPE_URL_DYNAMIC_FEE_TX'Length of output: 320
Script:
#!/bin/bash # Description: Verify the context and correctness of the usage of new constants in the test file. # Test: Display the lines around the usage of the constants in the test file. rg --type go -C 5 'TYPE_URL_WEB3_TX' eth/codec_test.go rg --type go -C 5 'TYPE_URL_DYNAMIC_FEE_TX' eth/codec_test.goLength of output: 555
eth/codec_test.go (2)
51-52
: LGTM! The interface registration and implementation checks are comprehensive.
Line range hint
91-97
: LGTM! The filtering logic is straightforward and effective.eth/chain_id_test.go (2)
12-41
: LGTM! The test cases for valid chain IDs are comprehensive and well-structured.
43-122
: LGTM! The test cases for invalid chain IDs are extensive and ensure thorough validation.eth/eth_account.go (3)
31-42
: LGTM! TheEthAccountI
interface is well-defined and comprehensive.
44-84
: LGTM! TheEthAccount
struct and its methods are correctly implemented.
21-29
: LGTM! TheEthAccType
constants are well-defined and appropriately used.x/evm/evmtest/eth.go (6)
27-29
: LGTM! The function correctly generates a new Ethereum address.
31-38
: LGTM! The function correctly generates a pair of Ethereum and Nibiru addresses.
40-42
: LGTM! The function correctly converts an Ethereum address to a Nibiru address.
Line range hint
44-50
: LGTM! The function correctly generates an Ethereum private key and address.
Line range hint
52-54
: LGTM! The function correctly returns a new Ethereum transaction message.
Line range hint
83-101
: LGTM! The function correctly converts an Ethereum transaction message to consensus engine bytes.cmd/nibid/cmd/decode_base64_test.go (5)
34-34
: LGTM! The test case correctly checks a valid base64 message.
34-34
: LGTM! The test case correctly checks a valid base64 message with an additional field.
34-34
: LGTM! The test case correctly checks a valid base64 message with an additional field in a different format.
34-34
: LGTM! The test case correctly checks an empty base64 message.
34-34
: LGTM! The test case correctly checks an invalid JSON message.app/ante.go (2)
33-34
: LGTM! The function correctly initializes the AnteHandler with the necessary decorators.
65-88
: LGTM! The function correctly validates and cleans the AnteHandlerOptions.x/common/testutil/cli/network_test.go (1)
89-89
: Update to useCodec
instead ofMarshaler
looks good.app/ante/testutil_test.go (1)
42-42
: Update to useCodec
instead ofMarshaler
looks good.x/epochs/genesis_test.go (1)
23-23
: Update to useCodec
instead ofMarshaler
looks good.x/evm/keeper/evm_state.go (2)
1-99
: The new types and methods for handling EVM state are well-defined and follow existing patterns. The use of collections for managing state is appropriate.
101-147
: The methods for setting and getting account code and state are well-implemented and handle edge cases appropriately.x/oracle/types/test_utils.go (1)
152-152
: The addition of theSharesFromTokensTruncated
method to theMockValidator
struct is consistent with the existing methods and follows the expected pattern.x/evm/keeper/grpc_query_test.go (1)
1-183
: The new test cases for queryingNibiruAccount
andEthAccount
are comprehensive and cover various scenarios. The use of helper functions and structs improves readability and maintainability.x/evm/evmmodule/module.go (1)
96-96
: Registering Ethereum-related interfaces is necessary for handling Ethereum accounts and transactions.eth/indexer/kv_indexer_test.go (1)
45-46
: Usingapp.MakeEncodingConfig()
ensures consistency with the application's encoding configuration.x/common/testutil/testapp/testapp.go (3)
39-39
: Usingencoding.Codec
ensures consistency with the updated encoding configuration.
89-89
: Usingencoding.Codec
ensures consistency with the updated encoding configuration.
124-124
: Usingencoding.Codec
ensures consistency with the updated encoding configuration.eth/rpc/backend/account_info.go (2)
98-98
: UsingQueryEthAccountRequest
ensures the function uses the correct query request type for Ethereum accounts.
102-102
: UsingEthAccount
ensures the function uses the correct response type for Ethereum accounts.x/tokenfactory/keeper/msg_server.go (1)
16-16
: Introducing a reusable error variable for nil gRPC messages improves code readability and maintainability.app/ibc_test.go (1)
37-37
: UsingencodingConfig.Codec
ensures consistency with the updated encoding configuration.x/sudo/cli/cli_test.go (1)
266-266
: Change aligns with the shift fromMarshaler
toCodec
.app/ante/fixed_gas_test.go (1)
200-200
: Update reflects the new expected gas value.cmd/nibid/cmd/root.go (1)
42-42
: Change aligns with the shift fromMarshaler
toCodec
.x/evm/keeper/grpc_query.go (7)
9-11
: Necessary imports for new gRPC query implementations.
19-29
: Comment provides a clear description of theEthAccount
method.
47-57
: Comment provides a clear description of theNibiruAccount
method.
114-116
: Validation check ensures request validity.
144-149
: Validation check ensures request validity.
192-196
: Comment provides a clear description of theParams
method.
231-243
: Comment provides a clear description of theEstimateGasForEvmCallType
method.proto/eth/evm/v1/query.proto (7)
16-18
: Addition of theEthAccount
RPC method aligns with new gRPC query implementations.
21-23
: Addition of theNibiruAccount
RPC method aligns with new gRPC query implementations.
80-81
: Addition of theQueryEthAccountRequest
message aligns with new gRPC query implementations.
89-90
: Addition of theQueryEthAccountResponse
message aligns with new gRPC query implementations.
99-101
: Addition of theQueryNibiruAccountRequest
message aligns with new gRPC query implementations.
109-111
: Addition of theQueryNibiruAccountResponse
message aligns with new gRPC query implementations.
133-133
: Addition of theQueryValidatorAccountResponse
message aligns with new gRPC query implementations.eth/rpc/backend/mocks/evm_query_client.go (2)
Line range hint
20-43
:EthAccount
method implementation looks good and follows the existing pattern for mock functions.
Line range hint
140-163
:NibiruAccount
method implementation looks good and follows the existing pattern for mock functions.eth/rpc/backend/evm_query_client_test.go (1)
287-288
: Update mock registration to useEthAccount
.The change to use
EthAccount
instead ofAccount
in theRegisterAccount
function is correct and aligns with the new naming conventions.app/app.go (1)
133-133
: Update encoding configuration to useCodec
.The change to use
Codec
instead ofMarshaler
in theNewNibiruApp
function is correct and aligns with the new encoding configurations.x/common/testutil/cli/network.go (1)
160-160
: Correctly replacedMarshaler
withCodec
in theBuildNetworkConfig
function to align with the updated encoding configuration.app/keepers.go (2)
108-108
: Ensure theeth
import is necessary and used correctly.The
eth
package is imported but not used in the provided code. Verify if this import is required or if it can be removed to avoid unnecessary dependencies.
401-402
: Verify the initialization ofEvmKeeper
withAccountKeeper
andBankKeeper
.Ensure that
AccountKeeper
andBankKeeper
are correctly initialized and passed toEvmKeeper
. This change should be consistent with the overall architecture and design of the application.
- [#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 |
There was a problem hiding this comment.
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.
- [#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 |
// TODO: chore(upgrade): Potential breaking change on AccountKeeper dur | ||
// to ProtoBaseAccount replacement. | ||
app.AccountKeeper = authkeeper.NewAccountKeeper( | ||
appCodec, | ||
keys[authtypes.StoreKey], | ||
authtypes.ProtoBaseAccount, | ||
eth.ProtoBaseAccount, |
There was a problem hiding this comment.
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.
// 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, |
@@ -58,7 +58,8 @@ | |||
- [#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 |
There was a problem hiding this comment.
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.
- [#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. |
|
||
var EmptyCodeHash = crypto.Keccak256(nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Define EmptyCodeHash
as a constant.
The EmptyCodeHash
variable should be defined as a constant since its value is immutable and represents a fixed value.
- var EmptyCodeHash = crypto.Keccak256(nil)
+ const EmptyCodeHash = crypto.Keccak256(nil)
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.
var EmptyCodeHash = crypto.Keccak256(nil) | |
const EmptyCodeHash = crypto.Keccak256(nil) |
// StoreKey: Persistent storage key for ethereum storage data, account code | ||
// (StateDB) or block related data for the Eth Web3 API. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improve comment clarity.
Consider rephrasing the comment for better clarity:
- // StoreKey: Persistent storage key for ethereum storage data, account code
- // (StateDB) or block related data for the Eth Web3 API.
+ // StoreKey: Persistent storage key for Ethereum storage data, account code (StateDB), or block-related data for the Eth Web3 API.
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.
// StoreKey: Persistent storage key for ethereum storage data, account code | |
// (StateDB) or block related data for the Eth Web3 API. | |
// StoreKey: Persistent storage key for Ethereum storage data, account code (StateDB), or block-related data for the Eth Web3 API. |
"bytes" | ||
"fmt" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove unnecessary blank line.
Remove the unnecessary blank line between the import statements.
- "bytes"
-
+ "bytes"
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.
"bytes" | |
"fmt" | |
"bytes" | |
"fmt" |
genState evm.GenesisState, | ||
) []abci.ValidatorUpdate { | ||
k.BeginBlock(ctx, abci.RequestBeginBlock{}) | ||
k.SetParams(ctx, genState.Params) | ||
|
||
if addr := accountKeeper.GetModuleAddress(evm.ModuleName); addr == nil { | ||
panic("the EVM module account has not been set") | ||
} | ||
|
||
for _, account := range genState.Accounts { | ||
address := gethcommon.HexToAddress(account.Address) | ||
accAddress := sdk.AccAddress(address.Bytes()) | ||
// check that the EVM balance the matches the account balance | ||
acc := accountKeeper.GetAccount(ctx, accAddress) | ||
if acc == nil { | ||
panic(fmt.Errorf("account not found for address %s", account.Address)) | ||
} | ||
|
||
ethAcct, ok := acc.(eth.EthAccountI) | ||
if !ok { | ||
panic( | ||
fmt.Errorf("account %s must be an EthAccount interface, got %T", | ||
account.Address, acc, | ||
), | ||
) | ||
} | ||
code := gethcommon.Hex2Bytes(account.Code) | ||
codeHash := crypto.Keccak256Hash(code) | ||
|
||
// we ignore the empty Code hash checking, see ethermint PR#1234 | ||
if len(account.Code) != 0 && !bytes.Equal(ethAcct.GetCodeHash().Bytes(), codeHash.Bytes()) { | ||
s := "the evm state code doesn't match with the codehash\n" | ||
panic(fmt.Sprintf("%s account: %s , evm state codehash: %v, ethAccount codehash: %v, evm state code: %s\n", | ||
s, account.Address, codeHash, ethAcct.GetCodeHash(), account.Code)) | ||
} | ||
|
||
k.SetCode(ctx, codeHash.Bytes(), code) | ||
|
||
for _, storage := range account.Storage { | ||
k.SetState(ctx, address, gethcommon.HexToHash(storage.Key), gethcommon.HexToHash(storage.Value).Bytes()) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improve error handling.
The InitGenesis
function should handle errors more gracefully instead of using panic
. Consider returning an error instead.
func InitGenesis(
ctx sdk.Context,
k *keeper.Keeper,
accountKeeper evm.AccountKeeper,
genState evm.GenesisState,
) ([]abci.ValidatorUpdate, error) {
k.BeginBlock(ctx, abci.RequestBeginBlock{})
k.SetParams(ctx, genState.Params)
if addr := accountKeeper.GetModuleAddress(evm.ModuleName); addr == nil {
return nil, fmt.Errorf("the EVM module account has not been set")
}
for _, account := range genState.Accounts {
address := gethcommon.HexToAddress(account.Address)
accAddress := sdk.AccAddress(address.Bytes())
// check that the EVM balance matches the account balance
acc := accountKeeper.GetAccount(ctx, accAddress)
if acc == nil {
return nil, fmt.Errorf("account not found for address %s", account.Address)
}
ethAcct, ok := acc.(eth.EthAccountI)
if !ok {
return nil, fmt.Errorf("account %s must be an EthAccount interface, got %T", account.Address, acc)
}
code := gethcommon.Hex2Bytes(account.Code)
codeHash := crypto.Keccak256Hash(code)
// we ignore the empty Code hash checking, see ethermint PR#1234
if len(account.Code) != 0 && !bytes.Equal(ethAcct.GetCodeHash().Bytes(), codeHash.Bytes()) {
s := "the evm state code doesn't match with the codehash\n"
return nil, fmt.Errorf("%s account: %s , evm state codehash: %v, ethAccount codehash: %v, evm state code: %s\n",
s, account.Address, codeHash, ethAcct.GetCodeHash(), account.Code)
}
k.SetCode(ctx, codeHash.Bytes(), code)
for _, storage := range account.Storage {
k.SetState(ctx, address, gethcommon.HexToHash(storage.Key), gethcommon.HexToHash(storage.Value).Bytes())
}
}
// TODO: impl InitGenesis
return []abci.ValidatorUpdate{}, nil
}
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.
genState evm.GenesisState, | |
) []abci.ValidatorUpdate { | |
k.BeginBlock(ctx, abci.RequestBeginBlock{}) | |
k.SetParams(ctx, genState.Params) | |
if addr := accountKeeper.GetModuleAddress(evm.ModuleName); addr == nil { | |
panic("the EVM module account has not been set") | |
} | |
for _, account := range genState.Accounts { | |
address := gethcommon.HexToAddress(account.Address) | |
accAddress := sdk.AccAddress(address.Bytes()) | |
// check that the EVM balance the matches the account balance | |
acc := accountKeeper.GetAccount(ctx, accAddress) | |
if acc == nil { | |
panic(fmt.Errorf("account not found for address %s", account.Address)) | |
} | |
ethAcct, ok := acc.(eth.EthAccountI) | |
if !ok { | |
panic( | |
fmt.Errorf("account %s must be an EthAccount interface, got %T", | |
account.Address, acc, | |
), | |
) | |
} | |
code := gethcommon.Hex2Bytes(account.Code) | |
codeHash := crypto.Keccak256Hash(code) | |
// we ignore the empty Code hash checking, see ethermint PR#1234 | |
if len(account.Code) != 0 && !bytes.Equal(ethAcct.GetCodeHash().Bytes(), codeHash.Bytes()) { | |
s := "the evm state code doesn't match with the codehash\n" | |
panic(fmt.Sprintf("%s account: %s , evm state codehash: %v, ethAccount codehash: %v, evm state code: %s\n", | |
s, account.Address, codeHash, ethAcct.GetCodeHash(), account.Code)) | |
} | |
k.SetCode(ctx, codeHash.Bytes(), code) | |
for _, storage := range account.Storage { | |
k.SetState(ctx, address, gethcommon.HexToHash(storage.Key), gethcommon.HexToHash(storage.Value).Bytes()) | |
} | |
} | |
func InitGenesis( | |
ctx sdk.Context, | |
k *keeper.Keeper, | |
accountKeeper evm.AccountKeeper, | |
genState evm.GenesisState, | |
) ([]abci.ValidatorUpdate, error) { | |
k.BeginBlock(ctx, abci.RequestBeginBlock{}) | |
k.SetParams(ctx, genState.Params) | |
if addr := accountKeeper.GetModuleAddress(evm.ModuleName); addr == nil { | |
return nil, fmt.Errorf("the EVM module account has not been set") | |
} | |
for _, account := range genState.Accounts { | |
address := gethcommon.HexToAddress(account.Address) | |
accAddress := sdk.AccAddress(address.Bytes()) | |
// check that the EVM balance matches the account balance | |
acc := accountKeeper.GetAccount(ctx, accAddress) | |
if acc == nil { | |
return nil, fmt.Errorf("account not found for address %s", account.Address) | |
} | |
ethAcct, ok := acc.(eth.EthAccountI) | |
if !ok { | |
return nil, fmt.Errorf("account %s must be an EthAccount interface, got %T", account.Address, acc) | |
} | |
code := gethcommon.Hex2Bytes(account.Code) | |
codeHash := crypto.Keccak256Hash(code) | |
// we ignore the empty Code hash checking, see ethermint PR#1234 | |
if len(account.Code) != 0 && !bytes.Equal(ethAcct.GetCodeHash().Bytes(), codeHash.Bytes()) { | |
s := "the evm state code doesn't match with the codehash\n" | |
return nil, fmt.Errorf("%s account: %s , evm state codehash: %v, ethAccount codehash: %v, evm state code: %s\n", | |
s, account.Address, codeHash, ethAcct.GetCodeHash(), account.Code) | |
} | |
k.SetCode(ctx, codeHash.Bytes(), code) | |
for _, storage := range account.Storage { | |
k.SetState(ctx, address, gethcommon.HexToHash(storage.Key), gethcommon.HexToHash(storage.Value).Bytes()) | |
} | |
} | |
// TODO: impl InitGenesis | |
return []abci.ValidatorUpdate{}, nil | |
} |
k.BeginBlock(ctx, abci.RequestBeginBlock{}) | ||
k.SetParams(ctx, genState.Params) | ||
|
||
if addr := accountKeeper.GetModuleAddress(evm.ModuleName); addr == nil { | ||
panic("the EVM module account has not been set") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improve error handling.
The InitGenesis
function should handle errors more gracefully instead of using panic
. Consider returning an error instead.
- if addr := accountKeeper.GetModuleAddress(evm.ModuleName); addr == nil {
- panic("the EVM module account has not been set")
- }
+ if addr := accountKeeper.GetModuleAddress(evm.ModuleName); addr == nil {
+ return nil, fmt.Errorf("the EVM module account has not been set")
+ }
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.
k.BeginBlock(ctx, abci.RequestBeginBlock{}) | |
k.SetParams(ctx, genState.Params) | |
if addr := accountKeeper.GetModuleAddress(evm.ModuleName); addr == nil { | |
panic("the EVM module account has not been set") | |
} | |
k.BeginBlock(ctx, abci.RequestBeginBlock{}) | |
k.SetParams(ctx, genState.Params) | |
if addr := accountKeeper.GetModuleAddress(evm.ModuleName); addr == nil { | |
return nil, fmt.Errorf("the EVM module account has not been set") | |
} |
if acc == nil { | ||
panic(fmt.Errorf("account not found for address %s", account.Address)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improve error handling.
The InitGenesis
function should handle errors more gracefully instead of using panic
. Consider returning an error instead.
- if acc == nil {
- panic(fmt.Errorf("account not found for address %s", account.Address))
- }
+ if acc == nil {
+ return nil, fmt.Errorf("account not found for address %s", account.Address)
+ }
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.
if acc == nil { | |
panic(fmt.Errorf("account not found for address %s", account.Address)) | |
} | |
if acc == nil { | |
return nil, fmt.Errorf("account not found for address %s", account.Address) | |
} |
if !ok { | ||
panic( | ||
fmt.Errorf("account %s must be an EthAccount interface, got %T", | ||
account.Address, acc, | ||
), | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improve error handling.
The InitGenesis
function should handle errors more gracefully instead of using panic
. Consider returning an error instead.
- if !ok {
- panic(
- fmt.Errorf("account %s must be an EthAccount interface, got %T",
- account.Address, acc,
- ),
- )
- }
+ if !ok {
+ return nil, fmt.Errorf("account %s must be an EthAccount interface, got %T", account.Address, acc)
+ }
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.
if !ok { | |
panic( | |
fmt.Errorf("account %s must be an EthAccount interface, got %T", | |
account.Address, acc, | |
), | |
) | |
} | |
if !ok { | |
return nil, fmt.Errorf("account %s must be an EthAccount interface, got %T", account.Address, acc) | |
} |
MapTransient
andItemTransient
NibiruAccount
andEthAccount
queries