|
|
@ -12,8 +12,8 @@ import ( |
|
|
|
"github.com/harmony-one/harmony/attack" |
|
|
|
"github.com/harmony-one/harmony/attack" |
|
|
|
"github.com/harmony-one/harmony/consensus" |
|
|
|
"github.com/harmony-one/harmony/consensus" |
|
|
|
"github.com/harmony-one/harmony/db" |
|
|
|
"github.com/harmony-one/harmony/db" |
|
|
|
"github.com/harmony-one/harmony/discovery" |
|
|
|
|
|
|
|
"github.com/harmony-one/harmony/log" |
|
|
|
"github.com/harmony-one/harmony/log" |
|
|
|
|
|
|
|
pkg_newnode "github.com/harmony-one/harmony/newnode" |
|
|
|
"github.com/harmony-one/harmony/node" |
|
|
|
"github.com/harmony-one/harmony/node" |
|
|
|
"github.com/harmony-one/harmony/p2p" |
|
|
|
"github.com/harmony-one/harmony/p2p" |
|
|
|
"github.com/harmony-one/harmony/profiler" |
|
|
|
"github.com/harmony-one/harmony/profiler" |
|
|
@ -73,9 +73,11 @@ func loggingInit(logFolder, role, ip, port string, onlyLogTps bool) { |
|
|
|
log.Root().SetHandler(h) |
|
|
|
log.Root().SetHandler(h) |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func main() { |
|
|
|
func main() { |
|
|
|
accountModel := flag.Bool("account_model", true, "Whether to use account model") |
|
|
|
accountModel := flag.Bool("account_model", true, "Whether to use account model") |
|
|
|
// TODO: use http://getmyipaddress.org/ or http://www.get-myip.com/ to retrieve my IP address
|
|
|
|
//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") |
|
|
|
ip := flag.String("ip", "127.0.0.1", "IP of the node") |
|
|
|
port := flag.String("port", "9000", "port of the node.") |
|
|
|
port := flag.String("port", "9000", "port of the node.") |
|
|
|
configFile := flag.String("config_file", "config.txt", "file containing all ip addresses") |
|
|
|
configFile := flag.String("config_file", "config.txt", "file containing all ip addresses") |
|
|
@ -88,12 +90,12 @@ func main() { |
|
|
|
syncNode := flag.Bool("sync_node", false, "Whether this node is a new node joining blockchain and it needs to get synced before joining consensus.") |
|
|
|
syncNode := flag.Bool("sync_node", false, "Whether this node is a new node joining blockchain and it needs to get synced before joining consensus.") |
|
|
|
onlyLogTps := flag.Bool("only_log_tps", false, "Only log TPS if true") |
|
|
|
onlyLogTps := flag.Bool("only_log_tps", false, "Only log TPS if true") |
|
|
|
|
|
|
|
|
|
|
|
// This IP belongs to jenkins.harmony.one
|
|
|
|
//This IP belongs to jenkins.harmony.one
|
|
|
|
idcIP := flag.String("idc", "54.183.5.66", "IP of the identity chain") |
|
|
|
idcIP := flag.String("idc", "127.0.0.1", "IP of the identity chain") |
|
|
|
idcPort := flag.String("idc_port", "8080", "port of the identity chain") |
|
|
|
idcPort := flag.String("idc_port", "8081", "port of the identity chain") |
|
|
|
peerDisvoery := flag.Bool("peer_discovery", false, "Enable Peer Discovery") |
|
|
|
peerDiscovery := flag.Bool("peer_discovery", true, "Enable Peer Discovery") |
|
|
|
|
|
|
|
|
|
|
|
// Leader needs to have a minimal number of peers to start consensus
|
|
|
|
// // Leader needs to have a minimal number of peers to start consensus
|
|
|
|
minPeers := flag.Int("min_peers", 100, "Minimal number of Peers in shard") |
|
|
|
minPeers := flag.Int("min_peers", 100, "Minimal number of Peers in shard") |
|
|
|
|
|
|
|
|
|
|
|
flag.Parse() |
|
|
|
flag.Parse() |
|
|
@ -113,37 +115,31 @@ func main() { |
|
|
|
var leader p2p.Peer |
|
|
|
var leader p2p.Peer |
|
|
|
var selfPeer p2p.Peer |
|
|
|
var selfPeer p2p.Peer |
|
|
|
var clientPeer *p2p.Peer |
|
|
|
var clientPeer *p2p.Peer |
|
|
|
// Use Peer Discovery to get shard/leader/peer/...
|
|
|
|
//Use Peer Discovery to get shard/leader/peer/...
|
|
|
|
priKey, pubKey := utils.GenKey(*ip, *port) |
|
|
|
if *peerDiscovery { |
|
|
|
if *peerDisvoery { |
|
|
|
candidateNode := pkg_newnode.New(*ip, *port) |
|
|
|
// Contact Identity Chain
|
|
|
|
BCPeer := p2p.Peer{IP: *idcIP, Port: *idcPort} |
|
|
|
// This is a blocking call
|
|
|
|
service := candidateNode.NewService(*ip, *port) |
|
|
|
// Assume @ak has get it working
|
|
|
|
candidateNode.ConnectBeaconChain(BCPeer) |
|
|
|
// TODO: this has to work with @ak's fix
|
|
|
|
shardID = candidateNode.GetShardID() |
|
|
|
discoveryConfig := discovery.New(priKey, pubKey) |
|
|
|
leader = candidateNode.GetLeader() |
|
|
|
|
|
|
|
selfPeer = candidateNode.GetSelfPeer() |
|
|
|
err := discoveryConfig.StartClientMode(*idcIP, *idcPort) |
|
|
|
clientPeer = candidateNode.GetClientPeer() |
|
|
|
if err != nil { |
|
|
|
service.Stop() |
|
|
|
fmt.Println("Unable to start peer discovery! ", err) |
|
|
|
selfPeer.PubKey = candidateNode.PubK |
|
|
|
os.Exit(1) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
shardID = discoveryConfig.GetShardID() |
|
|
|
|
|
|
|
leader = discoveryConfig.GetLeader() |
|
|
|
|
|
|
|
peers = discoveryConfig.GetPeers() |
|
|
|
|
|
|
|
selfPeer = discoveryConfig.GetSelfPeer() |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
distributionConfig := utils.NewDistributionConfig() |
|
|
|
distributionConfig := utils.NewDistributionConfig() |
|
|
|
distributionConfig.ReadConfigFile(*configFile) |
|
|
|
distributionConfig.ReadConfigFile(*configFile) |
|
|
|
shardID = distributionConfig.GetShardID(*ip, *port) |
|
|
|
shardID = distributionConfig.GetShardID(*ip, *port) |
|
|
|
peers = distributionConfig.GetPeers(*ip, *port, shardID) |
|
|
|
|
|
|
|
leader = distributionConfig.GetLeader(shardID) |
|
|
|
leader = distributionConfig.GetLeader(shardID) |
|
|
|
selfPeer = distributionConfig.GetSelfPeer(*ip, *port, shardID) |
|
|
|
selfPeer = distributionConfig.GetSelfPeer(*ip, *port, shardID) |
|
|
|
|
|
|
|
_, pubKey := utils.GenKey(*ip, *port) |
|
|
|
|
|
|
|
selfPeer.PubKey = pubKey |
|
|
|
// Create client peer.
|
|
|
|
// Create client peer.
|
|
|
|
clientPeer = distributionConfig.GetClientPeer() |
|
|
|
clientPeer = distributionConfig.GetClientPeer() |
|
|
|
} |
|
|
|
} |
|
|
|
selfPeer.PubKey = pubKey |
|
|
|
fmt.Println(peers, leader, selfPeer, clientPeer, *logFolder, *minPeers) |
|
|
|
|
|
|
|
|
|
|
|
var role string |
|
|
|
var role string |
|
|
|
if leader.IP == *ip && leader.Port == *port { |
|
|
|
if leader.IP == *ip && leader.Port == *port { |
|
|
@ -156,7 +152,6 @@ func main() { |
|
|
|
// Attack determination.
|
|
|
|
// Attack determination.
|
|
|
|
attack.GetInstance().SetAttackEnabled(attackDetermination(*attackedMode)) |
|
|
|
attack.GetInstance().SetAttackEnabled(attackDetermination(*attackedMode)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Init logging.
|
|
|
|
// Init logging.
|
|
|
|
loggingInit(*logFolder, role, *ip, *port, *onlyLogTps) |
|
|
|
loggingInit(*logFolder, role, *ip, *port, *onlyLogTps) |
|
|
|
|
|
|
|
|
|
|
@ -223,7 +218,7 @@ func main() { |
|
|
|
}() |
|
|
|
}() |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if *peerDisvoery { |
|
|
|
if *peerDiscovery { |
|
|
|
go currentNode.JoinShard(leader) |
|
|
|
go currentNode.JoinShard(leader) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|