Skip to content

Commit 76b7aab

Browse files
committed
feat: script to update operator names in telemetry
1 parent 399c50c commit 76b7aab

File tree

4 files changed

+81
-1
lines changed

4 files changed

+81
-1
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,10 @@ telemetry_compile_bls_verifier:
11161116
@cd telemetry_api/priv && \
11171117
go build ../bls_verifier/bls_verify.go
11181118

1119+
telemetry_fetch_operators_metadata:
1120+
@cd telemetry_api && \
1121+
./scripts/fetch_operators_metadata.sh $(FROM_BLOCK)
1122+
11191123
setup_local_aligned_all:
11201124
tmux kill-session -t aligned_layer || true
11211125
tmux new-session -d -s aligned_layer
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
defmodule Scripts.FetchOperatorsMetadata do
2+
require Logger
3+
alias TelemetryApi.ContractManagers.OperatorStateRetriever
4+
alias TelemetryApi.Operators.Operator
5+
alias TelemetryApi.Repo
6+
7+
# This Script is to fetch operators metadata from the blockchain activity
8+
# and insert/update them into the Ecto database
9+
10+
def run(fromBlock) do
11+
"Fetching old operators changes" |> Logger.debug()
12+
update_operators_metadata(fromBlock)
13+
14+
"Done" |> Logger.debug()
15+
end
16+
17+
def update_operators_metadata(fromBlock) do
18+
with {:ok, operators} <- OperatorStateRetriever.get_operators() do
19+
# Construct tuple {%Operator{}, op_data}
20+
operators = Enum.map(operators, fn op_data ->
21+
{Repo.get(Operator, op_data.address), op_data}
22+
end)
23+
24+
# Fetch metadata for all operators
25+
operators = Enum.map(operators, fn {op, op_data} ->
26+
case TelemetryApi.Operators.add_operator_metadata(op_data) do
27+
{:ok, data} -> {:ok, {op, data}}
28+
{:error, msg} -> {:error, msg}
29+
end
30+
end)
31+
|> tap(&dbg/1)
32+
# Filter status ok and map to {op, op_data}
33+
|> Enum.filter(fn {status, _} -> status == :ok end)
34+
|> Enum.map(fn {_, data} -> data end)
35+
36+
dbg(operators)
37+
38+
# Insert in db
39+
Enum.map(operators, fn {op, op_data} ->
40+
Operator.changeset(op, op_data) |> Repo.insert_or_update()
41+
end)
42+
end
43+
:ok
44+
end
45+
end

telemetry_api/lib/telemetry_api/operators.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ defmodule TelemetryApi.Operators do
116116
# iex> add_operator_metadata(operator)
117117
# {:error, string}
118118
#
119-
defp add_operator_metadata(op_data) do
119+
def add_operator_metadata(op_data) do
120120
with {:ok, url} <- DelegationManager.get_operator_url(op_data.address),
121121
{:ok, metadata} <- TelemetryApi.Utils.fetch_json_data(url) do
122122
operator = %{
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
source .env
4+
5+
export ENVIRONMENT=$ENVIRONMENT
6+
export RPC_URL=$RPC_URL
7+
ELIXIR_HOSTNAME=$(elixir -e 'IO.puts(:inet.gethostname() |> elem(1))')
8+
export ELIXIR_HOSTNAME=$ELIXIR_HOSTNAME
9+
export ALIGNED_CONFIG_FILE=$ALIGNED_CONFIG_FILE
10+
export OPERATOR_FETCHER_WAIT_TIME_MS=$OPERATOR_FETCHER_WAIT_TIME_MS
11+
12+
if [ "$#" -eq 0 ]; then
13+
echo "Error, No arguments provided."
14+
echo "Try running the make target with FROM_BLOCK=<n>"
15+
exit 1
16+
elif [ "$#" -eq 1 ]; then
17+
# argument provided, use it
18+
FROM=$1
19+
else
20+
echo "Please provide 1 arguments."
21+
exit 1
22+
fi
23+
24+
echo "Running fetch_operators_metadata.sh from block: $FROM"
25+
26+
mix compile --force #force recompile to get the latest .env values
27+
28+
echo "You will now connect to the Telemetry Node, make sure you run the following command inside it:"
29+
echo "Scripts.FetchOperatorsMetadata.run($FROM)"
30+
31+
iex --sname fetch_operators_metadata --remsh telemetry@$ELIXIR_HOSTNAME

0 commit comments

Comments
 (0)