mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-22 17:31:34 +00:00
FuncSignerAndApp allows custom signer and abci app
This commit is contained in:
@ -5,6 +5,7 @@ import (
|
|||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
cfg "github.com/tendermint/tendermint/config"
|
||||||
"github.com/tendermint/tendermint/node"
|
"github.com/tendermint/tendermint/node"
|
||||||
"github.com/tendermint/tendermint/proxy"
|
"github.com/tendermint/tendermint/proxy"
|
||||||
"github.com/tendermint/tendermint/types"
|
"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")
|
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
|
// NewRunNodeCmd returns the command that allows the CLI to start a
|
||||||
// node. It can be used with a custom PrivValidator.
|
// node. It can be used with a custom PrivValidator and in-process ABCI application.
|
||||||
func NewRunNodeCmd(privVal *types.PrivValidator) *cobra.Command {
|
func NewRunNodeCmd(signerAndApp FuncSignerAndApp) *cobra.Command {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "node",
|
Use: "node",
|
||||||
Short: "Run the tendermint node",
|
Short: "Run the tendermint node",
|
||||||
@ -53,12 +64,8 @@ func NewRunNodeCmd(privVal *types.PrivValidator) *cobra.Command {
|
|||||||
config.ChainID = genDoc.ChainID
|
config.ChainID = genDoc.ChainID
|
||||||
|
|
||||||
// Create & start node
|
// Create & start node
|
||||||
var n *node.Node
|
privVal, clientCreator := signerAndApp(config)
|
||||||
if privVal == nil {
|
n := node.NewNode(config, privVal, clientCreator, logger.With("module", "node"))
|
||||||
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"))
|
|
||||||
|
|
||||||
if _, err := n.Start(); err != nil {
|
if _, err := n.Start(); err != nil {
|
||||||
return fmt.Errorf("Failed to start node: %v", err)
|
return fmt.Errorf("Failed to start node: %v", err)
|
||||||
@ -76,10 +83,3 @@ func NewRunNodeCmd(privVal *types.PrivValidator) *cobra.Command {
|
|||||||
AddNodeFlags(cmd)
|
AddNodeFlags(cmd)
|
||||||
return 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 (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
// crypto "github.com/tendermint/go-crypto"
|
|
||||||
|
|
||||||
"github.com/tendermint/tmlibs/cli"
|
"github.com/tendermint/tmlibs/cli"
|
||||||
|
|
||||||
. "github.com/tendermint/tendermint/cmd/tendermint/commands"
|
cmd "github.com/tendermint/tendermint/cmd/tendermint/commands"
|
||||||
// "github.com/tendermint/tendermint/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
rootCmd := RootCmd
|
rootCmd := cmd.RootCmd
|
||||||
rootCmd.AddCommand(GenValidatorCmd, InitFilesCmd, ProbeUpnpCmd,
|
rootCmd.AddCommand(
|
||||||
ReplayCmd, ReplayConsoleCmd, ResetAllCmd, ResetPrivValidatorCmd,
|
cmd.GenValidatorCmd,
|
||||||
ShowValidatorCmd, TestnetFilesCmd, VersionCmd)
|
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
|
// NOTE:
|
||||||
// and then instantiate it here.
|
// Users wishing to:
|
||||||
/*
|
// * Use an external signer for their validators
|
||||||
signer := types.NewDefaultSigner(pk)
|
// * Supply an in-proc abci app
|
||||||
privValidator := types.LoadPrivValidatorWithSigner(signer)
|
// can copy this file and use something other than the
|
||||||
rootCmd.AddCommand(NewRunNodeCmd(privValidator))
|
// default SignerAndApp function
|
||||||
*/
|
signerAndApp := cmd.DefaultSignerAndApp
|
||||||
|
|
||||||
// Create & start node
|
// Create & start node
|
||||||
rootCmd.AddCommand(NewRunNodeCmd(nil))
|
rootCmd.AddCommand(cmd.NewRunNodeCmd(signerAndApp))
|
||||||
|
|
||||||
cmd := cli.PrepareBaseCmd(rootCmd, "TM", os.ExpandEnv("$HOME/.tendermint"))
|
cmd := cli.PrepareBaseCmd(rootCmd, "TM", os.ExpandEnv("$HOME/.tendermint"))
|
||||||
cmd.Execute()
|
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,
|
// It is the caller's duty to verify the msg before calling Sign,
|
||||||
// eg. to avoid double signing.
|
// eg. to avoid double signing.
|
||||||
// Currently, the only callers are SignVote and SignProposal
|
// Currently, the only callers are SignVote and SignProposal.
|
||||||
// Signer is an interface that describes how to sign votes.
|
|
||||||
type Signer interface {
|
type Signer interface {
|
||||||
PubKey() crypto.PubKey
|
PubKey() crypto.PubKey
|
||||||
Sign(msg []byte) (crypto.Signature, error)
|
Sign(msg []byte) (crypto.Signature, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultSigner implements Signer.
|
// DefaultSigner implements Signer.
|
||||||
|
// It uses a standard crypto.PrivKey.
|
||||||
type DefaultSigner struct {
|
type DefaultSigner struct {
|
||||||
priv crypto.PrivKey
|
priv crypto.PrivKey
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user