Skip to content

Commit

Permalink
[Node][6/N] Add node registration (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
jianoaix authored Jul 6, 2023
1 parent 21d4d59 commit 9dd3fcf
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 86 deletions.
161 changes: 79 additions & 82 deletions inabox/deploy/env_vars.go
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
package deploy

import "reflect"

type DisperserVars struct{

DISPERSER_PULL_INTERVAL string

DISPERSER_GRPC_PORT string

DISPERSER_ADDRESS string

DISPERSER_G1_PATH string

DISPERSER_G2_PATH string

DISPERSER_CACHE_PATH string

DISPERSER_SRS_ORDER string

DISPERSER_NUM_WORKERS string

DISPERSER_VERBOSE string

DISPERSER_CHAIN_RPC string

DISPERSER_PRIVATE_KEY string

DISPERSER_CHAIN_ID string

DISPERSER_STD_LOG_LEVEL string

DISPERSER_FILE_LOG_LEVEL string

DISPERSER_LOG_PATH string

package deploy

import "reflect"

type DisperserVars struct {
DISPERSER_PULL_INTERVAL string

DISPERSER_GRPC_PORT string

DISPERSER_ADDRESS string

DISPERSER_G1_PATH string

DISPERSER_G2_PATH string

DISPERSER_CACHE_PATH string

DISPERSER_SRS_ORDER string

DISPERSER_NUM_WORKERS string

DISPERSER_VERBOSE string

DISPERSER_CHAIN_RPC string

DISPERSER_PRIVATE_KEY string

DISPERSER_CHAIN_ID string

DISPERSER_STD_LOG_LEVEL string

DISPERSER_FILE_LOG_LEVEL string

DISPERSER_LOG_PATH string
}

func (vars DisperserVars) getEnvMap() map[string]string {
v := reflect.ValueOf(vars)
envMap := make(map[string]string)
Expand All @@ -43,52 +42,51 @@ func (vars DisperserVars) getEnvMap() map[string]string {
}
return envMap
}

type OperatorVars struct{

NODE_HOSTNAME string

NODE_GRPC_PORT string

NODE_ENABLE_METRICS string

NODE_METRICS_PORT string

NODE_TIMEOUT string

NODE_DB_PATH string

NODE_PRIVATE_BLS string

NODE_DLSM_ADDRESS string

NODE_CHALLENGE_ORDER string

NODE_G1_PATH string

NODE_G2_PATH string

NODE_CACHE_PATH string

NODE_SRS_ORDER string

NODE_NUM_WORKERS string

NODE_VERBOSE string

NODE_CHAIN_RPC string

NODE_PRIVATE_KEY string

NODE_CHAIN_ID string

NODE_STD_LOG_LEVEL string

NODE_FILE_LOG_LEVEL string

NODE_LOG_PATH string


type OperatorVars struct {
NODE_HOSTNAME string

NODE_GRPC_PORT string

NODE_ENABLE_METRICS string

NODE_METRICS_PORT string

NODE_TIMEOUT string

NODE_DB_PATH string

NODE_PRIVATE_BLS string

NODE_DLSM_ADDRESS string

NODE_CHALLENGE_ORDER string

NODE_G1_PATH string

NODE_G2_PATH string

NODE_CACHE_PATH string

NODE_SRS_ORDER string

NODE_NUM_WORKERS string

NODE_VERBOSE string

NODE_CHAIN_RPC string

NODE_PRIVATE_KEY string

NODE_CHAIN_ID string

NODE_STD_LOG_LEVEL string

NODE_FILE_LOG_LEVEL string

NODE_LOG_PATH string
}

func (vars OperatorVars) getEnvMap() map[string]string {
v := reflect.ValueOf(vars)
envMap := make(map[string]string)
Expand All @@ -97,4 +95,3 @@ func (vars OperatorVars) getEnvMap() map[string]string {
}
return envMap
}

14 changes: 14 additions & 0 deletions node/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package node

import (
"strconv"
"strings"
"time"

"github.com/Layr-Labs/eigenda/common/geth"
Expand All @@ -20,6 +22,7 @@ type Config struct {
MetricsPort string
Timeout time.Duration
ExpirationPollIntervalSec uint64
QuorumIDList []core.QuorumID
DbPath string
LogPath string
PrivateBls string
Expand All @@ -40,13 +43,24 @@ func NewConfig(ctx *cli.Context) (*Config, error) {
return &Config{}, err
}

idsStr := strings.Split(ctx.GlobalString(flags.QuorumIDListFlag.Name), ",")
ids := make([]core.QuorumID, 0)
for _, id := range idsStr {
val, err := strconv.Atoi(id)
if err != nil {
return nil, err
}
ids = append(ids, core.QuorumID(val))
}

return &Config{
Hostname: ctx.GlobalString(flags.HostnameFlag.Name),
GrpcPort: ctx.GlobalString(flags.GrpcPortFlag.Name),
EnableMetrics: ctx.GlobalBool(flags.EnableMetricsFlag.Name),
MetricsPort: ctx.GlobalString(flags.MetricsPortFlag.Name),
Timeout: timeout,
ExpirationPollIntervalSec: ctx.GlobalUint64(flags.ExpirationPollIntervalSecFlag.Name),
QuorumIDList: ids,
DbPath: ctx.GlobalString(flags.DbPathFlag.Name),
PrivateBls: ctx.GlobalString(flags.PrivateBlsFlag.Name),
EthClientConfig: geth.ReadEthClientConfig(ctx),
Expand Down
6 changes: 6 additions & 0 deletions node/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ var (
Value: "1",
EnvVar: common.PrefixEnvVar(envVarPrefix, "EXPIRATION_POLL_INTERVAL"),
}
QuorumIDListFlag = cli.StringFlag{
Name: "quorum-id-list",
Usage: "Comma separated list of quorum IDs that the node will participate in",
Required: true,
EnvVar: common.PrefixEnvVar(envVarPrefix, "QUORUM_ID_LIST"),
}
DbPathFlag = cli.StringFlag{
Name: "db-path",
Usage: "Path for level db",
Expand Down
12 changes: 8 additions & 4 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,13 @@ func (n *Node) Start(ctx context.Context) error {

go n.expireLoop()

// TODO(jianoaix): use the new chain client to get the operator registration
// state: if current node is registered, update its socket; otherwise register
// it on chain.
// TODO(jianoaix): check the existence of the operator on chain before trying to register.
socket := fmt.Sprintf("%s:%s", n.Config.Hostname, n.Config.GrpcPort)
err := n.Transactor.RegisterOperator(ctx, n.KeyPair.GetPubKeyG1(), socket, n.Config.QuorumIDList)
if err != nil {
n.Logger.Error("Failed to register the node:", err)
return err
}

return nil
}
Expand Down Expand Up @@ -231,4 +235,4 @@ func (n *Node) ValidateBatch(ctx context.Context, header *core.BatchHeader, chun

return nil

}
}

0 comments on commit 9dd3fcf

Please sign in to comment.