Browse Source

pass in NodeKey to NewNode (#2212)

Fixes #1544
pull/2235/head
bradyjoestar 6 years ago
committed by Anton Kaliaev
parent
commit
5446452b01
2 changed files with 18 additions and 10 deletions
  1. +12
    -9
      node/node.go
  2. +6
    -1
      rpc/test/helpers.go

+ 12
- 9
node/node.go View File

@ -80,8 +80,14 @@ type NodeProvider func(*cfg.Config, log.Logger) (*Node, error)
// PrivValidator, ClientCreator, GenesisDoc, and DBProvider.
// It implements NodeProvider.
func DefaultNewNode(config *cfg.Config, logger log.Logger) (*Node, error) {
// Generate node PrivKey
nodeKey, err := p2p.LoadOrGenNodeKey(config.NodeKeyFile())
if err != nil {
return nil,err
}
return NewNode(config,
privval.LoadOrGenFilePV(config.PrivValidatorFile()),
nodeKey,
proxy.DefaultClientCreator(config.ProxyApp, config.ABCI, config.DBDir()),
DefaultGenesisDocProviderFunc(config),
DefaultDBProvider,
@ -119,6 +125,7 @@ type Node struct {
// network
sw *p2p.Switch // p2p connections
addrBook pex.AddrBook // known peers
nodeKey *p2p.NodeKey // our node privkey
// services
eventBus *types.EventBus // pub/sub for services
@ -139,6 +146,7 @@ type Node struct {
// NewNode returns a new, ready to go, Tendermint Node.
func NewNode(config *cfg.Config,
privValidator types.PrivValidator,
nodeKey *p2p.NodeKey,
clientCreator proxy.ClientCreator,
genesisDocProvider GenesisDocProvider,
dbProvider DBProvider,
@ -293,6 +301,7 @@ func NewNode(config *cfg.Config,
sw.AddReactor("BLOCKCHAIN", bcReactor)
sw.AddReactor("CONSENSUS", consensusReactor)
sw.AddReactor("EVIDENCE", evidenceReactor)
p2pLogger.Info("P2P Node ID", "ID", nodeKey.ID(), "file", config.NodeKeyFile())
// Optionally, start the pex reactor
//
@ -392,6 +401,7 @@ func NewNode(config *cfg.Config,
sw: sw,
addrBook: addrBook,
nodeKey: nodeKey,
stateDB: stateDB,
blockStore: blockStore,
@ -424,17 +434,10 @@ func (n *Node) OnStart() error {
n.Logger.With("module", "p2p"))
n.sw.AddListener(l)
// Generate node PrivKey
// TODO: pass in like privValidator
nodeKey, err := p2p.LoadOrGenNodeKey(n.config.NodeKeyFile())
if err != nil {
return err
}
n.Logger.Info("P2P Node ID", "ID", nodeKey.ID(), "file", n.config.NodeKeyFile())
nodeInfo := n.makeNodeInfo(nodeKey.ID())
nodeInfo := n.makeNodeInfo(n.nodeKey.ID())
n.sw.SetNodeInfo(nodeInfo)
n.sw.SetNodeKey(nodeKey)
n.sw.SetNodeKey(n.nodeKey)
// Add ourselves to addrbook to prevent dialing ourselves
n.addrBook.AddOurAddress(nodeInfo.NetAddress())


+ 6
- 1
rpc/test/helpers.go View File

@ -15,6 +15,7 @@ import (
cfg "github.com/tendermint/tendermint/config"
nm "github.com/tendermint/tendermint/node"
"github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/privval"
"github.com/tendermint/tendermint/proxy"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
@ -120,7 +121,11 @@ func NewTendermint(app abci.Application) *nm.Node {
pvFile := config.PrivValidatorFile()
pv := privval.LoadOrGenFilePV(pvFile)
papp := proxy.NewLocalClientCreator(app)
node, err := nm.NewNode(config, pv, papp,
nodeKey, err := p2p.LoadOrGenNodeKey(config.NodeKeyFile())
if err != nil {
panic(err)
}
node, err := nm.NewNode(config, pv, nodeKey, papp,
nm.DefaultGenesisDocProviderFunc(config),
nm.DefaultDBProvider,
nm.DefaultMetricsProvider(config.Instrumentation),


Loading…
Cancel
Save