FuncSignerAndApp allows custom signer and abci app
This commit is contained in:
parent
66fcdf7c7a
commit
abe912c610
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
cfg "github.com/tendermint/tendermint/config"
|
||||
"github.com/tendermint/tendermint/node"
|
||||
"github.com/tendermint/tendermint/proxy"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
|
@ -38,9 +39,19 @@ func AddNodeFlags(cmd *cobra.Command) {
|
|||
cmd.Flags().Bool("consensus.create_empty_blocks", config.Consensus.CreateEmptyBlocks, "Set this to false to only produce blocks when there are txs or when the AppHash changes")
|
||||
}
|
||||
|
||||
// FuncSignerAndApp takes a config and returns a PrivValidator and ClientCreator.
|
||||
// It allows other projects to make Tendermint binaries with custom signers and applications.
|
||||
type FuncSignerAndApp func(*cfg.Config) (*types.PrivValidator, proxy.ClientCreator)
|
||||
|
||||
func DefaultSignerAndApp(config *cfg.Config) (*types.PrivValidator, proxy.ClientCreator) {
|
||||
privValidator := types.LoadOrGenPrivValidator(config.PrivValidatorFile())
|
||||
clientCreator := proxy.DefaultClientCreator(config.ProxyApp, config.ABCI, config.DBDir())
|
||||
return privValidator, clientCreator
|
||||
}
|
||||
|
||||
// NewRunNodeCmd returns the command that allows the CLI to start a
|
||||
// node. It can be used with a custom PrivValidator.
|
||||
func NewRunNodeCmd(privVal *types.PrivValidator) *cobra.Command {
|
||||
// node. It can be used with a custom PrivValidator and in-process ABCI application.
|
||||
func NewRunNodeCmd(signerAndApp FuncSignerAndApp) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "node",
|
||||
Short: "Run the tendermint node",
|
||||
|
@ -53,12 +64,8 @@ func NewRunNodeCmd(privVal *types.PrivValidator) *cobra.Command {
|
|||
config.ChainID = genDoc.ChainID
|
||||
|
||||
// Create & start node
|
||||
var n *node.Node
|
||||
if privVal == nil {
|
||||
n = node.NewNodeDefault(config, logger.With("module", "node"))
|
||||
}
|
||||
n = node.NewNode(config, privVal, proxy.DefaultClientCreator(config.ProxyApp,
|
||||
config.ABCI, config.DBDir()), logger.With("module", "node"))
|
||||
privVal, clientCreator := signerAndApp(config)
|
||||
n := node.NewNode(config, privVal, clientCreator, logger.With("module", "node"))
|
||||
|
||||
if _, err := n.Start(); err != nil {
|
||||
return fmt.Errorf("Failed to start node: %v", err)
|
||||
|
@ -76,10 +83,3 @@ func NewRunNodeCmd(privVal *types.PrivValidator) *cobra.Command {
|
|||
AddNodeFlags(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// Users wishing to:
|
||||
// * Use an external signer for their validators
|
||||
// * Supply an in-proc abci app
|
||||
// should import github.com/tendermint/tendermint/node and implement
|
||||
// their own run_node to call node.NewNode (instead of node.NewNodeDefault)
|
||||
// with their custom priv validator and/or custom proxy.ClientCreator
|
||||
|
|
|
@ -3,30 +3,35 @@ package main
|
|||
import (
|
||||
"os"
|
||||
|
||||
// crypto "github.com/tendermint/go-crypto"
|
||||
|
||||
"github.com/tendermint/tmlibs/cli"
|
||||
|
||||
. "github.com/tendermint/tendermint/cmd/tendermint/commands"
|
||||
// "github.com/tendermint/tendermint/types"
|
||||
cmd "github.com/tendermint/tendermint/cmd/tendermint/commands"
|
||||
)
|
||||
|
||||
func main() {
|
||||
rootCmd := RootCmd
|
||||
rootCmd.AddCommand(GenValidatorCmd, InitFilesCmd, ProbeUpnpCmd,
|
||||
ReplayCmd, ReplayConsoleCmd, ResetAllCmd, ResetPrivValidatorCmd,
|
||||
ShowValidatorCmd, TestnetFilesCmd, VersionCmd)
|
||||
rootCmd := cmd.RootCmd
|
||||
rootCmd.AddCommand(
|
||||
cmd.GenValidatorCmd,
|
||||
cmd.InitFilesCmd,
|
||||
cmd.ProbeUpnpCmd,
|
||||
cmd.ReplayCmd,
|
||||
cmd.ReplayConsoleCmd,
|
||||
cmd.ResetAllCmd,
|
||||
cmd.ResetPrivValidatorCmd,
|
||||
cmd.ShowValidatorCmd,
|
||||
cmd.TestnetFilesCmd,
|
||||
cmd.VersionCmd)
|
||||
|
||||
// NOTE: Implement your own type that implements the Signer interface
|
||||
// and then instantiate it here.
|
||||
/*
|
||||
signer := types.NewDefaultSigner(pk)
|
||||
privValidator := types.LoadPrivValidatorWithSigner(signer)
|
||||
rootCmd.AddCommand(NewRunNodeCmd(privValidator))
|
||||
*/
|
||||
// NOTE:
|
||||
// Users wishing to:
|
||||
// * Use an external signer for their validators
|
||||
// * Supply an in-proc abci app
|
||||
// can copy this file and use something other than the
|
||||
// default SignerAndApp function
|
||||
signerAndApp := cmd.DefaultSignerAndApp
|
||||
|
||||
// Create & start node
|
||||
rootCmd.AddCommand(NewRunNodeCmd(nil))
|
||||
rootCmd.AddCommand(cmd.NewRunNodeCmd(signerAndApp))
|
||||
|
||||
cmd := cli.PrepareBaseCmd(rootCmd, "TM", os.ExpandEnv("$HOME/.tendermint"))
|
||||
cmd.Execute()
|
||||
|
|
|
@ -34,17 +34,17 @@ func voteToStep(vote *Vote) int8 {
|
|||
}
|
||||
}
|
||||
|
||||
// This is used to sign votes.
|
||||
// Signer is an interface that defines how to sign votes.
|
||||
// It is the caller's duty to verify the msg before calling Sign,
|
||||
// eg. to avoid double signing.
|
||||
// Currently, the only callers are SignVote and SignProposal
|
||||
// Signer is an interface that describes how to sign votes.
|
||||
// Currently, the only callers are SignVote and SignProposal.
|
||||
type Signer interface {
|
||||
PubKey() crypto.PubKey
|
||||
Sign(msg []byte) (crypto.Signature, error)
|
||||
}
|
||||
|
||||
// DefaultSigner implements Signer.
|
||||
// It uses a standard crypto.PrivKey.
|
||||
type DefaultSigner struct {
|
||||
priv crypto.PrivKey
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue