Skip to content
This repository has been archived by the owner on Jun 9, 2024. It is now read-only.

feat(runtime): Polaris Runtime Module #1215

Merged
merged 190 commits into from
Oct 12, 2023
Merged

feat(runtime): Polaris Runtime Module #1215

merged 190 commits into from
Oct 12, 2023

Conversation

itsdevbear
Copy link

@itsdevbear itsdevbear commented Oct 11, 2023

Summary by CodeRabbit

  • New Feature: Introduced a new Go package runtime that provides a function ProvidePolarisRuntime for creating a new Polaris runtime.
  • Refactor: Updated the Keeper struct in the cosmos/x/evm/keeper package to include a chain field of type Blockchain and removed several methods.
  • New Feature: Added Precommit and PrepareCheckState functions to the Keeper struct in the cosmos/x/evm/keeper package.
  • Refactor: Updated the AppModule struct in the cosmos/x/evm package to include PrepareCheckState and Precommit methods.
  • New Feature: Added a new contract DeployAndConsumeGas in the contracts/scripts directory that consumes gas in a loop.
  • Refactor: Updated the MakeAppConfig function in the e2e/testapp package to include evmtypes.ModuleName in the PrepareCheckStaters and Precommiters lists.
  • New Feature: Added a safety check on the JSON-RPC config in the eth/polar/config.go file.

@coderabbitai
Copy link

coderabbitai bot commented Oct 11, 2023

Walkthrough

The changes primarily revolve around the integration of the Polaris EVM into the existing system. This includes the creation of a new runtime package, modifications to the Keeper struct, and the addition of new functions for state preparation and precommit checks. Additionally, there are changes to Solidity contracts to adjust gas consumption and minting behavior.

Changes

File(s) Summary
cosmos/runtime/depinject.go, cosmos/runtime/runtime.go Introduced a new runtime package with a function for creating a new Polaris runtime.
cosmos/x/evm/keeper/keeper.go, cosmos/x/evm/keeper/processor.go Modified the Keeper struct, introduced a Blockchain interface, and updated method calls.
cosmos/x/evm/keeper/abci.go, cosmos/x/evm/module.go Added new functions for state preparation and precommit checks.
e2e/testapp/app_config.go, e2e/testapp/app.go Integrated Polaris EVM into the SimApp and updated app configuration.
contracts/scripts/DeployAndCallERC20.sol, contracts/scripts/DeployAndConsumeGas.sol Updated Solidity contracts to adjust gas consumption and minting behavior.

🐇
"In the land of code, where logic is king,
Changes are made, and the devs start to sing.
With Polaris shining, and EVM in sight,
The system evolves, in the soft coder's light. 🌟"


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • Mention @coderabbitai in any review comment for bot assistance.
  • Note: Review comments are made on code diffs or files, not on the PR overview.

Pause Incremental Reviews

  • Insert @coderabbitai: ignore in the PR description to halt the bot's ongoing reviews. Remove the line to resume.
  • Additionally, enter @coderabbitai pause to halt the bot's ongoing reviews as any issue or review comment. To
    resume reviews, enter @coderabbitai resume as any issue or review comment.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 2

Commits Files that changed from the base of the PR and between 63d98bc and 0a87bc3.
Files ignored due to filter (2)
  • e2e/testapp/go.mod
  • go.work.sum
Files selected for processing (9)
  • cosmos/runtime/depinject.go (1 hunks)
  • cosmos/runtime/runtime.go (1 hunks)
  • cosmos/x/evm/genesis_test.go (3 hunks)
  • cosmos/x/evm/keeper/genesis.go (2 hunks)
  • cosmos/x/evm/keeper/host.go (5 hunks)
  • cosmos/x/evm/keeper/keeper.go (2 hunks)
  • cosmos/x/evm/keeper/processor.go (1 hunks)
  • e2e/testapp/app.go (7 hunks)
  • e2e/testapp/polard/cmd/root.go (2 hunks)
Files skipped from review due to trivial changes (3)
  • cosmos/x/evm/keeper/genesis.go
  • cosmos/x/evm/keeper/host.go
  • cosmos/x/evm/keeper/processor.go
Additional comments (Suppressed): 19
cosmos/runtime/runtime.go (5)
  • 44-53: The Polaris struct is defined with a pointer to polar.Polaris, EVMKeeper, mm and mp. Ensure that these fields are properly initialized before use to avoid nil pointer dereference errors.

  • 55-77: The Setup function initializes the Polaris struct and its components. It also sets up the precompile contracts and the blockchain. Ensure that the Setup function is called before any other operations on the Polaris struct to avoid runtime errors.

  • 79-92: The Init function initializes the services and registers them with Polaris. It is important to ensure that the Init function is called after Setup and before the services are used to avoid runtime errors.

  • 94-109: The RegisterServices function registers services with the EVM networking stack and starts them. Ensure that the services are properly initialized before they are registered and started.

  • 111-117: The LoadLastState function loads the last state of the blockchain. It is important to ensure that the blockchain is properly initialized before this function is called to avoid runtime errors.

e2e/testapp/polard/cmd/root.go (2)
  • 64-69: The import polarruntime "pkg.berachain.dev/polaris/cosmos/runtime" has been added. Ensure that the package exists and is accessible. Also, verify that the functions and types from this package are used correctly in the code.

  • 91-97: The polarruntime.ProvidePolarisRuntime function is now being provided as a dependency. Ensure that this function is correctly implemented and that it provides the expected functionality. Also, verify that it does not introduce any breaking changes or unexpected behavior.

cosmos/x/evm/genesis_test.go (3)
  • 33-40: The import of "github.com/ethereum/go-ethereum/consensus/beacon" is new. Ensure that this package is used appropriately in the code and that it doesn't introduce any breaking changes or security vulnerabilities.

  • 92-101: The k.SetBlockchain(core.NewChain(k.Host, beacon.NewFaker())) is a new addition. Ensure that the beacon.NewFaker() is suitable for this context and doesn't introduce any unexpected behavior. Also, verify that the SetBlockchain method is correctly implemented.

  • 118-145: The calls to k.Host.GetBlockPlugin() and k.Host.GetStatePlugin() have replaced the previous calls to k.Polaris().Host().GetBlockPlugin() and k.Polaris().Host().GetStatePlugin(). Ensure that these changes are intentional and that they don't break any existing functionality. Also, verify that the Host method is correctly implemented.

cosmos/x/evm/keeper/keeper.go (2)
  • 21-52: The Keeper struct has been refactored to include a chain field of type Blockchain and a SetBlockchain method. The chain field replaces the polaris field from the old hunk. Ensure that all references to polaris in the codebase have been updated to chain. Also, the Host field is now a pointer, which could potentially introduce null pointer exceptions if not handled properly. Make sure to check for null before dereferencing Host.

  • 71-88: The NewKeeper function no longer initializes a polaris instance and does not handle any errors during initialization. This could potentially lead to runtime errors if the chain field is not properly set before it's used. Consider adding error handling or checks to ensure that chain is properly initialized before use.

The Logger function remains unchanged and is approved.

e2e/testapp/app.go (7)
  • 42-47: The import of sdk "github.com/cosmos/cosmos-sdk/types" has been removed. Ensure that this does not affect any part of the code that might be using it.

  • 53-60: The import of "github.com/ethereum/go-ethereum/node", "pkg.berachain.dev/polaris/cosmos/lib/tx", "pkg.berachain.dev/polaris/cosmos/miner", "pkg.berachain.dev/polaris/cosmos/txpool", "pkg.berachain.dev/polaris/cosmos/x/evm/keeper", and "pkg.berachain.dev/polaris/cosmos/x/evm/types" have been removed. Ensure that this does not affect any part of the code that might be using them.

  • 90-96: The EVMKeeper, mm (miner), and mp (mempool) fields have been replaced with a single polaris field of type *polarruntime.Polaris. Ensure that all references to the removed fields have been updated accordingly.

  • 118-139: The app is now initialized with polaris: &polarruntime.Polaris{}. The ProvidePolarisRuntime function is now provided to depinject.Provide. Ensure that this does not affect the initialization of the application.

  • 178-200: The EVMKeeper is now accessed through app.polaris.EVMKeeper. The SetupPrecompiles and Init methods have been replaced with app.polaris.Setup(app.BaseApp). The SetMempool and SetPrepareProposal methods have been removed. Ensure that these changes do not affect the functionality of the application.

  • 206-220: The LoadLastState method is now called on app.polaris instead of app.EVMKeeper.Polaris().Blockchain(). Ensure that this does not affect the loading of the last state.

  • 259-272: The Init method is now called on app.polaris instead of app.mm and app.mp. The RegisterServices method has been removed. The Close method is now called on app.polaris instead of app.EVMKeeper.Polaris(). Ensure that these changes do not affect the initialization and closing of the application.

cosmos/runtime/depinject.go Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Oct 11, 2023

Codecov Report

Merging #1215 (e2f8f06) into main (05b91e4) will increase coverage by 0.06%.
The diff coverage is 3.03%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1215      +/-   ##
==========================================
+ Coverage   48.61%   48.68%   +0.06%     
==========================================
  Files          77       78       +1     
  Lines        4669     4667       -2     
==========================================
+ Hits         2270     2272       +2     
+ Misses       2236     2232       -4     
  Partials      163      163              
Files Coverage Δ
eth/core/chain_resources.go 0.00% <ø> (ø)
cosmos/x/evm/keeper/keeper.go 0.00% <0.00%> (ø)
cosmos/x/evm/module.go 21.42% <0.00%> (-3.58%) ⬇️
cosmos/x/evm/keeper/genesis.go 0.00% <0.00%> (ø)
cosmos/x/evm/plugins/state/plugin.go 72.22% <25.00%> (+0.74%) ⬆️
cosmos/x/evm/keeper/host.go 0.00% <0.00%> (ø)
cosmos/x/evm/keeper/processor.go 0.00% <0.00%> (ø)
cosmos/x/evm/keeper/abci.go 0.00% <0.00%> (ø)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 4

Commits Files that changed from the base of the PR and between 0a87bc3 and d836ae6.
Files ignored due to filter (10)
  • cosmos/go.mod
  • cosmos/go.sum
  • e2e/localnet/go.mod
  • e2e/localnet/go.sum
  • e2e/precompile/go.mod
  • e2e/precompile/go.sum
  • e2e/testapp/go.sum
  • eth/go.mod
  • eth/go.sum
  • go.work.sum
Files selected for processing (1)
  • cosmos/runtime/runtime.go (1 hunks)
Additional comments (Suppressed): 1
cosmos/runtime/runtime.go (1)
  • 55-77: The Setup method is well structured and handles errors properly. However, it's not clear why p.EVMKeeper.SetBlockchain(p.Blockchain()) is marked for deprecation. If it's not needed, consider removing it. If it's needed for now but will be removed in the future, provide a comment explaining why.

cosmos/runtime/runtime.go Show resolved Hide resolved
cosmos/runtime/runtime.go Show resolved Hide resolved
cosmos/runtime/runtime.go Show resolved Hide resolved
cosmos/runtime/runtime.go Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 4

Commits Files that changed from the base of the PR and between d836ae6 and 1bc9e61.
Files selected for processing (10)
  • contracts/scripts/DeployAndCallERC20.sol (1 hunks)
  • cosmos/runtime/depinject.go (1 hunks)
  • cosmos/x/evm/keeper/abci.go (1 hunks)
  • cosmos/x/evm/module.go (3 hunks)
  • cosmos/x/evm/plugins/state/plugin.go (5 hunks)
  • e2e/testapp/app_config.go (1 hunks)
  • eth/core/chain_resources.go (1 hunks)
  • eth/log/imported.go (1 hunks)
  • eth/polar/backend.go (1 hunks)
  • eth/polar/config.go (3 hunks)
Files skipped from review due to trivial changes (3)
  • eth/core/chain_resources.go
  • eth/log/imported.go
  • eth/polar/config.go
Additional comments (Suppressed): 11
eth/polar/backend.go (1)
  • 134-140: The new hunk introduces a safety message that warns the user if they are running with development configurations. This is a good practice as it helps prevent accidental use of development configurations in a production environment. However, ensure that the SafetyMessage function does not halt the execution or throw an error that is not handled.
cosmos/x/evm/module.go (2)
  • 43-50: The AppModule struct now implements the appmodule.HasPrepareCheckState interface. Ensure that the PrepareCheckState method is correctly implemented in the AppModule struct and that it behaves as expected.

  • 128-130: The PrepareCheckState method is added to the AppModule struct. This method calls the PrepareCheckState method of the keeper field of the AppModule struct. Ensure that the PrepareCheckState method of the keeper is correctly implemented and that it behaves as expected.

+func (am AppModule) PrepareCheckState(ctx context.Context) error {
+	return am.keeper.PrepareCheckState(ctx)
+}
e2e/testapp/app_config.go (1)
  • 126-128: The evmtypes.ModuleName has been added to the PrepareCheckStaters list. This change implies that the EVM module will now be checked before each block is processed. Ensure that the EVM module's PrepareCheckState function is implemented correctly and that it does not introduce any performance issues due to additional checks.
contracts/scripts/DeployAndCallERC20.sol (2)
  • 27-46: The contract DeployAndCallERC20 has been significantly modified. The SolmateERC20 contract is no longer being used, and instead, a new contract ConsumeGas is being instantiated. The loop now runs 10 times instead of 66, and the consumeGas method of the ConsumeGas contract is being called instead of the mint method of the SolmateERC20 contract. Ensure that these changes are intentional and that they do not break any dependencies or expectations in the rest of the codebase.

  • 38-38: The ConsumeGas contract is being instantiated without any constructor arguments. If the ConsumeGas contract requires any arguments for its constructor, this will result in a compilation error. Please verify if any arguments are needed.

cosmos/x/evm/plugins/state/plugin.go (5)
  • 115-120: The latestState field has been added to the plugin struct. This field is of type sdk.Context and is used to store the latest context state. This change could affect the behavior of the plugin, especially in methods that rely on the context state. Ensure that the latestState field is properly initialized and updated throughout the plugin's lifecycle.

  • 141-145: The Prepare method has been modified. The new implementation assigns the unwrapped context to latestState. This change could affect the behavior of the plugin, especially in methods that rely on the context state. Ensure that the latestState field is properly initialized and updated throughout the plugin's lifecycle.

-	p.ctx = sdk.UnwrapSDKContext(ctx).
-		WithKVGasConfig(storetypes.GasConfig{}).
-		WithTransientKVGasConfig(storetypes.GasConfig{})
+	p.latestState = sdk.UnwrapSDKContext(ctx)
  • 199-201: The Finalize method has been added to the plugin struct. This method calls the Finalize method on the Controller field of the plugin struct. Ensure that the Controller field is properly initialized before this method is called to avoid a nil pointer dereference.

  • 544-550: The if condition has been updated to compare int64Number with p.latestState.BlockHeight() instead of p.ctx.BlockHeight(). This change could affect the behavior of the plugin, especially in methods that rely on the context state. Ensure that the latestState field is properly initialized and updated throughout the plugin's lifecycle.

-	if int64Number >= p.ctx.BlockHeight() {
+	if int64Number >= p.latestState.BlockHeight() {
  • 563-565: The if condition has been updated to check p.latestState.MultiStore() instead of p.ctx.MultiStore(). This change could affect the behavior of the plugin, especially in methods that rely on the context state. Ensure that the latestState field is properly initialized and updated throughout the plugin's lifecycle.
-	if p.ctx.MultiStore() != nil {
+	if p.latestState.MultiStore() != nil {

cosmos/x/evm/keeper/abci.go Show resolved Hide resolved
cosmos/runtime/depinject.go Show resolved Hide resolved
cosmos/runtime/depinject.go Show resolved Hide resolved
contracts/scripts/DeployAndCallERC20.sol Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 5

Commits Files that changed from the base of the PR and between 1bc9e61 and e2f8f06.
Files ignored due to filter (12)
  • contracts/go.sum
  • cosmos/go.mod
  • cosmos/go.sum
  • e2e/localnet/go.mod
  • e2e/localnet/go.sum
  • e2e/precompile/go.mod
  • e2e/precompile/go.sum
  • e2e/testapp/go.mod
  • e2e/testapp/go.sum
  • eth/go.mod
  • eth/go.sum
  • go.work.sum
Files selected for processing (7)
  • contracts/scripts/DeployAndCallERC20.sol (1 hunks)
  • contracts/scripts/DeployAndConsumeGas.sol (1 hunks)
  • cosmos/x/evm/keeper/abci.go (1 hunks)
  • cosmos/x/evm/keeper/keeper.go (2 hunks)
  • cosmos/x/evm/keeper/processor.go (1 hunks)
  • cosmos/x/evm/module.go (3 hunks)
  • e2e/testapp/app_config.go (2 hunks)
Files skipped from review due to trivial changes (2)
  • contracts/scripts/DeployAndCallERC20.sol
  • cosmos/x/evm/keeper/abci.go
Additional comments (Suppressed): 12
e2e/testapp/app_config.go (2)
  • 123-131: The evmtypes.ModuleName has been added to the PrepareCheckStaters list. Ensure that the EVM module is prepared to handle check state operations and that this change doesn't introduce any unexpected behavior.

  • 143-148: The evmtypes.ModuleName has been added to the Precommiters list. Make sure that the EVM module is ready to handle precommit operations and that this change doesn't introduce any unexpected behavior.

cosmos/x/evm/module.go (3)
  • 21-28: No significant changes in the import section. The context package has been added, which is used in the new methods.

  • 43-51: The AppModule struct now implements two additional interfaces: appmodule.HasPrepareCheckState and appmodule.HasPrecommit. Ensure that the AppModule struct has the PrepareCheckState and Precommit methods as required by these interfaces.

  • 125-135: Two new methods PrepareCheckState and Precommit have been added to the AppModule struct. These methods call the corresponding methods on the keeper field of the AppModule struct. Ensure that the keeper field has these methods and that they are implemented correctly.

cosmos/x/evm/keeper/keeper.go (5)
  • 39-43: The Blockchain interface is introduced here. Ensure that all methods required by this interface are implemented by any struct that uses it. Also, consider adding comments to describe what each method in the interface does.

  • 45-53: The Keeper struct has been refactored. The polaris field has been replaced with a chain field of type Blockchain. The Host field is now a pointer. Ensure that these changes do not break any existing functionality that relies on the Keeper struct.

  • 72-78: The NewKeeper function has been updated to reflect the changes in the Keeper struct. Ensure that all calls to this function have been updated accordingly.

  • 82-84: The SetBlockchain method has been added to the Keeper struct. This method allows setting the chain field of the Keeper struct. Ensure that this method is called before any operations that require the chain field.

  • 87-89: The Logger method remains unchanged. It returns a module-specific logger.

cosmos/x/evm/keeper/processor.go (2)
  • 41-41: The TODO comment suggests a potential simplification of the gas consumption logic. If the block gas limit is known and fixed, consuming it upfront could simplify the code and improve performance by avoiding the need to track and consume gas usage during block execution. However, this would also remove the ability to refund unused gas. Consider the trade-offs and decide whether to implement this change.

  • 63-63: The comment suggests that the PreparePlugins method should be moved to the Blockchain struct. If this method is more related to the blockchain than to the Keeper struct, moving it could improve the code's organization and clarity. However, this would require changes to the Blockchain interface and potentially to other parts of the codebase. Consider the impact of this change on the overall system architecture and maintainability.

contracts/scripts/DeployAndConsumeGas.sol Show resolved Hide resolved
contracts/scripts/DeployAndConsumeGas.sol Show resolved Hide resolved
contracts/scripts/DeployAndConsumeGas.sol Show resolved Hide resolved
cosmos/x/evm/keeper/processor.go Show resolved Hide resolved
cosmos/x/evm/keeper/processor.go Show resolved Hide resolved
@itsdevbear itsdevbear merged commit c1edabd into main Oct 12, 2023
14 checks passed
@itsdevbear itsdevbear deleted the polaris-runtime branch October 12, 2023 16:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants