From d3498160b1f8b5793c801d2e108878947559e59b Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Tue, 19 Feb 2019 22:41:07 -0800 Subject: [PATCH 1/3] fix consensus after reorg the code Signed-off-by: Leo Chen --- node/node.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/node/node.go b/node/node.go index 571ec7129..f491a5060 100644 --- a/node/node.go +++ b/node/node.go @@ -749,10 +749,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 { From 00c40743a9799e3dff26a0196a26df72f947019b Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Tue, 19 Feb 2019 23:09:12 -0800 Subject: [PATCH 2/3] enable testing of libp2p based consensus Signed-off-by: Leo Chen --- test/configs/oneshard1.txt | 7 +++++++ test/deploy.sh | 17 +++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) 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 From 074480ea1e6007b75c0ffade60bf49a5fc5483f8 Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Tue, 19 Feb 2019 23:14:22 -0800 Subject: [PATCH 3/3] add ClientNode role for txgen/wallet Signed-off-by: Leo Chen --- cmd/client/txgen/main.go | 5 ++--- node/node.go | 12 ++++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) 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 f491a5060..a7fc04acb 100644 --- a/node/node.go +++ b/node/node.go @@ -73,6 +73,7 @@ const ( BeaconLeader BeaconValidator NewNode + ClientNode ) func (state State) String() string { @@ -848,6 +849,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{} @@ -862,6 +872,8 @@ func (node *Node) ServiceManagerSetup() { node.setupForBeaconValidator() case NewNode: node.setupForNewNode() + case ClientNode: + node.setupForClientNode() } }