Merge pull request #472 from LeoHChen/libp2p

libp2p integration clean up
pull/473/head
Leo Chen 6 years ago committed by GitHub
commit 4accb287e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      cmd/client/txgen/main.go
  2. 29
      node/node.go
  3. 7
      test/configs/oneshard1.txt
  4. 17
      test/deploy.sh

@ -196,9 +196,7 @@ func main() {
clientNode.Client.UpdateBlocks = updateBlocksFunc clientNode.Client.UpdateBlocks = updateBlocksFunc
for _, leader := range shardIDLeaderMap { for _, leader := range shardIDLeaderMap {
if *libp2pPD { if !*libp2pPD {
clientNode.Role = node.NewNode
} else {
clientNode.GetHost().AddPeer(&leader) clientNode.GetHost().AddPeer(&leader)
utils.GetLogInstance().Debug("Client Join Shard", "leader", leader) utils.GetLogInstance().Debug("Client Join Shard", "leader", leader)
go clientNode.JoinShard(leader) go clientNode.JoinShard(leader)
@ -207,6 +205,7 @@ func main() {
} }
if *libp2pPD { if *libp2pPD {
clientNode.Role = node.ClientNode
clientNode.ServiceManagerSetup() clientNode.ServiceManagerSetup()
clientNode.RunServices() clientNode.RunServices()
go clientNode.StartServer() go clientNode.StartServer()

@ -71,6 +71,7 @@ const (
BeaconLeader BeaconLeader
BeaconValidator BeaconValidator
NewNode NewNode
ClientNode
) )
func (state State) String() string { func (state State) String() string {
@ -726,10 +727,23 @@ func (node *Node) initNodeConfiguration() (service.NodeConfig, chan p2p.Peer) {
} }
func (node *Node) initBeaconNodeConfiguration() (service.NodeConfig, chan p2p.Peer) { func (node *Node) initBeaconNodeConfiguration() (service.NodeConfig, chan p2p.Peer) {
nodeConfig, chanPeer := node.initNodeConfiguration() chanPeer := make(chan p2p.Peer)
nodeConfig.IsBeacon = true
nodeConfig := service.NodeConfig{
IsBeacon: true,
IsClient: true,
Beacon: p2p.GroupIDBeacon,
Group: p2p.GroupIDUnknown,
Actions: make(map[p2p.GroupID]p2p.ActionType),
}
nodeConfig.Actions[p2p.GroupIDBeaconClient] = p2p.ActionStart
var err error var err error
node.groupReceiver, err = node.host.GroupReceiver(p2p.GroupIDBeacon)
if err != nil {
utils.GetLogInstance().Error("create group receiver error", "msg", err)
}
// All beacon chain node will subscribe to BeaconClient topic // All beacon chain node will subscribe to BeaconClient topic
node.clientReceiver, err = node.host.GroupReceiver(p2p.GroupIDBeaconClient) node.clientReceiver, err = node.host.GroupReceiver(p2p.GroupIDBeaconClient)
if err != nil { if err != nil {
@ -812,6 +826,15 @@ func (node *Node) setupForNewNode() {
// TODO: how to restart networkinfo and discovery service after receiving shard id info from beacon chain? // TODO: how to restart networkinfo and discovery service after receiving shard id info from beacon chain?
} }
func (node *Node) setupForClientNode() {
nodeConfig, chanPeer := node.initNodeConfiguration()
// Register peer discovery service.
node.serviceManager.RegisterService(service_manager.PeerDiscovery, discovery.New(node.host, nodeConfig, chanPeer))
// Register networkinfo service. "0" is the beacon shard ID
node.serviceManager.RegisterService(service_manager.NetworkInfo, networkinfo.New(node.host, p2p.GroupIDBeacon, chanPeer))
}
// ServiceManagerSetup setups service store. // ServiceManagerSetup setups service store.
func (node *Node) ServiceManagerSetup() { func (node *Node) ServiceManagerSetup() {
node.serviceManager = &service_manager.Manager{} node.serviceManager = &service_manager.Manager{}
@ -826,6 +849,8 @@ func (node *Node) ServiceManagerSetup() {
node.setupForBeaconValidator() node.setupForBeaconValidator()
case NewNode: case NewNode:
node.setupForNewNode() node.setupForNewNode()
case ClientNode:
node.setupForClientNode()
} }
} }

@ -3,3 +3,10 @@
127.0.0.1 9002 validator 0 127.0.0.1 9002 validator 0
127.0.0.1 9003 validator 0 127.0.0.1 9003 validator 0
127.0.0.1 9004 validator 0 127.0.0.1 9004 validator 0
127.0.0.1 9005 validator 0
127.0.0.1 9006 validator 0
127.0.0.1 9007 validator 0
127.0.0.1 9008 validator 0
127.0.0.1 9009 validator 0
127.0.0.1 9010 validator 0
127.0.0.1 19999 client 0

@ -73,7 +73,7 @@ EOU
DB= DB=
TXGEN=true TXGEN=true
DURATION=90 DURATION=90
MIN=2 MIN=5
SHARDS=2 SHARDS=2
KILLPORT=9004 KILLPORT=9004
SYNC=true SYNC=true
@ -103,7 +103,7 @@ if [ -z "$config" ]; then
fi fi
if [ "$SYNC" == "true" ]; then if [ "$SYNC" == "true" ]; then
DURATION=600 DURATION=300
fi fi
# Kill nodes if any # Kill nodes if any
@ -131,6 +131,7 @@ LOG_FILE=$log_folder/r.log
HMY_OPT= HMY_OPT=
HMY_OPT2= HMY_OPT2=
HMY_OPT3=
if [ "$P2P" == "false" ]; then if [ "$P2P" == "false" ]; then
echo "launching beacon chain ..." echo "launching beacon chain ..."
@ -144,8 +145,8 @@ else
sleep 1 sleep 1
BN_MA=$(grep "BN_MA" $log_folder/bootnode.log | awk -F\= ' { print $2 } ') BN_MA=$(grep "BN_MA" $log_folder/bootnode.log | awk -F\= ' { print $2 } ')
HMY_OPT2=" -bootnodes $BN_MA" HMY_OPT2=" -bootnodes $BN_MA"
HMY_OPT2+=" -libp2p_pd -is_beacon" HMY_OPT2+=" -libp2p_pd"
TXGEN=false HMY_OPT3=" -is_beacon"
fi fi
NUM_NN=0 NUM_NN=0
@ -154,15 +155,15 @@ NUM_NN=0
while IFS='' read -r line || [[ -n "$line" ]]; do while IFS='' read -r line || [[ -n "$line" ]]; do
IFS=' ' read ip port mode shardID <<< $line IFS=' ' read ip port mode shardID <<< $line
if [ "$mode" == "leader" ]; then if [ "$mode" == "leader" ]; then
$DRYRUN $ROOT/bin/harmony -ip $ip -port $port -log_folder $log_folder $DB -min_peers $MIN $HMY_OPT $HMY_OPT2 -key /tmp/$ip-$port.key -is_leader 2>&1 | tee -a $LOG_FILE & $DRYRUN $ROOT/bin/harmony -ip $ip -port $port -log_folder $log_folder $DB -min_peers $MIN $HMY_OPT $HMY_OPT2 $HMY_OPT3 -key /tmp/$ip-$port.key -is_leader 2>&1 | tee -a $LOG_FILE &
fi fi
if [ "$mode" == "validator" ]; then if [ "$mode" == "validator" ]; then
$DRYRUN $ROOT/bin/harmony -ip $ip -port $port -log_folder $log_folder $DB -min_peers $MIN $HMY_OPT $HMY_OPT2 -key /tmp/$ip-$port.key 2>&1 | tee -a $LOG_FILE & $DRYRUN $ROOT/bin/harmony -ip $ip -port $port -log_folder $log_folder $DB -min_peers $MIN $HMY_OPT $HMY_OPT2 $HMY_OPT3 -key /tmp/$ip-$port.key 2>&1 | tee -a $LOG_FILE &
fi fi
sleep 0.5 sleep 0.5
if [[ "$mode" == "newnode" && "$SYNC" == "true" ]]; then if [[ "$mode" == "newnode" && "$SYNC" == "true" ]]; then
(( NUM_NN += 35 )) (( NUM_NN += 35 ))
(sleep $NUM_NN; $DRYRUN $ROOT/bin/harmony -ip $ip -port $port -log_folder $log_folder $DB -min_peers $MIN $HMY_OPT $HMY_OPT2 -key /tmp/$ip-$port.key 2>&1 | tee -a $LOG_FILE ) & (sleep $NUM_NN; $DRYRUN $ROOT/bin/harmony -ip $ip -port $port -log_folder $log_folder $DB -min_peers $MIN $HMY_OPT $HMY_OPT2 $HMY_OPT3 -key /tmp/$ip-$port.key 2>&1 | tee -a $LOG_FILE ) &
fi fi
done < $config done < $config
@ -177,7 +178,7 @@ if [ "$TXGEN" == "true" ]; then
line=$(grep client $config) line=$(grep client $config)
IFS=' ' read ip port mode shardID <<< $line IFS=' ' read ip port mode shardID <<< $line
if [ "$mode" == "client" ]; then if [ "$mode" == "client" ]; then
$DRYRUN $ROOT/bin/txgen -log_folder $log_folder -duration $DURATION -ip $ip -port $port $HMY_OPT 2>&1 | tee -a $LOG_FILE $DRYRUN $ROOT/bin/txgen -log_folder $log_folder -duration $DURATION -ip $ip -port $port $HMY_OPT $HMY_OPT2 2>&1 | tee -a $LOG_FILE
fi fi
else else
sleep $DURATION sleep $DURATION

Loading…
Cancel
Save