Merge pull request #176 from harmony-one/open_source_cleanup

remove static config file support code
pull/180/head
Leo Chen 6 years ago committed by GitHub
commit 83521223e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      benchmark.go
  2. 18
      client/txgen/main.go
  3. 29
      deploy_btctx.sh
  4. 22
      deploy_linux.sh
  5. 70
      discovery/discovery.go
  6. 3
      lint_before_submit.sh
  7. 10
      run_commander.sh
  8. 22
      run_experiment.sh
  9. 18
      sysctl.sh
  10. 0
      test/configs/local_config.txt
  11. 0
      test/configs/local_config1.txt
  12. 0
      test/configs/local_config2.txt
  13. 0
      test/configs/local_config3.txt
  14. 0
      test/configs/local_config4.txt
  15. 0
      test/configs/local_config5.txt
  16. 0
      test/configs/local_config_8shards.txt
  17. 0
      test/configs/local_config_shards.txt
  18. 27
      test/deploy.sh
  19. 0
      test/kill_node.sh
  20. 0
      test/send_txn.sh
  21. 173
      utils/distribution_config.go

@ -19,7 +19,6 @@ import (
"github.com/harmony-one/harmony/node"
"github.com/harmony-one/harmony/p2p"
"github.com/harmony-one/harmony/profiler"
"github.com/harmony-one/harmony/utils"
)
var (
@ -79,7 +78,6 @@ func main() {
// TODO: use http://getmyipaddress.org/ or http://www.get-myip.com/ to retrieve my IP address
ip := flag.String("ip", "127.0.0.1", "IP of the node")
port := flag.String("port", "9000", "port of the node.")
configFile := flag.String("config_file", "config.txt", "file containing all ip addresses")
logFolder := flag.String("log_folder", "latest", "the folder collecting the logs of this execution")
attackedMode := flag.Int("attacked_mode", 0, "0 means not attacked, 1 means attacked, 2 means being open to be selected as attacked")
dbSupported := flag.Bool("db_supported", false, "false means not db_supported, true means db_supported")
@ -91,7 +89,6 @@ func main() {
//This IP belongs to jenkins.harmony.one
bcIP := flag.String("bc", "127.0.0.1", "IP of the identity chain")
bcPort := flag.String("bc_port", "8081", "port of the identity chain")
peerDiscovery := flag.Bool("peer_discovery", true, "Enable Peer Discovery")
//Leader needs to have a minimal number of peers to start consensus
minPeers := flag.Int("min_peers", 100, "Minimal number of Peers in shard")
@ -114,7 +111,6 @@ func main() {
var selfPeer p2p.Peer
var clientPeer *p2p.Peer
//Use Peer Discovery to get shard/leader/peer/...
if *peerDiscovery {
candidateNode := pkg_newnode.New(*ip, *port)
BCPeer := p2p.Peer{IP: *bcIP, Port: *bcPort}
candidateNode.ContactBeaconChain(BCPeer)
@ -124,19 +120,6 @@ func main() {
clientPeer = candidateNode.GetClientPeer()
selfPeer.PubKey = candidateNode.PubK
} else {
distributionConfig := utils.NewDistributionConfig()
distributionConfig.ReadConfigFile(*configFile)
shardID = distributionConfig.GetShardID(*ip, *port)
leader = distributionConfig.GetLeader(shardID)
selfPeer = distributionConfig.GetSelfPeer(*ip, *port, shardID)
_, pubKey := utils.GenKey(*ip, *port)
peers = distributionConfig.GetPeers(*ip, *port, shardID)
selfPeer.PubKey = pubKey
// Create client peer.
clientPeer = distributionConfig.GetClientPeer()
}
// fmt.Println(peers, leader, selfPeer, clientPeer, *logFolder, *minPeers) //TODO: to be replaced by a logger later: ak, rl
var role string
@ -202,11 +185,7 @@ func main() {
currentNode.WaitForConsensusReady(consensus.ReadySignal)
}()
} else {
if *peerDiscovery {
go currentNode.JoinShard(leader)
} else {
currentNode.State = node.NodeDoingConsensus
}
}
go currentNode.SupportSyncing()

@ -10,8 +10,6 @@ import (
"time"
"github.com/harmony-one/harmony/client"
client_config "github.com/harmony-one/harmony/client/config"
"github.com/harmony-one/harmony/client/txgen/txgen"
"github.com/harmony-one/harmony/consensus"
"github.com/harmony-one/harmony/core/types"
@ -41,7 +39,6 @@ func main() {
ip := flag.String("ip", "127.0.0.1", "IP of the node")
port := flag.String("port", "9999", "port of the node.")
configFile := flag.String("config_file", "local_config.txt", "file containing all ip addresses and config")
maxNumTxsPerBatch := flag.Int("max_num_txs_per_batch", 20000, "number of transactions to send per message")
logFolder := flag.String("log_folder", "latest", "the folder collecting the logs of this execution")
duration := flag.Int("duration", 10, "duration of the tx generation in second. If it's negative, the experiment runs forever.")
@ -50,7 +47,6 @@ func main() {
bcIP := flag.String("bc", "127.0.0.1", "IP of the identity chain")
bcPort := flag.String("bc_port", "8081", "port of the identity chain")
peerDiscovery := flag.Bool("peer_discovery", false, "Enable Peer Discovery")
flag.Parse()
@ -63,9 +59,7 @@ func main() {
var clientPeer *p2p.Peer
var shardIDLeaderMap map[uint32]p2p.Peer
var config *client_config.Config
if *peerDiscovery {
candidateNode := newnode.New(*ip, *port)
BCPeer := p2p.Peer{IP: *bcIP, Port: *bcPort}
candidateNode.ContactBeaconChain(BCPeer)
@ -74,15 +68,7 @@ func main() {
clientPeer.PubKey = pubKey
shardIDLeaderMap = candidateNode.Leaders
} else {
// Read the configs
config = client_config.NewConfig()
config.ReadConfigFile(*configFile)
shardIDLeaderMap = config.GetShardIDToLeaderMap()
clientPeer = config.GetClientPeer()
_, pubKey := utils.GenKey(clientPeer.IP, clientPeer.Port)
clientPeer.PubKey = pubKey
}
if clientPeer == nil {
panic("Client Peer is nil!")
}
@ -155,7 +141,6 @@ func main() {
// Start the client server to listen to leader's message
go clientNode.StartServer()
if *peerDiscovery {
for _, leader := range shardIDLeaderMap {
log.Debug("Client Join Shard", "leader", leader)
go clientNode.JoinShard(leader)
@ -164,7 +149,6 @@ func main() {
clientNode.StopPing <- struct{}{}
clientNode.State = node.NodeJoinedShard
}
}
// Transaction generation process
time.Sleep(5 * time.Second) // wait for nodes to be ready

@ -1,29 +0,0 @@
# Kill nodes if any
./kill_node.sh
# Since `go run` will generate a temporary exe every time,
# On windows, your system will pop up a network security dialog for each instance
# and you won't be able to turn it off. With `go build` generating one
# exe, the dialog will only pop up once at the very first time.
# Also it's recommended to use `go build` for testing the whole exe.
go build -o bin/benchmark
go build -o bin/btctxgen client/btctxgen/main.go
# Create a tmp folder for logs
t=`date +"%Y%m%d-%H%M%S"`
log_folder="tmp_log/log-$t"
mkdir -p $log_folder
# Start nodes
config=$1
while IFS='' read -r line || [[ -n "$line" ]]; do
IFS=' ' read ip port mode shardID <<< $line
#echo $ip $port $mode
if [ "$mode" != "client" ]; then
./bin/benchmark -ip $ip -port $port -config_file $config -log_folder $log_folder&
fi
done < $config
# Generate transactions
./bin/btctxgen -config_file $config -log_folder $log_folder

@ -1,22 +0,0 @@
#!/bin/bash -x
##The commented suffix is for linux
##Reference: https://github.com/Zilliqa/Zilliqa/blob/master/tests/Node/test_node_simple.sh
sudo sysctl net.core.somaxconn=1024
sudo sysctl net.core.netdev_max_backlog=65536;
sudo sysctl net.ipv4.tcp_tw_reuse=1;
sudo sysctl -w net.ipv4.tcp_rmem='65536 873800 1534217728';
sudo sysctl -w net.ipv4.tcp_wmem='65536 873800 1534217728';
sudo sysctl -w net.ipv4.tcp_mem='65536 873800 1534217728';
./kill_node.sh
source ~/.bash_profile
echo "Inside deploy linux"
echo $GOPATH
echo "Inside deploy linux line 2"
config=$1
while read ip port mode; do
#echo $ip $port $mode $config
go run ./benchmark.go -ip $ip -port $port -config_file $config&
done < $config
go run ./client/txgen/main.go -config_file $config

@ -1,70 +0,0 @@
package discovery
import (
"fmt"
"github.com/dedis/kyber"
"github.com/harmony-one/harmony/p2p"
)
// ConfigEntry is the config entry.
type ConfigEntry struct {
IP string
Port string
Role string
ShardID string
ValidatorID int // Validator ID in its shard.
leader p2p.Peer
self p2p.Peer
peers []p2p.Peer
priK kyber.Scalar
pubK kyber.Point
}
func (config ConfigEntry) String() string {
return fmt.Sprintf("bc: %v:%v", config.IP, config.Port)
}
// New return new ConfigEntry.
// TODO: This should be change because this package is discovery and New here implies New Discovery.
func New(priK kyber.Scalar, pubK kyber.Point) *ConfigEntry {
var config ConfigEntry
config.priK = priK
config.pubK = pubK
config.peers = make([]p2p.Peer, 0)
return &config
}
// StartClientMode starts client mode.
func (config *ConfigEntry) StartClientMode(bcIP, bcPort string) error {
config.IP = "myip"
config.Port = "myport"
fmt.Printf("bc ip/port: %v/%v\n", bcIP, bcPort)
// ...
// TODO: connect to bc, and wait unless acknowledge
return nil
}
// GetShardID ...
func (config *ConfigEntry) GetShardID() string {
return config.ShardID
}
// GetPeers ...
func (config *ConfigEntry) GetPeers() []p2p.Peer {
return config.peers
}
// GetLeader ...
func (config *ConfigEntry) GetLeader() p2p.Peer {
return config.leader
}
// GetSelfPeer ...
func (config *ConfigEntry) GetSelfPeer() p2p.Peer {
return config.self
}

@ -1,3 +0,0 @@
go get -u golang.org/x/lint/golint
golint ./...

@ -1,10 +0,0 @@
cd ~/projects/src/harmony-benchmark/
# Compile
sudo go build -o bin/commander aws-experiment-launch/experiment/commander/main.go
cd bin
sudo cp /tmp/distribution_config.txt .
sudo cp /tmp/commander_info.txt .
# Take ip address
IP=`head -n 1 commander_info.txt`
# Run commander
sudo ./commander -ip $IP -port 9000 -config_file distribution_config.txt

@ -1,22 +0,0 @@
# Kill nodes if any
./kill_node.sh
go build -o bin/benchmark
go build -o bin/txgen client/txgen/main.go
cd bin
# Create a tmp folder for logs
t=`date +"%Y%m%d-%H%M%S"`
log_folder="tmp_log/log-$t"
mkdir -p $log_folder
# For each of the nodes, start soldier
config=distribution_config.txt
while IFS='' read -r line || [[ -n "$line" ]]; do
IFS=' ' read ip port mode shardID <<< $line
#echo $ip $port $mode
./soldier -ip $ip -port $port&
done < $config
./commander

@ -1,18 +0,0 @@
# System kernel setup (Mac)
# Reference: http://www.macfreek.nl/memory/Kernel_Configuration
sudo sysctl -w kern.ipc.somaxconn=10240 # Limit of number of new connections
#sudo sysctl -w kern.ipc.maxsockets=10240 # Initial number of sockets in memory
sudo sysctl -w net.inet.tcp.msl=1000 # TIME_WAIT
#sudo sysctl -w net.inet.tcp.rfc1323=1 # Enable TCP window scaling
sudo sysctl -w kern.ipc.maxsockbuf=4194304 # Maximum TCP Window size
sudo sysctl -w net.inet.tcp.sendspace=131072 # Default send buffer
sudo sysctl -w net.inet.tcp.recvspace=358400 # Default receive buffer
# The commented suffix is for linux
# Reference: https://github.com/Zilliqa/Zilliqa/blob/master/tests/Node/test_node_simple.sh
#sudo sysctl net.core.somaxconn=1024
#sudo sysctl net.core.netdev_max_backlog=65536;
#sudo sysctl net.ipv4.tcp_tw_reuse=1;
#sudo sysctl -w net.ipv4.tcp_rmem='65536 873800 1534217728';
#sudo sysctl -w net.ipv4.tcp_wmem='65536 873800 1534217728';
#sudo sysctl -w net.ipv4.tcp_mem='65536 873800 1534217728';

@ -1,5 +1,7 @@
#!/bin/bash
ROOT=$(dirname $0)/..
set -eo pipefail
function cleanup() {
@ -30,8 +32,6 @@ function usage {
USAGE: $ME [OPTIONS] config_file_name
-h print this help message
-p use peer discovery (default: $PEER)
-P do not use peer discovery
-d enable db support (default: $DB)
-t toggle txgen (default: $TXGEN)
-D duration txgen run duration (default: $DURATION)
@ -50,7 +50,6 @@ EOU
exit 0
}
PEER=-peer_discovery
DB=
TXGEN=true
DURATION=90
@ -58,11 +57,9 @@ MIN=5
SHARDS=2
KILLPORT=9004
while getopts "hpdtD:m:s:k:P" option; do
while getopts "hdtD:m:s:k:" option; do
case $option in
h) usage ;;
p) PEER='-peer_discovery' ;;
P) PEER= ;;
d) DB='-db_supported' ;;
t) TXGEN=$OPTARG ;;
D) DURATION=$OPTARG ;;
@ -88,10 +85,12 @@ cleanup
# and you won't be able to turn it off. With `go build` generating one
# exe, the dialog will only pop up once at the very first time.
# Also it's recommended to use `go build` for testing the whole exe.
pushd $ROOT
echo "compiling ..."
go build -o bin/benchmark
go build -o bin/txgen client/txgen/main.go
go build -o bin/beacon beaconchain/main/main.go
popd
# Create a tmp folder for logs
t=`date +"%Y%m%d-%H%M%S"`
@ -99,24 +98,18 @@ log_folder="tmp_log/log-$t"
mkdir -p $log_folder
if [ -n "$PEER" ]; then
echo "launching beacon chain ..."
./bin/beacon -numShards $SHARDS > $log_folder/beacon.log 2>&1 &
$ROOT/bin/beacon -numShards $SHARDS > $log_folder/beacon.log 2>&1 &
sleep 1 #wait or beachchain up
fi
# Start nodes
while IFS='' read -r line || [[ -n "$line" ]]; do
IFS=' ' read ip port mode shardID <<< $line
#echo $ip $port $mode
if [ "$mode" != "client" ]; then
if [ -z "$PEER" ]; then
./bin/benchmark -ip $ip -port $port -config_file $config -log_folder $log_folder $DB -min_peers $MIN &
else
./bin/benchmark -ip $ip -port $port -log_folder $log_folder $DB $PEER -min_peers $MIN &
$ROOT/bin/benchmark -ip $ip -port $port -log_folder $log_folder $DB -min_peers $MIN &
sleep 0.5
fi
fi
done < $config
# Emulate node offline
@ -125,11 +118,7 @@ done < $config
echo "launching txgen ..."Z
if [ "$TXGEN" == "true" ]; then
echo "launching txgen ..."
if [ -z "$PEER" ]; then
./bin/txgen -config_file $config -log_folder $log_folder -duration $DURATION
else
./bin/txgen -log_folder $log_folder -duration $DURATION $PEER
fi
$ROOT/bin/txgen -log_folder $log_folder -duration $DURATION
fi
cleanup

@ -1,173 +0,0 @@
package utils
import (
"bufio"
"log"
"os"
"strconv"
"strings"
"github.com/harmony-one/harmony/crypto"
"github.com/harmony-one/harmony/crypto/pki"
"github.com/harmony-one/harmony/p2p"
)
// ConfigEntry is the config entry.
type ConfigEntry struct {
IP string
Port string
Role string
ShardID string
ValidatorID int // Validator ID in its shard.
}
// DistributionConfig is the distribution config.
type DistributionConfig struct {
config []ConfigEntry
}
// NewDistributionConfig creates new DistributionConfig
func NewDistributionConfig() *DistributionConfig {
config := DistributionConfig{}
return &config
}
// GetLeadersAndShardIDs gets all the leader peers and corresponding shard Ids
func (config *DistributionConfig) GetLeadersAndShardIDs() ([]p2p.Peer, []uint32) {
var peerList []p2p.Peer
var shardIDs []uint32
for _, entry := range config.config {
if entry.Role == "leader" {
peerList = append(peerList, p2p.Peer{IP: entry.IP, Port: entry.Port})
val, err := strconv.Atoi(entry.ShardID)
if err == nil {
shardIDs = append(shardIDs, uint32(val))
} else {
log.Print("[Generator] Error parsing the shard Id ", entry.ShardID)
}
}
}
return peerList, shardIDs
}
// GetClientPeer returns client peer.
func (config *DistributionConfig) GetClientPeer() *p2p.Peer {
for _, entry := range config.config {
if entry.Role != "client" {
continue
}
peer := p2p.Peer{Port: entry.Port, IP: entry.IP}
return &peer
}
return nil
}
// GetClientPort gets the port of the client node in the config
func (config *DistributionConfig) GetClientPort() string {
for _, entry := range config.config {
if entry.Role == "client" {
return entry.Port
}
}
return ""
}
// ReadConfigFile parses the config file and return a 2d array containing the file data
func (config *DistributionConfig) ReadConfigFile(filename string) error {
file, err := os.Open(filename)
if err != nil {
log.Fatal("Failed to read config file ", filename)
return err
}
defer file.Close()
fscanner := bufio.NewScanner(file)
result := []ConfigEntry{}
validatorMap := map[int]int{}
for fscanner.Scan() {
p := strings.Split(fscanner.Text(), " ")
shardID, _ := strconv.Atoi(p[3])
validatorID := -1
if p[2] == "validator" {
validatorMap[shardID]++
validatorID = validatorMap[shardID]
}
entry := ConfigEntry{p[0], p[1], p[2], p[3], validatorID}
result = append(result, entry)
}
config.config = result
return nil
}
// GetShardID Gets the shard id of the node corresponding to this ip and port
func (config *DistributionConfig) GetShardID(ip, port string) string {
for _, entry := range config.config {
if entry.IP == ip && entry.Port == port {
return entry.ShardID
}
}
return "N/A"
}
// GetPeers Gets the validator list
func (config *DistributionConfig) GetPeers(ip, port, shardID string) []p2p.Peer {
var peerList []p2p.Peer
for _, entry := range config.config {
if entry.Role != "validator" || entry.ShardID != shardID {
continue
}
// Get public key deterministically based on ip and port
peer := p2p.Peer{Port: entry.Port, IP: entry.IP, ValidatorID: entry.ValidatorID}
setKey(&peer)
peerList = append(peerList, peer)
}
return peerList
}
// GetSelfPeer Gets the validator list
func (config *DistributionConfig) GetSelfPeer(ip, port, shardID string) p2p.Peer {
for _, entry := range config.config {
if entry.IP == ip && entry.Port == port && entry.ShardID == shardID {
peer := p2p.Peer{Port: entry.Port, IP: entry.IP, ValidatorID: entry.ValidatorID}
return peer
}
}
return p2p.Peer{}
}
// GetLeader Gets the leader of this shard id
func (config *DistributionConfig) GetLeader(shardID string) p2p.Peer {
var leaderPeer p2p.Peer
for _, entry := range config.config {
if entry.Role == "leader" && entry.ShardID == shardID {
leaderPeer.IP = entry.IP
leaderPeer.Port = entry.Port
setKey(&leaderPeer)
}
}
return leaderPeer
}
// GetConfigEntries returns a list of ConfigEntry.
func (config *DistributionConfig) GetConfigEntries() []ConfigEntry {
return config.config
}
// GetMyConfigEntry ...
func (config *DistributionConfig) GetMyConfigEntry(ip string, port string) *ConfigEntry {
if config.config == nil {
return nil
}
for _, entry := range config.config {
if entry.IP == ip && entry.Port == port {
return &entry
}
}
return nil
}
func setKey(peer *p2p.Peer) {
// Get public key deterministically based on ip and port
priKey := crypto.Ed25519Curve.Scalar().SetInt64(int64(GetUniqueIDFromPeer(*peer))) // TODO: figure out why using a random hash value doesn't work for private key (schnorr)
peer.PubKey = pki.GetPublicKeyFromScalar(priKey)
}
Loading…
Cancel
Save