Merge pull request #1248 from chaosma/initial-shard-setup

Initial shard setup using latest epoch information
pull/1274/head
chaosma 5 years ago committed by GitHub
commit e106ac035f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      api/service/syncing/downloader/client.go
  2. 3
      api/service/syncing/downloader/interface.go
  3. 11
      api/service/syncing/downloader/server.go
  4. 14
      api/service/syncing/syncing.go
  5. 1
      cmd/client/txgen/main.go
  6. 114
      cmd/harmony/main.go
  7. 2
      consensus/consensus_v2.go
  8. 30
      internal/configs/node/config.go
  9. 19
      internal/configs/node/config_test.go
  10. 4
      internal/configs/sharding/localnet.go
  11. 62
      node/node.go
  12. 21
      node/node_handler.go
  13. 4
      node/node_syncing.go
  14. 59
      node/service_setup.go
  15. 20
      test/configs/local-resharding.txt
  16. 7
      test/deploy.sh

@ -41,10 +41,12 @@ func (client *Client) Close() {
}
// GetBlockHashes gets block hashes from all the peers by calling grpc request.
func (client *Client) GetBlockHashes(startHash []byte, size uint32) *pb.DownloaderResponse {
func (client *Client) GetBlockHashes(startHash []byte, size uint32, ip, port string) *pb.DownloaderResponse {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
request := &pb.DownloaderRequest{Type: pb.DownloaderRequest_HEADER, BlockHash: startHash, Size: size}
request.Ip = ip
request.Port = port
response, err := client.dlClient.Query(ctx, request)
if err != nil {
utils.Logger().Error().Err(err).Msg("[SYNC] GetBlockHashes query failed")
@ -109,13 +111,13 @@ func (client *Client) PushNewBlock(selfPeerHash [20]byte, blockHash []byte, time
}
// GetBlockChainHeight gets the blockheight from peer
func (client *Client) GetBlockChainHeight() *pb.DownloaderResponse {
func (client *Client) GetBlockChainHeight() (*pb.DownloaderResponse, error) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
request := &pb.DownloaderRequest{Type: pb.DownloaderRequest_BLOCKHEIGHT}
response, err := client.dlClient.Query(ctx, request)
if err != nil {
utils.Logger().Error().Err(err).Msg("[SYNC] unable to get blockchain height")
return nil, err
}
return response
return response, nil
}

@ -7,5 +7,6 @@ import (
// DownloadInterface is the interface for downloader package.
type DownloadInterface interface {
// State Syncing server-side interface, responsible for all kinds of state syncing grpc calls
CalculateResponse(request *pb.DownloaderRequest) (*pb.DownloaderResponse, error)
// incomingPeer is incoming peer ip:port information
CalculateResponse(request *pb.DownloaderRequest, incomingPeer string) (*pb.DownloaderResponse, error)
}

@ -9,6 +9,7 @@ import (
"github.com/harmony-one/harmony/internal/utils"
"google.golang.org/grpc"
"google.golang.org/grpc/peer"
)
// Constants for downloader server.
@ -24,7 +25,15 @@ type Server struct {
// Query returns the feature at the given point.
func (s *Server) Query(ctx context.Context, request *pb.DownloaderRequest) (*pb.DownloaderResponse, error) {
response, err := s.downloadInterface.CalculateResponse(request)
var pinfo string
// retrieve ip/port information; used for debug only
p, ok := peer.FromContext(ctx)
if !ok {
pinfo = ""
} else {
pinfo = p.Addr.String()
}
response, err := s.downloadInterface.CalculateResponse(request, pinfo)
if err != nil {
return nil, err
}

@ -334,8 +334,12 @@ func (ss *StateSync) GetConsensusHashes(startHash []byte, size uint32) bool {
wg.Add(1)
go func() {
defer wg.Done()
response := peerConfig.client.GetBlockHashes(startHash, size)
response := peerConfig.client.GetBlockHashes(startHash, size, ss.selfip, ss.selfport)
if response == nil {
utils.Logger().Warn().
Str("peer IP", peerConfig.ip).
Str("peer Port", peerConfig.port).
Msg("[SYNC] GetConsensusHashes Nil Response")
return
}
if len(response.Payload) > int(size+1) {
@ -677,8 +681,12 @@ func (ss *StateSync) getMaxPeerHeight() uint64 {
go func() {
defer wg.Done()
//debug
// utils.Logger().Warn().Str("IP", peerConfig.ip).Str("Port", peerConfig.port).Msg("[Sync] getMaxPeerHeight")
response := peerConfig.client.GetBlockChainHeight()
// utils.Logger().Warn().Str("IP", peerConfig.ip).Str("Port", peerConfig.port).Msg("[Sync]getMaxPeerHeight")
response, err := peerConfig.client.GetBlockChainHeight()
if err != nil {
utils.Logger().Warn().Err(err).Str("IP", peerConfig.ip).Str("Port", peerConfig.port).Msg("[Sync]GetBlockChainHeight failed")
return
}
ss.syncMux.Lock()
if response != nil && maxHeight < response.BlockHeight {
maxHeight = response.BlockHeight

@ -119,7 +119,6 @@ func setUpTXGen() *node.Node {
}
txGen.NodeConfig.SetRole(nodeconfig.ClientNode)
if shardID == 0 {
txGen.NodeConfig.SetIsBeacon(true)
txGen.NodeConfig.SetShardGroupID(p2p.GroupIDBeacon)
} else {
txGen.NodeConfig.SetShardGroupID(p2p.NewGroupIDByShardID(p2p.ShardID(shardID)))

@ -88,9 +88,7 @@ var (
// 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.
blockPeriod = flag.Int("block_period", 8, "how long in second the leader waits to propose a new block.")
// isNewNode indicates this node is a new node
isNewNode = flag.Bool("is_newnode", false, "true means this node is a new node")
blockPeriod = flag.Int("block_period", 8, "how long in second the leader waits to propose a new block.")
leaderOverride = flag.Bool("leader_override", false, "true means override the default leader role and acts as validator")
// shardID indicates the shard ID of this node
shardID = flag.Int("shard_id", -1, "the shard ID of this node")
@ -110,7 +108,7 @@ var (
keystoreDir = flag.String("keystore", hmykey.DefaultKeyStoreDir, "The default keystore directory")
genesisAccount = &genesis.DeployAccount{}
initialAccount = &genesis.DeployAccount{}
// logging verbosity
verbosity = flag.Int("verbosity", 5, "Logging verbosity: 0=silent, 1=error, 2=warn, 3=info, 4=debug, 5=detail (default: 5)")
@ -176,34 +174,34 @@ func passphraseForBls() {
blsPassphrase = passphrase
}
func setupGenesisAccount() (isLeader bool) {
func setupInitialAccount() (isLeader bool) {
genesisShardingConfig := core.ShardingSchedule.InstanceForEpoch(big.NewInt(core.GenesisEpoch))
pubKey := setUpConsensusKey(nodeconfig.GetDefaultConfig())
pubKey := setupConsensusKey(nodeconfig.GetDefaultConfig())
reshardingEpoch := genesisShardingConfig.ReshardingEpoch()
if reshardingEpoch != nil && len(reshardingEpoch) > 0 {
for _, epoch := range reshardingEpoch {
config := core.ShardingSchedule.InstanceForEpoch(epoch)
isLeader, genesisAccount = config.FindAccount(pubKey.SerializeToHexStr())
if genesisAccount != nil {
isLeader, initialAccount = config.FindAccount(pubKey.SerializeToHexStr())
if initialAccount != nil {
break
}
}
} else {
isLeader, genesisAccount = genesisShardingConfig.FindAccount(pubKey.SerializeToHexStr())
isLeader, initialAccount = genesisShardingConfig.FindAccount(pubKey.SerializeToHexStr())
}
if genesisAccount == nil {
if initialAccount == nil {
fmt.Printf("cannot find your BLS key in the genesis/FN tables: %s\n", pubKey.SerializeToHexStr())
os.Exit(100)
}
fmt.Printf("My Genesis Account: %v\n", *genesisAccount)
fmt.Printf("My Genesis Account: %v\n", *initialAccount)
return isLeader
}
func setUpConsensusKey(nodeConfig *nodeconfig.ConfigType) *bls.PublicKey {
func setupConsensusKey(nodeConfig *nodeconfig.ConfigType) *bls.PublicKey {
consensusPriKey, err := blsgen.LoadBlsKeyWithPassPhrase(*blsKeyFile, blsPassphrase)
if err != nil {
fmt.Printf("error when loading bls key, err :%v\n", err)
@ -220,13 +218,13 @@ func setUpConsensusKey(nodeConfig *nodeconfig.ConfigType) *bls.PublicKey {
return pubKey
}
func createGlobalConfig(isLeader bool) *nodeconfig.ConfigType {
func createGlobalConfig() *nodeconfig.ConfigType {
var err error
nodeConfig := nodeconfig.GetShardConfig(genesisAccount.ShardID)
nodeConfig := nodeconfig.GetShardConfig(initialAccount.ShardID)
if !*isExplorer {
// Set up consensus keys.
setUpConsensusKey(nodeConfig)
setupConsensusKey(nodeConfig)
} else {
nodeConfig.ConsensusPriKey = &bls.SecretKey{} // set dummy bls key for consensus object
}
@ -252,13 +250,6 @@ func createGlobalConfig(isLeader bool) *nodeconfig.ConfigType {
}
nodeConfig.SelfPeer = p2p.Peer{IP: *ip, Port: *port, ConsensusPubKey: nodeConfig.ConsensusPubKey}
if isLeader && !*isExplorer && !*leaderOverride { // The first node in a shard is the leader at genesis
nodeConfig.Leader = nodeConfig.SelfPeer
nodeConfig.StringRole = "leader"
} else {
nodeConfig.StringRole = "validator"
}
nodeConfig.Host, err = p2pimpl.NewHost(&nodeConfig.SelfPeer, nodeConfig.P2pPriKey)
if *logConn && nodeConfig.GetNetworkType() != nodeconfig.Mainnet {
nodeConfig.Host.GetP2PHost().Network().Notify(utils.NewConnLogger(utils.GetLogInstance()))
@ -267,22 +258,17 @@ func createGlobalConfig(isLeader bool) *nodeconfig.ConfigType {
panic("unable to new host in harmony")
}
if err := nodeConfig.Host.AddPeer(&nodeConfig.Leader); err != nil {
ctxerror.Warn(utils.GetLogger(), err, "(*p2p.Host).AddPeer failed",
"peer", &nodeConfig.Leader)
}
nodeConfig.DBDir = *dbDir
return nodeConfig
}
func setUpConsensusAndNode(nodeConfig *nodeconfig.ConfigType) *node.Node {
func setupConsensusAndNode(nodeConfig *nodeconfig.ConfigType) *node.Node {
// Consensus object.
// TODO: consensus object shouldn't start here
// TODO(minhdoan): During refactoring, found out that the peers list is actually empty. Need to clean up the logic of consensus later.
currentConsensus, err := consensus.New(nodeConfig.Host, nodeConfig.ShardID, nodeConfig.Leader, nodeConfig.ConsensusPriKey)
currentConsensus.SelfAddress = common.ParseAddr(genesisAccount.Address)
currentConsensus.SelfAddress = common.ParseAddr(initialAccount.Address)
if err != nil {
fmt.Fprintf(os.Stderr, "Error :%v \n", err)
@ -296,10 +282,6 @@ func setUpConsensusAndNode(nodeConfig *nodeconfig.ConfigType) *node.Node {
currentConsensus.SetCommitDelay(commitDelay)
currentConsensus.MinPeers = *minPeers
if *isNewNode {
currentConsensus.SetMode(consensus.Listening)
}
if *disableViewChange {
currentConsensus.DisableViewChangeForTestingOnly()
}
@ -312,7 +294,6 @@ func setUpConsensusAndNode(nodeConfig *nodeconfig.ConfigType) *node.Node {
} else if *dnsFlag {
currentNode.SetDNSZone("t.hmny.io")
}
currentNode.NodeConfig.SetRole(nodeconfig.NewNode)
// TODO: add staking support
// currentNode.StakingAccount = myAccount
utils.GetLogInstance().Info("node account set",
@ -321,45 +302,21 @@ func setUpConsensusAndNode(nodeConfig *nodeconfig.ConfigType) *node.Node {
// TODO: refactor the creation of blockchain out of node.New()
currentConsensus.ChainReader = currentNode.Blockchain()
// TODO: the setup should only based on shard state
if *isGenesis {
// TODO: need change config file and use switch instead of complicated "if else" condition
if nodeConfig.ShardID == 0 { // Beacon chain
nodeConfig.SetIsBeacon(true)
if nodeConfig.StringRole == "leader" {
currentNode.NodeConfig.SetRole(nodeconfig.BeaconLeader)
} else {
currentNode.NodeConfig.SetRole(nodeconfig.BeaconValidator)
}
if *isExplorer {
currentNode.NodeConfig.SetRole(nodeconfig.ExplorerNode)
currentNode.NodeConfig.SetShardGroupID(p2p.NewGroupIDByShardID(p2p.ShardID(*shardID)))
currentNode.NodeConfig.SetClientGroupID(p2p.NewClientGroupIDByShardID(p2p.ShardID(*shardID)))
} else {
if nodeConfig.ShardID == 0 {
currentNode.NodeConfig.SetRole(nodeconfig.Validator)
currentNode.NodeConfig.SetShardGroupID(p2p.GroupIDBeacon)
currentNode.NodeConfig.SetClientGroupID(p2p.GroupIDBeaconClient)
} else {
if nodeConfig.StringRole == "leader" {
currentNode.NodeConfig.SetRole(nodeconfig.ShardLeader)
} else {
currentNode.NodeConfig.SetRole(nodeconfig.ShardValidator)
}
currentNode.NodeConfig.SetRole(nodeconfig.Validator)
currentNode.NodeConfig.SetShardGroupID(p2p.NewGroupIDByShardID(p2p.ShardID(nodeConfig.ShardID)))
currentNode.NodeConfig.SetClientGroupID(p2p.NewClientGroupIDByShardID(p2p.ShardID(nodeConfig.ShardID)))
}
} else {
if *isNewNode {
if nodeConfig.ShardID == 0 { // Beacon chain
nodeConfig.SetIsBeacon(true)
currentNode.NodeConfig.SetRole(nodeconfig.BeaconValidator)
currentNode.NodeConfig.SetShardGroupID(p2p.GroupIDBeacon)
currentNode.NodeConfig.SetClientGroupID(p2p.GroupIDBeaconClient)
} else {
currentNode.NodeConfig.SetRole(nodeconfig.ShardValidator)
currentNode.NodeConfig.SetShardGroupID(p2p.NewGroupIDByShardID(p2p.ShardID(nodeConfig.ShardID)))
currentNode.NodeConfig.SetClientGroupID(p2p.NewClientGroupIDByShardID(p2p.ShardID(nodeConfig.ShardID)))
}
}
if *isExplorer {
currentNode.NodeConfig.SetRole(nodeconfig.ExplorerNode)
currentNode.NodeConfig.SetShardGroupID(p2p.NewGroupIDByShardID(p2p.ShardID(*shardID)))
currentNode.NodeConfig.SetClientGroupID(p2p.NewClientGroupIDByShardID(p2p.ShardID(*shardID)))
}
}
currentNode.NodeConfig.ConsensusPubKey = nodeConfig.ConsensusPubKey
currentNode.NodeConfig.ConsensusPriKey = nodeConfig.ConsensusPriKey
@ -375,12 +332,9 @@ func setUpConsensusAndNode(nodeConfig *nodeconfig.ConfigType) *node.Node {
// currentNode.DRand = dRand
// This needs to be executed after consensus and drand are setup
if !*isNewNode || *shardID > -1 { // initial staking new node doesn't need to initialize shard state
// TODO: Have a better way to distinguish non-genesis node
if err := currentNode.InitShardState(*shardID == -1 && !*isNewNode); err != nil {
ctxerror.Crit(utils.GetLogger(), err, "InitShardState failed",
"shardID", *shardID, "isNewNode", *isNewNode)
}
if err := currentNode.InitShardState(); err != nil {
ctxerror.Crit(utils.GetLogger(), err, "InitShardState failed",
"shardID", *shardID)
}
// Set the consensus ID to be the current block number
@ -438,17 +392,17 @@ func main() {
memprofiling.MaybeCallGCPeriodically()
}
isLeader := false
if !*isExplorer { // Explorer node doesn't need the following setup
isLeader = setupGenesisAccount()
if !*isExplorer {
setupInitialAccount()
}
if *shardID >= 0 {
utils.GetLogInstance().Info("ShardID Override", "original", genesisAccount.ShardID, "override", *shardID)
genesisAccount.ShardID = uint32(*shardID)
utils.GetLogInstance().Info("ShardID Override", "original", initialAccount.ShardID, "override", *shardID)
initialAccount.ShardID = uint32(*shardID)
}
nodeConfig := createGlobalConfig(isLeader)
currentNode := setUpConsensusAndNode(nodeConfig)
nodeConfig := createGlobalConfig()
currentNode := setupConsensusAndNode(nodeConfig)
//if consensus.ShardID != 0 {
// go currentNode.SupportBeaconSyncing()

@ -792,7 +792,7 @@ func (consensus *Consensus) onCommitted(msg *msg_pb.Message) {
consensus.getLogger().Info().Msg("[OnCommitted] PublicKeys is Empty, Cannot update public keys")
return
}
consensus.getLogger().Info().Int("numKeys", len(pubKeys)).Msg("[OnCommitted] Update Shard Info and PublicKeys")
consensus.getLogger().Info().Int("numKeys", len(pubKeys)).Msg("[OnCommitted] Try to Update Shard Info and PublicKeys")
for _, key := range pubKeys {
if key.IsEqual(consensus.PubKey) {

@ -21,11 +21,7 @@ type Role byte
// All constants for different node roles.
const (
Unknown Role = iota
ShardLeader
ShardValidator
BeaconLeader
BeaconValidator
NewNode
Validator
ClientNode
WalletNode
ExplorerNode
@ -35,16 +31,8 @@ func (role Role) String() string {
switch role {
case Unknown:
return "Unknown"
case ShardLeader:
return "ShardLeader"
case ShardValidator:
return "ShardValidator"
case BeaconLeader:
return "BeaconLeader"
case BeaconValidator:
return "BeaconValidator"
case NewNode:
return "NewNode"
case Validator:
return "Validator"
case ClientNode:
return "ClientNode"
case WalletNode:
@ -145,7 +133,7 @@ func GetDefaultConfig() *ConfigType {
}
func (conf *ConfigType) String() string {
return fmt.Sprintf("%s/%s/%s:%v,%v,%v", conf.beacon, conf.group, conf.client, conf.isClient, conf.IsBeacon(), conf.ShardID)
return fmt.Sprintf("%s/%s/%s:%v,%v", conf.beacon, conf.group, conf.client, conf.isClient, conf.ShardID)
}
// SetBeaconGroupID set the groupID for beacon group
@ -168,11 +156,6 @@ func (conf *ConfigType) SetIsClient(b bool) {
conf.isClient = b
}
// SetIsBeacon sets the isBeacon configuration
func (conf *ConfigType) SetIsBeacon(b bool) {
conf.isBeacon = b
}
// SetShardID set the ShardID
func (conf *ConfigType) SetShardID(s uint32) {
conf.ShardID = s
@ -203,11 +186,6 @@ func (conf *ConfigType) IsClient() bool {
return conf.isClient
}
// IsBeacon returns the isBeacon configuration
func (conf *ConfigType) IsBeacon() bool {
return conf.isBeacon
}
// Role returns the role
func (conf *ConfigType) Role() Role {
return conf.role

@ -26,7 +26,6 @@ func TestNodeConfigSingleton(t *testing.T) {
func TestNodeConfigMultiple(t *testing.T) {
// init 3 configs
c := GetShardConfig(2)
d := GetShardConfig(1)
e := GetShardConfig(0)
f := GetShardConfig(42)
@ -35,16 +34,6 @@ func TestNodeConfigMultiple(t *testing.T) {
t.Errorf("expecting nil, got: %v", f)
}
if c.IsBeacon() != false {
t.Errorf("expecting the node to not be beacon yet, got: %v", c.IsBeacon())
}
c.SetIsBeacon(true)
if c.IsBeacon() != true {
t.Errorf("expecting the node to be beacon, got: %v", c.IsBeacon())
}
d.SetShardGroupID("abcd")
if d.GetShardGroupID() != "abcd" {
t.Errorf("expecting abcd, got: %v", d.GetShardGroupID())
@ -59,12 +48,4 @@ func TestNodeConfigMultiple(t *testing.T) {
if e.IsClient() != false {
t.Errorf("expecting false, got: %v", e.IsClient())
}
c.SetRole(NewNode)
if c.Role() != NewNode {
t.Errorf("expecting NewNode, got: %s", c.Role())
}
if c.Role().String() != "NewNode" {
t.Errorf("expecting NewNode, got: %s", c.Role().String())
}
}

@ -16,8 +16,8 @@ const (
localnetV1Epoch = 1
localnetV2Epoch = 2
localnetEpochBlock1 = 36
twoOne = 11
localnetEpochBlock1 = 10
twoOne = 5
)
func (localnetSchedule) InstanceForEpoch(epoch *big.Int) Instance {

@ -2,15 +2,11 @@ package node
import (
"crypto/ecdsa"
"encoding/hex"
"fmt"
"math/big"
"sync"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
"github.com/harmony-one/bls/ffi/go/bls"
"github.com/harmony-one/harmony/accounts"
"github.com/harmony-one/harmony/api/client"
clientService "github.com/harmony-one/harmony/api/client/service"
@ -391,46 +387,41 @@ func New(host p2p.Host, consensusObj *consensus.Consensus, chainDBFactory shardc
return &node
}
// InitShardState initialize genesis shard state and update committee pub keys for consensus and drand
func (node *Node) InitShardState(isGenesis bool) (err error) {
logger := utils.GetLogInstance().New("isGenesis", isGenesis)
getLogger := func() log.Logger { return utils.WithCallerSkip(logger, 1) }
// InitShardState initialize shard state from latest epoch and update committee pub keys for consensus and drand
func (node *Node) InitShardState() (err error) {
if node.Consensus == nil {
getLogger().Crit("consensus is nil; cannot figure out shard ID")
return ctxerror.New("[InitShardState] consenus is nil; Cannot figure out shardID")
}
shardID := node.Consensus.ShardID
logger = logger.New("shardID", shardID)
getLogger().Info("initializing shard state")
// Get genesis epoch shard state from chain
genesisEpoch := big.NewInt(core.GenesisEpoch)
shardState, err := node.Beaconchain().GetShardState(genesisEpoch, nil)
if err != nil {
return ctxerror.New("cannot read genesis shard state").WithCause(err)
blockNum := node.Blockchain().CurrentBlock().NumberU64()
node.Consensus.SetMode(consensus.Listening)
epoch := core.ShardingSchedule.CalcEpochNumber(blockNum)
utils.Logger().Info().
Uint64("blockNum", blockNum).
Uint32("shardID", shardID).
Uint64("epoch", epoch.Uint64()).
Msg("[InitShardState] Try To Get PublicKeys from database")
pubKeys := core.GetPublicKeys(epoch, shardID)
if len(pubKeys) == 0 {
return ctxerror.New(
"[InitShardState] PublicKeys is Empty, Cannot update public keys",
"shardID", shardID,
"blockNum", blockNum)
}
getLogger().Info("Successfully loaded epoch shard state")
// Update validator public keys
committee := shardState.FindCommitteeByID(shardID)
if committee == nil {
return ctxerror.New("our shard is not found in genesis shard state",
"shardID", shardID)
}
pubKeys := []*bls.PublicKey{}
for _, node := range committee.NodeList {
pubKey := &bls.PublicKey{}
pubKeyBytes := node.BlsPublicKey[:]
err = pubKey.Deserialize(pubKeyBytes)
if err != nil {
return ctxerror.New("cannot deserialize BLS public key",
"shardID", shardID,
"pubKeyBytes", hex.EncodeToString(pubKeyBytes),
).WithCause(err)
for _, key := range pubKeys {
if key.IsEqual(node.Consensus.PubKey) {
utils.Logger().Info().
Uint64("blockNum", blockNum).
Int("numPubKeys", len(pubKeys)).
Msg("[InitShardState] Successfully updated public keys")
node.Consensus.UpdatePublicKeys(pubKeys)
node.Consensus.SetMode(consensus.Normal)
return nil
}
pubKeys = append(pubKeys, pubKey)
}
getLogger().Info("initialized shard state", "numPubKeys", len(pubKeys))
node.Consensus.UpdatePublicKeys(pubKeys)
// TODO: Disable drand. Currently drand isn't functioning but we want to compeletely turn it off for full protection.
// node.DRand.UpdatePublicKeys(pubKeys)
return nil
@ -475,7 +466,6 @@ func (node *Node) initNodeConfiguration() (service.NodeConfig, chan p2p.Peer) {
chanPeer := make(chan p2p.Peer)
nodeConfig := service.NodeConfig{
IsBeacon: node.NodeConfig.IsBeacon(),
IsClient: node.NodeConfig.IsClient(),
Beacon: p2p.GroupIDBeacon,
ShardGroupID: node.NodeConfig.GetShardGroupID(),

@ -29,7 +29,6 @@ import (
"github.com/harmony-one/harmony/contracts/structs"
"github.com/harmony-one/harmony/core"
"github.com/harmony-one/harmony/core/types"
common2 "github.com/harmony-one/harmony/internal/common"
nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
"github.com/harmony-one/harmony/internal/ctxerror"
"github.com/harmony-one/harmony/internal/utils"
@ -148,10 +147,9 @@ func (node *Node) messageHandler(content []byte, sender libp2p_peer.ID) {
utils.Logger().Debug().Msg("NET: Received staking message")
msgPayload, _ := proto.GetStakingMessagePayload(content)
// Only beacon leader processes staking txn
if node.NodeConfig.Role() != nodeconfig.BeaconLeader {
return
if node.Consensus != nil && node.Consensus.ShardID == 0 && node.Consensus.IsLeader() {
node.processStakingMessage(msgPayload)
}
node.processStakingMessage(msgPayload)
case proto.Node:
actionType := proto_node.MessageType(msgType)
switch actionType {
@ -173,10 +171,11 @@ func (node *Node) messageHandler(content []byte, sender libp2p_peer.ID) {
} else {
// for non-beaconchain node, subscribe to beacon block broadcast
role := node.NodeConfig.Role()
if proto_node.BlockMessageType(msgPayload[0]) == proto_node.Sync && (role == nodeconfig.ShardValidator || role == nodeconfig.ShardLeader || role == nodeconfig.NewNode) {
if proto_node.BlockMessageType(msgPayload[0]) == proto_node.Sync && role == nodeconfig.Validator {
utils.Logger().Info().
Uint64("block", blocks[0].NumberU64()).
Msg("Block being handled by block channel")
for _, block := range blocks {
node.BeaconBlockChannel <- block
}
@ -590,16 +589,6 @@ func (node *Node) pingMessageHandler(msgPayload []byte, sender libp2p_peer.ID) i
err = ctxerror.New("cannot convert BLS public key").WithCause(err)
ctxerror.Log15(utils.GetLogger().Warn, err)
}
if genesisNode := getGenesisNodeByConsensusKey(k); genesisNode != nil {
utils.Logger().Info().
Uint32("genesisShardID", genesisNode.ShardID).
Int("genesisMemberIndex", genesisNode.MemberIndex).
Str("genesisStakingAccount", common2.MustAddressToBech32(genesisNode.NodeID.EcdsaAddress))
} else {
utils.Logger().Info().
Str("BlsPubKey", peer.ConsensusPubKey.SerializeToHexStr()).
Msg("cannot find genesis node")
}
utils.Logger().Info().
Str("Peer Version", ping.NodeVer).
Interface("PeerID", peer).
@ -766,7 +755,7 @@ func (node *Node) epochShardStateMessageHandler(msgPayload []byte) error {
if err != nil {
return ctxerror.New("Can't get shard state message").WithCause(err)
}
if node.Consensus == nil && node.NodeConfig.Role() != nodeconfig.NewNode {
if node.Consensus == nil {
return nil
}
receivedEpoch := big.NewInt(int64(epochShardState.Epoch))

@ -228,7 +228,7 @@ func (node *Node) SendNewBlockToUnsync() {
}
// CalculateResponse implements DownloadInterface on Node object.
func (node *Node) CalculateResponse(request *downloader_pb.DownloaderRequest) (*downloader_pb.DownloaderResponse, error) {
func (node *Node) CalculateResponse(request *downloader_pb.DownloaderRequest, incomingPeer string) (*downloader_pb.DownloaderResponse, error) {
response := &downloader_pb.DownloaderResponse{}
switch request.Type {
case downloader_pb.DownloaderRequest_HEADER:
@ -248,7 +248,7 @@ func (node *Node) CalculateResponse(request *downloader_pb.DownloaderRequest) (*
startHeight := startBlock.NumberU64()
endHeight := node.Blockchain().CurrentBlock().NumberU64()
if startHeight >= endHeight {
utils.GetLogInstance().Debug("[SYNC] GetBlockHashes Request: I am not higher than requested node", "myHeight", endHeight, "requestHeight", startHeight)
utils.GetLogInstance().Debug("[SYNC] GetBlockHashes Request: I am not higher than requested node", "myHeight", endHeight, "requestHeight", startHeight, "incomingIP", request.Ip, "incomingPort", request.Port, "incomingPeer", incomingPeer)
return response, nil
}

@ -15,7 +15,7 @@ import (
"github.com/harmony-one/harmony/p2p"
)
func (node *Node) setupForShardLeader() {
func (node *Node) setupForValidator() {
nodeConfig, chanPeer := node.initNodeConfiguration()
// Register peer discovery service. No need to do staking for beacon chain node.
@ -28,56 +28,13 @@ func (node *Node) setupForShardLeader() {
node.serviceManager.RegisterService(service.BlockProposal, blockproposal.New(node.Consensus.ReadySignal, node.WaitForConsensusReadyv2))
// Register client support service.
node.serviceManager.RegisterService(service.ClientSupport, clientsupport.New(node.Blockchain().State, node.CallFaucetContract, node.getDeployedStakingContract, node.SelfPeer.IP, node.SelfPeer.Port))
}
func (node *Node) setupForShardValidator() {
nodeConfig, chanPeer := node.initNodeConfiguration()
// Register client support service.
node.serviceManager.RegisterService(service.ClientSupport, clientsupport.New(node.Blockchain().State, node.CallFaucetContract, node.getDeployedStakingContract, node.SelfPeer.IP, node.SelfPeer.Port))
// Register peer discovery service. "0" is the beacon shard ID. No need to do staking for beacon chain node.
node.serviceManager.RegisterService(service.PeerDiscovery, discovery.New(node.host, nodeConfig, chanPeer, node.AddBeaconPeer))
// Register networkinfo service. "0" is the beacon shard ID
node.serviceManager.RegisterService(service.NetworkInfo, networkinfo.New(node.host, node.NodeConfig.GetShardGroupID(), chanPeer, nil))
// Register consensus service.
node.serviceManager.RegisterService(service.Consensus, consensus.New(node.BlockChannel, node.Consensus, node.startConsensus))
// Register new block service.
node.serviceManager.RegisterService(service.BlockProposal, blockproposal.New(node.Consensus.ReadySignal, node.WaitForConsensusReadyv2))
}
func (node *Node) setupForBeaconLeader() {
nodeConfig, chanPeer := node.initNodeConfiguration()
// Register peer discovery service. No need to do staking for beacon chain node.
node.serviceManager.RegisterService(service.PeerDiscovery, discovery.New(node.host, nodeConfig, chanPeer, nil))
// Register networkinfo service.
node.serviceManager.RegisterService(service.NetworkInfo, networkinfo.New(node.host, node.NodeConfig.GetShardGroupID(), chanPeer, nil))
// Register client support service.
node.serviceManager.RegisterService(service.ClientSupport, clientsupport.New(node.Blockchain().State, node.CallFaucetContract, node.getDeployedStakingContract, node.SelfPeer.IP, node.SelfPeer.Port))
// Register consensus service.
node.serviceManager.RegisterService(service.Consensus, consensus.New(node.BlockChannel, node.Consensus, node.startConsensus))
// Register new block service.
node.serviceManager.RegisterService(service.BlockProposal, blockproposal.New(node.Consensus.ReadySignal, node.WaitForConsensusReadyv2))
// Register randomness service
// TODO: Disable drand. Currently drand isn't functioning but we want to compeletely turn it off for full protection.
// Enable it back after mainnet.
// Need Dynamically enable for beacon validators
// node.serviceManager.RegisterService(service.Randomness, randomness.New(node.DRand))
}
func (node *Node) setupForBeaconValidator() {
nodeConfig, chanPeer := node.initNodeConfiguration()
// Register peer discovery service. No need to do staking for beacon chain node.
node.serviceManager.RegisterService(service.PeerDiscovery, discovery.New(node.host, nodeConfig, chanPeer, nil))
// Register networkinfo service.
node.serviceManager.RegisterService(service.NetworkInfo, networkinfo.New(node.host, node.NodeConfig.GetShardGroupID(), chanPeer, nil))
// Register consensus service.
node.serviceManager.RegisterService(service.Consensus, consensus.New(node.BlockChannel, node.Consensus, node.startConsensus))
// Register new block service.
node.serviceManager.RegisterService(service.BlockProposal, blockproposal.New(node.Consensus.ReadySignal, node.WaitForConsensusReadyv2))
// Register client support service.
node.serviceManager.RegisterService(service.ClientSupport, clientsupport.New(node.Blockchain().State, node.CallFaucetContract, node.getDeployedStakingContract, node.SelfPeer.IP, node.SelfPeer.Port))
}
func (node *Node) setupForNewNode() {
@ -126,16 +83,8 @@ func (node *Node) ServiceManagerSetup() {
node.serviceManager = &service.Manager{}
node.serviceMessageChan = make(map[service.Type]chan *msg_pb.Message)
switch node.NodeConfig.Role() {
case nodeconfig.ShardLeader:
node.setupForShardLeader()
case nodeconfig.ShardValidator:
node.setupForShardValidator()
case nodeconfig.BeaconLeader:
node.setupForBeaconLeader()
case nodeconfig.BeaconValidator:
node.setupForBeaconValidator()
case nodeconfig.NewNode:
node.setupForNewNode()
case nodeconfig.Validator:
node.setupForValidator()
case nodeconfig.ClientNode:
node.setupForClientNode()
case nodeconfig.ExplorerNode:

@ -13,13 +13,13 @@
127.0.0.1 9012 validator one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7 678ec9670899bf6af85b877058bea4fc1301a5a3a376987e826e3ca150b80e3eaadffedad0fedfa111576fa76ded980c
127.0.0.1 9013 validator one129r9pj3sk0re76f7zs3qz92rggmdgjhtwge62k 63f479f249c59f0486fda8caa2ffb247209489dae009dfde6144ff38c370230963d360dffd318cfb26c213320e89a512
127.0.0.1 9100 newnode one1ghkz3frhske7emk79p7v2afmj4a5t0kmjyt4s5 eca09c1808b729ca56f1b5a6a287c6e1c3ae09e29ccf7efa35453471fcab07d9f73cee249e2b91f5ee44eb9618be3904
127.0.0.1 9101 newnode one1d7jfnr6yraxnrycgaemyktkmhmajhp8kl0yahv f47238daef97d60deedbde5302d05dea5de67608f11f406576e363661f7dcbc4a1385948549b31a6c70f6fde8a391486
127.0.0.1 9102 newnode one1r4zyyjqrulf935a479sgqlpa78kz7zlcg2jfen fc4b9c535ee91f015efff3f32fbb9d32cdd9bfc8a837bb3eee89b8fff653c7af2050a4e147ebe5c7233dc2d5df06ee0a
127.0.0.1 9103 newnode one1p7ht2d4kl8ve7a8jxw746yfnx4wnfxtp8jqxwe ca86e551ee42adaaa6477322d7db869d3e203c00d7b86c82ebee629ad79cb6d57b8f3db28336778ec2180e56a8e07296
127.0.0.1 9104 newnode one1z05g55zamqzfw9qs432n33gycdmyvs38xjemyl 95117937cd8c09acd2dfae847d74041a67834ea88662a7cbed1e170350bc329e53db151e5a0ef3e712e35287ae954818
127.0.0.1 9105 newnode one1ljznytjyn269azvszjlcqvpcj6hjm822yrcp2e 68ae289d73332872ec8d04ac256ca0f5453c88ad392730c5741b6055bc3ec3d086ab03637713a29f459177aaa8340615
127.0.0.1 9107 newnode one1uyshu2jgv8w465yc8kkny36thlt2wvel89tcmg 1c1fb28d2de96e82c3d9b4917eb54412517e2763112a3164862a6ed627ac62e87ce274bb4ea36e6a61fb66a15c263a06
127.0.0.1 9108 newnode one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7 b179c4fdc0bee7bd0b6698b792837dd13404d3f985b59d4a9b1cd0641a76651e271518b61abbb6fbebd4acf963358604
127.0.0.1 9109 newnode one1658znfwf40epvy7e46cqrmzyy54h4n0qa73nep 576d3c48294e00d6be4a22b07b66a870ddee03052fe48a5abbd180222e5d5a1f8946a78d55b025de21635fd743bbad90
127.0.0.1 9110 newnode one1d2rngmem4x2c6zxsjjz29dlah0jzkr0k2n88wc 16513c487a6bb76f37219f3c2927a4f281f9dd3fd6ed2e3a64e500de6545cf391dd973cc228d24f9bd01efe94912e714
127.0.0.1 9100 validator one1ghkz3frhske7emk79p7v2afmj4a5t0kmjyt4s5 eca09c1808b729ca56f1b5a6a287c6e1c3ae09e29ccf7efa35453471fcab07d9f73cee249e2b91f5ee44eb9618be3904
127.0.0.1 9101 validator one1d7jfnr6yraxnrycgaemyktkmhmajhp8kl0yahv f47238daef97d60deedbde5302d05dea5de67608f11f406576e363661f7dcbc4a1385948549b31a6c70f6fde8a391486
127.0.0.1 9102 validator one1r4zyyjqrulf935a479sgqlpa78kz7zlcg2jfen fc4b9c535ee91f015efff3f32fbb9d32cdd9bfc8a837bb3eee89b8fff653c7af2050a4e147ebe5c7233dc2d5df06ee0a
127.0.0.1 9103 validator one1p7ht2d4kl8ve7a8jxw746yfnx4wnfxtp8jqxwe ca86e551ee42adaaa6477322d7db869d3e203c00d7b86c82ebee629ad79cb6d57b8f3db28336778ec2180e56a8e07296
127.0.0.1 9104 validator one1z05g55zamqzfw9qs432n33gycdmyvs38xjemyl 95117937cd8c09acd2dfae847d74041a67834ea88662a7cbed1e170350bc329e53db151e5a0ef3e712e35287ae954818
127.0.0.1 9105 validator one1ljznytjyn269azvszjlcqvpcj6hjm822yrcp2e 68ae289d73332872ec8d04ac256ca0f5453c88ad392730c5741b6055bc3ec3d086ab03637713a29f459177aaa8340615
127.0.0.1 9107 validator one1uyshu2jgv8w465yc8kkny36thlt2wvel89tcmg 1c1fb28d2de96e82c3d9b4917eb54412517e2763112a3164862a6ed627ac62e87ce274bb4ea36e6a61fb66a15c263a06
127.0.0.1 9108 validator one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7 b179c4fdc0bee7bd0b6698b792837dd13404d3f985b59d4a9b1cd0641a76651e271518b61abbb6fbebd4acf963358604
127.0.0.1 9109 validator one1658znfwf40epvy7e46cqrmzyy54h4n0qa73nep 576d3c48294e00d6be4a22b07b66a870ddee03052fe48a5abbd180222e5d5a1f8946a78d55b025de21635fd743bbad90
127.0.0.1 9110 validator one1d2rngmem4x2c6zxsjjz29dlah0jzkr0k2n88wc 16513c487a6bb76f37219f3c2927a4f281f9dd3fd6ed2e3a64e500de6545cf391dd973cc228d24f9bd01efe94912e714

@ -177,13 +177,6 @@ while IFS='' read -r line || [[ -n "$line" ]]; do
case "${mode}" in *archival|archival) args=("${args[@]}" -is_archival);; esac
case "${mode}" in explorer*) args=("${args[@]}" -is_genesis=false -is_explorer=true -shard_id=0);; esac
case "${mode}" in
newnode)
sleep "${NUM_NN}"
NUM_NN=$((${NUM_NN} + 1))
args=("${args[@]}" -is_newnode)
;;
esac
case "${mode}" in
client) ;;
*) $DRYRUN "${ROOT}/bin/harmony" "${args[@]}" "${extra_args[@]}" 2>&1 | tee -a "${LOG_FILE}" &;;
esac

Loading…
Cancel
Save