Merge branch 'master' into move_host_to_p2p_package

pull/289/head
Eugene Kim 6 years ago committed by GitHub
commit 248c0faa53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      cmd/client/txgen/main.go
  2. 23
      cmd/harmony.go
  3. 5
      core/genesis.go
  4. 14
      internal/utils/singleton.go
  5. 13
      node/node.go
  6. 1
      test/deploy.sh
  7. 34
      test/leader_run.sh

@ -165,14 +165,14 @@ func main() {
log.Debug("Client Join Shard", "leader", leader)
clientNode.GetHost().AddPeer(&leader)
go clientNode.JoinShard(leader)
// wait for 3 seconds for client to send ping message to leader
time.Sleep(3 * time.Second)
clientNode.StopPing <- struct{}{}
clientNode.State = node.NodeJoinedShard
}
// wait for 1 seconds for client to send ping message to leader
time.Sleep(time.Second)
clientNode.StopPing <- struct{}{}
clientNode.State = node.NodeJoinedShard
// Transaction generation process
time.Sleep(5 * time.Second) // wait for nodes to be ready
time.Sleep(2 * time.Second) // wait for nodes to be ready
start := time.Now()
totalTime := float64(*duration)

@ -15,10 +15,10 @@ import (
"github.com/harmony-one/harmony/internal/attack"
pkg_newnode "github.com/harmony-one/harmony/internal/newnode"
"github.com/harmony-one/harmony/internal/profiler"
"github.com/harmony-one/harmony/internal/utils"
"github.com/harmony-one/harmony/node"
"github.com/harmony-one/harmony/p2p"
"github.com/harmony-one/harmony/p2p/p2pimpl"
peerstore "github.com/libp2p/go-libp2p-peerstore"
multiaddr "github.com/multiformats/go-multiaddr"
)
@ -48,12 +48,13 @@ func attackDetermination(attackedMode int) bool {
}
// InitLDBDatabase initializes a LDBDatabase.
func InitLDBDatabase(ip string, port string) (*ethdb.LDBDatabase, error) {
// TODO(minhdoan): Refactor this.
dbFileName := "/tmp/harmony_" + ip + port + ".dat"
var err = os.RemoveAll(dbFileName)
if err != nil {
fmt.Println(err.Error())
func InitLDBDatabase(ip string, port string, freshDB bool) (*ethdb.LDBDatabase, error) {
dbFileName := fmt.Sprintf("./db/harmony_%s_%s", ip, port)
if freshDB {
var err = os.RemoveAll(dbFileName)
if err != nil {
fmt.Println(err.Error())
}
}
return ethdb.NewLDBDatabase(dbFileName, 0, 0)
}
@ -82,7 +83,8 @@ func main() {
port := flag.String("port", "9000", "port of the node.")
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")
dbSupported := flag.Bool("db_supported", true, "false means not db_supported, true means db_supported")
freshDB := flag.Bool("fresh_db", false, "true means the existing disk based db will be removed")
profile := flag.Bool("profile", false, "Turn on profiling (CPU, Memory).")
metricsReportURL := flag.String("metrics_report_url", "", "If set, reports metrics to this URL.")
versionFlag := flag.Bool("version", false, "Output version info")
@ -102,6 +104,9 @@ func main() {
printVersion(os.Args[0])
}
// Logging setup
utils.SetPortAndIP(*port, *ip)
// Add GOMAXPROCS to achieve max performance.
runtime.GOMAXPROCS(1024)
@ -164,7 +169,7 @@ func main() {
var ldb *ethdb.LDBDatabase
if *dbSupported {
ldb, _ = InitLDBDatabase(*ip, *port)
ldb, _ = InitLDBDatabase(*ip, *port, *freshDB)
}
host, err := p2pimpl.NewHost(&selfPeer)

@ -23,6 +23,7 @@ import (
"errors"
"fmt"
"math/big"
"os"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
@ -33,6 +34,7 @@ import (
"github.com/harmony-one/harmony/core/rawdb"
"github.com/harmony-one/harmony/core/state"
"github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/internal/utils"
)
//go:generate gencodec -type Genesis -field-override genesisSpecMarshaling -out gen_genesis.go
@ -221,7 +223,8 @@ func (g *Genesis) configOrDefault(ghash common.Hash) *params.ChainConfig {
// to the given database (or discards it if nil).
func (g *Genesis) ToBlock(db ethdb.Database) *types.Block {
if db == nil {
db = ethdb.NewMemDatabase()
utils.GetLogInstance().Error("db should be initialized")
os.Exit(1)
}
statedb, _ := state.New(common.Hash{}, state.NewDatabase(db))
for addr, account := range g.Alloc {

@ -9,6 +9,18 @@ import (
"github.com/ethereum/go-ethereum/log"
)
// Global Port and IP for logging.
var (
Port string
IP string
)
// SetPortAndIP used to print out loggings of node with Port and IP.
func SetPortAndIP(port, ip string) {
Port = port
IP = ip
}
// UniqueValidatorID defines the structure of unique validator ID
type UniqueValidatorID struct {
uniqueID uint32
@ -37,7 +49,7 @@ func (s *UniqueValidatorID) GetUniqueID() uint32 {
// GetLogInstance returns logging singleton.
func GetLogInstance() log.Logger {
onceForLog.Do(func() {
logInstance = log.New()
logInstance = log.New("port", Port, "ip", IP)
})
return logInstance
}

@ -208,7 +208,7 @@ func DeserializeNode(d []byte) *NetworkNode {
}
// New creates a new node.
func New(host p2p.Host, consensus *bft.Consensus, db *ethdb.LDBDatabase) *Node {
func New(host p2p.Host, consensus *bft.Consensus, db ethdb.Database) *Node {
node := Node{}
if host != nil {
@ -217,15 +217,12 @@ func New(host p2p.Host, consensus *bft.Consensus, db *ethdb.LDBDatabase) *Node {
}
// Logger
node.log = log.New()
node.log = log.New("IP", host.GetSelfPeer().IP, "Port", host.GetSelfPeer().Port)
if host != nil && consensus != nil {
// Consensus and associated channel to communicate blocks
node.Consensus = consensus
// Initialize level db.
node.db = db
// Initialize genesis block and blockchain
genesisAlloc := node.CreateGenesisAllocWithTestingAddresses(100)
contractKey, _ := ecdsa.GenerateKey(crypto.S256(), strings.NewReader("Test contract key string stream that is fixed so that generated test key are deterministic every time"))
@ -235,7 +232,11 @@ func New(host p2p.Host, consensus *bft.Consensus, db *ethdb.LDBDatabase) *Node {
genesisAlloc[contractAddress] = core.GenesisAccount{Balance: contractFunds}
node.ContractKeys = append(node.ContractKeys, contractKey)
database := ethdb.NewMemDatabase()
database := db
if database == nil {
database = ethdb.NewMemDatabase()
}
chainConfig := params.TestChainConfig
chainConfig.ChainID = big.NewInt(int64(node.Consensus.ShardID)) // Use ChainID as piggybacked ShardID
gspec := core.Genesis{

@ -24,6 +24,7 @@ function cleanup() {
done
# Remove bc_config.json before starting experiment.
rm -f bc_config.json
rm -rf ./db/harmony_*
}
function killnode() {

@ -0,0 +1,34 @@
#!/bin/bash
ROOT=$(dirname $0)/..
USER=$(whoami)
DRYRUN=
set -x
set -eo pipefail
echo "compiling ..."
go build -o bin/harmony cmd/harmony.go
go build -o bin/beacon cmd/beaconchain/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
LOG_FILE=$log_folder/r.log
rm -f bc_config.json
echo "launching beacon chain ..."
$DRYRUN $ROOT/bin/beacon -numShards 3 > $log_folder/beacon.log 2>&1 | tee -a $LOG_FILE &
sleep 2 #waiting for beaconchain
MA=$(grep "Beacon Chain Started" $log_folder/beacon.log | awk -F: ' { print $2 } ')
if [ -n "$MA" ]; then
HMY_OPT="-bc_addr $MA"
fi
DB='-db_supported'
$ROOT/bin/harmony -ip 127.0.0.1 -port 9000 -log_folder $log_folder $DB -min_peers 0 $HMY_OPT 2>&1 | tee -a $LOG_FILE &
Loading…
Cancel
Save