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

feat(abci): add a custom process proposal #1286

Merged
merged 7 commits into from
Nov 3, 2023
Merged

feat(abci): add a custom process proposal #1286

merged 7 commits into from
Nov 3, 2023

Conversation

itsdevbear
Copy link
Contributor

@itsdevbear itsdevbear commented Nov 3, 2023

Summary by CodeRabbit

  • New Features
    • Introduced a new configuration option "IsMainnet" for the "Polar" settings.
    • Added a new "ProcessProposal" function to process proposals and prepare the chain state.
    • Introduced a new "WrappedBlockchain" struct with methods for writing the genesis state and inserting blocks.
  • Bug Fixes
    • Modified the "EndBlock" function to obtain the block variable from a different chain implementation.
    • Updated the "InitGenesis" function to use the new "WrappedBlockchain" interface.
  • Refactor
    • Replaced the "Blockchain" interface with the new "WrappedBlockchain" interface in the "Keeper" struct.
    • Updated import paths and test descriptions in various files.
  • Documentation
    • Added comments to highlight issues with state changes in the "PreBlock" and "BeginBlock" functions.

Copy link

coderabbitai bot commented Nov 3, 2023

Walkthrough

The changes primarily revolve around the introduction of a new configuration option IsMainnet and the implementation of a WrappedBlockchain struct. The IsMainnet flag is used to enable additional safety checks for the mainnet. The WrappedBlockchain struct wraps the core blockchain with additional application context and is used to modify the way blocks are inserted and the genesis state is written. The changes also include modifications to the proposal processing logic and miner functionality.

Changes

File(s) Summary
cosmos/config/config.go, cosmos/config/flags/flags.go, cosmos/config/template.go Introduced a new configuration option IsMainnet and modified the logic to read this flag from the parser.
eth/core/chain.go, eth/core/chain_writer.go, eth/polar/backend.go, eth/polar/config.go Added a new field isMainnet to the blockchain struct and modified the NewChain function to accept this as an additional parameter. Introduced new conditions for block validation based on the isMainnet flag.
cosmos/runtime/chain/abci.go, cosmos/runtime/chain/chain.go, cosmos/runtime/chain/interfaces.go Introduced a new WrappedBlockchain struct and added methods for writing the genesis state and inserting blocks. Also added a new ProcessProposal function to process proposals.
cosmos/runtime/miner/abci.go, cosmos/runtime/miner/interfaces.go, cosmos/runtime/miner/miner.go Modified the Miner struct and its PrepareProposal function to accommodate changes in the proposal processing logic.
cosmos/x/evm/genesis_test.go, cosmos/x/evm/keeper/abci.go, cosmos/x/evm/keeper/genesis.go, cosmos/x/evm/keeper/keeper.go, cosmos/x/evm/keeper/processor.go Made changes to use the WrappedBlockchain struct instead of the core blockchain. Modified the Setup function and the ProcessPayloadEnvelope function to accommodate these changes.

🐇🍂
As the leaves fall and the season changes,
So does our code, in wide ranges.
With IsMainnet and WrappedBlockchain in sight,
Our code now takes a different flight.
Celebrate the changes, for they bring delight,
In the world of code, it's always bright! 🌟🎉


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai help to get help.
  • @coderabbitai resolve to resolve all the CodeRabbit review comments.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.json

@itsdevbear itsdevbear requested review from ocnc and calbera November 3, 2023 16:38
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

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 3f15a11 and d8df223.
Files selected for processing (8)
  • cosmos/config/config.go (1 hunks)
  • cosmos/config/flags/flags.go (1 hunks)
  • cosmos/config/template.go (1 hunks)
  • cosmos/x/evm/genesis_test.go (1 hunks)
  • eth/core/chain.go (3 hunks)
  • eth/core/chain_writer.go (2 hunks)
  • eth/polar/backend.go (1 hunks)
  • eth/polar/config.go (1 hunks)
Files skipped from review due to trivial changes (3)
  • cosmos/config/flags/flags.go
  • cosmos/config/template.go
  • eth/polar/config.go
Additional comments: 6
cosmos/config/config.go (1)
  • 83-93: The new configuration option IsMainnet is being read from the parser and assigned to the Polar struct in the Config struct. If the flag is not found or there is an error retrieving its value, an error is returned. This is a good practice as it allows the function to fail early and propagate the error up the call stack.
eth/polar/backend.go (1)
  • 114-117: The core.NewChain function now accepts an additional isMainnet parameter. Ensure that the function definition and all calls to this function throughout the codebase have been updated to match the new signature.
- blockchain: core.NewChain(host, &config.Chain, engine),
+ blockchain: core.NewChain(host, &config.Chain, engine, config.IsMainnet),
cosmos/x/evm/genesis_test.go (1)
  • 83-87: Ensure that all calls to core.NewChain throughout the codebase have been updated to match the new signature. Also, consider the implications of hardcoding true for the isMainnet parameter. If this test is meant to represent a mainnet scenario, this is fine. However, if you want to test both mainnet and testnet scenarios, you might want to parameterize this value.
eth/core/chain.go (3)
  • 102-105: The isMainnet field has been added to the blockchain struct. This field will be used to determine whether the blockchain is running on the mainnet or not.

  • 114-115: The NewChain function now accepts an additional isMainnet parameter. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.

  • 130-131: The isMainnet field is being set in the NewChain function. This is the correct place to set this field as it is part of the initialization of the blockchain struct.

eth/core/chain_writer.go Outdated Show resolved Hide resolved
eth/core/chain_writer.go 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: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between d8df223 and 83cd457.
Files selected for processing (1)
  • cosmos/config/template.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • cosmos/config/template.go

Copy link

codecov bot commented Nov 3, 2023

Codecov Report

Merging #1286 (5e040e6) into main (3f15a11) will decrease coverage by 0.13%.
The diff coverage is 0.00%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1286      +/-   ##
==========================================
- Coverage   48.73%   48.61%   -0.13%     
==========================================
  Files          84       84              
  Lines        4838     4850      +12     
==========================================
  Hits         2358     2358              
- Misses       2306     2318      +12     
  Partials      174      174              
Files Coverage Δ
cosmos/runtime/txpool/ante.go 0.00% <ø> (ø)
cosmos/runtime/txpool/handler.go 64.28% <ø> (ø)
cosmos/runtime/txpool/mempool.go 48.57% <ø> (ø)
cosmos/x/evm/plugins/state/plugin.go 73.03% <ø> (ø)
cosmos/x/evm/keeper/abci.go 0.00% <0.00%> (ø)
cosmos/x/evm/keeper/genesis.go 0.00% <0.00%> (ø)
cosmos/x/evm/keeper/keeper.go 0.00% <0.00%> (ø)
cosmos/x/evm/keeper/processor.go 0.00% <0.00%> (ø)
eth/core/chain_writer.go 0.00% <0.00%> (ø)

@itsdevbear itsdevbear changed the title feat(flag): IsMainnet feat(abci): add a custom process proposal Nov 3, 2023
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: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 83cd457 and 9c8d58f.
Files ignored due to filter (2)
  • cosmos/go.mod
  • cosmos/go.sum
Files selected for processing (17)
  • cosmos/config/config.go (1 hunks)
  • cosmos/runtime/ante/ante.go (1 hunks)
  • cosmos/runtime/chain/abci.go (1 hunks)
  • cosmos/runtime/chain/chain.go (1 hunks)
  • cosmos/runtime/chain/interfaces.go (1 hunks)
  • cosmos/runtime/miner/abci.go (1 hunks)
  • cosmos/runtime/miner/interfaces.go (1 hunks)
  • cosmos/runtime/miner/miner.go (2 hunks)
  • cosmos/runtime/runtime.go (4 hunks)
  • cosmos/runtime/txpool/handler_test.go (2 hunks)
  • cosmos/runtime/txpool/mempool_test.go (1 hunks)
  • cosmos/x/evm/genesis_test.go (2 hunks)
  • cosmos/x/evm/keeper/abci.go (1 hunks)
  • cosmos/x/evm/keeper/genesis.go (2 hunks)
  • cosmos/x/evm/keeper/keeper.go (3 hunks)
  • cosmos/x/evm/keeper/processor.go (1 hunks)
  • eth/core/chain_writer.go (2 hunks)
Files skipped from review due to trivial changes (7)
  • cosmos/config/config.go
  • cosmos/runtime/ante/ante.go
  • cosmos/runtime/chain/abci.go
  • cosmos/runtime/miner/abci.go
  • cosmos/runtime/txpool/handler_test.go
  • cosmos/runtime/txpool/mempool_test.go
  • eth/core/chain_writer.go
Additional comments: 30
cosmos/x/evm/keeper/processor.go (1)
  • 65-71: The InsertBlockAndSetHead function is now being used instead of PreparePlugins. Ensure that the InsertBlockAndSetHead function performs all the necessary operations that were previously done by PreparePlugins. Also, ensure that the error handling is adequate and that the function behaves as expected in all scenarios.
cosmos/x/evm/keeper/abci.go (1)
  • 32-38: The GetBlockByNumber method is now called on k.wrappedChain instead of k.chain. Ensure that k.wrappedChain is correctly initialized and that it has the same behavior as k.chain in this context.
- block := k.chain.GetBlockByNumber(blockNum)
+ block := k.wrappedChain.GetBlockByNumber(blockNum)
cosmos/runtime/chain/interfaces.go (3)
  • 1-19: The license header is included correctly. Ensure that the license is compatible with the project's license.

  • 21-27: The package and import statements are correct.

  • 29-33: The App interface is defined correctly with four methods. Ensure that all implementations of this interface throughout the codebase have been updated to include these methods.

cosmos/x/evm/keeper/genesis.go (2)
  • 31-37: The genState.Config assignment has been updated to use k.wrappedChain.Config(). Ensure that k.wrappedChain.Config() is correctly initialized and has the expected values before this assignment.

  • 47-47: The k.chain.WriteGenesisBlock function has been replaced with k.wrappedChain.WriteGenesisState. Ensure that k.wrappedChain.WriteGenesisState is correctly implemented and that it correctly writes the genesis state.

cosmos/runtime/miner/interfaces.go (2)
  • 1-19: Ensure that the license is appropriate for your project and that it is correctly referenced. If the license is not appropriate, you may need to update it.

  • 35-53: The interfaces and types defined here look good. They are well-documented and seem to cover the necessary functionality for the miner application. However, ensure that all methods defined in the interfaces are implemented wherever these interfaces are used.

cosmos/x/evm/genesis_test.go (2)
  • 34-38: The new import statement for the package "pkg.berachain.dev/polaris/cosmos/runtime/chain" is introduced correctly. Ensure that the package is available and accessible.

  • 84-88: The Setup function call is modified correctly to pass a new argument "chain.New(core.NewChain(k.Host, params.DefaultChainConfig, beacon.NewFaker()), nil)" instead of "core.NewChain(k.Host, params.DefaultChainConfig, beacon.NewFaker())". Ensure that the function signatures for chain.New and core.NewChain are updated accordingly throughout the codebase.

cosmos/runtime/runtime.go (4)
  • 30-30: Ensure that the newly added import is used in the code. Unused imports can lead to compilation errors.

  • 62-68: The CosmosApp interface has been extended with new methods. Make sure all implementations of this interface are updated to include these new methods.

  • 77-85: The Polaris struct has been extended with a new field WrappedBlockchain. Ensure that all instances of Polaris are updated to include this new field.

  • 113-126: The Build method of the Polaris struct has been updated to include the initialization of WrappedBlockchain. Ensure that all calls to this method are updated to handle the new field.

cosmos/x/evm/keeper/keeper.go (4)
  • 31-38: The import statements look fine. Ensure that all the imported packages are being used in the code.

  • 40-46: The WrappedBlockchain interface is well defined. It encapsulates the methods related to blockchain operations.

  • 50-54: The Keeper struct has been updated to use the WrappedBlockchain interface. This change should be reflected wherever the Keeper struct is used.

  • 73-79: The Setup function now accepts a WrappedBlockchain parameter and assigns it to the wrappedChain field of the Keeper struct. Ensure that all calls to this function have been updated to match the new signature.

cosmos/runtime/miner/miner.go (4)
  • 24-35: The import statements are well organized and separated by functionality. Good practice.

  • 37-45: The Miner struct has been updated to include a chain field of type core.Blockchain. This is in line with the pull request summary.

  • 48-55: The New function now accepts an additional parameter chain core.Blockchain and assigns it to the chain field of the Miner struct. This is in line with the pull request summary.

  • 59-64: The buildBlock function seems to be unchanged. It's not clear why this hunk is included in the diff. If there are no changes, it can be ignored.

cosmos/runtime/chain/chain.go (7)
  • 1-19: The license header is well formatted and clear. It's good to see that the copyright and license information is included at the top of the file.

  • 23-28: The import statements are well organized and correctly formatted.

  • 30-36: The WrappedBlockchain struct is well defined and includes the necessary fields. The comments provide a clear explanation of the struct and its fields.

  • 38-42: The New function is correctly implemented and returns a new instance of WrappedBlockchain. The function signature is clear and the function body is concise.

  • 44-51: The WriteGenesisState method is correctly implemented. It prepares the plugins and writes the genesis block to the blockchain. The function signature is clear and the function body is concise.

  • 53-60: The InsertBlockAndSetHead method is correctly implemented. It prepares the plugins and inserts a block into the blockchain, setting it as the head. The function signature is clear and the function body is concise.

  • 62-69: The InsertBlockWithoutSetHead method is correctly implemented. It prepares the plugins and inserts a block into the blockchain without setting it as the head. The function signature is clear and the function body is concise.

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: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 9c8d58f and 3c5e3e3.
Files selected for processing (1)
  • .mockery.yaml (1 hunks)
Files skipped from review due to trivial changes (1)
  • .mockery.yaml

Copy link

@nivasan1 nivasan1 left a comment

Choose a reason for hiding this comment

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

Comments + questions. TLDR is that ensure that the execution env of Process / Prepare are the same. Otherwise, you may introduce liveness failures

cosmos/runtime/chain/abci.go Show resolved Hide resolved
cosmos/runtime/chain/abci.go Show resolved Hide resolved
eth/core/chain_writer.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: 5

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 3c5e3e3 and bc47bf4.
Files selected for processing (3)
  • cosmos/runtime/chain/abci.go (1 hunks)
  • cosmos/runtime/miner/abci.go (1 hunks)
  • cosmos/x/evm/plugins/state/plugin.go (1 hunks)
Additional comments: 9
cosmos/runtime/miner/abci.go (7)
  • 1-19: The license header is correct and up-to-date.

  • 38-82: The function PrepareProposal has been updated to include new logic for preparing a proposal. It now runs the PreBlocker and BeginBlocker functions, refunds gas, sets gas configurations, and triggers the buildBlock function. Ensure that these changes are compatible with the rest of the codebase and that all necessary tests have been updated or added to reflect these changes.

  • 46-59: The error handling for the PreBlocker and BeginBlocker functions is correct. If either function returns an error, the PrepareProposal function will immediately return the error.

  • 61-66: The gas refunding and configuration setting logic seems correct. However, it's important to ensure that the gas configurations are being set correctly and that the refunding of gas is not causing any unexpected behavior.

  • 68-73: The context is being set on the state plugin. If the SetLatestQueryContext function returns an error, the PrepareProposal function will immediately return the error. This is correct error handling.

  • 75-78: The buildBlock function is being triggered and its error is being handled correctly. If the buildBlock function returns an error, the PrepareProposal function will immediately return the error.

  • 80-81: The function returns the payload as a transaction in the proposal. This seems correct, but ensure that this is the expected behavior and that the payload is being correctly included in the proposal.

cosmos/runtime/chain/abci.go (2)
  • 38-115: The ProcessProposal function seems to be handling errors correctly and returning appropriate responses. However, it's important to ensure that all the functions it calls (PreBlocker, BeginBlocker, TxDecode, ExecutableDataToBlock, InsertBlockWithoutSetHead) are also handling their errors correctly. If any of these functions can panic, it would be a good idea to add a defer statement with a recover function at the beginning of ProcessProposal to handle any panics and prevent the entire program from crashing.

  • 88-93: The function assumes that the proposal must contain an Ethereum envelope and rejects the proposal if it does not. This may not be the desired behavior if the system is expected to handle proposals that do not contain Ethereum envelopes. If this is the case, the function should be updated to handle such proposals appropriately.

cosmos/x/evm/plugins/state/plugin.go Show resolved Hide resolved
cosmos/runtime/chain/abci.go Show resolved Hide resolved
cosmos/runtime/chain/abci.go Outdated Show resolved Hide resolved
cosmos/runtime/chain/abci.go Show resolved Hide resolved
cosmos/runtime/chain/abci.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: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between bc47bf4 and 5e040e6.
Files selected for processing (1)
  • cosmos/runtime/chain/abci.go (1 hunks)
Additional comments: 3
cosmos/runtime/chain/abci.go (3)
  • 45-62: The previous comment about checking for nil before calling PreBlocker and BeginBlocker is still valid. This will prevent potential runtime panics.

  • 95-102: The previous comment about checking the success of the conversion from ExecutionPayloadEnvelope to a block is still valid. This will prevent potential errors when inserting the block into the chain.

  • 104-110: The previous comment about checking the success of the block insertion into the chain is still valid. This will ensure the response accurately reflects the outcome of the proposal processing.

@itsdevbear itsdevbear merged commit cd12ec4 into main Nov 3, 2023
14 checks passed
@itsdevbear itsdevbear deleted the mainnet-flag branch November 3, 2023 18:46
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.

5 participants