Browse Source

cmd: modify `gen_node_key` to print key to STDOUT (#5772)

closes: #5770
closes: #5769

also, include node ID in the output (#5769) and modify NodeKey to use
value semantics (it makes perfect sense for NodeKey to not be a
pointer).
pull/5778/head v0.34.1-dev1
Anton Kaliaev 4 years ago
committed by GitHub
parent
commit
28e79a4d02
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 147 additions and 131 deletions
  1. +2
    -0
      CHANGELOG_PENDING.md
  2. +12
    -1
      UPGRADING.md
  3. +11
    -11
      cmd/tendermint/commands/gen_node_key.go
  4. +8
    -4
      cmd/tendermint/commands/gen_validator.go
  5. +1
    -1
      cmd/tendermint/commands/show_node_id.go
  6. +1
    -1
      cmd/tendermint/commands/testnet.go
  7. +12
    -12
      node/node.go
  8. +37
    -32
      p2p/key.go
  9. +1
    -5
      p2p/key_test.go
  10. +3
    -4
      p2p/mock/peer.go
  11. +8
    -10
      p2p/node_info_test.go
  12. +2
    -3
      p2p/peer_set_test.go
  13. +2
    -2
      p2p/switch.go
  14. +4
    -7
      p2p/test_util.go
  15. +28
    -23
      p2p/transport_test.go
  16. +3
    -3
      test/e2e/app/main.go
  17. +12
    -12
      test/maverick/node/node.go

+ 2
- 0
CHANGELOG_PENDING.md View File

@ -11,6 +11,7 @@ Friendly reminder, we have a [bug bounty program](https://hackerone.com/tendermi
- CLI/RPC/Config
- [config] \#5598 The `test_fuzz` and `test_fuzz_config` P2P settings have been removed. (@erikgrinaker)
- [config] \#5728 `fast_sync = "v1"` is no longer supported (@melekes)
- [cli] \#5772 `gen_node_key` prints JSON-encoded `NodeKey` rather than ID and does not save it to `node_key.json` (@melekes)
- Apps
- [ABCI] \#5447 Remove `SetOption` method from `ABCI.Client` interface
@ -38,6 +39,7 @@ Friendly reminder, we have a [bug bounty program](https://hackerone.com/tendermi
- [abci] \#5706 Added `AbciVersion` to `RequestInfo` allowing applications to check ABCI version when connecting to Tendermint. (@marbar3778)
- [blockchain/v1] \#5728 Remove in favor of v2 (@melekes)
- [blockchain/v0] \#5741 Relax termination conditions and increase sync timeout (@melekes)
- [cli] \#5772 `gen_node_key` output now contains node ID (`id` field) (@melekes)
### BUG FIXES


+ 12
- 1
UPGRADING.md View File

@ -8,12 +8,23 @@ This guide provides instructions for upgrading to specific versions of Tendermin
* Added `AbciVersion` to `RequestInfo`. Applications should check that the ABCI version they expect is being used in order to avoid unimplemented changes errors.
* The method `SetOption` has been removed from the ABCI.Client interface. This feature was used in the early ABCI implementation's.
* The method `SetOption` has been removed from the ABCI.Client interface. This feature was used in the early ABCI implementation's.
### Config Changes
* `fast_sync = "v1"` is no longer supported. Please use `v2` instead.
### CLI Changes
* If you had previously used `tendermint gen_node_key` to generate a new node
key, keep in mind that it no longer saves the output to a file. You can use
`tendermint init` or pipe the output of `tendermint gen_node_key` to
`$TMHOME/config/node_key.json`:
```
$ tendermint gen_node_key > $TMHOME/config/node_key.json
```
## v0.34.0
**Upgrading to Tendermint 0.34 requires a blockchain restart.**


+ 11
- 11
cmd/tendermint/commands/gen_node_key.go View File

@ -5,28 +5,28 @@ import (
"github.com/spf13/cobra"
tmos "github.com/tendermint/tendermint/libs/os"
tmjson "github.com/tendermint/tendermint/libs/json"
"github.com/tendermint/tendermint/p2p"
)
// GenNodeKeyCmd allows the generation of a node key. It prints node's ID to
// the standard output.
// GenNodeKeyCmd allows the generation of a node key. It prints JSON-encoded
// NodeKey to the standard output.
var GenNodeKeyCmd = &cobra.Command{
Use: "gen_node_key",
Short: "Generate a node key for this node and print its ID",
Short: "Generate new node key",
RunE: genNodeKey,
}
func genNodeKey(cmd *cobra.Command, args []string) error {
nodeKeyFile := config.NodeKeyFile()
if tmos.FileExists(nodeKeyFile) {
return fmt.Errorf("node key at %s already exists", nodeKeyFile)
}
nodeKey := p2p.GenNodeKey()
nodeKey, err := p2p.LoadOrGenNodeKey(nodeKeyFile)
bz, err := tmjson.Marshal(nodeKey)
if err != nil {
return err
return fmt.Errorf("nodeKey -> json: %w", err)
}
fmt.Println(nodeKey.ID())
fmt.Printf(`%v
`, string(bz))
return nil
}

+ 8
- 4
cmd/tendermint/commands/gen_validator.go View File

@ -15,7 +15,7 @@ import (
var GenValidatorCmd = &cobra.Command{
Use: "gen_validator",
Short: "Generate new validator keypair",
Run: genValidator,
RunE: genValidator,
}
func init() {
@ -23,15 +23,19 @@ func init() {
"Key type to generate privval file with. Options: ed25519, secp256k1")
}
func genValidator(cmd *cobra.Command, args []string) {
func genValidator(cmd *cobra.Command, args []string) error {
pv, err := privval.GenFilePV("", "", keyType)
if err != nil {
panic(err)
return err
}
jsbz, err := tmjson.Marshal(pv)
if err != nil {
panic(err)
return fmt.Errorf("validator -> json: %w", err)
}
fmt.Printf(`%v
`, string(jsbz))
return nil
}

+ 1
- 1
cmd/tendermint/commands/show_node_id.go View File

@ -21,6 +21,6 @@ func showNodeID(cmd *cobra.Command, args []string) error {
return err
}
fmt.Println(nodeKey.ID())
fmt.Println(nodeKey.ID)
return nil
}

+ 1
- 1
cmd/tendermint/commands/testnet.go View File

@ -263,7 +263,7 @@ func persistentPeersString(config *cfg.Config) (string, error) {
if err != nil {
return "", err
}
persistentPeers[i] = p2p.IDAddressString(nodeKey.ID(), fmt.Sprintf("%s:%d", hostnameOrIP(i), p2pPort))
persistentPeers[i] = p2p.IDAddressString(nodeKey.ID, fmt.Sprintf("%s:%d", hostnameOrIP(i), p2pPort))
}
return strings.Join(persistentPeers, ","), nil
}


+ 12
- 12
node/node.go View File

@ -184,7 +184,7 @@ type Node struct {
sw *p2p.Switch // p2p connections
addrBook pex.AddrBook // known peers
nodeInfo p2p.NodeInfo
nodeKey *p2p.NodeKey // our node privkey
nodeKey p2p.NodeKey // our node privkey
isListening bool
// services
@ -411,7 +411,7 @@ func createConsensusReactor(config *cfg.Config,
func createTransport(
config *cfg.Config,
nodeInfo p2p.NodeInfo,
nodeKey *p2p.NodeKey,
nodeKey p2p.NodeKey,
proxyApp proxy.AppConns,
) (
*p2p.MultiplexTransport,
@ -419,7 +419,7 @@ func createTransport(
) {
var (
mConnConfig = p2p.MConnConfig(config.P2P)
transport = p2p.NewMultiplexTransport(nodeInfo, *nodeKey, mConnConfig)
transport = p2p.NewMultiplexTransport(nodeInfo, nodeKey, mConnConfig)
connFilters = []p2p.ConnFilterFunc{}
peerFilters = []p2p.PeerFilterFunc{}
)
@ -487,7 +487,7 @@ func createSwitch(config *cfg.Config,
consensusReactor *cs.Reactor,
evidenceReactor *evidence.Reactor,
nodeInfo p2p.NodeInfo,
nodeKey *p2p.NodeKey,
nodeKey p2p.NodeKey,
p2pLogger log.Logger) *p2p.Switch {
sw := p2p.NewSwitch(
@ -506,26 +506,26 @@ func createSwitch(config *cfg.Config,
sw.SetNodeInfo(nodeInfo)
sw.SetNodeKey(nodeKey)
p2pLogger.Info("P2P Node ID", "ID", nodeKey.ID(), "file", config.NodeKeyFile())
p2pLogger.Info("P2P Node ID", "ID", nodeKey.ID, "file", config.NodeKeyFile())
return sw
}
func createAddrBookAndSetOnSwitch(config *cfg.Config, sw *p2p.Switch,
p2pLogger log.Logger, nodeKey *p2p.NodeKey) (pex.AddrBook, error) {
p2pLogger log.Logger, nodeKey p2p.NodeKey) (pex.AddrBook, error) {
addrBook := pex.NewAddrBook(config.P2P.AddrBookFile(), config.P2P.AddrBookStrict)
addrBook.SetLogger(p2pLogger.With("book", config.P2P.AddrBookFile()))
// Add ourselves to addrbook to prevent dialing ourselves
if config.P2P.ExternalAddress != "" {
addr, err := p2p.NewNetAddressString(p2p.IDAddressString(nodeKey.ID(), config.P2P.ExternalAddress))
addr, err := p2p.NewNetAddressString(p2p.IDAddressString(nodeKey.ID, config.P2P.ExternalAddress))
if err != nil {
return nil, fmt.Errorf("p2p.external_address is incorrect: %w", err)
}
addrBook.AddOurAddress(addr)
}
if config.P2P.ListenAddress != "" {
addr, err := p2p.NewNetAddressString(p2p.IDAddressString(nodeKey.ID(), config.P2P.ListenAddress))
addr, err := p2p.NewNetAddressString(p2p.IDAddressString(nodeKey.ID, config.P2P.ListenAddress))
if err != nil {
return nil, fmt.Errorf("p2p.laddr is incorrect: %w", err)
}
@ -617,7 +617,7 @@ func startStateSync(ssR *statesync.Reactor, bcR fastSyncReactor, conR *cs.Reacto
// NewNode returns a new, ready to go, Tendermint Node.
func NewNode(config *cfg.Config,
privValidator types.PrivValidator,
nodeKey *p2p.NodeKey,
nodeKey p2p.NodeKey,
clientCreator proxy.ClientCreator,
genesisDocProvider GenesisDocProvider,
dbProvider DBProvider,
@ -878,7 +878,7 @@ func (n *Node) OnStart() error {
}
// Start the transport.
addr, err := p2p.NewNetAddressString(p2p.IDAddressString(n.nodeKey.ID(), n.config.P2P.ListenAddress))
addr, err := p2p.NewNetAddressString(p2p.IDAddressString(n.nodeKey.ID, n.config.P2P.ListenAddress))
if err != nil {
return err
}
@ -1240,7 +1240,7 @@ func (n *Node) NodeInfo() p2p.NodeInfo {
func makeNodeInfo(
config *cfg.Config,
nodeKey *p2p.NodeKey,
nodeKey p2p.NodeKey,
txIndexer txindex.TxIndexer,
genDoc *types.GenesisDoc,
state sm.State,
@ -1266,7 +1266,7 @@ func makeNodeInfo(
state.Version.Consensus.Block,
state.Version.Consensus.App,
),
DefaultNodeID: nodeKey.ID(),
DefaultNodeID: nodeKey.ID,
Network: genDoc.ChainID,
Version: version.TMCoreSemVer,
Channels: []byte{


+ 37
- 32
p2p/key.go View File

@ -24,19 +24,30 @@ const IDByteLength = crypto.AddressSize
// NodeKey is the persistent peer key.
// It contains the nodes private key for authentication.
type NodeKey struct {
PrivKey crypto.PrivKey `json:"priv_key"` // our priv key
}
// ID returns the peer's canonical ID - the hash of its public key.
func (nodeKey *NodeKey) ID() ID {
return PubKeyToID(nodeKey.PubKey())
// Canonical ID - hex-encoded pubkey's address (IDByteLength bytes)
ID ID `json:"id"`
// Private key
PrivKey crypto.PrivKey `json:"priv_key"`
}
// PubKey returns the peer's PubKey
func (nodeKey *NodeKey) PubKey() crypto.PubKey {
func (nodeKey NodeKey) PubKey() crypto.PubKey {
return nodeKey.PrivKey.PubKey()
}
// SaveAs persists the NodeKey to filePath.
func (nodeKey NodeKey) SaveAs(filePath string) error {
jsonBytes, err := tmjson.Marshal(nodeKey)
if err != nil {
return err
}
err = ioutil.WriteFile(filePath, jsonBytes, 0600)
if err != nil {
return err
}
return nil
}
// PubKeyToID returns the ID corresponding to the given PubKey.
// It's the hex-encoding of the pubKey.Address().
func PubKeyToID(pubKey crypto.PubKey) ID {
@ -45,50 +56,44 @@ func PubKeyToID(pubKey crypto.PubKey) ID {
// LoadOrGenNodeKey attempts to load the NodeKey from the given filePath. If
// the file does not exist, it generates and saves a new NodeKey.
func LoadOrGenNodeKey(filePath string) (*NodeKey, error) {
func LoadOrGenNodeKey(filePath string) (NodeKey, error) {
if tmos.FileExists(filePath) {
nodeKey, err := LoadNodeKey(filePath)
if err != nil {
return nil, err
return NodeKey{}, err
}
return nodeKey, nil
}
privKey := ed25519.GenPrivKey()
nodeKey := &NodeKey{
PrivKey: privKey,
}
nodeKey := GenNodeKey()
if err := nodeKey.SaveAs(filePath); err != nil {
return nil, err
return NodeKey{}, err
}
return nodeKey, nil
}
// LoadNodeKey loads NodeKey located in filePath.
func LoadNodeKey(filePath string) (*NodeKey, error) {
jsonBytes, err := ioutil.ReadFile(filePath)
if err != nil {
return nil, err
}
nodeKey := new(NodeKey)
err = tmjson.Unmarshal(jsonBytes, nodeKey)
if err != nil {
return nil, err
// GenNodeKey generates a new node key.
func GenNodeKey() NodeKey {
privKey := ed25519.GenPrivKey()
return NodeKey{
ID: PubKeyToID(privKey.PubKey()),
PrivKey: privKey,
}
return nodeKey, nil
}
// SaveAs persists the NodeKey to filePath.
func (nodeKey *NodeKey) SaveAs(filePath string) error {
jsonBytes, err := tmjson.Marshal(nodeKey)
// LoadNodeKey loads NodeKey located in filePath.
func LoadNodeKey(filePath string) (NodeKey, error) {
jsonBytes, err := ioutil.ReadFile(filePath)
if err != nil {
return err
return NodeKey{}, err
}
err = ioutil.WriteFile(filePath, jsonBytes, 0600)
nodeKey := NodeKey{}
err = tmjson.Unmarshal(jsonBytes, &nodeKey)
if err != nil {
return err
return NodeKey{}, err
}
return nil
nodeKey.ID = PubKeyToID(nodeKey.PubKey())
return nodeKey, nil
}

+ 1
- 5
p2p/key_test.go View File

@ -8,7 +8,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto/ed25519"
tmrand "github.com/tendermint/tendermint/libs/rand"
)
@ -43,10 +42,7 @@ func TestNodeKeySaveAs(t *testing.T) {
assert.NoFileExists(t, filePath)
privKey := ed25519.GenPrivKey()
nodeKey := &NodeKey{
PrivKey: privKey,
}
nodeKey := GenNodeKey()
err := nodeKey.SaveAs(filePath)
assert.NoError(t, err)
assert.FileExists(t, filePath)


+ 3
- 4
p2p/mock/peer.go View File

@ -3,7 +3,6 @@ package mock
import (
"net"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/libs/service"
"github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/p2p/conn"
@ -27,11 +26,11 @@ func NewPeer(ip net.IP) *Peer {
} else {
netAddr = p2p.NewNetAddressIPPort(ip, 26656)
}
nodeKey := p2p.NodeKey{PrivKey: ed25519.GenPrivKey()}
netAddr.ID = nodeKey.ID()
nodeKey := p2p.GenNodeKey()
netAddr.ID = nodeKey.ID
mp := &Peer{
ip: ip,
id: nodeKey.ID(),
id: nodeKey.ID,
addr: netAddr,
kv: make(map[string]interface{}),
}


+ 8
- 10
p2p/node_info_test.go View File

@ -4,8 +4,6 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/tendermint/tendermint/crypto/ed25519"
)
func TestNodeInfoValidate(t *testing.T) {
@ -66,16 +64,16 @@ func TestNodeInfoValidate(t *testing.T) {
{"Good RPCAddress", func(ni *DefaultNodeInfo) { ni.Other.RPCAddress = "0.0.0.0:26657" }, false},
}
nodeKey := NodeKey{PrivKey: ed25519.GenPrivKey()}
nodeKey := GenNodeKey()
name := "testing"
// test case passes
ni = testNodeInfo(nodeKey.ID(), name).(DefaultNodeInfo)
ni = testNodeInfo(nodeKey.ID, name).(DefaultNodeInfo)
ni.Channels = channels
assert.NoError(t, ni.Validate())
for _, tc := range testCases {
ni := testNodeInfo(nodeKey.ID(), name).(DefaultNodeInfo)
ni := testNodeInfo(nodeKey.ID, name).(DefaultNodeInfo)
ni.Channels = channels
tc.malleateNodeInfo(&ni)
err := ni.Validate()
@ -90,15 +88,15 @@ func TestNodeInfoValidate(t *testing.T) {
func TestNodeInfoCompatible(t *testing.T) {
nodeKey1 := NodeKey{PrivKey: ed25519.GenPrivKey()}
nodeKey2 := NodeKey{PrivKey: ed25519.GenPrivKey()}
nodeKey1 := GenNodeKey()
nodeKey2 := GenNodeKey()
name := "testing"
var newTestChannel byte = 0x2
// test NodeInfo is compatible
ni1 := testNodeInfo(nodeKey1.ID(), name).(DefaultNodeInfo)
ni2 := testNodeInfo(nodeKey2.ID(), name).(DefaultNodeInfo)
ni1 := testNodeInfo(nodeKey1.ID, name).(DefaultNodeInfo)
ni2 := testNodeInfo(nodeKey2.ID, name).(DefaultNodeInfo)
assert.NoError(t, ni1.CompatibleWith(ni2))
// add another channel; still compatible
@ -120,7 +118,7 @@ func TestNodeInfoCompatible(t *testing.T) {
}
for _, tc := range testCases {
ni := testNodeInfo(nodeKey2.ID(), name).(DefaultNodeInfo)
ni := testNodeInfo(nodeKey2.ID, name).(DefaultNodeInfo)
tc.malleateNodeInfo(&ni)
assert.Error(t, ni1.CompatibleWith(ni))
}


+ 2
- 3
p2p/peer_set_test.go View File

@ -7,7 +7,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/libs/service"
)
@ -38,10 +37,10 @@ func newMockPeer(ip net.IP) *mockPeer {
if ip == nil {
ip = net.IP{127, 0, 0, 1}
}
nodeKey := NodeKey{PrivKey: ed25519.GenPrivKey()}
nodeKey := GenNodeKey()
return &mockPeer{
ip: ip,
id: nodeKey.ID(),
id: nodeKey.ID,
}
}


+ 2
- 2
p2p/switch.go View File

@ -76,7 +76,7 @@ type Switch struct {
dialing *cmap.CMap
reconnecting *cmap.CMap
nodeInfo NodeInfo // our node info
nodeKey *NodeKey // our node privkey
nodeKey NodeKey // our node privkey
addrBook AddrBook
// peers addresses with whom we'll maintain constant connection
persistentPeersAddrs []*NetAddress
@ -212,7 +212,7 @@ func (sw *Switch) NodeInfo() NodeInfo {
// SetNodeKey sets the switch's private key for authenticated encryption.
// NOTE: Not goroutine safe.
func (sw *Switch) SetNodeKey(nodeKey *NodeKey) {
func (sw *Switch) SetNodeKey(nodeKey NodeKey) {
sw.nodeKey = nodeKey
}


+ 4
- 7
p2p/test_util.go View File

@ -6,7 +6,6 @@ import (
"time"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/libs/log"
tmnet "github.com/tendermint/tendermint/libs/net"
tmrand "github.com/tendermint/tendermint/libs/rand"
@ -181,12 +180,10 @@ func MakeSwitch(
opts ...SwitchOption,
) *Switch {
nodeKey := NodeKey{
PrivKey: ed25519.GenPrivKey(),
}
nodeInfo := testNodeInfo(nodeKey.ID(), fmt.Sprintf("node%d", i))
nodeKey := GenNodeKey()
nodeInfo := testNodeInfo(nodeKey.ID, fmt.Sprintf("node%d", i))
addr, err := NewNetAddressString(
IDAddressString(nodeKey.ID(), nodeInfo.(DefaultNodeInfo).ListenAddr),
IDAddressString(nodeKey.ID, nodeInfo.(DefaultNodeInfo).ListenAddr),
)
if err != nil {
panic(err)
@ -201,7 +198,7 @@ func MakeSwitch(
// TODO: let the config be passed in?
sw := initSwitch(i, NewSwitch(cfg, t, opts...))
sw.SetLogger(log.TestingLogger().With("switch", i))
sw.SetNodeKey(&nodeKey)
sw.SetNodeKey(nodeKey)
ni := nodeInfo.(DefaultNodeInfo)
for ch := range sw.reactorsByCh {


+ 28
- 23
p2p/transport_test.go View File

@ -37,11 +37,9 @@ func newMultiplexTransport(
func TestTransportMultiplexConnFilter(t *testing.T) {
mt := newMultiplexTransport(
emptyNodeInfo(),
NodeKey{
PrivKey: ed25519.GenPrivKey(),
},
GenNodeKey(),
)
id := mt.nodeKey.ID()
id := mt.nodeKey.ID
MultiplexTransportConnFilters(
func(_ ConnSet, _ net.Conn, _ []net.IP) error { return nil },
@ -91,11 +89,9 @@ func TestTransportMultiplexConnFilter(t *testing.T) {
func TestTransportMultiplexConnFilterTimeout(t *testing.T) {
mt := newMultiplexTransport(
emptyNodeInfo(),
NodeKey{
PrivKey: ed25519.GenPrivKey(),
},
GenNodeKey(),
)
id := mt.nodeKey.ID()
id := mt.nodeKey.ID
MultiplexTransportFilterTimeout(5 * time.Millisecond)(mt)
MultiplexTransportConnFilters(
@ -145,6 +141,7 @@ func TestTransportMultiplexMaxIncomingConnections(t *testing.T) {
id, "transport",
),
NodeKey{
ID: id,
PrivKey: pv,
},
)
@ -161,7 +158,7 @@ func TestTransportMultiplexMaxIncomingConnections(t *testing.T) {
t.Fatal(err)
}
laddr := NewNetAddress(mt.nodeKey.ID(), mt.listener.Addr())
laddr := NewNetAddress(mt.nodeKey.ID, mt.listener.Addr())
// Connect more peers than max
for i := 0; i <= maxIncomingConns; i++ {
@ -188,7 +185,7 @@ func TestTransportMultiplexMaxIncomingConnections(t *testing.T) {
func TestTransportMultiplexAcceptMultiple(t *testing.T) {
mt := testSetupMultiplexTransport(t)
laddr := NewNetAddress(mt.nodeKey.ID(), mt.listener.Addr())
laddr := NewNetAddress(mt.nodeKey.ID, mt.listener.Addr())
var (
seed = rand.New(rand.NewSource(time.Now().UnixNano()))
@ -243,9 +240,11 @@ func TestTransportMultiplexAcceptMultiple(t *testing.T) {
func testDialer(dialAddr NetAddress, errc chan error) {
var (
pv = ed25519.GenPrivKey()
id = PubKeyToID(pv.PubKey())
dialer = newMultiplexTransport(
testNodeInfo(PubKeyToID(pv.PubKey()), defaultNodeName),
testNodeInfo(id, defaultNodeName),
NodeKey{
ID: id,
PrivKey: pv,
},
)
@ -275,7 +274,7 @@ func TestTransportMultiplexAcceptNonBlocking(t *testing.T) {
// Simulate slow Peer.
go func() {
addr := NewNetAddress(mt.nodeKey.ID(), mt.listener.Addr())
addr := NewNetAddress(mt.nodeKey.ID, mt.listener.Addr())
c, err := addr.Dial()
if err != nil {
@ -323,11 +322,12 @@ func TestTransportMultiplexAcceptNonBlocking(t *testing.T) {
dialer = newMultiplexTransport(
fastNodeInfo,
NodeKey{
ID: PubKeyToID(fastNodePV.PubKey()),
PrivKey: fastNodePV,
},
)
)
addr := NewNetAddress(mt.nodeKey.ID(), mt.listener.Addr())
addr := NewNetAddress(mt.nodeKey.ID, mt.listener.Addr())
_, err := dialer.Dial(*addr, peerConfig{})
if err != nil {
@ -362,15 +362,17 @@ func TestTransportMultiplexValidateNodeInfo(t *testing.T) {
go func() {
var (
pv = ed25519.GenPrivKey()
id = PubKeyToID(pv.PubKey())
dialer = newMultiplexTransport(
testNodeInfo(PubKeyToID(pv.PubKey()), ""), // Should not be empty
testNodeInfo(id, ""), // Should not be empty
NodeKey{
ID: id,
PrivKey: pv,
},
)
)
addr := NewNetAddress(mt.nodeKey.ID(), mt.listener.Addr())
addr := NewNetAddress(mt.nodeKey.ID, mt.listener.Addr())
_, err := dialer.Dial(*addr, peerConfig{})
if err != nil {
@ -405,11 +407,9 @@ func TestTransportMultiplexRejectMissmatchID(t *testing.T) {
testNodeInfo(
PubKeyToID(ed25519.GenPrivKey().PubKey()), "dialer",
),
NodeKey{
PrivKey: ed25519.GenPrivKey(),
},
GenNodeKey(),
)
addr := NewNetAddress(mt.nodeKey.ID(), mt.listener.Addr())
addr := NewNetAddress(mt.nodeKey.ID, mt.listener.Addr())
_, err := dialer.Dial(*addr, peerConfig{})
if err != nil {
@ -439,9 +439,11 @@ func TestTransportMultiplexDialRejectWrongID(t *testing.T) {
var (
pv = ed25519.GenPrivKey()
id = PubKeyToID(pv.PubKey())
dialer = newMultiplexTransport(
testNodeInfo(PubKeyToID(pv.PubKey()), ""), // Should not be empty
testNodeInfo(id, ""), // Should not be empty
NodeKey{
ID: id,
PrivKey: pv,
},
)
@ -471,14 +473,16 @@ func TestTransportMultiplexRejectIncompatible(t *testing.T) {
go func() {
var (
pv = ed25519.GenPrivKey()
id = PubKeyToID(pv.PubKey())
dialer = newMultiplexTransport(
testNodeInfoWithNetwork(PubKeyToID(pv.PubKey()), "dialer", "incompatible-network"),
testNodeInfoWithNetwork(id, "dialer", "incompatible-network"),
NodeKey{
ID: id,
PrivKey: pv,
},
)
)
addr := NewNetAddress(mt.nodeKey.ID(), mt.listener.Addr())
addr := NewNetAddress(mt.nodeKey.ID, mt.listener.Addr())
_, err := dialer.Dial(*addr, peerConfig{})
if err != nil {
@ -505,7 +509,7 @@ func TestTransportMultiplexRejectSelf(t *testing.T) {
errc := make(chan error)
go func() {
addr := NewNetAddress(mt.nodeKey.ID(), mt.listener.Addr())
addr := NewNetAddress(mt.nodeKey.ID, mt.listener.Addr())
_, err := mt.Dial(*addr, peerConfig{})
if err != nil {
@ -631,6 +635,7 @@ func testSetupMultiplexTransport(t *testing.T) *MultiplexTransport {
id, "transport",
),
NodeKey{
ID: id,
PrivKey: pv,
},
)


+ 3
- 3
test/e2e/app/main.go View File

@ -122,7 +122,7 @@ func startNode(cfg *Config) error {
}
n, err := node.NewNode(tmcfg,
pval,
nodeKey,
*nodeKey,
proxy.NewLocalClientCreator(app),
node.DefaultGenesisDocProviderFunc(tmcfg),
node.DefaultDBProvider,
@ -156,7 +156,7 @@ func startMaverick(cfg *Config) error {
n, err := maverick.NewNode(tmcfg,
maverick.LoadOrGenFilePV(tmcfg.PrivValidatorKeyFile(), tmcfg.PrivValidatorStateFile()),
nodeKey,
*nodeKey,
proxy.NewLocalClientCreator(app),
maverick.DefaultGenesisDocProviderFunc(tmcfg),
maverick.DefaultDBProvider,
@ -233,5 +233,5 @@ func setupNode() (*config.Config, log.Logger, *p2p.NodeKey, error) {
return nil, nil, nil, fmt.Errorf("failed to load or gen node key %s: %w", tmcfg.NodeKeyFile(), err)
}
return tmcfg, nodeLogger, nodeKey, nil
return tmcfg, nodeLogger, &nodeKey, nil
}

+ 12
- 12
test/maverick/node/node.go View File

@ -226,7 +226,7 @@ type Node struct {
sw *p2p.Switch // p2p connections
addrBook pex.AddrBook // known peers
nodeInfo p2p.NodeInfo
nodeKey *p2p.NodeKey // our node privkey
nodeKey p2p.NodeKey // our node privkey
isListening bool
// services
@ -455,7 +455,7 @@ func createConsensusReactor(config *cfg.Config,
func createTransport(
config *cfg.Config,
nodeInfo p2p.NodeInfo,
nodeKey *p2p.NodeKey,
nodeKey p2p.NodeKey,
proxyApp proxy.AppConns,
) (
*p2p.MultiplexTransport,
@ -463,7 +463,7 @@ func createTransport(
) {
var (
mConnConfig = p2p.MConnConfig(config.P2P)
transport = p2p.NewMultiplexTransport(nodeInfo, *nodeKey, mConnConfig)
transport = p2p.NewMultiplexTransport(nodeInfo, nodeKey, mConnConfig)
connFilters = []p2p.ConnFilterFunc{}
peerFilters = []p2p.PeerFilterFunc{}
)
@ -531,7 +531,7 @@ func createSwitch(config *cfg.Config,
consensusReactor *cs.Reactor,
evidenceReactor *evidence.Reactor,
nodeInfo p2p.NodeInfo,
nodeKey *p2p.NodeKey,
nodeKey p2p.NodeKey,
p2pLogger log.Logger) *p2p.Switch {
sw := p2p.NewSwitch(
@ -550,26 +550,26 @@ func createSwitch(config *cfg.Config,
sw.SetNodeInfo(nodeInfo)
sw.SetNodeKey(nodeKey)
p2pLogger.Info("P2P Node ID", "ID", nodeKey.ID(), "file", config.NodeKeyFile())
p2pLogger.Info("P2P Node ID", "ID", nodeKey.ID, "file", config.NodeKeyFile())
return sw
}
func createAddrBookAndSetOnSwitch(config *cfg.Config, sw *p2p.Switch,
p2pLogger log.Logger, nodeKey *p2p.NodeKey) (pex.AddrBook, error) {
p2pLogger log.Logger, nodeKey p2p.NodeKey) (pex.AddrBook, error) {
addrBook := pex.NewAddrBook(config.P2P.AddrBookFile(), config.P2P.AddrBookStrict)
addrBook.SetLogger(p2pLogger.With("book", config.P2P.AddrBookFile()))
// Add ourselves to addrbook to prevent dialing ourselves
if config.P2P.ExternalAddress != "" {
addr, err := p2p.NewNetAddressString(p2p.IDAddressString(nodeKey.ID(), config.P2P.ExternalAddress))
addr, err := p2p.NewNetAddressString(p2p.IDAddressString(nodeKey.ID, config.P2P.ExternalAddress))
if err != nil {
return nil, fmt.Errorf("p2p.external_address is incorrect: %w", err)
}
addrBook.AddOurAddress(addr)
}
if config.P2P.ListenAddress != "" {
addr, err := p2p.NewNetAddressString(p2p.IDAddressString(nodeKey.ID(), config.P2P.ListenAddress))
addr, err := p2p.NewNetAddressString(p2p.IDAddressString(nodeKey.ID, config.P2P.ListenAddress))
if err != nil {
return nil, fmt.Errorf("p2p.laddr is incorrect: %w", err)
}
@ -661,7 +661,7 @@ func startStateSync(ssR *statesync.Reactor, bcR fastSyncReactor, conR *cs.Reacto
// NewNode returns a new, ready to go, Tendermint Node.
func NewNode(config *cfg.Config,
privValidator types.PrivValidator,
nodeKey *p2p.NodeKey,
nodeKey p2p.NodeKey,
clientCreator proxy.ClientCreator,
genesisDocProvider GenesisDocProvider,
dbProvider DBProvider,
@ -922,7 +922,7 @@ func (n *Node) OnStart() error {
}
// Start the transport.
addr, err := p2p.NewNetAddressString(p2p.IDAddressString(n.nodeKey.ID(), n.config.P2P.ListenAddress))
addr, err := p2p.NewNetAddressString(p2p.IDAddressString(n.nodeKey.ID, n.config.P2P.ListenAddress))
if err != nil {
return err
}
@ -1282,7 +1282,7 @@ func (n *Node) NodeInfo() p2p.NodeInfo {
func makeNodeInfo(
config *cfg.Config,
nodeKey *p2p.NodeKey,
nodeKey p2p.NodeKey,
txIndexer txindex.TxIndexer,
genDoc *types.GenesisDoc,
state sm.State,
@ -1308,7 +1308,7 @@ func makeNodeInfo(
state.Version.Consensus.Block,
state.Version.Consensus.App,
),
DefaultNodeID: nodeKey.ID(),
DefaultNodeID: nodeKey.ID,
Network: genDoc.ChainID,
Version: version.TMCoreSemVer,
Channels: []byte{


Loading…
Cancel
Save