Merge pull request #1670 from tendermint/xla/extract-privval
Extract priv_validator into first class package
This commit is contained in:
commit
c85c21d1bc
|
@ -8,7 +8,7 @@ import (
|
||||||
cmn "github.com/tendermint/tmlibs/common"
|
cmn "github.com/tendermint/tmlibs/common"
|
||||||
"github.com/tendermint/tmlibs/log"
|
"github.com/tendermint/tmlibs/log"
|
||||||
|
|
||||||
priv_val "github.com/tendermint/tendermint/types/priv_validator"
|
"github.com/tendermint/tendermint/privval"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -30,13 +30,13 @@ func main() {
|
||||||
"privPath", *privValPath,
|
"privPath", *privValPath,
|
||||||
)
|
)
|
||||||
|
|
||||||
privVal := priv_val.LoadFilePV(*privValPath)
|
pv := privval.LoadFilePV(*privValPath)
|
||||||
|
|
||||||
rs := priv_val.NewRemoteSigner(
|
rs := privval.NewRemoteSigner(
|
||||||
logger,
|
logger,
|
||||||
*chainID,
|
*chainID,
|
||||||
*addr,
|
*addr,
|
||||||
privVal,
|
pv,
|
||||||
crypto.GenPrivKeyEd25519(),
|
crypto.GenPrivKeyEd25519(),
|
||||||
)
|
)
|
||||||
err := rs.Start()
|
err := rs.Start()
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
pvm "github.com/tendermint/tendermint/types/priv_validator"
|
"github.com/tendermint/tendermint/privval"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GenValidatorCmd allows the generation of a keypair for a
|
// GenValidatorCmd allows the generation of a keypair for a
|
||||||
|
@ -17,7 +17,7 @@ var GenValidatorCmd = &cobra.Command{
|
||||||
}
|
}
|
||||||
|
|
||||||
func genValidator(cmd *cobra.Command, args []string) {
|
func genValidator(cmd *cobra.Command, args []string) {
|
||||||
pv := pvm.GenFilePV("")
|
pv := privval.GenFilePV("")
|
||||||
jsbz, err := cdc.MarshalJSON(pv)
|
jsbz, err := cdc.MarshalJSON(pv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|
|
@ -7,8 +7,8 @@ import (
|
||||||
|
|
||||||
cfg "github.com/tendermint/tendermint/config"
|
cfg "github.com/tendermint/tendermint/config"
|
||||||
"github.com/tendermint/tendermint/p2p"
|
"github.com/tendermint/tendermint/p2p"
|
||||||
|
"github.com/tendermint/tendermint/privval"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
pvm "github.com/tendermint/tendermint/types/priv_validator"
|
|
||||||
cmn "github.com/tendermint/tmlibs/common"
|
cmn "github.com/tendermint/tmlibs/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -26,12 +26,12 @@ func initFiles(cmd *cobra.Command, args []string) error {
|
||||||
func initFilesWithConfig(config *cfg.Config) error {
|
func initFilesWithConfig(config *cfg.Config) error {
|
||||||
// private validator
|
// private validator
|
||||||
privValFile := config.PrivValidatorFile()
|
privValFile := config.PrivValidatorFile()
|
||||||
var pv *pvm.FilePV
|
var pv *privval.FilePV
|
||||||
if cmn.FileExists(privValFile) {
|
if cmn.FileExists(privValFile) {
|
||||||
pv = pvm.LoadFilePV(privValFile)
|
pv = privval.LoadFilePV(privValFile)
|
||||||
logger.Info("Found private validator", "path", privValFile)
|
logger.Info("Found private validator", "path", privValFile)
|
||||||
} else {
|
} else {
|
||||||
pv = pvm.GenFilePV(privValFile)
|
pv = privval.GenFilePV(privValFile)
|
||||||
pv.Save()
|
pv.Save()
|
||||||
logger.Info("Generated private validator", "path", privValFile)
|
logger.Info("Generated private validator", "path", privValFile)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
pvm "github.com/tendermint/tendermint/types/priv_validator"
|
"github.com/tendermint/tendermint/privval"
|
||||||
"github.com/tendermint/tmlibs/log"
|
"github.com/tendermint/tmlibs/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -50,11 +50,11 @@ func resetPrivValidator(cmd *cobra.Command, args []string) {
|
||||||
func resetFilePV(privValFile string, logger log.Logger) {
|
func resetFilePV(privValFile string, logger log.Logger) {
|
||||||
// Get PrivValidator
|
// Get PrivValidator
|
||||||
if _, err := os.Stat(privValFile); err == nil {
|
if _, err := os.Stat(privValFile); err == nil {
|
||||||
pv := pvm.LoadFilePV(privValFile)
|
pv := privval.LoadFilePV(privValFile)
|
||||||
pv.Reset()
|
pv.Reset()
|
||||||
logger.Info("Reset PrivValidator", "file", privValFile)
|
logger.Info("Reset PrivValidator", "file", privValFile)
|
||||||
} else {
|
} else {
|
||||||
pv := pvm.GenFilePV(privValFile)
|
pv := privval.GenFilePV(privValFile)
|
||||||
pv.Save()
|
pv.Save()
|
||||||
logger.Info("Generated PrivValidator", "file", privValFile)
|
logger.Info("Generated PrivValidator", "file", privValFile)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
privval "github.com/tendermint/tendermint/types/priv_validator"
|
"github.com/tendermint/tendermint/privval"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ShowValidatorCmd adds capabilities for showing the validator info.
|
// ShowValidatorCmd adds capabilities for showing the validator info.
|
||||||
|
|
|
@ -12,8 +12,8 @@ import (
|
||||||
|
|
||||||
cfg "github.com/tendermint/tendermint/config"
|
cfg "github.com/tendermint/tendermint/config"
|
||||||
"github.com/tendermint/tendermint/p2p"
|
"github.com/tendermint/tendermint/p2p"
|
||||||
|
"github.com/tendermint/tendermint/privval"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
pvm "github.com/tendermint/tendermint/types/priv_validator"
|
|
||||||
cmn "github.com/tendermint/tmlibs/common"
|
cmn "github.com/tendermint/tmlibs/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ func testnetFiles(cmd *cobra.Command, args []string) error {
|
||||||
initFilesWithConfig(config)
|
initFilesWithConfig(config)
|
||||||
|
|
||||||
pvFile := filepath.Join(nodeDir, config.BaseConfig.PrivValidator)
|
pvFile := filepath.Join(nodeDir, config.BaseConfig.PrivValidator)
|
||||||
pv := pvm.LoadFilePV(pvFile)
|
pv := privval.LoadFilePV(pvFile)
|
||||||
genVals[i] = types.GenesisValidator{
|
genVals[i] = types.GenesisValidator{
|
||||||
PubKey: pv.GetPubKey(),
|
PubKey: pv.GetPubKey(),
|
||||||
Power: 1,
|
Power: 1,
|
||||||
|
|
|
@ -19,9 +19,9 @@ import (
|
||||||
cstypes "github.com/tendermint/tendermint/consensus/types"
|
cstypes "github.com/tendermint/tendermint/consensus/types"
|
||||||
mempl "github.com/tendermint/tendermint/mempool"
|
mempl "github.com/tendermint/tendermint/mempool"
|
||||||
"github.com/tendermint/tendermint/p2p"
|
"github.com/tendermint/tendermint/p2p"
|
||||||
|
"github.com/tendermint/tendermint/privval"
|
||||||
sm "github.com/tendermint/tendermint/state"
|
sm "github.com/tendermint/tendermint/state"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
pvm "github.com/tendermint/tendermint/types/priv_validator"
|
|
||||||
cmn "github.com/tendermint/tmlibs/common"
|
cmn "github.com/tendermint/tmlibs/common"
|
||||||
dbm "github.com/tendermint/tmlibs/db"
|
dbm "github.com/tendermint/tmlibs/db"
|
||||||
"github.com/tendermint/tmlibs/log"
|
"github.com/tendermint/tmlibs/log"
|
||||||
|
@ -278,10 +278,10 @@ func newConsensusStateWithConfigAndBlockStore(thisConfig *cfg.Config, state sm.S
|
||||||
return cs
|
return cs
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadPrivValidator(config *cfg.Config) *pvm.FilePV {
|
func loadPrivValidator(config *cfg.Config) *privval.FilePV {
|
||||||
privValidatorFile := config.PrivValidatorFile()
|
privValidatorFile := config.PrivValidatorFile()
|
||||||
ensureDir(path.Dir(privValidatorFile), 0700)
|
ensureDir(path.Dir(privValidatorFile), 0700)
|
||||||
privValidator := pvm.LoadOrGenFilePV(privValidatorFile)
|
privValidator := privval.LoadOrGenFilePV(privValidatorFile)
|
||||||
privValidator.Reset()
|
privValidator.Reset()
|
||||||
return privValidator
|
return privValidator
|
||||||
}
|
}
|
||||||
|
@ -379,7 +379,7 @@ func randConsensusNetWithPeers(nValidators, nPeers int, testName string, tickerF
|
||||||
privVal = privVals[i]
|
privVal = privVals[i]
|
||||||
} else {
|
} else {
|
||||||
_, tempFilePath := cmn.Tempfile("priv_validator_")
|
_, tempFilePath := cmn.Tempfile("priv_validator_")
|
||||||
privVal = pvm.GenFilePV(tempFilePath)
|
privVal = privval.GenFilePV(tempFilePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
app := appFunc()
|
app := appFunc()
|
||||||
|
|
|
@ -23,10 +23,10 @@ import (
|
||||||
dbm "github.com/tendermint/tmlibs/db"
|
dbm "github.com/tendermint/tmlibs/db"
|
||||||
|
|
||||||
cfg "github.com/tendermint/tendermint/config"
|
cfg "github.com/tendermint/tendermint/config"
|
||||||
|
"github.com/tendermint/tendermint/privval"
|
||||||
"github.com/tendermint/tendermint/proxy"
|
"github.com/tendermint/tendermint/proxy"
|
||||||
sm "github.com/tendermint/tendermint/state"
|
sm "github.com/tendermint/tendermint/state"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
pvm "github.com/tendermint/tendermint/types/priv_validator"
|
|
||||||
"github.com/tendermint/tmlibs/log"
|
"github.com/tendermint/tmlibs/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -329,7 +329,7 @@ func testHandshakeReplay(t *testing.T, nBlocks int, mode uint) {
|
||||||
walFile := tempWALWithData(walBody)
|
walFile := tempWALWithData(walBody)
|
||||||
config.Consensus.SetWalFile(walFile)
|
config.Consensus.SetWalFile(walFile)
|
||||||
|
|
||||||
privVal := pvm.LoadFilePV(config.PrivValidatorFile())
|
privVal := privval.LoadFilePV(config.PrivValidatorFile())
|
||||||
|
|
||||||
wal, err := NewWAL(walFile)
|
wal, err := NewWAL(walFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -13,10 +13,10 @@ import (
|
||||||
"github.com/tendermint/abci/example/kvstore"
|
"github.com/tendermint/abci/example/kvstore"
|
||||||
bc "github.com/tendermint/tendermint/blockchain"
|
bc "github.com/tendermint/tendermint/blockchain"
|
||||||
cfg "github.com/tendermint/tendermint/config"
|
cfg "github.com/tendermint/tendermint/config"
|
||||||
|
"github.com/tendermint/tendermint/privval"
|
||||||
"github.com/tendermint/tendermint/proxy"
|
"github.com/tendermint/tendermint/proxy"
|
||||||
sm "github.com/tendermint/tendermint/state"
|
sm "github.com/tendermint/tendermint/state"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
pvm "github.com/tendermint/tendermint/types/priv_validator"
|
|
||||||
auto "github.com/tendermint/tmlibs/autofile"
|
auto "github.com/tendermint/tmlibs/autofile"
|
||||||
cmn "github.com/tendermint/tmlibs/common"
|
cmn "github.com/tendermint/tmlibs/common"
|
||||||
"github.com/tendermint/tmlibs/db"
|
"github.com/tendermint/tmlibs/db"
|
||||||
|
@ -40,7 +40,7 @@ func WALWithNBlocks(numBlocks int) (data []byte, err error) {
|
||||||
// COPY PASTE FROM node.go WITH A FEW MODIFICATIONS
|
// COPY PASTE FROM node.go WITH A FEW MODIFICATIONS
|
||||||
// NOTE: we can't import node package because of circular dependency
|
// NOTE: we can't import node package because of circular dependency
|
||||||
privValidatorFile := config.PrivValidatorFile()
|
privValidatorFile := config.PrivValidatorFile()
|
||||||
privValidator := pvm.LoadOrGenFilePV(privValidatorFile)
|
privValidator := privval.LoadOrGenFilePV(privValidatorFile)
|
||||||
genDoc, err := types.GenesisDocFromFile(config.GenesisFile())
|
genDoc, err := types.GenesisDocFromFile(config.GenesisFile())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to read genesis file")
|
return nil, errors.Wrap(err, "failed to read genesis file")
|
||||||
|
|
10
node/node.go
10
node/node.go
|
@ -21,6 +21,7 @@ import (
|
||||||
mempl "github.com/tendermint/tendermint/mempool"
|
mempl "github.com/tendermint/tendermint/mempool"
|
||||||
"github.com/tendermint/tendermint/p2p"
|
"github.com/tendermint/tendermint/p2p"
|
||||||
"github.com/tendermint/tendermint/p2p/pex"
|
"github.com/tendermint/tendermint/p2p/pex"
|
||||||
|
"github.com/tendermint/tendermint/privval"
|
||||||
"github.com/tendermint/tendermint/proxy"
|
"github.com/tendermint/tendermint/proxy"
|
||||||
rpccore "github.com/tendermint/tendermint/rpc/core"
|
rpccore "github.com/tendermint/tendermint/rpc/core"
|
||||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||||
|
@ -32,7 +33,6 @@ import (
|
||||||
"github.com/tendermint/tendermint/state/txindex/kv"
|
"github.com/tendermint/tendermint/state/txindex/kv"
|
||||||
"github.com/tendermint/tendermint/state/txindex/null"
|
"github.com/tendermint/tendermint/state/txindex/null"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
pvm "github.com/tendermint/tendermint/types/priv_validator"
|
|
||||||
"github.com/tendermint/tendermint/version"
|
"github.com/tendermint/tendermint/version"
|
||||||
|
|
||||||
_ "net/http/pprof"
|
_ "net/http/pprof"
|
||||||
|
@ -77,7 +77,7 @@ type NodeProvider func(*cfg.Config, log.Logger) (*Node, error)
|
||||||
// It implements NodeProvider.
|
// It implements NodeProvider.
|
||||||
func DefaultNewNode(config *cfg.Config, logger log.Logger) (*Node, error) {
|
func DefaultNewNode(config *cfg.Config, logger log.Logger) (*Node, error) {
|
||||||
return NewNode(config,
|
return NewNode(config,
|
||||||
pvm.LoadOrGenFilePV(config.PrivValidatorFile()),
|
privval.LoadOrGenFilePV(config.PrivValidatorFile()),
|
||||||
proxy.DefaultClientCreator(config.ProxyApp, config.ABCI, config.DBDir()),
|
proxy.DefaultClientCreator(config.ProxyApp, config.ABCI, config.DBDir()),
|
||||||
DefaultGenesisDocProviderFunc(config),
|
DefaultGenesisDocProviderFunc(config),
|
||||||
DefaultDBProvider,
|
DefaultDBProvider,
|
||||||
|
@ -177,8 +177,8 @@ func NewNode(config *cfg.Config,
|
||||||
// TODO: persist this key so external signer
|
// TODO: persist this key so external signer
|
||||||
// can actually authenticate us
|
// can actually authenticate us
|
||||||
privKey = crypto.GenPrivKeyEd25519()
|
privKey = crypto.GenPrivKeyEd25519()
|
||||||
pvsc = pvm.NewSocketPV(
|
pvsc = privval.NewSocketPV(
|
||||||
logger.With("module", "pvm"),
|
logger.With("module", "privval"),
|
||||||
config.PrivValidatorListenAddr,
|
config.PrivValidatorListenAddr,
|
||||||
privKey,
|
privKey,
|
||||||
)
|
)
|
||||||
|
@ -447,7 +447,7 @@ func (n *Node) OnStop() {
|
||||||
n.eventBus.Stop()
|
n.eventBus.Stop()
|
||||||
n.indexerService.Stop()
|
n.indexerService.Stop()
|
||||||
|
|
||||||
if pvsc, ok := n.privValidator.(*pvm.SocketPV); ok {
|
if pvsc, ok := n.privValidator.(*privval.SocketPV); ok {
|
||||||
if err := pvsc.Stop(); err != nil {
|
if err := pvsc.Stop(); err != nil {
|
||||||
n.Logger.Error("Error stopping priv validator socket client", "err", err)
|
n.Logger.Error("Error stopping priv validator socket client", "err", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,11 +15,11 @@ import (
|
||||||
|
|
||||||
cfg "github.com/tendermint/tendermint/config"
|
cfg "github.com/tendermint/tendermint/config"
|
||||||
nm "github.com/tendermint/tendermint/node"
|
nm "github.com/tendermint/tendermint/node"
|
||||||
|
"github.com/tendermint/tendermint/privval"
|
||||||
"github.com/tendermint/tendermint/proxy"
|
"github.com/tendermint/tendermint/proxy"
|
||||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||||
core_grpc "github.com/tendermint/tendermint/rpc/grpc"
|
core_grpc "github.com/tendermint/tendermint/rpc/grpc"
|
||||||
rpcclient "github.com/tendermint/tendermint/rpc/lib/client"
|
rpcclient "github.com/tendermint/tendermint/rpc/lib/client"
|
||||||
pvm "github.com/tendermint/tendermint/types/priv_validator"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var globalConfig *cfg.Config
|
var globalConfig *cfg.Config
|
||||||
|
@ -118,7 +118,7 @@ func NewTendermint(app abci.Application) *nm.Node {
|
||||||
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
|
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
|
||||||
logger = log.NewFilter(logger, log.AllowError())
|
logger = log.NewFilter(logger, log.AllowError())
|
||||||
pvFile := config.PrivValidatorFile()
|
pvFile := config.PrivValidatorFile()
|
||||||
pv := pvm.LoadOrGenFilePV(pvFile)
|
pv := privval.LoadOrGenFilePV(pvFile)
|
||||||
papp := proxy.NewLocalClientCreator(app)
|
papp := proxy.NewLocalClientCreator(app)
|
||||||
node, err := nm.NewNode(config, pv, papp,
|
node, err := nm.NewNode(config, pv, papp,
|
||||||
nm.DefaultGenesisDocProviderFunc(config),
|
nm.DefaultGenesisDocProviderFunc(config),
|
||||||
|
|
|
@ -13,8 +13,8 @@ import (
|
||||||
cmn "github.com/tendermint/tmlibs/common"
|
cmn "github.com/tendermint/tmlibs/common"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/p2p"
|
"github.com/tendermint/tendermint/p2p"
|
||||||
|
"github.com/tendermint/tendermint/privval"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
priv_val "github.com/tendermint/tendermint/types/priv_validator"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type GenesisValidator struct {
|
type GenesisValidator struct {
|
||||||
|
@ -84,7 +84,7 @@ func convertPrivVal(cdc *amino.Codec, jsonBytes []byte) ([]byte, error) {
|
||||||
var pubKey crypto.PubKeyEd25519
|
var pubKey crypto.PubKeyEd25519
|
||||||
copy(pubKey[:], privVal.PubKey.Data)
|
copy(pubKey[:], privVal.PubKey.Data)
|
||||||
|
|
||||||
privValNew := priv_val.FilePV{
|
privValNew := privval.FilePV{
|
||||||
Address: pubKey.Address(),
|
Address: pubKey.Address(),
|
||||||
PubKey: pubKey,
|
PubKey: pubKey,
|
||||||
LastHeight: privVal.LastHeight,
|
LastHeight: privVal.LastHeight,
|
||||||
|
|
Loading…
Reference in New Issue