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

feat(miner): Allow allowlisted sdk.Msgs (mainly for validator configuration) #1269

Merged
merged 24 commits into from
Nov 6, 2023

Conversation

itsdevbear
Copy link
Contributor

@itsdevbear itsdevbear commented Nov 2, 2023

Summary by CodeRabbit

  • New Features
    • Introduced validator transactions and their inclusion in the proposal.
    • Added a new map to determine which messages can be submitted by external users.
  • Refactor
    • Adjusted function parameters and return values to accommodate the new validator transactions feature.
  • Tests
    • Updated test function calls to match the new function signatures.

Copy link

coderabbitai bot commented Nov 2, 2023

Walkthrough

The changes introduced in the codebase primarily revolve around the handling of validator transactions in the miner package of the Cosmos SDK. The Miner struct and its associated functions have been modified to process and include validator transactions in the proposal. A new map of allowed validator messages has been introduced, and the Polaris struct's Build function now accepts this map as a parameter.

Changes

File(s) Summary
cosmos/miner/miner.go, cosmos/runtime/miner/abci.go, cosmos/runtime/miner/miner.go Introduced changes to the Miner struct and its functions to process and include validator transactions in the proposal. Added a new map of allowed validator messages.
cosmos/miner/msgs.go Added a new file defining a map of allowed validator messages from various modules.
cosmos/runtime/runtime.go Modified the Build function in the Polaris struct to accept a map of allowed validator messages as a parameter.
e2e/testapp/app.go Added an import statement for the "miner" package and modified the call to the Build function of the Polaris struct to include the map of allowed validator messages.
cosmos/runtime/txpool/handler.go, cosmos/runtime/txpool/handler_test.go, cosmos/runtime/txpool/mocks/geth_tx_pool.go, cosmos/runtime/txpool/mocks/tx_sub_provider.go, eth/eth.go, eth/polar/api_backend.go Renamed the SubscribeNewTxsEvent function to SubscribeTransactions and added a new boolean parameter reorgs.

Poem

As the leaves fall, the code does change, 🍂

Validator transactions, no longer strange. 📜

In the miner's realm, they now take stage, 💻

A map of messages, a new age. 🗺️

As we hop through the autumn haze, 🐇

We celebrate these coding days. 🎉

With every keystroke, we engage, ⌨️

In the art of code, we turn the page. 📖


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.v2.json

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 949a826 and fba91fb.
Files ignored due to filter (17)
  • build/tools/go.mod
  • build/tools/go.sum
  • contracts/go.mod
  • 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
  • lib/go.mod
  • lib/go.sum
Files selected for processing (4)
  • cosmos/miner/miner.go (6 hunks)
  • cosmos/miner/msgs.go (1 hunks)
  • cosmos/runtime/runtime.go (1 hunks)
  • e2e/testapp/app.go (2 hunks)
Files skipped from review due to trivial changes (2)
  • cosmos/miner/msgs.go
  • cosmos/runtime/runtime.go
Additional comments: 8
e2e/testapp/app.go (2)
  • 57-63: The import statement for the "miner" package has been added. This is necessary to access the DefaultAllowedMsgs map defined in the miner package.

  • 192-197: The call to the Build function of the Polaris struct now includes miner.DefaultAllowedMsgs as an argument. This change affects the signature of the Build function in the Polaris struct. Ensure that the Build function in the Polaris struct has been updated to accept this new argument.

cosmos/miner/miner.go (6)
  • 24-34: Imports look fine. No changes needed.

  • 52-56: The App interface has been updated to include baseapp.ProposalTxVerifier. Ensure that all implementations of this interface have been updated accordingly.

  • 67-85: The Miner struct and New function have been updated to include a valTxSelector field and an allowedValMsgs parameter respectively. Ensure that all calls to New have been updated to match the new signature.

  • 91-109: The PrepareProposal function has been updated to process validator messages. Ensure that the function is being used correctly in the context of these changes.

  • 122-135: The PrepareProposal function now returns a combination of the payload envelope and the validator transactions. Ensure that the function's return value is being handled correctly in all places where it is called.

  • 194-225: The new function processValidatorMsgs has been added to process validator messages. Ensure that this function is being used correctly in the context of these changes.

Copy link

codecov bot commented Nov 2, 2023

Codecov Report

Merging #1269 (6b00438) into main (594360d) will not change coverage.
The diff coverage is n/a.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1269   +/-   ##
=======================================
  Coverage   48.54%   48.54%           
=======================================
  Files          84       84           
  Lines        4857     4857           
=======================================
  Hits         2358     2358           
  Misses       2325     2325           
  Partials      174      174           

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 fba91fb and cfc890f.
Files selected for processing (1)
  • cosmos/miner/miner.go (6 hunks)
Additional comments: 5
cosmos/miner/miner.go (5)
  • 24-34: The new import statements are correctly placed and formatted. Ensure that the imported packages are used in the code.

  • 52-56: The baseapp.ProposalTxVerifier interface has been added to the App interface. This is a good practice as it ensures that any type that satisfies the App interface also satisfies the baseapp.ProposalTxVerifier interface.

  • 67-84: The Miner struct and New function have been updated to include a valTxSelector field and an allowedValMsgs parameter respectively. This is a good practice as it allows for more flexibility and control over the behavior of the Miner.

  • 91-109: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [91-135]

The PrepareProposal function has been modified to process validator messages and include them in the proposal. This is a good practice as it allows for more control over the proposal preparation process.

  • 194-225: The processValidatorMsgs function has been added to process validator messages. This is a good practice as it allows for more control over the processing of validator messages.

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 cfc890f and b606312.
Files ignored due to filter (3)
  • cosmos/go.sum
  • e2e/testapp/go.sum
  • go.work.sum
Files selected for processing (1)
  • cosmos/miner/miner.go (6 hunks)
Additional comments: 8
cosmos/miner/miner.go (8)
  • 24-36: The import statements look fine. Ensure that all the imported packages are being used in the code.

  • 54-58: The App interface now includes the baseapp.ProposalTxVerifier interface. This change is fine as long as all implementations of the App interface have been updated to include the methods of baseapp.ProposalTxVerifier.

  • 69-76: The Miner struct now includes a valTxSelector field of type baseapp.TxSelector and an allowedValMsgs map. This is fine as long as all instances of Miner are updated to include these new fields.

  • 79-87: The New function for creating a Miner now takes an additional allowedValMsgs parameter. This is fine as long as all calls to New have been updated to include this new parameter.

  • 122-157: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [95-144]

The PrepareProposal function now takes a req parameter of type *abci.RequestPrepareProposal. This is fine as long as all calls to PrepareProposal have been updated to include this new parameter. The function now also processes validator messages and combines them with the payload envelope. This is a significant change and should be thoroughly tested.

  • 146-155: The buildBlock function now returns the ethGasUsed value in addition to the payload. This is fine as long as all calls to buildBlock have been updated to handle this additional return value.

  • 186-197: The resolveEnvelope function now returns the gasUsed value in addition to the envelope. This is fine as long as all calls to resolveEnvelope have been updated to handle this additional return value.

  • 204-239: The processValidatorMsgs function is added to process validator messages. This is a significant addition and should be thoroughly tested.

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 b606312 and 014109d.
Files ignored due to filter (2)
  • e2e/testapp/go.mod
  • e2e/testapp/go.sum
Files selected for processing (6)
  • cosmos/runtime/miner/abci.go (2 hunks)
  • cosmos/runtime/miner/interfaces.go (1 hunks)
  • cosmos/runtime/miner/miner.go (3 hunks)
  • cosmos/runtime/miner/msgs.go (1 hunks)
  • cosmos/runtime/runtime.go (1 hunks)
  • e2e/testapp/app.go (2 hunks)
Files skipped from review due to trivial changes (2)
  • cosmos/runtime/miner/msgs.go
  • cosmos/runtime/runtime.go
Additional comments: 13
cosmos/runtime/miner/interfaces.go (1)
  • 42-46: The new method TxDecode has been added to the App interface. Ensure that all implementations of this interface have been updated to include this method.
TxDecode(txBytes []byte) (sdk.Tx, error)
e2e/testapp/app.go (2)
  • 58-63: The import statement for the "miner" package is added. Ensure that the package path is correct and accessible.

  • 192-197: The Build function of the Polaris struct is called with an additional argument miner.DefaultAllowedMsgs. Ensure that the Build function is updated to accept this new argument in its signature.

cosmos/runtime/miner/abci.go (4)
  • 41-46: The introduction of valTxs and ethGasUsed variables is consistent with the changes described in the pull request summary. Ensure that these variables are used correctly throughout the function.

  • 50-53: The PreBlocker function is now called with a nil argument instead of req. Ensure that this change does not cause any issues, especially if the PreBlocker function uses the argument in its implementation.

  • 68-75: The buildBlock function now returns an additional ethGasUsed variable and the processValidatorMsgs function is called with additional arguments: req.MaxTxBytes, ethGasUsed, and req.Txs. Ensure that these changes are consistent with the updated function signatures.

  • 78-83: The PrepareProposal function now returns a new variable valTxs and modifies the return value to include both payloadEnvelopeBz and valTxs in the Txs field of abci.ResponsePrepareProposal. This change is consistent with the pull request summary.

cosmos/runtime/miner/miner.go (6)
  • 24-37: New import statements have been added. Ensure that these packages are included in your project dependencies.

  • 41-48: The Miner struct has been updated to include valTxSelector and allowedValMsgs fields. Ensure that these fields are properly initialized and used throughout the codebase.

  • 51-59: The New function now accepts allowedValMsgs as a parameter. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.

  • 68-75: The buildBlock function now returns the resolved envelope and gas used. Ensure that all calls to this function throughout the codebase have been updated to handle the new return values.

  • 107-117: The resolveEnvelope function now returns the resolved envelope and gas used. Ensure that all calls to this function throughout the codebase have been updated to handle the new return values.

  • 124-159: The new processValidatorMsgs function processes validator messages. Ensure that this function is properly called and its return values are correctly handled.

@itsdevbear
Copy link
Contributor Author

@BrickBera please verify

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 014109d and 64e401a.
Files ignored due to filter (17)
  • build/tools/go.mod
  • build/tools/go.sum
  • contracts/go.mod
  • 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
  • lib/go.mod
  • lib/go.sum
Files selected for processing (7)
  • cosmos/runtime/miner/miner.go (3 hunks)
  • cosmos/runtime/txpool/handler.go (2 hunks)
  • cosmos/runtime/txpool/handler_test.go (1 hunks)
  • cosmos/runtime/txpool/mocks/geth_tx_pool.go (2 hunks)
  • cosmos/runtime/txpool/mocks/tx_sub_provider.go (2 hunks)
  • eth/eth.go (1 hunks)
  • eth/polar/api_backend.go (1 hunks)
Additional comments: 14
eth/eth.go (1)
  • 50-56: The SubscribeTransactions function has been renamed and its signature has been updated. Ensure that all calls to this function throughout the codebase have been updated to match the new signature. Also, make sure to handle the returned event.Subscription correctly in the calling code.
cosmos/runtime/txpool/handler.go (1)
  • 53-54: The SubscribeTransactions method now accepts a reorgs parameter. Ensure that all calls to this method throughout the codebase have been updated to match the new signature.
cosmos/runtime/txpool/mocks/tx_sub_provider.go (2)
  • 22-34: The SubscribeTransactions method has been updated to include a new parameter reorgs. Ensure that all calls to this method throughout the codebase have been updated to match the new signature.

  • 38-68: The TxSubProvider_SubscribeTransactions_Call struct and its methods have been updated to reflect the changes in the SubscribeTransactions method. This looks fine as long as the changes are consistent with the rest of the codebase.

cosmos/runtime/txpool/handler_test.go (1)
  • 57-63: Ensure that the SubscribeTransactions function is correctly implemented and that the two arguments it now requires are being provided correctly. Also, verify that all instances of SubscribeTransactions in the codebase have been updated to match the new function signature.
- subprovider.On("SubscribeTransactions", mock.Anything, mock.Anything).Return(subscription)
+ subprovider.On("SubscribeTransactions", mock.Anything, mock.Anything).Return(subscription)
cosmos/runtime/txpool/mocks/geth_tx_pool.go (2)
  • 209-221: The function SubscribeTransactions has been updated to take two arguments and return a different type. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.

  • 228-254: The GethTxPool_SubscribeTransactions_Call struct and its methods have been updated to reflect the changes in the SubscribeTransactions function. Ensure that these changes are consistent with the intended functionality.

eth/polar/api_backend.go (1)
  • 523-527: The function call b.polar.txPool.SubscribeNewTxsEvent(ch) has been replaced with b.polar.txPool.SubscribeTransactions(ch, true). Ensure that the new function SubscribeTransactions is implemented correctly and that it behaves as expected. Also, verify that all instances of SubscribeNewTxsEvent have been replaced with SubscribeTransactions throughout the codebase.
- return b.polar.txPool.SubscribeNewTxsEvent(ch)
+ return b.polar.txPool.SubscribeTransactions(ch, true)
cosmos/runtime/miner/miner.go (6)
  • 24-37: Ensure that all the new imports are being used in the code. Unused imports can lead to confusion and unnecessary dependencies.

  • 41-48: The Miner struct has been updated to include a valTxSelector field and an allowedValMsgs map. Ensure that these new fields are being used appropriately throughout the code.

  • 51-59: The New function now accepts an allowedValMsgs map as a parameter. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.

  • 65-75: The buildBlock function now returns the resolved envelope and the gas used. Ensure that all calls to this function throughout the codebase have been updated to handle the new return values.

  • 104-117: The resolveEnvelope function now returns the resolved envelope and the gas used. Ensure that all calls to this function throughout the codebase have been updated to handle the new return values.

  • 124-159: The new processValidatorMsgs function processes validator messages. Ensure that this function is being called appropriately throughout the codebase.

@itsdevbear itsdevbear changed the base branch from main to bump-geth-sdk November 6, 2023 00:53
Base automatically changed from bump-geth-sdk to main November 6, 2023 01:30
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 64e401a and 6b00438.
Files selected for processing (1)
  • cosmos/runtime/miner/abci.go (2 hunks)
Additional comments: 5
cosmos/runtime/miner/abci.go (5)
  • 41-46: The introduction of new variables valTxs and ethGasUsed is clear and straightforward. Ensure that these variables are used correctly throughout the function.

  • 75-77: The buildBlock function now returns payloadEnvelopeBz and ethGasUsed in addition to an error. Ensure that the function is updated accordingly and that the returned values are used correctly.

  • 80-82: The processValidatorMsgs function is called to process validator messages and returns valTxs and an error. Ensure that this function is implemented correctly and that the returned valTxs are used correctly.

  • 84-90: The payloadEnvelopeBz and valTxs are combined into a new slice called allTxs. This is a logical step to combine all transactions into a single slice.

  • 93-93: The allTxs slice is returned as a transaction in the proposal. This is a logical step to return all transactions in the proposal.

@itsdevbear itsdevbear merged commit 061492a into main Nov 6, 2023
14 checks passed
@itsdevbear itsdevbear deleted the allow-msgs branch November 6, 2023 02:13
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