Skip to content

Commit

Permalink
fix: broken links for nodeapi (Layr-Labs#232)
Browse files Browse the repository at this point in the history
* fix: broken links for nodeapi

* refactor: remove one outdated api, make fmt

* fix: broken link for metrics

* fix: broken link
  • Loading branch information
renlulu authored May 6, 2024
1 parent be4b790 commit 1fcd296
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 44 deletions.
7 changes: 5 additions & 2 deletions chainio/clients/eth/instrumented_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ func NewInstrumentedClient(rpcAddress string, rpcCallsCollector *rpccalls.Collec
return NewInstrumentedClientFromClient(client, rpcCallsCollector), nil
}

func NewInstrumentedClientFromClient(client *ethclient.Client, rpcCallsCollector *rpccalls.Collector) *InstrumentedClient {
func NewInstrumentedClientFromClient(
client *ethclient.Client,
rpcCallsCollector *rpccalls.Collector,
) *InstrumentedClient {
clientAndVersion := getClientAndVersion(client)
return &InstrumentedClient{
client: client,
Expand Down Expand Up @@ -495,7 +498,7 @@ func (iec *InstrumentedClient) WaitForTransactionReceipt(ctx context.Context, tx

// Not sure why this method is not exposed in the ethclient itself...
// but it is needed to comply with the rpc metrics defined in avs-node spec
// https://eigen.nethermind.io/docs/metrics/metrics-prom-spec
// https://docs.eigenlayer.xyz/eigenlayer/avs-guides/spec/metrics/metrics-prom-spec
func getClientAndVersion(client *ethclient.Client) string {
var clientVersion string
err := client.Client().Call(&clientVersion, "web3_clientVersion")
Expand Down
3 changes: 2 additions & 1 deletion chainio/txmgr/txmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import (
)

var (
// FallbackGasTipCap 5 gwei in case the backend does not support eth_maxPriorityFeePerGas (no idea if/when this ever happens..)
// FallbackGasTipCap 5 gwei in case the backend does not support eth_maxPriorityFeePerGas (no idea if/when this ever
// happens..)
FallbackGasTipCap = big.NewInt(5_000_000_000)
// FallbackGasLimitMultiplier 1.20x gas limit multiplier. This is arbitrary but should be safe for most cases
FallbackGasLimitMultiplier = 1.20
Expand Down
4 changes: 3 additions & 1 deletion crypto/bn254/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ func VerifySig(sig *bn254.G1Affine, pubkey *bn254.G2Affine, msgBytes [32]byte) (
// MapToCurve implements the simple hash-and-check (also sometimes try-and-increment) algorithm
// see https://hackmd.io/@benjaminion/bls12-381#Hash-and-check
// Note that this function needs to be the same as the one used in the contract:
// https://github.com/Layr-Labs/eigenlayer-middleware/blob/1feb6ae7e12f33ce8eefb361edb69ee26c118b5d/src/libraries/BN254.sol#L292
//
// https://github.com/Layr-Labs/eigenlayer-middleware/blob/1feb6ae7e12f33ce8eefb361edb69ee26c118b5d/src/libraries/BN254.sol#L292
//
// we don't use the newer constant time hash-to-curve algorithms as they are gas-expensive to compute onchain
func MapToCurve(digest [32]byte) *bn254.G1Affine {

Expand Down
4 changes: 2 additions & 2 deletions metrics/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Eigen Metrics

This package implements the eigenlayer avs node spec [eigen metrics](https://eigen.nethermind.io/docs/category/metrics).
This package implements the eigenlayer avs node spec [eigen metrics](https://docs.eigenlayer.xyz/category/metrics).

For an example of how to use this package, see [node-api-example](./eigenmetrics_example_test.go)
For an example of how to use this package, see [eigen-metrics-example](./eigenmetrics_example_test.go)
2 changes: 1 addition & 1 deletion metrics/collectors/economic/economic.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

// Collector exports the economic metrics listed at
//
// https://eigen.nethermind.io/docs/spec/metrics/metrics-examples#economics-metrics
// https://docs.eigenlayer.xyz/eigenlayer/avs-guides/spec/metrics/metrics-prom-spec#economics-metrics
//
// these are metrics that are exported not via instrumentation, but instead by proxying
// a call to the relevant eigenlayer contracts
Expand Down
2 changes: 1 addition & 1 deletion metrics/eigenmetrics.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package metrics implements the avs node prometheus metrics spec: https://eigen.nethermind.io/docs/metrics/metrics-prom-spec
// Package metrics implements the avs node prometheus metrics spec: https://docs.eigenlayer.xyz/eigenlayer/avs-guides/spec/metrics/metrics-prom-spec
package metrics

import (
Expand Down
2 changes: 1 addition & 1 deletion metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// Metrics is the interface for the EigenMetrics server
// it only wraps 2 of the 6 methods required by the spec (https://eigen.nethermind.io/docs/spec/metrics/metrics-prom-spec)
// it only wraps 2 of the 6 methods required by the spec (https://docs.eigenlayer.xyz/eigenlayer/avs-guides/spec/metrics/metrics-prom-spec)
// the others are implemented by the economics and rpc_calls collectors,
// and need to be registered with the metrics server prometheus registry
type Metrics interface {
Expand Down
2 changes: 1 addition & 1 deletion nodeapi/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Node Api

This package implements the eigenlayer avs node spec [node-api](https://eigen.nethermind.io/docs/category/avs-node-api).
This package implements the eigenlayer avs node spec [node-api](https://docs.eigenlayer.xyz/eigenlayer/avs-guides/spec/api/).

For an example of how to use this package, see [node-api-example](./nodeapi_example_test.go#L8)
23 changes: 6 additions & 17 deletions nodeapi/nodeapi.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package nodeapi

// Implementation of https://eigen.nethermind.io/docs/spec/api/#api-versioning
// Implementation of https://docs.eigenlayer.xyz/eigenlayer/avs-guides/spec/api/#api-versioning

import (
"context"
Expand All @@ -18,7 +18,7 @@ import (
const (
baseUrl = "/eigen"
// Spec version is the version of the avs node spec that this node is implementing
// see https://eigen.nethermind.io/docs/spec/api/#api-versioning
// see https://docs.eigenlayer.xyz/eigenlayer/avs-guides/spec/api/#api-versioning
specSemVer = "v0.0.1"
)

Expand Down Expand Up @@ -120,18 +120,7 @@ func (api *NodeApi) Start() <-chan error {
return errChan
}

// https://eigen.nethermind.io/docs/metrics/metrics-api#get-eigennodespec-version
func (api *NodeApi) specVersionHandler(w http.ResponseWriter, r *http.Request) {
response := map[string]string{
"spec_version": specSemVer,
}
err := jsonResponse(w, response)
if err != nil {
api.logger.Error("Error in specVersionHandler", "err", err)
}
}

// https://eigen.nethermind.io/docs/metrics/metrics-api#get-eigennodeversion
// https://docs.eigenlayer.xyz/eigenlayer/avs-guides/spec/api/#get-eigennode
func (api *NodeApi) nodeHandler(w http.ResponseWriter, r *http.Request) {
response := map[string]string{
"node_name": api.avsNodeName,
Expand All @@ -144,7 +133,7 @@ func (api *NodeApi) nodeHandler(w http.ResponseWriter, r *http.Request) {
}
}

// https://eigen.nethermind.io/docs/metrics/metrics-api#get-eigennodehealth
// https://docs.eigenlayer.xyz/eigenlayer/avs-guides/spec/api/#get-eigennodehealth
func (api *NodeApi) healthHandler(w http.ResponseWriter, r *http.Request) {
switch api.health {
case Healthy:
Expand All @@ -163,7 +152,7 @@ func (api *NodeApi) healthHandler(w http.ResponseWriter, r *http.Request) {
}
}

// https://eigen.nethermind.io/docs/metrics/metrics-api#get-eigennodeservices
// https://docs.eigenlayer.xyz/eigenlayer/avs-guides/spec/api/#get-eigennodeservices
func (api *NodeApi) servicesHandler(w http.ResponseWriter, r *http.Request) {
response := map[string][]nodeService{
"services": api.nodeServices,
Expand All @@ -174,7 +163,7 @@ func (api *NodeApi) servicesHandler(w http.ResponseWriter, r *http.Request) {
}
}

// https://eigen.nethermind.io/docs/metrics/metrics-api#get-eigennodeservicesservice_idhealth
// https://docs.eigenlayer.xyz/eigenlayer/avs-guides/spec/api/#get-eigennodeservicesservice_idhealth
func (api *NodeApi) serviceHealthHandler(w http.ResponseWriter, r *http.Request) {
suffix, found := strings.CutPrefix(r.URL.Path, "/eigen/node/services/")
if !found {
Expand Down
2 changes: 1 addition & 1 deletion nodeapi/nodeapi_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func ExampleNodeApi() {

nodeApi := nodeapi.NewNodeApi("testAvs", "v0.0.1", "localhost:8080", logger)
// register a service with the nodeApi. This could be a db, a cache, a queue, etc.
// see https://eigen.nethermind.io/docs/spec/api/#get-eigennodeservices
// see https://docs.eigenlayer.xyz/eigenlayer/avs-guides/spec/api/#get-eigennodeservices
nodeApi.RegisterNewService("testServiceId", "testServiceName", "testServiceDescription", nodeapi.ServiceStatusInitializing)

// this starts the nodeApi server in a goroutine, so no need to wrap it in a go func
Expand Down
16 changes: 0 additions & 16 deletions nodeapi/nodeapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,6 @@ func TestStart(t *testing.T) {
}
}

func TestSpecVersionHandler(t *testing.T) {
req := httptest.NewRequest(http.MethodGet, "/eigen/node/spec-version", nil)
w := httptest.NewRecorder()

testNodeApi.specVersionHandler(w, req)

res := w.Result()
defer res.Body.Close()

data, err := io.ReadAll(res.Body)
assert.NoError(t, err)

assert.Equal(t, http.StatusOK, res.StatusCode)
assert.Equal(t, "{\"spec_version\":\"v0.0.1\"}\n", string(data))
}

func TestNodeHandler(t *testing.T) {
req := httptest.NewRequest(http.MethodGet, "/eigen/node", nil)
w := httptest.NewRecorder()
Expand Down

0 comments on commit 1fcd296

Please sign in to comment.