Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: simapp/v2 #20412

Draft
wants to merge 84 commits into
base: main
Choose a base branch
from
Draft

feat: simapp/v2 #20412

wants to merge 84 commits into from

Conversation

kocubinski
Copy link
Member

@kocubinski kocubinski commented May 16, 2024

Description

Introduce simapp/v2 which runs on server/v2 infrastructure.

Depends on: #20387
Includes: #20483, #20485
Closes: #20492

Testing

❯ scripts/simapp-v2-init.sh
❯ go run simapp/v2/simdv2/main.go start

Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

  • New Features

    • Introduced new methods for setting and retrieving application versions.
    • Added functionality for exporting application state for a genesis file.
    • Introduced commands for initializing and managing a Cosmos SDK application.
  • Bug Fixes

    • Corrected handling of zero-length Hash and AppHash fields in the Info struct.
    • Fixed comparison for AppHash length to ensure proper encoding.
  • Refactor

    • Renamed methods in ReaderMap and WriterMap interfaces for consistency.
    • Updated method signatures and initialization logic for various components.
  • Chores

    • Added and updated configurations for launching Go programs and Docker builds.
    • Updated initialization scripts and configuration files for simulation applications.

Copy link
Contributor

coderabbitai bot commented May 16, 2024

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The updates span multiple files, focusing on enhancing the Go program's debugging configurations, refining module imports and initializations, improving state handling and encoding logic, and introducing new methods for state changes and consensus handling. These changes collectively aim to streamline the debugging process, enhance modularity, and ensure more robust state management and error handling.

Changes

Files/Directories Change Summaries
.vscode/launch.json Added configurations for launching and debugging "simapp v2" with specific initialization arguments.
codec/depinject.go Added import for registry, changed ProvideInterfaceRegistry function to use panic instead of returning errors.
contrib/images/simd-env/Dockerfile Added COPY commands for various modules under server/v2/ directory.
core/context/context.go Converted contextKey type constants to anonymous structs for key handling.
core/header/service.go Updated Bytes method in Info struct to initialize Hash and AppHash fields if they have zero lengths.
core/store/store.go Renamed methods in ReaderMap and WriterMap interfaces.
go.work.example Added imports for ./simapp/v2 and removed import for ./x/accounts/defaults/lockup.
runtime/v2/app.go Added methods SetAppVersion and AppVersion to App struct.
runtime/v2/manager.go Removed conditional block for "genutil" module and refactored EndBlock function signature.
runtime/v2/module.go Added ProvideAppVersionModifier function, removed commented-out code, and adjusted ProvideAppBuilder function.
scripts/simapp-v2-init.sh Script to automate initialization of simulation application version 2 node.
server/mock/tx.go Added new methods to KVStoreTx struct and modified Type() method.
server/v2/cometbft/abci_test.go Added TestConsensus function and various helper functions for consensus handling.
server/v2/cometbft/mock_store.go Added fields and methods to MockStore struct for state management and querying.
server/v2/stf/branch/writer_map.go Refactored GetStateChanges method to use recurseStateChanges method for state changes.
server/v2/stf/core_router_service.go Updated InvokeTyped method to lazily initialize handler and added reflection for message handling.
simapp/app.go Modified NewSimApp function to include cometService in distrkeeper.NewKeeper call.
simapp/v2/README.md New file showcasing an application developed with Cosmos SDK for testing and educational use.
simapp/v2/app_config.go Defined configurations for various modules in a Cosmos SDK application.
simapp/v2/app_di.go Introduced SimApp struct with configurations and keepers for various modules.
simapp/v2/default.nix Nix expression for building a Go application named simd with specific configurations.
simapp/v2/export.go Introduced functionality to export the state of the application for a genesis file.
simapp/v2/genesis_account.go Introduced SimGenesisAccount type for simulation accounts in the genesis state.
simapp/v2/simdv2/cmd/commands.go Added command handling functionality for initializing, starting, querying, and managing transactions.
simapp/v2/simdv2/cmd/config.go Added functions to initialize custom configurations for CometBFT, client, and application settings.
store/v2/commitment/store.go Added IsEmpty method and modified flushCommitInfo and Commit methods.
store/v2/root/store.go Added check for empty SC store before setting version value in writeSC method.
store/v2/database.go Added IsEmpty() method to Committer interface.
tests/integration/distribution/keeper/msg_server_test.go Modified distrKeeper initialization and added ProposerAddress field in test fixture initialization.
x/auth/tx/config.go Updated NewTxConfig function to accept customSignModes and included ProtoCodec in NewTxConfigWithOptions.
core/context/context_test.go Added Test_Sanity function to ensure specific keys are not equal.
runtime/v2/services/comet.go Modified CometInfo method to retrieve comet.Info from context.

Sequence Diagram(s) (Beta)

No significant control flow changes requiring sequence diagrams were identified.

Assessment against linked issues

Objective (Issue #20492) Addressed Explanation
Ensure simapp/v2 starts without crashing with panic: proto:not found when using go.mod replaces The changes include various updates, but it's not clear if this specific issue is resolved.

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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

server/v2/cometbft/server.go Fixed Show fixed Hide fixed
server/v2/cometbft/snapshots.go Fixed Show fixed Hide fixed
server/v2/streaming/examples/file/file.go Dismissed Show dismissed Hide dismissed
server/v2/commands.go Dismissed Show dismissed Hide dismissed
server/v2/api/grpc/gogoreflection/fix_registration.go Dismissed Show dismissed Hide dismissed
server/v2/api/grpc/gogoreflection/serverreflection.go Dismissed Show dismissed Hide dismissed
server/v2/api/grpc/gogoreflection/fix_registration.go Dismissed Show dismissed Hide dismissed
if fd.IsExtension() {
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.consensus.v1.CometInfo"))
}
panic(fmt.Errorf("message cosmos.consensus.v1.CometInfo does not contain field %s", fd.FullName()))

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
api/cosmos/consensus/v1/tx.pulsar.go Fixed Show fixed Hide fixed
api/cosmos/consensus/v1/tx.pulsar.go Fixed Show fixed Hide fixed
api/cosmos/consensus/v1/tx.pulsar.go Fixed Show fixed Hide fixed
api/cosmos/consensus/v1/tx.pulsar.go Fixed Show fixed Hide fixed
@@ -113,6 +112,18 @@ func (c *CommitStore) GetLatestVersion() (uint64, error) {
return version, nil
}

func (c *CommitStore) IsEmpty() (bool, error) {
Copy link
Member

Choose a reason for hiding this comment

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

godoc

Copy link
Contributor

@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.

Actionable comments posted: 4

Outside diff range and nitpick comments (2)
x/tx/decode/decode.go (2)

23-24: Ensure the new fields DynamicMessages and Messages are properly documented.

Adding comments to explain the purpose of these fields would enhance code readability and maintainability.


Line range hint 122-172: Review the logic for handling dynamic and gogoproto messages.

The logic for handling different types of messages can be complex. Consider simplifying this logic or breaking it down into smaller, more manageable functions.

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ce36a1c and faf1450.

Files selected for processing (2)
  • simapp/v2/export.go (1 hunks)
  • x/tx/decode/decode.go (6 hunks)
Files skipped from review as they are similar to previous changes (1)
  • simapp/v2/export.go
Additional context used
Path-based instructions (1)
x/tx/decode/decode.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

Additional comments not posted (2)
x/tx/decode/decode.go (2)

64-64: Ensure codec is used correctly in the Decoder struct.

Verification successful

The codec field in the Decoder struct is used correctly. The NewDecoder method ensures that options.ProtoCodec is not nil before assigning it to the codec field. The Decode method then uses this codec field to unmarshal messages, which is consistent with its intended purpose.

  • NewDecoder method checks for options.ProtoCodec and assigns it to codec.
  • Decode method uses d.codec.Unmarshal to unmarshal messages.

No issues found with the usage of codec in the Decoder struct.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that `codec` is used correctly throughout the `Decoder` struct.

# Test: Search for the usage of `codec`. Expect: Correct and consistent usage.
rg --type go 'codec' x/tx/decode/decode.go

Length of output: 237



Script:

#!/bin/bash
# Description: Extract the full implementation of the `Decoder` struct and its methods for comprehensive review.

# Search for the `Decoder` struct definition and its methods.
ast-grep --lang go --pattern $'type Decoder struct {
  $$$
}' x/tx/decode/decode.go

# Search for methods associated with the `Decoder` struct.
ast-grep --lang go --pattern $'func ($_ Decoder) $_($_) $_ {
  $$$
}' x/tx/decode/decode.go

Length of output: 357



Script:

#!/bin/bash
# Description: Search for the instantiation and usage of the `Decoder` struct in the codebase.

# Search for the instantiation of the `Decoder` struct.
rg --type go 'Decoder{' .

# Search for the usage of the `Decoder` struct.
rg --type go 'Decoder' .

Length of output: 20998



Script:

#!/bin/bash
# Description: Extract the implementation of `NewDecoder` and `Decode` methods for comprehensive review.

# Extract the implementation of `NewDecoder` method.
ast-grep --lang go --pattern $'func NewDecoder(options Options) (*Decoder, error) {
  $$$
}' x/tx/decode/decode.go

# Extract the implementation of `Decode` method.
ast-grep --lang go --pattern $'func (d *Decoder) Decode(txBytes []byte) (*DecodedTx, error) {
  $$$
}' x/tx/decode/decode.go

Length of output: 6916


45-45: Ensure codec is properly initialized and used.

Verification successful

To ensure that codec is properly initialized and used, we need to verify the initialization of options.ProtoCodec and check its usage throughout the codebase.


The search results indicate that options.ProtoCodec is indeed initialized and used in various parts of the codebase. Specifically, it is assigned to codec and used in the Unmarshal method, among other places.

  • x/tx/decode/decode.go: codec: options.ProtoCodec
  • x/tx/decode/decode.go: err = d.codec.Unmarshal(anyMsg.Value, msg)

Additionally, ProtoCodec is initialized in multiple files, ensuring that it is properly set up.

  • codec/proto_codec.go: func NewProtoCodec(interfaceRegistry types.InterfaceRegistry) *ProtoCodec {

Given this information, it is clear that codec is properly initialized and used.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that `codec` is properly initialized and used in all relevant parts of the code.

# Test: Search for the usage of `codec`. Expect: Proper initialization and usage.
rg --type go 'codec' x/tx/decode/decode.go

Length of output: 237



Script:

#!/bin/bash
# Description: Verify the initialization and usage of `options.ProtoCodec`.

# Search for the initialization of `options.ProtoCodec`.
rg --type go 'ProtoCodec' 

# Search for the usage of `options.ProtoCodec`.
rg --type go 'options.ProtoCodec'

Length of output: 21727

x/tx/decode/decode.go Show resolved Hide resolved
x/tx/decode/decode.go Show resolved Hide resolved
x/tx/decode/decode.go Show resolved Hide resolved
}

return msgs, nil
return dtx.Messages, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

Ensure that dtx.Messages is properly populated before calling GetMessages. Currently, there are no assignments to dtx.Messages in the codebase, which will result in GetMessages returning nil or an error.

Analysis chain

Ensure that GetMessages method returns correct data.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that `GetMessages` method returns the correct data.

# Test: Check the return values of `GetMessages`. Expect: Correct data based on input conditions.
rg --type go 'GetMessages' x/tx/decode/decode.go

Length of output: 113



Script:

#!/bin/bash
# Description: Extract the full implementation of the `GetMessages` method and analyze how `dtx.Messages` is populated.

# Extract the full implementation of the `GetMessages` method.
ast-grep --lang go --pattern $'func (dtx *DecodedTx) GetMessages() ([]transaction.Msg, error) {
  $$$
}' x/tx/decode/decode.go

# Search for where `dtx.Messages` is populated within the codebase.
rg --type go 'dtx.Messages' 

Length of output: 646



Script:

#!/bin/bash
# Description: Search for assignments to `dtx.Messages` within the codebase to verify how it is populated.

# Search for assignments to `dtx.Messages`.
rg --type go 'dtx.Messages\s*='

Length of output: 95

Copy link
Contributor

@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.

Actionable comments posted: 2

Outside diff range and nitpick comments (6)
store/v2/commitment/store.go (4)

Line range hint 375-375: Address the undefined error for ErrorExportDone.

- if errors.Is(err, ErrorExportDone) {
+ if errors.Is(err, io.EOF) {

Line range hint 407-407: Address the undefined error for Importer.

- var importer Importer
+ var importer snapshots.Importer

Line range hint 409-409: Remove the unused variable storeKey.

- storeKey declared and not used (typecheck)

Line range hint 8-8: Remove the unused import "math".

- "math"
server/v2/stf/stf.go (2)

Line range hint 38-40: Define missing types for branchFn, makeGasMeterFn, and makeGasMeteredStateFn.

The types branchFn, makeGasMeterFn, and makeGasMeteredStateFn are used in the STF struct but are not defined anywhere in the provided code. This will cause a compilation error. You should define these types or import them if they are defined in another package.


Line range hint 558-560: Define or import the undefined types used in newExecutionContext.

The function newExecutionContext uses several types (branchFn, makeGasMeterFn, makeGasMeteredStateFn) that are not defined in the provided code snippet. Ensure these types are properly defined or imported to avoid compilation errors.

Also applies to: 606-608

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between faf1450 and 2ad7cbf.

Files selected for processing (4)
  • server/v2/stf/stf.go (6 hunks)
  • simapp/v2/simdv2/cmd/root_di.go (1 hunks)
  • store/v2/commitment/store.go (1 hunks)
  • store/v2/root/store.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • simapp/v2/simdv2/cmd/root_di.go
Additional context used
Path-based instructions (3)
store/v2/commitment/store.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

store/v2/root/store.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

server/v2/stf/stf.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

golangci-lint
store/v2/commitment/store.go

42-42: undefined: Tree (typecheck)


29-29: undefined: store (typecheck)


31-31: undefined: store (typecheck)


46-46: undefined: Tree (typecheck)


375-375: undefined: ErrorExportDone (typecheck)


407-407: undefined: Importer (typecheck)


409-409: storeKey declared and not used (typecheck)


8-8: "math" imported and not used (typecheck)

store/v2/root/store.go

33-33: undefined: store (typecheck)


36-36: undefined: store (typecheck)


22-22: undefined: store (typecheck)


67-67: undefined: store (typecheck)


68-68: undefined: store (typecheck)


72-72: undefined: store (typecheck)


130-130: undefined: store (typecheck)


134-134: undefined: store (typecheck)


166-166: undefined: store (typecheck)


115-115: undefined: NewReaderMap (typecheck)


127-127: undefined: NewReaderMap (typecheck)


177-177: undefined: store (typecheck)


182-182: undefined: store (typecheck)


191-191: undefined: store (typecheck)


197-197: undefined: store (typecheck)


206-206: undefined: store (typecheck)


395-395: no new variables on left side of := (typecheck)

server/v2/stf/stf.go

38-38: undefined: branchFn (typecheck)


39-39: undefined: makeGasMeterFn (typecheck)


40-40: undefined: makeGasMeteredStateFn (typecheck)


558-558: undefined: branchFn (typecheck)


559-559: undefined: makeGasMeterFn (typecheck)


560-560: undefined: makeGasMeteredStateFn (typecheck)


606-606: undefined: makeGasMeterFn (typecheck)


607-607: undefined: makeGasMeteredStateFn (typecheck)


608-608: undefined: branchFn (typecheck)


// setHeaderInfo sets the header info in the state to be used by queries in the future.
func (s STF[T]) setHeaderInfo(state store.WriterMap, headerInfo header.Info) error {
runtimeStore, err := state.GetWriter(appmanager.RuntimeIdentity)
// TODO storing header info is too low level here, stf should be stateless.
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider abstracting header info storage.

The comment suggests that storing header info at this level might be too low. It could be beneficial to abstract this functionality into a separate keeper or service to maintain the statelessness of the STF. This would align with the separation of concerns principle and potentially simplify the STF structure.

isEmpty, err := s.stateCommitment.IsEmpty()
if err != nil {
return fmt.Errorf("failed to check if SC store is empty: %w", err)
}

isEmpty, err := s.stateCommitment.IsEmpty()
Copy link
Contributor

Choose a reason for hiding this comment

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

Correct the variable redeclaration issue.

- isEmpty, err := s.stateCommitment.IsEmpty()
+ isEmpty, err = s.stateCommitment.IsEmpty()
Committable suggestion

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

Suggested change
isEmpty, err := s.stateCommitment.IsEmpty()
isEmpty, err = s.stateCommitment.IsEmpty()
Tools
golangci-lint

395-395: no new variables on left side of := (typecheck)

store/v2/root/store.go Fixed Show fixed Hide fixed
x/distribution/keeper/abci.go Fixed Show fixed Hide fixed
@@ -101,6 +101,7 @@ func init() {
ProvideModuleManager,
ProvideGenesisTxHandler,
ProvideCometService,
ProvideAppVersionModifier,
Copy link
Contributor

Choose a reason for hiding this comment

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

this seems to be present in main 🤔

@tac0turtle tac0turtle marked this pull request as draft June 10, 2024 09:06
@github-actions github-actions bot removed the C:x/distribution distribution module related label Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

simapp/v2 start crashes with panic: proto:not found when using go.mod replaces instead of go.work
7 participants