From 9f7e8d8ab417f71f8d486878886c1a7639279b2e Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 9 Sep 2024 13:35:03 +0200 Subject: [PATCH 1/9] make validator key injectable by application developers --- baseapp/baseapp.go | 9 +++++++++ baseapp/options.go | 11 +++++++++++ runtime/app.go | 4 ++++ server/start.go | 4 +--- server/types/app.go | 4 ++++ simapp/app.go | 4 ++++ 6 files changed, 33 insertions(+), 3 deletions(-) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 89748eadf053..3d3d41b524ef 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -12,6 +12,8 @@ import ( abci "github.com/cometbft/cometbft/api/cometbft/abci/v1" cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1" + cmtcrypto "github.com/cometbft/cometbft/crypto" + cmted25519 "github.com/cometbft/cometbft/crypto/ed25519" "github.com/cometbft/cometbft/crypto/tmhash" "github.com/cosmos/gogoproto/proto" "google.golang.org/protobuf/reflect/protoreflect" @@ -60,6 +62,8 @@ const ( var _ servertypes.ABCI = (*BaseApp)(nil) +type KeyGenF = func() (cmtcrypto.PrivKey, error) + // BaseApp reflects the ABCI application implementation. type BaseApp struct { // initialized on creation @@ -190,6 +194,8 @@ type BaseApp struct { // includeNestedMsgsGas holds a set of message types for which gas costs for its nested messages are calculated. includeNestedMsgsGas map[string]struct{} + + validatorKeyProvider KeyGenF } // NewBaseApp returns a reference to an initialized BaseApp. It accepts a @@ -210,6 +216,9 @@ func NewBaseApp( fauxMerkleMode: false, sigverifyTx: true, queryGasLimit: math.MaxUint64, + validatorKeyProvider: func() (cmtcrypto.PrivKey, error) { + return cmted25519.GenPrivKey(), nil + }, } for _, option := range options { diff --git a/baseapp/options.go b/baseapp/options.go index 53286b2540b9..a01b475b364b 100644 --- a/baseapp/options.go +++ b/baseapp/options.go @@ -406,3 +406,14 @@ func (app *BaseApp) SetMsgServiceRouter(msgServiceRouter *MsgServiceRouter) { func (app *BaseApp) SetGRPCQueryRouter(grpcQueryRouter *GRPCQueryRouter) { app.grpcQueryRouter = grpcQueryRouter } + +func (app *BaseApp) SetPrivValidatorKeyGen(keyGenF KeyGenF) { + if app.sealed { + panic("SetPrivValidatorProvider() on sealed BaseApp") + } + app.validatorKeyProvider = keyGenF +} + +func (app *BaseApp) ValidatorKeyProvider() KeyGenF { + return app.validatorKeyProvider +} diff --git a/runtime/app.go b/runtime/app.go index 0c2d070bea5b..23e38519bb7b 100644 --- a/runtime/app.go +++ b/runtime/app.go @@ -305,3 +305,7 @@ var _ servertypes.Application = &App{} type hasServicesV1 interface { RegisterServices(grpc.ServiceRegistrar) error } + +func (a *App) ValidatorKeyPrvoder() baseapp.KeyGenF { + return a.ValidatorKeyProvider() +} diff --git a/server/start.go b/server/start.go index dce5ae198e6a..56b2a3fd0573 100644 --- a/server/start.go +++ b/server/start.go @@ -374,9 +374,7 @@ func startCmtNode( return nil, cleanupFn, err } - pv, err := pvm.LoadOrGenFilePV(cfg.PrivValidatorKeyFile(), cfg.PrivValidatorStateFile(), func() (cmtcrypto.PrivKey, error) { - return cmted25519.GenPrivKey(), nil - }) // TODO: make this modular + pv, err := pvm.LoadOrGenFilePV(cfg.PrivValidatorKeyFile(), cfg.PrivValidatorStateFile(), app.ValidatorKeyProvider()) if err != nil { return nil, cleanupFn, err } diff --git a/server/types/app.go b/server/types/app.go index 798a4475dbbe..582f4dcacdfc 100644 --- a/server/types/app.go +++ b/server/types/app.go @@ -5,6 +5,7 @@ import ( "io" cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1" + cmtcrypto "github.com/cometbft/cometbft/crypto" cmttypes "github.com/cometbft/cometbft/types" "github.com/cosmos/gogoproto/grpc" @@ -58,6 +59,9 @@ type ( // SnapshotManager return the snapshot manager SnapshotManager() *snapshots.Manager + // ValidatorKeyProvider returns a function that generates a validator key + ValidatorKeyProvider() func() (cmtcrypto.PrivKey, error) + // Close is called in start cmd to gracefully cleanup resources. // Must be safe to be called multiple times. Close() error diff --git a/simapp/app.go b/simapp/app.go index 6cf93e4046d0..d36777ebef6e 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -828,6 +828,10 @@ func (app *SimApp) RegisterNodeService(clientCtx client.Context, cfg config.Conf nodeservice.RegisterNodeService(clientCtx, app.GRPCQueryRouter(), cfg) } +func (app *SimApp) ValidatorKeyProvider() baseapp.KeyGenF { + return app.ValidatorKeyProvider() +} + // GetMaccPerms returns a copy of the module account permissions // // NOTE: This is solely to be used for testing purposes. From e169ad094545043c2e4144e8ca0b412653f22cf6 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 16 Sep 2024 10:56:02 +0200 Subject: [PATCH 2/9] address customization --- baseapp/options.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/baseapp/options.go b/baseapp/options.go index a01b475b364b..056bcc238655 100644 --- a/baseapp/options.go +++ b/baseapp/options.go @@ -14,6 +14,10 @@ import ( "cosmossdk.io/store/snapshots" snapshottypes "cosmossdk.io/store/snapshots/types" storetypes "cosmossdk.io/store/types" + cmtcrypto "github.com/cometbft/cometbft/crypto" + cmtBLS12381 "github.com/cometbft/cometbft/crypto/bls12381" + cmted25519 "github.com/cometbft/cometbft/crypto/ed25519" + cmtsecp256k1 "github.com/cometbft/cometbft/crypto/secp256k1" "github.com/cosmos/cosmos-sdk/baseapp/oe" "github.com/cosmos/cosmos-sdk/codec" @@ -407,10 +411,32 @@ func (app *BaseApp) SetGRPCQueryRouter(grpcQueryRouter *GRPCQueryRouter) { app.grpcQueryRouter = grpcQueryRouter } +// SetPrivValidatorKeyGen sets the function that generates the private validator key. +// Only comet keys are supported: Ed25519, Secp256k1, BLS12-381. func (app *BaseApp) SetPrivValidatorKeyGen(keyGenF KeyGenF) { if app.sealed { panic("SetPrivValidatorProvider() on sealed BaseApp") } + key, err := keyGenF() + if err != nil { + panic(err) + } + switch key.(type) { + case cmted25519.PrivKey: + app.validatorKeyProvider = func() (cmtcrypto.PrivKey, error) { + return key, nil + } + case cmtsecp256k1.PrivKey: + app.validatorKeyProvider = func() (cmtcrypto.PrivKey, error) { + return key, nil + } + case cmtBLS12381.PrivKey: + app.validatorKeyProvider = func() (cmtcrypto.PrivKey, error) { + return key, nil + } + default: + panic(fmt.Errorf("unsupported priv validator key type %T", key)) + } app.validatorKeyProvider = keyGenF } From f2788ad5cc38d244d822c2ed8e5d97b593de2681 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 16 Sep 2024 11:08:52 +0200 Subject: [PATCH 3/9] v2 --- baseapp/options.go | 9 +++++---- schema/diff/diff_test.go | 1 + server/v2/cometbft/options.go | 7 +++++++ server/v2/cometbft/server.go | 6 +----- simapp/app.go | 6 +++++- types/module/simulation.go | 4 ++-- x/simulation/params.go | 6 +++--- x/simulation/params_test.go | 2 +- 8 files changed, 25 insertions(+), 16 deletions(-) diff --git a/baseapp/options.go b/baseapp/options.go index 056bcc238655..09e051321795 100644 --- a/baseapp/options.go +++ b/baseapp/options.go @@ -7,6 +7,11 @@ import ( "io" "math" + cmtcrypto "github.com/cometbft/cometbft/crypto" + cmtBLS12381 "github.com/cometbft/cometbft/crypto/bls12381" + cmted25519 "github.com/cometbft/cometbft/crypto/ed25519" + cmtsecp256k1 "github.com/cometbft/cometbft/crypto/secp256k1" + "cosmossdk.io/core/server" corestore "cosmossdk.io/core/store" "cosmossdk.io/store/metrics" @@ -14,10 +19,6 @@ import ( "cosmossdk.io/store/snapshots" snapshottypes "cosmossdk.io/store/snapshots/types" storetypes "cosmossdk.io/store/types" - cmtcrypto "github.com/cometbft/cometbft/crypto" - cmtBLS12381 "github.com/cometbft/cometbft/crypto/bls12381" - cmted25519 "github.com/cometbft/cometbft/crypto/ed25519" - cmtsecp256k1 "github.com/cometbft/cometbft/crypto/secp256k1" "github.com/cosmos/cosmos-sdk/baseapp/oe" "github.com/cosmos/cosmos-sdk/codec" diff --git a/schema/diff/diff_test.go b/schema/diff/diff_test.go index 2785afc575e3..6b12c6c2e6cb 100644 --- a/schema/diff/diff_test.go +++ b/schema/diff/diff_test.go @@ -332,6 +332,7 @@ func TestCompareModuleSchemas(t *testing.T) { } func requireModuleSchema(t *testing.T, types ...schema.Type) schema.ModuleSchema { + t.Helper() s, err := schema.CompileModuleSchema(types...) if err != nil { t.Fatal(err) diff --git a/server/v2/cometbft/options.go b/server/v2/cometbft/options.go index 1e0a389882e0..cc9aabe67b19 100644 --- a/server/v2/cometbft/options.go +++ b/server/v2/cometbft/options.go @@ -1,6 +1,9 @@ package cometbft import ( + cmtcrypto "github.com/cometbft/cometbft/crypto" + cmted22519 "github.com/cometbft/cometbft/crypto/ed25519" + "cosmossdk.io/core/transaction" "cosmossdk.io/server/v2/cometbft/handlers" "cosmossdk.io/server/v2/cometbft/mempool" @@ -8,6 +11,8 @@ import ( "cosmossdk.io/store/v2/snapshots" ) +type keyGenF = func() (cmtcrypto.PrivKey, error) + // ServerOptions defines the options for the CometBFT server. type ServerOptions[T transaction.Tx] struct { Mempool mempool.Mempool[T] @@ -15,6 +20,7 @@ type ServerOptions[T transaction.Tx] struct { ProcessProposalHandler handlers.ProcessHandler[T] VerifyVoteExtensionHandler handlers.VerifyVoteExtensionhandler ExtendVoteHandler handlers.ExtendVoteHandler + KeygenF keyGenF SnapshotOptions snapshots.SnapshotOptions @@ -34,5 +40,6 @@ func DefaultServerOptions[T transaction.Tx]() ServerOptions[T] { SnapshotOptions: snapshots.NewSnapshotOptions(0, 0), AddrPeerFilter: nil, IdPeerFilter: nil, + KeygenF: func() (cmtcrypto.PrivKey, error) { return cmted22519.GenPrivKey(), nil }, } } diff --git a/server/v2/cometbft/server.go b/server/v2/cometbft/server.go index 26cd99ff97cd..9cd56f7d53bf 100644 --- a/server/v2/cometbft/server.go +++ b/server/v2/cometbft/server.go @@ -11,8 +11,6 @@ import ( abciserver "github.com/cometbft/cometbft/abci/server" cmtcmd "github.com/cometbft/cometbft/cmd/cometbft/commands" cmtcfg "github.com/cometbft/cometbft/config" - cmtcrypto "github.com/cometbft/cometbft/crypto" - cmted25519 "github.com/cometbft/cometbft/crypto/ed25519" "github.com/cometbft/cometbft/node" "github.com/cometbft/cometbft/p2p" pvm "github.com/cometbft/cometbft/privval" @@ -159,9 +157,7 @@ func (s *CometBFTServer[T]) Start(ctx context.Context) error { pv, err := pvm.LoadOrGenFilePV( s.config.ConfigTomlConfig.PrivValidatorKeyFile(), s.config.ConfigTomlConfig.PrivValidatorStateFile(), - func() (cmtcrypto.PrivKey, error) { - return cmted25519.GenPrivKey(), nil - }, + s.serverOptions.KeygenF, ) if err != nil { return err diff --git a/simapp/app.go b/simapp/app.go index 844c90d2a56a..47abc8a25b6a 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -11,6 +11,8 @@ import ( "path/filepath" abci "github.com/cometbft/cometbft/api/cometbft/abci/v1" + cmtcrypto "github.com/cometbft/cometbft/crypto" + cmted25519 "github.com/cometbft/cometbft/crypto/ed25519" "github.com/cosmos/gogoproto/proto" "github.com/spf13/cast" @@ -832,7 +834,9 @@ func (app *SimApp) RegisterNodeService(clientCtx client.Context, cfg config.Conf } func (app *SimApp) ValidatorKeyProvider() baseapp.KeyGenF { - return app.ValidatorKeyProvider() + return func() (cmtcrypto.PrivKey, error) { + return cmted25519.GenPrivKey(), nil + } } // GetMaccPerms returns a copy of the module account permissions diff --git a/types/module/simulation.go b/types/module/simulation.go index 20bb46ba1976..2766dedd0051 100644 --- a/types/module/simulation.go +++ b/types/module/simulation.go @@ -37,7 +37,7 @@ type HasProposalMsgs interface { // 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 //nolint:staticcheck // legacy v1beta1 governance + ProposalContents(simState SimulationState) []simulation.WeightedProposalContent } // SimulationManager defines a simulation manager that provides the high level utility @@ -158,7 +158,7 @@ type SimulationState struct { GenTimestamp time.Time // genesis timestamp UnbondTime time.Duration // staking unbond time stored to use it as the slashing maximum evidence duration LegacyParamChange []simulation.LegacyParamChange // simulated parameter changes from modules - //nolint:staticcheck // legacy used for testing + 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 } diff --git a/x/simulation/params.go b/x/simulation/params.go index 4fce44cff82e..e2af5bd3e18d 100644 --- a/x/simulation/params.go +++ b/x/simulation/params.go @@ -160,14 +160,14 @@ func (w WeightedProposalMsg) MsgSimulatorFn() simulation.MsgSimulatorFnX { // WeightedProposalContent defines a common struct for proposal content defined by external modules (i.e outside gov) // -//nolint:staticcheck // used for legacy testing + 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 { return &WeightedProposalContent{appParamsKey: appParamsKey, defaultWeight: defaultWeight, contentSimulatorFn: contentSimulatorFn} } @@ -179,7 +179,7 @@ func (w WeightedProposalContent) DefaultWeight() int { return w.defaultWeight } -func (w WeightedProposalContent) ContentSimulatorFn() simulation.ContentSimulatorFn { //nolint:staticcheck // used for legacy testing +func (w WeightedProposalContent) ContentSimulatorFn() simulation.ContentSimulatorFn { return w.contentSimulatorFn } diff --git a/x/simulation/params_test.go b/x/simulation/params_test.go index e4d6f380d101..483f1efcc870 100644 --- a/x/simulation/params_test.go +++ b/x/simulation/params_test.go @@ -29,7 +29,7 @@ func TestNewWeightedProposalContent(t *testing.T) { key := "theKey" weight := 1 content := &testContent{} - f := func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) simtypes.Content { //nolint:staticcheck // used for legacy testing + f := func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) simtypes.Content { return content } From d30d54664582afa4b36efee39e755e308cec4f5e Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 16 Sep 2024 11:14:22 +0200 Subject: [PATCH 4/9] cleanup unneeded code --- baseapp/baseapp.go | 6 ------ baseapp/options.go | 38 -------------------------------------- runtime/app.go | 8 ++++++-- 3 files changed, 6 insertions(+), 46 deletions(-) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 3d3d41b524ef..5282603354ee 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -13,7 +13,6 @@ import ( abci "github.com/cometbft/cometbft/api/cometbft/abci/v1" cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1" cmtcrypto "github.com/cometbft/cometbft/crypto" - cmted25519 "github.com/cometbft/cometbft/crypto/ed25519" "github.com/cometbft/cometbft/crypto/tmhash" "github.com/cosmos/gogoproto/proto" "google.golang.org/protobuf/reflect/protoreflect" @@ -194,8 +193,6 @@ type BaseApp struct { // includeNestedMsgsGas holds a set of message types for which gas costs for its nested messages are calculated. includeNestedMsgsGas map[string]struct{} - - validatorKeyProvider KeyGenF } // NewBaseApp returns a reference to an initialized BaseApp. It accepts a @@ -216,9 +213,6 @@ func NewBaseApp( fauxMerkleMode: false, sigverifyTx: true, queryGasLimit: math.MaxUint64, - validatorKeyProvider: func() (cmtcrypto.PrivKey, error) { - return cmted25519.GenPrivKey(), nil - }, } for _, option := range options { diff --git a/baseapp/options.go b/baseapp/options.go index 09e051321795..53286b2540b9 100644 --- a/baseapp/options.go +++ b/baseapp/options.go @@ -7,11 +7,6 @@ import ( "io" "math" - cmtcrypto "github.com/cometbft/cometbft/crypto" - cmtBLS12381 "github.com/cometbft/cometbft/crypto/bls12381" - cmted25519 "github.com/cometbft/cometbft/crypto/ed25519" - cmtsecp256k1 "github.com/cometbft/cometbft/crypto/secp256k1" - "cosmossdk.io/core/server" corestore "cosmossdk.io/core/store" "cosmossdk.io/store/metrics" @@ -411,36 +406,3 @@ func (app *BaseApp) SetMsgServiceRouter(msgServiceRouter *MsgServiceRouter) { func (app *BaseApp) SetGRPCQueryRouter(grpcQueryRouter *GRPCQueryRouter) { app.grpcQueryRouter = grpcQueryRouter } - -// SetPrivValidatorKeyGen sets the function that generates the private validator key. -// Only comet keys are supported: Ed25519, Secp256k1, BLS12-381. -func (app *BaseApp) SetPrivValidatorKeyGen(keyGenF KeyGenF) { - if app.sealed { - panic("SetPrivValidatorProvider() on sealed BaseApp") - } - key, err := keyGenF() - if err != nil { - panic(err) - } - switch key.(type) { - case cmted25519.PrivKey: - app.validatorKeyProvider = func() (cmtcrypto.PrivKey, error) { - return key, nil - } - case cmtsecp256k1.PrivKey: - app.validatorKeyProvider = func() (cmtcrypto.PrivKey, error) { - return key, nil - } - case cmtBLS12381.PrivKey: - app.validatorKeyProvider = func() (cmtcrypto.PrivKey, error) { - return key, nil - } - default: - panic(fmt.Errorf("unsupported priv validator key type %T", key)) - } - app.validatorKeyProvider = keyGenF -} - -func (app *BaseApp) ValidatorKeyProvider() KeyGenF { - return app.validatorKeyProvider -} diff --git a/runtime/app.go b/runtime/app.go index 590f938ce78a..57d343247b1b 100644 --- a/runtime/app.go +++ b/runtime/app.go @@ -6,6 +6,8 @@ import ( "slices" abci "github.com/cometbft/cometbft/api/cometbft/abci/v1" + cmtcrypto "github.com/cometbft/cometbft/crypto" + cmted25519 "github.com/cometbft/cometbft/crypto/ed25519" "google.golang.org/grpc" runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1" @@ -309,6 +311,8 @@ type hasServicesV1 interface { RegisterServices(grpc.ServiceRegistrar) error } -func (a *App) ValidatorKeyPrvoder() baseapp.KeyGenF { - return a.ValidatorKeyProvider() +func (a *App) ValidatorKeyProvider() baseapp.KeyGenF { + return func() (cmtcrypto.PrivKey, error) { + return cmted25519.GenPrivKey(), nil + } } From 2c8c887e5fc39291a4bb3e8afa18fced1c89177e Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 16 Sep 2024 11:15:35 +0200 Subject: [PATCH 5/9] cleanup unneeded code --- baseapp/baseapp.go | 3 --- runtime/app.go | 4 +++- simapp/app.go | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 5282603354ee..89748eadf053 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -12,7 +12,6 @@ import ( abci "github.com/cometbft/cometbft/api/cometbft/abci/v1" cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1" - cmtcrypto "github.com/cometbft/cometbft/crypto" "github.com/cometbft/cometbft/crypto/tmhash" "github.com/cosmos/gogoproto/proto" "google.golang.org/protobuf/reflect/protoreflect" @@ -61,8 +60,6 @@ const ( var _ servertypes.ABCI = (*BaseApp)(nil) -type KeyGenF = func() (cmtcrypto.PrivKey, error) - // BaseApp reflects the ABCI application implementation. type BaseApp struct { // initialized on creation diff --git a/runtime/app.go b/runtime/app.go index 57d343247b1b..2508f7aed669 100644 --- a/runtime/app.go +++ b/runtime/app.go @@ -32,6 +32,8 @@ import ( authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" ) +type KeyGenF = func() (cmtcrypto.PrivKey, error) + // App is a wrapper around BaseApp and ModuleManager that can be used in hybrid // app.go/app config scenarios or directly as a servertypes.Application instance. // To get an instance of *App, *AppBuilder must be requested as a dependency @@ -311,7 +313,7 @@ type hasServicesV1 interface { RegisterServices(grpc.ServiceRegistrar) error } -func (a *App) ValidatorKeyProvider() baseapp.KeyGenF { +func (a *App) ValidatorKeyProvider() KeyGenF { return func() (cmtcrypto.PrivKey, error) { return cmted25519.GenPrivKey(), nil } diff --git a/simapp/app.go b/simapp/app.go index 47abc8a25b6a..11ac69f3a12e 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -833,7 +833,7 @@ func (app *SimApp) RegisterNodeService(clientCtx client.Context, cfg config.Conf nodeservice.RegisterNodeService(clientCtx, app.GRPCQueryRouter(), cfg) } -func (app *SimApp) ValidatorKeyProvider() baseapp.KeyGenF { +func (app *SimApp) ValidatorKeyProvider() runtime.KeyGenF { return func() (cmtcrypto.PrivKey, error) { return cmted25519.GenPrivKey(), nil } From d18491a9ead52858981ef1c775d4d071d7a2de43 Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Mon, 16 Sep 2024 11:17:17 +0200 Subject: [PATCH 6/9] godoc --- simapp/app.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/simapp/app.go b/simapp/app.go index 11ac69f3a12e..71f7547675d4 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -833,6 +833,8 @@ func (app *SimApp) RegisterNodeService(clientCtx client.Context, cfg config.Conf nodeservice.RegisterNodeService(clientCtx, app.GRPCQueryRouter(), cfg) } +// ValidatorKeyProvider returns a function that generates a validator key +// Supported key types are those supported by Comet: ed25519, secp256k1, bls12-381 func (app *SimApp) ValidatorKeyProvider() runtime.KeyGenF { return func() (cmtcrypto.PrivKey, error) { return cmted25519.GenPrivKey(), nil From c69aa19eaac895e2e0ba73eb44a2316f9d4a390c Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Wed, 18 Sep 2024 13:59:41 +0200 Subject: [PATCH 7/9] comments --- runtime/app.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/runtime/app.go b/runtime/app.go index 48e49b67db10..e63da54c0e12 100644 --- a/runtime/app.go +++ b/runtime/app.go @@ -32,6 +32,7 @@ import ( authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" ) +// KeyGenF is a function that generates a private key for use by comet. type KeyGenF = func() (cmtcrypto.PrivKey, error) // App is a wrapper around BaseApp and ModuleManager that can be used in hybrid @@ -313,6 +314,7 @@ type hasServicesV1 interface { RegisterServices(grpc.ServiceRegistrar) error } +// ValidatorKeyProvider returns a function that generates a private key for use by comet. func (a *App) ValidatorKeyProvider() KeyGenF { return func() (cmtcrypto.PrivKey, error) { return cmted25519.GenPrivKey(), nil From f5e6e366aafd3778e5e05050abde35962e6fc77a Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Wed, 18 Sep 2024 14:03:59 +0200 Subject: [PATCH 8/9] linting --- x/simulation/params.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/simulation/params.go b/x/simulation/params.go index 1e51cf152cce..058f5ccaa262 100644 --- a/x/simulation/params.go +++ b/x/simulation/params.go @@ -167,7 +167,7 @@ type WeightedProposalContent struct { contentSimulatorFn simulation.ContentSimulatorFn // content simulator function } -func NewWeightedProposalContent(appParamsKey string, defaultWeight int, contentSimulatorFn simulation.ContentSimulatorFn) simulation.WeightedProposalContent { +func NewWeightedProposalContent(appParamsKey string, defaultWeight int, contentSimulatorFn simulation.ContentSimulatorFn) simulation.WeightedProposalContent { return &WeightedProposalContent{appParamsKey: appParamsKey, defaultWeight: defaultWeight, contentSimulatorFn: contentSimulatorFn} } @@ -179,7 +179,7 @@ func (w WeightedProposalContent) DefaultWeight() int { return w.defaultWeight } -func (w WeightedProposalContent) ContentSimulatorFn() simulation.ContentSimulatorFn { +func (w WeightedProposalContent) ContentSimulatorFn() simulation.ContentSimulatorFn { return w.contentSimulatorFn } From 47de04d11e458271d8b9312ef0bc0223c91ba2ba Mon Sep 17 00:00:00 2001 From: marbar3778 Date: Wed, 18 Sep 2024 14:11:10 +0200 Subject: [PATCH 9/9] linting --- x/simulation/params.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x/simulation/params.go b/x/simulation/params.go index 058f5ccaa262..1c6032c867c1 100644 --- a/x/simulation/params.go +++ b/x/simulation/params.go @@ -160,14 +160,14 @@ func (w WeightedProposalMsg) MsgSimulatorFn() simulation.MsgSimulatorFnX { // WeightedProposalContent defines a common struct for proposal content defined by external modules (i.e outside gov) // - +//nolint:staticcheck // used for legacy testing 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 { +func NewWeightedProposalContent(appParamsKey string, defaultWeight int, contentSimulatorFn simulation.ContentSimulatorFn) simulation.WeightedProposalContent { //nolint:staticcheck // used for legacy testing return &WeightedProposalContent{appParamsKey: appParamsKey, defaultWeight: defaultWeight, contentSimulatorFn: contentSimulatorFn} } @@ -179,7 +179,7 @@ func (w WeightedProposalContent) DefaultWeight() int { return w.defaultWeight } -func (w WeightedProposalContent) ContentSimulatorFn() simulation.ContentSimulatorFn { +func (w WeightedProposalContent) ContentSimulatorFn() simulation.ContentSimulatorFn { //nolint:staticcheck // used for legacy testing return w.contentSimulatorFn }