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: make validator key injectable by application developers #21608

Merged
merged 12 commits into from
Sep 18, 2024

Conversation

tac0turtle
Copy link
Member

@tac0turtle tac0turtle commented Sep 9, 2024

Description

Closes: #21587

allow application developers to pick their validator key


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, you can find examples of the prefixes below:
  • 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.

Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.

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 a key generation mechanism for validators, enhancing security and flexibility in key management.
    • Added a method to retrieve a validator key, supporting multiple key types for improved functionality.
  • Bug Fixes

    • Improved test output clarity by marking helper functions, aiding in debugging.
  • Refactor

    • Streamlined private key management by abstracting key generation logic, enhancing modularity.
  • Chores

    • Cleaned up legacy comments in the codebase for better readability and maintainability.

Copy link
Contributor

coderabbitai bot commented Sep 9, 2024

Walkthrough

Walkthrough

The changes introduce a modular approach to private key generation within the application, allowing developers to specify custom key generation functions. This is achieved through the addition of a ValidatorKeyProvider method and related function type aliases across various components. The modifications enhance flexibility in key management, particularly for validator operations, and improve the overall structure of the codebase by removing legacy comments and improving test clarity.

Changes

File Change Summary
runtime/app.go Added KeyGenF type alias and ValidatorKeyProvider method for generating private keys.
schema/diff/diff_test.go Added t.Helper() to requireModuleSchema function to improve test output clarity.
server/start.go Modified startCmtNode to use app.ValidatorKeyProvider() for private key generation instead of direct generation.
server/types/app.go Added ValidatorKeyProvider() method to interface for retrieving a validator key generation function.
server/v2/cometbft/options.go Introduced keyGenF type and added it to ServerOptions struct, allowing custom key generation functions. Updated DefaultServerOptions to use this new field.
server/v2/cometbft/server.go Removed imports for cmtcrypto and cmted25519, replaced inline key generation with reference to s.serverOptions.KeygenF.
simapp/app.go Added ValidatorKeyProvider to SimApp struct for generating validator keys using ed25519.
x/simulation/params.go Removed legacy comments from NewWeightedProposalContent and ContentSimulatorFn function signatures.

Assessment against linked issues

Objective Addressed Explanation
Allow the application developer from baseapp and/or serverv2 to pass in a validator key (#[21587])

Possibly related PRs

  • refactor: decouple comet from modules #21382: This PR discusses changes related to the removal of deprecated structures in the staking module, which may indirectly relate to the key management functionalities introduced in the main PR.
  • chore: remove duplicate proto files for the same proto file #21648: The changes in this PR involve modifications to the SimApp class, which is relevant as the main PR also introduces a ValidatorKeyProvider method in the SimApp struct, indicating a connection in terms of key management.
  • ci: remove duplicate gosec & lint fixes #21685: While primarily focused on CI configurations, this PR's context around code cleanup and organization may relate to the overall improvements in the codebase that the main PR aims to achieve.
  • chore: remove consensus authority  #21734: This PR's focus on removing the consensus authority could relate to the modularity and configurability aspects introduced in the main PR, particularly in how key management is handled within the application.

Suggested labels

C:x/auth, C:CLI

Suggested reviewers

  • facundomedica
  • sontrinh16
  • kocubinski
  • alpe
  • testinginprod
  • julienrbrt

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>, please review it.
    -- 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 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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

baseapp/options.go Outdated Show resolved Hide resolved
Copy link
Contributor

@tac0turtle your pull request is missing a changelog!

Copy link
Member

@sontrinh16 sontrinh16 left a comment

Choose a reason for hiding this comment

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

lgtm, just need to resolve the conflict and go mod tidy

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

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d18491a and 66d1fa9.

Files selected for processing (7)
  • runtime/app.go (3 hunks)
  • schema/diff/diff_test.go (1 hunks)
  • server/start.go (1 hunks)
  • server/v2/cometbft/options.go (2 hunks)
  • server/v2/cometbft/server.go (1 hunks)
  • simapp/app.go (2 hunks)
  • types/module/simulation.go (2 hunks)
Files skipped from review as they are similar to previous changes (6)
  • runtime/app.go
  • schema/diff/diff_test.go
  • server/start.go
  • server/v2/cometbft/options.go
  • server/v2/cometbft/server.go
  • simapp/app.go
Additional context used
Path-based instructions (1)
types/module/simulation.go (1)

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

GitHub Check: tests (03)
types/module/simulation.go

[failure] 39-39:
syntax error: unexpected <<, expected name


[failure] 41-41:
syntax error: unexpected type, expected name


[failure] 43-43:
syntax error: unexpected [ after top level declaration


[failure] 51-51:
syntax error: non-declaration statement outside function body


[failure] 63-63:
syntax error: non-declaration statement outside function body


[failure] 39-39:
syntax error: unexpected <<, expected name


[failure] 167-167:
syntax error: unexpected <<, expected field name or embedded type


[failure] 171-171:
syntax error: unexpected ||, expected field name or embedded type


[failure] 175-175:
syntax error: unexpected ==, expected field name or embedded type

GitHub Check: tests (02)
types/module/simulation.go

[failure] 39-39:
syntax error: unexpected <<, expected name


[failure] 41-41:
syntax error: unexpected type, expected name


[failure] 43-43:
syntax error: unexpected [ after top level declaration


[failure] 51-51:
syntax error: non-declaration statement outside function body


[failure] 63-63:
syntax error: non-declaration statement outside function body


[failure] 39-39:
syntax error: unexpected <<, expected name


[failure] 41-41:
syntax error: unexpected type, expected name


[failure] 167-167:
syntax error: unexpected <<, expected field name or embedded type


[failure] 171-171:
syntax error: unexpected ||, expected field name or embedded type


[failure] 175-175:
syntax error: unexpected ==, expected field name or embedded type

GitHub Check: tests (01)
types/module/simulation.go

[failure] 39-39:
syntax error: unexpected <<, expected name


[failure] 41-41:
syntax error: unexpected type, expected name


[failure] 43-43:
syntax error: unexpected [ after top level declaration


[failure] 51-51:
syntax error: non-declaration statement outside function body


[failure] 63-63:
syntax error: non-declaration statement outside function body


[failure] 39-39:
syntax error: unexpected <<, expected name


[failure] 41-41:
syntax error: unexpected type, expected name


[failure] 167-167:
syntax error: unexpected <<, expected field name or embedded type


[failure] 171-171:
syntax error: unexpected ||, expected field name or embedded type


[failure] 175-175:
syntax error: unexpected ==, expected field name or embedded type

GitHub Check: tests (00)
types/module/simulation.go

[failure] 39-39:
syntax error: unexpected <<, expected name


[failure] 41-41:
syntax error: unexpected type, expected name


[failure] 43-43:
syntax error: unexpected [ after top level declaration


[failure] 51-51:
syntax error: non-declaration statement outside function body


[failure] 63-63:
syntax error: non-declaration statement outside function body


[failure] 39-39:
syntax error: unexpected <<, expected name


[failure] 41-41:
syntax error: unexpected type, expected name


[failure] 167-167:
syntax error: unexpected <<, expected field name or embedded type


[failure] 171-171:
syntax error: unexpected ||, expected field name or embedded type


[failure] 175-175:
syntax error: unexpected ==, expected field name or embedded type

GitHub Check: dependency-review
types/module/simulation.go

[failure] 39-39:
expected 'IDENT', found '<<'


[failure] 39-39:
expected type, found '<<'


[failure] 41-41:
expected 'IDENT', found 'type'


[failure] 41-41:
expected ';', found 'interface'


[failure] 47-47:
expected 'IDENT', found 'type'


[failure] 47-47:
expected ';', found 'interface'


[failure] 53-53:
expected 'IDENT', found 'type'


[failure] 53-53:
expected ';', found 'interface'


[failure] 59-59:
expected 'IDENT', found 'type'


[failure] 59-59:
expected ';', found 'interface'

GitHub Check: golangci-lint
types/module/simulation.go

[failure] 39-39:
syntax error: unexpected <<, expected name


[failure] 41-41:
syntax error: unexpected type, expected name


[failure] 43-43:
syntax error: unexpected [ after top level declaration


[failure] 51-51:
syntax error: non-declaration statement outside function body


[failure] 63-63:
syntax error: non-declaration statement outside function body


[failure] 167-167:
syntax error: unexpected <<, expected field name or embedded type


[failure] 171-171:
syntax error: unexpected ||, expected field name or embedded type


[failure] 175-175:
syntax error: unexpected ==, expected field name or embedded type) (typecheck)

Additional comments not posted (2)
types/module/simulation.go (2)

49-50: LGTM!

The ProposalContents method is well-defined in the HasProposalContents interface, with a clear comment indicating its purpose for simulating legacy governance proposals. The explicit definition ensures backward compatibility.


169-170: LGTM!

The addition of the LegacyProposalContents and ProposalMsgs fields to the SimulationState struct enhances its structure and clarity. The field names are descriptive, and their types are appropriate for storing the respective generator functions and their metadata.

Comment on lines 39 to 50
<<<<<<< HEAD
// HasProposalMsgs defines the messages that can be used to simulate governance (v1) proposals
type HasProposalMsgs interface {
// msg functions used to simulate governance proposals
ProposalMsgs(simState SimulationState) []simulation.WeightedProposalMsg
}

// HasProposalContents defines the contents that can be used to simulate legacy governance (v1beta1) proposals
type HasProposalContents interface {
// content functions used to simulate governance proposals
ProposalContents(simState SimulationState) []simulation.WeightedProposalContent
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Resolve the merge conflict.

The code segment contains merge conflict markers, indicating an unresolved merge conflict. Please resolve the conflict and ensure the code is valid before proceeding with the review.

Tools
GitHub Check: tests (03)

[failure] 39-39:
syntax error: unexpected <<, expected name


[failure] 41-41:
syntax error: unexpected type, expected name


[failure] 43-43:
syntax error: unexpected [ after top level declaration


[failure] 39-39:
syntax error: unexpected <<, expected name

GitHub Check: tests (02)

[failure] 39-39:
syntax error: unexpected <<, expected name


[failure] 41-41:
syntax error: unexpected type, expected name


[failure] 43-43:
syntax error: unexpected [ after top level declaration


[failure] 39-39:
syntax error: unexpected <<, expected name


[failure] 41-41:
syntax error: unexpected type, expected name

GitHub Check: tests (01)

[failure] 39-39:
syntax error: unexpected <<, expected name


[failure] 41-41:
syntax error: unexpected type, expected name


[failure] 43-43:
syntax error: unexpected [ after top level declaration


[failure] 39-39:
syntax error: unexpected <<, expected name


[failure] 41-41:
syntax error: unexpected type, expected name

GitHub Check: tests (00)

[failure] 39-39:
syntax error: unexpected <<, expected name


[failure] 41-41:
syntax error: unexpected type, expected name


[failure] 43-43:
syntax error: unexpected [ after top level declaration


[failure] 39-39:
syntax error: unexpected <<, expected name


[failure] 41-41:
syntax error: unexpected type, expected name

GitHub Check: dependency-review

[failure] 39-39:
expected 'IDENT', found '<<'


[failure] 39-39:
expected type, found '<<'


[failure] 41-41:
expected 'IDENT', found 'type'


[failure] 41-41:
expected ';', found 'interface'


[failure] 47-47:
expected 'IDENT', found 'type'


[failure] 47-47:
expected ';', found 'interface'

GitHub Check: golangci-lint

[failure] 39-39:
syntax error: unexpected <<, expected name


[failure] 41-41:
syntax error: unexpected type, expected name


[failure] 43-43:
syntax error: unexpected [ after top level declaration

Comment on lines 167 to 171
<<<<<<< HEAD

LegacyProposalContents []simulation.WeightedProposalContent // proposal content generator functions with their default weight and app sim key
ProposalMsgs []simulation.WeightedProposalMsg // proposal msg generator functions with their default weight and app sim key
||||||| c0eced8d7e
Copy link
Contributor

Choose a reason for hiding this comment

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

Resolve the merge conflict.

The code segment contains merge conflict markers, indicating an unresolved merge conflict. Please resolve the conflict and ensure the code is valid before proceeding with the review.

Tools
GitHub Check: tests (03)

[failure] 167-167:
syntax error: unexpected <<, expected field name or embedded type


[failure] 171-171:
syntax error: unexpected ||, expected field name or embedded type

GitHub Check: tests (02)

[failure] 167-167:
syntax error: unexpected <<, expected field name or embedded type


[failure] 171-171:
syntax error: unexpected ||, expected field name or embedded type

GitHub Check: tests (01)

[failure] 167-167:
syntax error: unexpected <<, expected field name or embedded type


[failure] 171-171:
syntax error: unexpected ||, expected field name or embedded type

GitHub Check: tests (00)

[failure] 167-167:
syntax error: unexpected <<, expected field name or embedded type


[failure] 171-171:
syntax error: unexpected ||, expected field name or embedded type

GitHub Check: golangci-lint

[failure] 167-167:
syntax error: unexpected <<, expected field name or embedded type


[failure] 171-171:
syntax error: unexpected ||, expected field name or embedded type

@julienrbrt julienrbrt added the backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release label Sep 18, 2024
Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

lgtm! just missing go docs.

@@ -30,6 +32,8 @@ import (
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
)

type KeyGenF = func() (cmtcrypto.PrivKey, error)
Copy link
Member

Choose a reason for hiding this comment

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

can we have a godoc here?

// ServerOptions defines the options for the CometBFT server.
// When an option takes a map[string]any, it can access the app.tom's cometbft section and the config.toml config.
type ServerOptions[T transaction.Tx] struct {
PrepareProposalHandler handlers.PrepareHandler[T]
ProcessProposalHandler handlers.ProcessHandler[T]
VerifyVoteExtensionHandler handlers.VerifyVoteExtensionhandler
ExtendVoteHandler handlers.ExtendVoteHandler
KeygenF keyGenF
Copy link
Member

Choose a reason for hiding this comment

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

I really like that it doesn't leak in the app in v2 🙏🏾

Copy link
Member

Choose a reason for hiding this comment

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

Can we have a go doc here too? It's less descriptive than the above.

Copy link
Member

Choose a reason for hiding this comment

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

you will probably need to revert this file to make the linter happy

@@ -308,3 +312,9 @@ var _ servertypes.Application = &App{}
type hasServicesV1 interface {
RegisterServices(grpc.ServiceRegistrar) error
}

func (a *App) ValidatorKeyProvider() KeyGenF {
Copy link
Member

Choose a reason for hiding this comment

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

go doc here too please

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

Outside diff range and nitpick comments (1)
x/simulation/params.go (1)

163-163: Deprecation notice acknowledged. Consider updating the codebase.

The comment correctly indicates that the WeightedProposalContent struct is deprecated. As confirmed by the static analysis hints, simulation.ContentSimulatorFn should be replaced with simulation.MsgSimulatorFn throughout the codebase.

Consider updating the codebase to use simulation.MsgSimulatorFn instead of simulation.ContentSimulatorFn to align with the deprecation notice.

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c69aa19 and f5e6e36.

Files selected for processing (1)
  • x/simulation/params.go (2 hunks)
Additional context used
Path-based instructions (1)
x/simulation/params.go (1)

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

GitHub Check: golangci-lint
x/simulation/params.go

[failure] 167-167:
SA1019: simulation.ContentSimulatorFn is deprecated: Use MsgSimulatorFn instead. (staticcheck)


[failure] 170-170:
SA1019: simulation.ContentSimulatorFn is deprecated: Use MsgSimulatorFn instead. (staticcheck)


[failure] 182-182:
SA1019: simulation.ContentSimulatorFn is deprecated: Use MsgSimulatorFn instead. (staticcheck)

type WeightedProposalContent struct {
appParamsKey string // key used to retrieve the value of the weight from the simulation application params
defaultWeight int // default weight
contentSimulatorFn simulation.ContentSimulatorFn // content simulator function
}

func NewWeightedProposalContent(appParamsKey string, defaultWeight int, contentSimulatorFn simulation.ContentSimulatorFn) simulation.WeightedProposalContent { //nolint:staticcheck // used for legacy testing
func NewWeightedProposalContent(appParamsKey string, defaultWeight int, contentSimulatorFn simulation.ContentSimulatorFn) simulation.WeightedProposalContent {
Copy link
Contributor

Choose a reason for hiding this comment

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

Update the function signatures to use simulation.MsgSimulatorFn.

The function signatures of NewWeightedProposalContent and ContentSimulatorFn use the deprecated simulation.ContentSimulatorFn type. As confirmed by the static analysis hints, simulation.ContentSimulatorFn should be replaced with simulation.MsgSimulatorFn.

Please update the function signatures to use simulation.MsgSimulatorFn instead of simulation.ContentSimulatorFn. This will also require updating the corresponding function implementations and any code that invokes these functions.

Do you want me to open a GitHub issue to track the refactoring task or provide a diff with the necessary changes?

Also applies to: 182-182

Tools
GitHub Check: golangci-lint

[failure] 170-170:
SA1019: simulation.ContentSimulatorFn is deprecated: Use MsgSimulatorFn instead. (staticcheck)

@tac0turtle tac0turtle added this pull request to the merge queue Sep 18, 2024
Merged via the queue into main with commit f1dd03f Sep 18, 2024
71 of 72 checks passed
@tac0turtle tac0turtle deleted the marko/21587 branch September 18, 2024 12:32
mergify bot pushed a commit that referenced this pull request Sep 18, 2024
(cherry picked from commit f1dd03f)

# Conflicts:
#	schema/diff/diff_test.go
tac0turtle added a commit that referenced this pull request Sep 18, 2024
alpe added a commit that referenced this pull request Sep 18, 2024
* main:
  refactor(mempool)!: match server/v2/cometbft and sdk mempool interface (#21744)
  feat: make validator key injectable by application developers (#21608)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release C:schema C:server/v2 cometbft C:server/v2 Issues related to server/v2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: make val privkey modular
5 participants