Skip to content

Commit

Permalink
# This is a combination of 16 commits.
Browse files Browse the repository at this point in the history
# This is the 1st commit message:

Fix travis

# This is the commit message harmony-one#2:

[cleanup] remove is_genesis flag

Signed-off-by: Leo Chen <leo@harmony.one>

# This is the commit message harmony-one#3:

[nodetype] add nodetype to replace is_explorer

Signed-off-by: Leo Chen <leo@harmony.one>

# This is the commit message harmony-one#4:

fix beacon sync channel blocking issue

# This is the commit message harmony-one#5:

use lastMileMux to protect lastMileBlock queue to avoid potential blocking; use sleep instead of ticker

# This is the commit message harmony-one#6:

Fix the beacon committee check

# This is the commit message harmony-one#7:

[release] add release action to go_executable_build.sh

Signed-off-by: Leo Chen <leo@harmony.one>

# This is the commit message harmony-one#8:

[node.sh] add -d option

-d              download only

Signed-off-by: Leo Chen <leo@harmony.one>

# This is the commit message harmony-one#9:

[node.sh] add -T node_type option

-T node_type       support node type (validator/explorer)

Signed-off-by: Leo Chen <leo@harmony.one>

# This is the commit message harmony-one#10:

[node.sh] backward compatible with older harmony binary

Signed-off-by: Leo Chen <leo@harmony.one>

# This is the commit message harmony-one#11:

[node.sh] support -i shard_id option

-i shard_id             specify shard_id, this is applicable only to
explorer node

Signed-off-by: Leo Chen <leo@harmony.one>

# This is the commit message harmony-one#12:

Revisited api

# This is the commit message harmony-one#13:

Fix rpc integration

# This is the commit message harmony-one#14:

address some minor issues in comments and code

# This is the commit message harmony-one#15:

addressed comments on others' buckets

# This is the commit message harmony-one#16:

Add Global Access to OS Temp Directory Variable and Move DHT Files Into Temp Directory
  • Loading branch information
flicker-harmony committed Sep 17, 2019
1 parent 8982926 commit 49b94e7
Show file tree
Hide file tree
Showing 16 changed files with 422 additions and 275 deletions.
240 changes: 136 additions & 104 deletions api/service/explorer/service.go

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion api/service/networkinfo/service.go
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/ethereum/go-ethereum/rpc"
msg_pb "github.com/harmony-one/harmony/api/proto/message"
nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
"github.com/harmony-one/harmony/internal/utils"
"github.com/harmony-one/harmony/p2p"
badger "github.com/ipfs/go-ds-badger"
Expand Down Expand Up @@ -60,7 +61,7 @@ const (
func New(h p2p.Host, rendezvous p2p.GroupID, peerChan chan p2p.Peer, bootnodes utils.AddrList) *Service {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(context.Background(), connectionTimeout)
dataStore, err := badger.NewDatastore(fmt.Sprintf(".dht-%s-%s", h.GetSelfPeer().IP, h.GetSelfPeer().Port), nil)
dataStore, err := badger.NewDatastore(fmt.Sprintf("%s/.dht-%s-%s", nodeconfig.GetTempDir(), h.GetSelfPeer().IP, h.GetSelfPeer().Port), nil)
if err != nil {
panic(err)
}
Expand Down
10 changes: 8 additions & 2 deletions api/service/syncing/syncing.go
Expand Up @@ -32,6 +32,7 @@ const (
inSyncThreshold = 0 // when peerBlockHeight - myBlockHeight <= inSyncThreshold, it's ready to join consensus
BatchSize uint32 = 1000 //maximum size for one query of block hashes
SyncLoopFrequency = 1 // unit in second
LastMileBlocksSize = 10
)

// SyncPeerConfig is peer config to sync.
Expand Down Expand Up @@ -105,6 +106,7 @@ type StateSync struct {
syncConfig *SyncConfig
stateSyncTaskQueue *queue.Queue
syncMux sync.Mutex
lastMileMux sync.Mutex
}

func (ss *StateSync) purgeAllBlocksFromCache() {
Expand All @@ -130,9 +132,13 @@ func (ss *StateSync) purgeOldBlocksFromCache() {
}

// AddLastMileBlock add the lastest a few block into queue for syncing
// only keep the latest blocks with size capped by LastMileBlocksSize
func (ss *StateSync) AddLastMileBlock(block *types.Block) {
ss.syncMux.Lock()
defer ss.syncMux.Unlock()
ss.lastMileMux.Lock()
defer ss.lastMileMux.Unlock()
if len(ss.lastMileBlocks) >= LastMileBlocksSize {
ss.lastMileBlocks = ss.lastMileBlocks[1:]
}
ss.lastMileBlocks = append(ss.lastMileBlocks, block)
}

Expand Down
35 changes: 22 additions & 13 deletions cmd/harmony/main.go
Expand Up @@ -42,7 +42,7 @@ var (
commit string
)

// InitLDBDatabase initializes a LDBDatabase. isGenesis=true will return the beacon chain database for normal shard nodes
// InitLDBDatabase initializes a LDBDatabase. will return the beacon chain database for normal shard nodes
func InitLDBDatabase(ip string, port string, freshDB bool, isBeacon bool) (*ethdb.LDBDatabase, error) {
var dbFileName string
if isBeacon {
Expand Down Expand Up @@ -80,14 +80,12 @@ var (
minPeers = flag.Int("min_peers", 32, "Minimal number of Peers in shard")
// Key file to store the private key
keyFile = flag.String("key", "./.hmykey", "the p2p key file of the harmony node")
// isGenesis indicates this node is a genesis node
isGenesis = flag.Bool("is_genesis", true, "true means this node is a genesis node")
// isArchival indicates this node is an archival node that will save and archive current blockchain
isArchival = flag.Bool("is_archival", true, "false makes node faster by turning caching off")
// delayCommit is the commit-delay timer, used by Harmony nodes
delayCommit = flag.String("delay_commit", "0ms", "how long to delay sending commit messages in consensus, ex: 500ms, 1s")
// isExplorer indicates this node is a node to serve explorer
isExplorer = flag.Bool("is_explorer", false, "true means this node is a node to serve explorer")
// nodeType indicates the type of the node: validator, explorer
nodeType = flag.String("node_type", "validator", "node type: validator, explorer")
// networkType indicates the type of the network
networkType = flag.String("network_type", "mainnet", "type of the network: mainnet, testnet, devnet, localnet")
// blockPeriod indicates the how long the leader waits to propose a new block.
Expand Down Expand Up @@ -170,9 +168,11 @@ func initSetup() {

func passphraseForBls() {
// If FN node running, they should either specify blsPrivateKey or the file with passphrase
if *isExplorer {
// However, explorer or non-validator nodes need no blskey
if *nodeType != "validator" {
return
}

if *blsKeyFile == "" || *blsPass == "" {
fmt.Println("Internal nodes need to have pass to decrypt blskey")
os.Exit(101)
Expand Down Expand Up @@ -233,7 +233,7 @@ func createGlobalConfig() *nodeconfig.ConfigType {
var err error

nodeConfig := nodeconfig.GetShardConfig(initialAccount.ShardID)
if !*isExplorer {
if *nodeType == "validator" {
// Set up consensus keys.
setupConsensusKey(nodeConfig)
} else {
Expand Down Expand Up @@ -336,17 +336,17 @@ func setupConsensusAndNode(nodeConfig *nodeconfig.ConfigType) *node.Node {

currentNode.NodeConfig.SetBeaconGroupID(p2p.NewGroupIDByShardID(0))

if *isExplorer {
switch *nodeType {
case "explorer":
currentNode.NodeConfig.SetRole(nodeconfig.ExplorerNode)
currentNode.NodeConfig.SetShardGroupID(p2p.NewGroupIDByShardID(p2p.ShardID(*shardID)))
currentNode.NodeConfig.SetClientGroupID(p2p.NewClientGroupIDByShardID(p2p.ShardID(*shardID)))
} else {
case "validator":
currentNode.NodeConfig.SetRole(nodeconfig.Validator)
if nodeConfig.ShardID == 0 {
currentNode.NodeConfig.SetRole(nodeconfig.Validator)
currentNode.NodeConfig.SetShardGroupID(p2p.GroupIDBeacon)
currentNode.NodeConfig.SetClientGroupID(p2p.GroupIDBeaconClient)
} else {
currentNode.NodeConfig.SetRole(nodeconfig.Validator)
currentNode.NodeConfig.SetShardGroupID(p2p.NewGroupIDByShardID(p2p.ShardID(nodeConfig.ShardID)))
currentNode.NodeConfig.SetClientGroupID(p2p.NewClientGroupIDByShardID(p2p.ShardID(nodeConfig.ShardID)))
}
Expand Down Expand Up @@ -397,6 +397,15 @@ func main() {
flag.Var(&utils.BootNodes, "bootnodes", "a list of bootnode multiaddress (delimited by ,)")
flag.Parse()

switch *nodeType {
case "validator":
case "explorer":
break
default:
fmt.Fprintf(os.Stderr, "Unknown node type: %s\n", *nodeType)
os.Exit(1)
}

nodeconfig.SetVersion(fmt.Sprintf("Harmony (C) 2019. %v, version %v-%v (%v %v)", path.Base(os.Args[0]), version, commit, builtBy, builtAt))
if *versionFlag {
printVersion()
Expand Down Expand Up @@ -433,7 +442,7 @@ func main() {
memprofiling.MaybeCallGCPeriodically()
}

if !*isExplorer {
if *nodeType == "validator" {
setupInitialAccount()
}

Expand All @@ -454,7 +463,7 @@ func main() {
}

startMsg := "==== New Harmony Node ===="
if *isExplorer {
if *nodeType == "explorer" {
startMsg = "==== New Explorer Node ===="
}

Expand Down
1 change: 1 addition & 0 deletions hmy/api_backend.go
Expand Up @@ -246,6 +246,7 @@ func (b *APIBackend) ResendCx(ctx context.Context, txID common.Hash) (uint64, bo
return 0, false
}
tx := txs[int(index)]
// check whether it is a valid cross shard tx
if tx.ShardID() == tx.ToShardID() || blk.Header().ShardID() != tx.ShardID() {
return 0, false
}
Expand Down
6 changes: 6 additions & 0 deletions internal/configs/node/config.go
Expand Up @@ -7,6 +7,7 @@ import (
"crypto/ecdsa"
"errors"
"fmt"
"os"
"sync"

"github.com/harmony-one/bls/ffi/go/bls"
Expand Down Expand Up @@ -246,3 +247,8 @@ func SetVersion(ver string) {
func GetVersion() string {
return version
}

// GetTempDir return temporary directory
func GetTempDir() string {
return os.TempDir()
}
5 changes: 5 additions & 0 deletions node/node.go
Expand Up @@ -569,3 +569,8 @@ func (node *Node) initNodeConfiguration() (service.NodeConfig, chan p2p.Peer) {
func (node *Node) AccountManager() *accounts.Manager {
return node.accountManager
}

// ServiceManager ...
func (node *Node) ServiceManager() *service.Manager {
return node.serviceManager
}
2 changes: 1 addition & 1 deletion node/node_cross_shard.go
Expand Up @@ -91,7 +91,7 @@ func (node *Node) BroadcastMissingCXReceipts() {
}
sig := nextHeader.LastCommitSignature()
bitmap := nextHeader.LastCommitBitmap()
go node.BroadcastCXReceiptsWithShardID(blk, sig[:], bitmap, toShardID)
node.BroadcastCXReceiptsWithShardID(blk, sig[:], bitmap, toShardID)
}
node.CxPool.Clear()
// this should not happen or maybe happen for impatient user
Expand Down
5 changes: 2 additions & 3 deletions node/node_handler.go
Expand Up @@ -165,9 +165,7 @@ func (node *Node) messageHandler(content []byte, sender libp2p_peer.ID) {
Msg("block sync")
} else {
// for non-beaconchain node, subscribe to beacon block broadcast
role := node.NodeConfig.Role()
if role == nodeconfig.Validator {

if node.Blockchain().ShardID() != 0 {
for _, block := range blocks {
if block.ShardID() == 0 {
utils.Logger().Info().
Expand Down Expand Up @@ -392,6 +390,7 @@ func (node *Node) PostConsensusProcessing(newBlock *types.Block, commitSigAndBit
}
}

// Broadcast client requested missing cross shard receipts if there is any
node.BroadcastMissingCXReceipts()

// TODO chao: uncomment this after beacon syncing is stable
Expand Down

0 comments on commit 49b94e7

Please sign in to comment.