Skip to content
9 changes: 9 additions & 0 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions baseapp/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 4 additions & 0 deletions runtime/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,7 @@ var _ servertypes.Application = &App{}
type hasServicesV1 interface {
RegisterServices(grpc.ServiceRegistrar) error
}

func (a *App) ValidatorKeyPrvoder() baseapp.KeyGenF {
return a.ValidatorKeyProvider()
}
4 changes: 1 addition & 3 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions server/types/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down