Skip to content

Commit

Permalink
Merge pull request #9 from Layr-Labs/samlaf/add-nodeapi-to-operator
Browse files Browse the repository at this point in the history
added node api to operator
  • Loading branch information
samlaf authored Oct 29, 2023
2 parents e255ec6 + 410c4a6 commit 19611a8
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 9 deletions.
6 changes: 5 additions & 1 deletion config-files/operator-docker-compose.anvil.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ bls_private_key_store_path: tests/keys/test.bls.key.json

# address which the aggregator listens on for operator signed messages
aggregator_server_ip_port_address: incredible-squaring-aggregator:8090

# avs node spec compliance https://eigen.nethermind.io/docs/spec/intro
eigen_metrics_ip_port_address: 0.0.0.0:9090
use_instrumented_eth_client: false
enable_metrics: true
node_api_ip_port_address: 0.0.0.0:9010
enable_nodeapi: true

# we need to register the operator on startup when running the docker compose file
# because unfortunately we cannot register the operator previously and save it in the anvil json file
Expand Down
6 changes: 5 additions & 1 deletion config-files/operator.anvil.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ ecdsa_private_key_store_path: tests/keys/test.ecdsa.key.json
bls_private_key_store_path: tests/keys/test.bls.key.json

aggregator_server_ip_port_address: localhost:8090

# avs node spec compliance https://eigen.nethermind.io/docs/spec/intro
eigen_metrics_ip_port_address: localhost:9090
use_instrumented_eth_client: false
enable_metrics: true
node_api_ip_port_address: localhost:9010
enable_nodeapi: true

register_operator_on_startup: false
16 changes: 16 additions & 0 deletions core/chainio/mocks/avs_reader.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.21
toolchain go1.21.0

require (
github.com/Layr-Labs/eigensdk-go v0.0.7-0.20231024030907-fbc0e500c28c
github.com/Layr-Labs/eigensdk-go v0.0.7-0.20231025231957-23a0dfd1db78
github.com/ethereum/go-ethereum v1.13.4
github.com/prometheus/client_golang v1.17.0
github.com/stretchr/testify v1.8.4
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ github.com/DataDog/zstd v1.5.2/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwS
github.com/Joker/hpp v1.0.0/go.mod h1:8x5n+M1Hp5hC0g8okX3sR3vFQwynaX/UgSOM9MeBKzY=
github.com/Layr-Labs/eigensdk-go v0.0.7-0.20231024030907-fbc0e500c28c h1:k/yFS2gVdOQM3pWP7/4t50OuBQfAWhHCWuvQY/Connk=
github.com/Layr-Labs/eigensdk-go v0.0.7-0.20231024030907-fbc0e500c28c/go.mod h1:hoKX+RE2GvXx1BZqhJ15w9pQFFaG2uinaCbRbdxevVQ=
github.com/Layr-Labs/eigensdk-go v0.0.7-0.20231025231957-23a0dfd1db78 h1:sBC2dfH8Q5qBIhrFhy3dzCpbOyNeQds/MZnz7EbIheg=
github.com/Layr-Labs/eigensdk-go v0.0.7-0.20231025231957-23a0dfd1db78/go.mod h1:hoKX+RE2GvXx1BZqhJ15w9pQFFaG2uinaCbRbdxevVQ=
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
github.com/Microsoft/hcsshim v0.11.0 h1:7EFNIY4igHEXUdj1zXgAyU3fLc7QfOKHbkldRVTBdiM=
Expand Down
21 changes: 19 additions & 2 deletions operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@ import (
sdkmetrics "github.com/Layr-Labs/eigensdk-go/metrics"
"github.com/Layr-Labs/eigensdk-go/metrics/collectors/economic"
rpccalls "github.com/Layr-Labs/eigensdk-go/metrics/collectors/rpc_calls"
"github.com/Layr-Labs/eigensdk-go/nodeapi"
"github.com/Layr-Labs/eigensdk-go/signer"
sdktypes "github.com/Layr-Labs/eigensdk-go/types"
)

const AVS_NAME = "incredible-squaring"
const SEM_VER = "0.0.1"

type Operator struct {
config types.NodeConfig
logger logging.Logger
ethClient eth.EthClient
// TODO(samlaf): remove both avsWriter and eigenlayerWrite from operator
Expand All @@ -43,6 +46,7 @@ type Operator struct {
// writing to the chain should be done via the cli only
metricsReg *prometheus.Registry
metrics metrics.Metrics
nodeApi *nodeapi.NodeApi
avsWriter *chainio.AvsWriter
avsReader chainio.AvsReaderer
avsSubscriber chainio.AvsSubscriberer
Expand Down Expand Up @@ -76,8 +80,11 @@ func NewOperatorFromConfig(c types.NodeConfig) (*Operator, error) {
eigenMetrics := sdkmetrics.NewEigenMetrics(AVS_NAME, c.EigenMetricsIpPortAddress, reg, logger)
avsAndEigenMetrics := metrics.NewAvsAndEigenMetrics(AVS_NAME, eigenMetrics, reg)

// Setup Node Api
nodeApi := nodeapi.NewNodeApi(AVS_NAME, SEM_VER, c.NodeApiIpPortAddress, logger)

var ethRpcClient, ethWsClient eth.EthClient
if c.UseInstrumentedEthClient {
if c.EnableMetrics {
rpcCallsCollector := rpccalls.NewCollector(AVS_NAME, reg)
ethRpcClient, err = eth.NewInstrumentedClient(c.EthRpcUrl, rpcCallsCollector)
if err != nil {
Expand Down Expand Up @@ -221,9 +228,11 @@ func NewOperatorFromConfig(c types.NodeConfig) (*Operator, error) {
}

operator := &Operator{
config: c,
logger: logger,
metricsReg: reg,
metrics: avsAndEigenMetrics,
nodeApi: nodeApi,
ethClient: ethRpcClient,
avsWriter: avsWriter,
avsReader: avsReader,
Expand Down Expand Up @@ -276,7 +285,15 @@ func (o *Operator) Start(ctx context.Context) error {

o.logger.Infof("Starting operator.")

metricsErrChan := o.metrics.Start(ctx, o.metricsReg)
if o.config.EnableNodeApi {
o.nodeApi.Start()
}
var metricsErrChan <-chan error
if o.config.EnableMetrics {
metricsErrChan = o.metrics.Start(ctx, o.metricsReg)
} else {
metricsErrChan = make(chan error, 1)
}

// TODO(samlaf): wrap this call with increase in avs-node-spec metric
sub := o.avsSubscriber.SubscribeToNewTasks(o.newTaskCreatedChan)
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ func TestIntegration(t *testing.T) {
t.Fatalf("Failed to create aggregator: %s", err.Error())
}
go agg.Start(ctx)
log.Println("Started aggregator. Sleeping 15 seconds to give operator time to answer task 1...")
time.Sleep(15 * time.Second)
log.Println("Started aggregator. Sleeping 20 seconds to give operator time to answer task 1...")
time.Sleep(20 * time.Second)

// get avsRegistry client to interact with the chain
avsReader, err := chainio.NewAvsReaderFromConfig(config)
Expand Down
6 changes: 4 additions & 2 deletions types/avs_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ type NodeConfig struct {
BlsPrivateKeyStorePath string `yaml:"bls_private_key_store_path"`
EcdsaPrivateKeyStorePath string `yaml:"ecdsa_private_key_store_path"`
AggregatorServerIpPortAddress string `yaml:"aggregator_server_ip_port_address"`
EigenMetricsIpPortAddress string `yaml:"eigen_metrics_ip_port_address"`
RegisterOperatorOnStartup bool `yaml:"register_operator_on_startup"`
UseInstrumentedEthClient bool `yaml:"use_instrumented_eth_client"`
EigenMetricsIpPortAddress string `yaml:"eigen_metrics_ip_port_address"`
EnableMetrics bool `yaml:"enable_metrics"`
NodeApiIpPortAddress string `yaml:"node_api_ip_port_address"`
EnableNodeApi bool `yaml:"enable_node_api"`
}

0 comments on commit 19611a8

Please sign in to comment.