diff --git a/cmd/client/txgen/main.go b/cmd/client/txgen/main.go index a784d0264..e9ed3e44c 100644 --- a/cmd/client/txgen/main.go +++ b/cmd/client/txgen/main.go @@ -196,9 +196,7 @@ func main() { clientNode.Client.UpdateBlocks = updateBlocksFunc for _, leader := range shardIDLeaderMap { - if *libp2pPD { - clientNode.Role = node.NewNode - } else { + if !*libp2pPD { clientNode.GetHost().AddPeer(&leader) utils.GetLogInstance().Debug("Client Join Shard", "leader", leader) go clientNode.JoinShard(leader) @@ -207,6 +205,7 @@ func main() { } if *libp2pPD { + clientNode.Role = node.ClientNode clientNode.ServiceManagerSetup() clientNode.RunServices() go clientNode.StartServer() diff --git a/node/node.go b/node/node.go index 372ce160c..26d0f34ac 100644 --- a/node/node.go +++ b/node/node.go @@ -71,6 +71,7 @@ const ( BeaconLeader BeaconValidator NewNode + ClientNode ) 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) { - nodeConfig, chanPeer := node.initNodeConfiguration() - nodeConfig.IsBeacon = true + chanPeer := make(chan p2p.Peer) + + 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 + 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 node.clientReceiver, err = node.host.GroupReceiver(p2p.GroupIDBeaconClient) 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? } +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. func (node *Node) ServiceManagerSetup() { node.serviceManager = &service_manager.Manager{} @@ -826,6 +849,8 @@ func (node *Node) ServiceManagerSetup() { node.setupForBeaconValidator() case NewNode: node.setupForNewNode() + case ClientNode: + node.setupForClientNode() } } diff --git a/test/configs/oneshard1.txt b/test/configs/oneshard1.txt index 995c9ec97..2e8297ff4 100644 --- a/test/configs/oneshard1.txt +++ b/test/configs/oneshard1.txt @@ -3,3 +3,10 @@ 127.0.0.1 9002 validator 0 127.0.0.1 9003 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 diff --git a/test/deploy.sh b/test/deploy.sh index 15e2fc671..d4315bc5b 100755 --- a/test/deploy.sh +++ b/test/deploy.sh @@ -73,7 +73,7 @@ EOU DB= TXGEN=true DURATION=90 -MIN=2 +MIN=5 SHARDS=2 KILLPORT=9004 SYNC=true @@ -103,7 +103,7 @@ if [ -z "$config" ]; then fi if [ "$SYNC" == "true" ]; then - DURATION=600 + DURATION=300 fi # Kill nodes if any @@ -131,6 +131,7 @@ LOG_FILE=$log_folder/r.log HMY_OPT= HMY_OPT2= +HMY_OPT3= if [ "$P2P" == "false" ]; then echo "launching beacon chain ..." @@ -144,8 +145,8 @@ else sleep 1 BN_MA=$(grep "BN_MA" $log_folder/bootnode.log | awk -F\= ' { print $2 } ') HMY_OPT2=" -bootnodes $BN_MA" - HMY_OPT2+=" -libp2p_pd -is_beacon" - TXGEN=false + HMY_OPT2+=" -libp2p_pd" + HMY_OPT3=" -is_beacon" fi NUM_NN=0 @@ -154,15 +155,15 @@ NUM_NN=0 while IFS='' read -r line || [[ -n "$line" ]]; do IFS=' ' read ip port mode shardID <<< $line 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 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 sleep 0.5 if [[ "$mode" == "newnode" && "$SYNC" == "true" ]]; then (( 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 done < $config @@ -177,7 +178,7 @@ if [ "$TXGEN" == "true" ]; then line=$(grep client $config) IFS=' ' read ip port mode shardID <<< $line 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 else sleep $DURATION