mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-10 06:57:24 +00:00
p2p: introduce peerConn to simplify peer creation (#1226)
* expose AuthEnc in the P2P config if AuthEnc is true, dialed peers must have a node ID in the address and it must match the persistent pubkey from the secret handshake. Refs #1157 * fixes after my own review * fix docs * fix build failure ``` p2p/pex/pex_reactor_test.go:288:88: cannot use seed.NodeInfo().NetAddress() (type *p2p.NetAddress) as type string in array or slice literal ``` * p2p: introduce peerConn to simplify peer creation * Introduce `peerConn` containing the known fields of `peer` * `peer` only created in `sw.addPeer` once handshake is complete and NodeInfo is checked * Eliminates some mutable variables and makes the code flow better * Simplifies the `newXxxPeer` funcs * Use ID instead of PubKey where possible. * SetPubKeyFilter -> SetIDFilter * nodeInfo.Validate takes ID * remove peer.PubKey() * persistent node ids * fixes from review * test: use ip_plus_id.sh more * fix invalid memory panic during fast_sync test ``` 2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: panic: runtime error: invalid memory address or nil pointer dereference 2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: [signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x98dd3e] 2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: 2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: goroutine 3432 [running]: 2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.newOutboundPeerConn(0xc423fd1380, 0xc420933e00, 0x1, 0x1239a60, 0 xc420128c40, 0x2, 0x42caf6, 0xc42001f300, 0xc422831d98, 0xc4227951c0, ...) 2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/peer.go:123 +0x31e 2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).addOutboundPeerWithConfig(0xc4200ad040, 0xc423fd1380, 0 xc420933e00, 0xc423f48801, 0x28, 0x2) 2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:455 +0x12b 2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).DialPeerWithAddress(0xc4200ad040, 0xc423fd1380, 0x1, 0x 0, 0x0) 2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:371 +0xdc 2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: github.com/tendermint/tendermint/p2p.(*Switch).reconnectToPeer(0xc4200ad040, 0x123e000, 0xc42007bb00) 2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:290 +0x25f 2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: created by github.com/tendermint/tendermint/p2p.(*Switch).StopPeerForError 2018-02-21T06:30:05Z box887.localdomain docker/local_testnet_4[14907]: #011/go/src/github.com/tendermint/tendermint/p2p/switch.go:256 +0x1b7 ```
This commit is contained in:
committed by
Anton Kaliaev
parent
2fd023a239
commit
9293ae76bf
@@ -1,4 +1,4 @@
|
||||
FROM golang:1.9.2
|
||||
FROM golang:1.9.4
|
||||
|
||||
# Add testing deps for curl
|
||||
RUN echo 'deb http://httpredir.debian.org/debian testing main non-free contrib' >> /etc/apt/sources.list
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
#! /bin/bash
|
||||
# This is a sample bash script for tendermint core
|
||||
# Edit this script before "mintnet start" to change
|
||||
# the core blockchain engine.
|
||||
|
||||
TMREPO="github.com/tendermint/tendermint"
|
||||
BRANCH="master"
|
||||
|
||||
go get -d $TMREPO/cmd/tendermint
|
||||
### DEPENDENCIES (example)
|
||||
# cd $GOPATH/src/github.com/tendermint/abci
|
||||
# git fetch origin $BRANCH
|
||||
# git checkout $BRANCH
|
||||
### DEPENDENCIES END
|
||||
cd $GOPATH/src/$TMREPO
|
||||
git fetch origin $BRANCH
|
||||
git checkout $BRANCH
|
||||
make install
|
||||
|
||||
tendermint node --p2p.seeds="$TMSEEDS" --moniker="$TMNAME" --proxy_app="$PROXYAPP" --rpc.unsafe
|
||||
1
test/p2p/data/mach1/core/config/node_key.json
Normal file
1
test/p2p/data/mach1/core/config/node_key.json
Normal file
@@ -0,0 +1 @@
|
||||
{"priv_key":{"type":"ed25519","data":"06962D169F314ABB9D05AE5A04B46E48F0FBD8F1830149B47493910CBDCA7796096E5B94CD179F545AE3C281D9BF5C9E0E3D8FF719048B62F7849094CFFA8591"}}
|
||||
1
test/p2p/data/mach2/core/config/node_key.json
Normal file
1
test/p2p/data/mach2/core/config/node_key.json
Normal file
@@ -0,0 +1 @@
|
||||
{"priv_key":{"type":"ed25519","data":"B8CE8B0D5138C10208526ABDADCE91C735FCCC4186E06E0972EC35E64973428A45EBC61F24CE1B91B3D26AFBAB11C2789EF04CBAC28183619C01116B66A9C528"}}
|
||||
1
test/p2p/data/mach3/core/config/node_key.json
Normal file
1
test/p2p/data/mach3/core/config/node_key.json
Normal file
@@ -0,0 +1 @@
|
||||
{"priv_key":{"type":"ed25519","data":"913DE8AC6D18922A53F6B0196EF023B4693FECFBB565E084F0B4941768F3DAE892B35ADD954562FE071C465BC244B2AFAED4A270EC849269341473CE192DE682"}}
|
||||
1
test/p2p/data/mach4/core/config/node_key.json
Normal file
1
test/p2p/data/mach4/core/config/node_key.json
Normal file
@@ -0,0 +1 @@
|
||||
{"priv_key":{"type":"ed25519","data":"408226F3F40411AC22262DD9A33BFE27D6FED42B9F084906B3797118C951CB82F81552170A85C94F0608AE8B59B70A0CA8B604A9057585B28A266140DC615E97"}}
|
||||
@@ -19,20 +19,20 @@ echo "Testing fastsync on node $ID"
|
||||
|
||||
# kill peer
|
||||
set +e # circle sigh :(
|
||||
docker rm -vf local_testnet_$ID
|
||||
set -e
|
||||
docker rm -vf local_testnet_$ID
|
||||
set -e
|
||||
|
||||
# restart peer - should have an empty blockchain
|
||||
PERSISTENT_PEERS="$(test/p2p/ip.sh 1):46656"
|
||||
for j in `seq 2 $N`; do
|
||||
PERSISTENT_PEERS="$PERSISTENT_PEERS,$(test/p2p/ip.sh $j):46656"
|
||||
done
|
||||
bash test/p2p/peer.sh $DOCKER_IMAGE $NETWORK_NAME $ID $PROXY_APP "--p2p.persistent_peers $PERSISTENT_PEERS --p2p.pex --rpc.unsafe"
|
||||
# restart peer - should have an empty blockchain
|
||||
PERSISTENT_PEERS="$(test/p2p/ip_plus_id.sh 1 $DOCKER_IMAGE):46656"
|
||||
for j in `seq 2 $N`; do
|
||||
PERSISTENT_PEERS="$PERSISTENT_PEERS,$(test/p2p/ip_plus_id.sh $j $DOCKER_IMAGE):46656"
|
||||
done
|
||||
bash test/p2p/peer.sh $DOCKER_IMAGE $NETWORK_NAME $ID $PROXY_APP "--p2p.persistent_peers $PERSISTENT_PEERS --p2p.pex --rpc.unsafe"
|
||||
|
||||
# wait for peer to sync and check the app hash
|
||||
bash test/p2p/client.sh $DOCKER_IMAGE $NETWORK_NAME fs_$ID "test/p2p/fast_sync/check_peer.sh $ID"
|
||||
# wait for peer to sync and check the app hash
|
||||
bash test/p2p/client.sh $DOCKER_IMAGE $NETWORK_NAME fs_$ID "test/p2p/fast_sync/check_peer.sh $ID"
|
||||
|
||||
echo ""
|
||||
echo "PASS"
|
||||
echo ""
|
||||
echo ""
|
||||
echo "PASS"
|
||||
echo ""
|
||||
|
||||
|
||||
@@ -3,5 +3,3 @@ set -eu
|
||||
|
||||
ID=$1
|
||||
echo "172.57.0.$((100+$ID))"
|
||||
|
||||
|
||||
|
||||
7
test/p2p/ip_plus_id.sh
Executable file
7
test/p2p/ip_plus_id.sh
Executable file
@@ -0,0 +1,7 @@
|
||||
#! /bin/bash
|
||||
set -eu
|
||||
|
||||
ID=$1
|
||||
DOCKER_IMAGE=$2
|
||||
NODEID="$(docker run --rm -e TMHOME=/go/src/github.com/tendermint/tendermint/test/p2p/data/mach$ID/core $DOCKER_IMAGE tendermint show_node_id)"
|
||||
echo "$NODEID@172.57.0.$((100+$ID))"
|
||||
@@ -2,11 +2,12 @@
|
||||
set -eu
|
||||
|
||||
N=$1
|
||||
DOCKER_IMAGE=$2
|
||||
|
||||
cd "$GOPATH/src/github.com/tendermint/tendermint"
|
||||
|
||||
persistent_peers="$(test/p2p/ip.sh 1):46656"
|
||||
persistent_peers="$(test/p2p/ip_plus_id.sh 1 $DOCKER_IMAGE):46656"
|
||||
for i in $(seq 2 $N); do
|
||||
persistent_peers="$persistent_peers,$(test/p2p/ip.sh $i):46656"
|
||||
persistent_peers="$persistent_peers,$(test/p2p/ip_plus_id.sh $i $DOCKER_IMAGE):46656"
|
||||
done
|
||||
echo "$persistent_peers"
|
||||
|
||||
@@ -2,31 +2,22 @@
|
||||
set -u
|
||||
|
||||
N=$1
|
||||
PEERS=$2
|
||||
|
||||
cd $GOPATH/src/github.com/tendermint/tendermint
|
||||
cd "$GOPATH/src/github.com/tendermint/tendermint"
|
||||
|
||||
echo "Waiting for nodes to come online"
|
||||
for i in `seq 1 $N`; do
|
||||
addr=$(test/p2p/ip.sh $i):46657
|
||||
curl -s $addr/status > /dev/null
|
||||
for i in $(seq 1 "$N"); do
|
||||
addr=$(test/p2p/ip.sh "$i"):46657
|
||||
curl -s "$addr/status" > /dev/null
|
||||
ERR=$?
|
||||
while [ "$ERR" != 0 ]; do
|
||||
sleep 1
|
||||
curl -s $addr/status > /dev/null
|
||||
curl -s "$addr/status" > /dev/null
|
||||
ERR=$?
|
||||
done
|
||||
echo "... node $i is up"
|
||||
done
|
||||
|
||||
set -e
|
||||
# peers need quotes
|
||||
peers="\"$(test/p2p/ip.sh 1):46656\""
|
||||
for i in `seq 2 $N`; do
|
||||
peers="$peers,\"$(test/p2p/ip.sh $i):46656\""
|
||||
done
|
||||
echo $peers
|
||||
|
||||
echo $peers
|
||||
IP=$(test/p2p/ip.sh 1)
|
||||
curl "$IP:46657/dial_peers?persistent=true&peers=\[$peers\]"
|
||||
|
||||
curl "$IP:46657/dial_peers?persistent=true&peers=\\[$PEERS\\]"
|
||||
|
||||
@@ -21,14 +21,17 @@ set -e
|
||||
|
||||
# start the testnet on a local network
|
||||
# NOTE we re-use the same network for all tests
|
||||
PERSISTENT_PEERS=""
|
||||
bash test/p2p/local_testnet_start.sh $DOCKER_IMAGE $NETWORK_NAME $N $PROXY_APP $PERSISTENT_PEERS
|
||||
|
||||
bash test/p2p/local_testnet_start.sh $DOCKER_IMAGE $NETWORK_NAME $N $PROXY_APP ""
|
||||
|
||||
PERSISTENT_PEERS="\"$(test/p2p/ip_plus_id.sh 1 $DOCKER_IMAGE):46656\""
|
||||
for i in $(seq 2 $N); do
|
||||
PERSISTENT_PEERS="$PERSISTENT_PEERS,\"$(test/p2p/ip_plus_id.sh $i $DOCKER_IMAGE):46656\""
|
||||
done
|
||||
echo "$PERSISTENT_PEERS"
|
||||
|
||||
# dial peers from one node
|
||||
CLIENT_NAME="dial_peers"
|
||||
bash test/p2p/client.sh $DOCKER_IMAGE $NETWORK_NAME $CLIENT_NAME "test/p2p/pex/dial_peers.sh $N"
|
||||
bash test/p2p/client.sh $DOCKER_IMAGE $NETWORK_NAME $CLIENT_NAME "test/p2p/pex/dial_peers.sh $N $PERSISTENT_PEERS"
|
||||
|
||||
# test basic connectivity and consensus
|
||||
# start client container and check the num peers and height for all nodes
|
||||
|
||||
@@ -13,7 +13,7 @@ set +e
|
||||
bash test/p2p/local_testnet_stop.sh "$NETWORK_NAME" "$N"
|
||||
set -e
|
||||
|
||||
PERSISTENT_PEERS=$(bash test/p2p/persistent_peers.sh $N)
|
||||
PERSISTENT_PEERS=$(bash test/p2p/persistent_peers.sh $N $DOCKER_IMAGE)
|
||||
|
||||
# start the testnet on a local network
|
||||
# NOTE we re-use the same network for all tests
|
||||
|
||||
Reference in New Issue
Block a user