Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hotfix: telemetry script to rewrite operator names #1600

Open
wants to merge 2 commits into
base: testnet
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,10 @@ telemetry_compile_bls_verifier:
@cd telemetry_api/priv && \
go build ../bls_verifier/bls_verify.go

telemetry_fetch_operators_metadata:
@cd telemetry_api && \
./scripts/fetch_operators_metadata.sh $(FROM_BLOCK)

setup_local_aligned_all:
tmux kill-session -t aligned_layer || true
tmux new-session -d -s aligned_layer
Expand Down
45 changes: 45 additions & 0 deletions telemetry_api/lib/scripts/fetch_operators_metadata.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
defmodule Scripts.FetchOperatorsMetadata do
require Logger
alias TelemetryApi.ContractManagers.OperatorStateRetriever
alias TelemetryApi.Operators.Operator
alias TelemetryApi.Repo

# This Script is to fetch operators metadata from the blockchain activity
# and insert/update them into the Ecto database

def run() do
"Fetching old operators changes" |> Logger.debug()
update_operators_metadata()

"Done" |> Logger.debug()
end

def update_operators_metadata() do
with {:ok, operators} <- OperatorStateRetriever.get_operators() do
# Construct tuple {%Operator{}, op_data}
operators = Enum.map(operators, fn op_data ->
{Repo.get(Operator, op_data.address), op_data}
end)

# Fetch metadata for all operators
operators = Enum.map(operators, fn {op, op_data} ->
case TelemetryApi.Operators.add_operator_metadata(op_data) do
{:ok, data} -> {:ok, {op, data}}
{:error, msg} -> {:error, msg}
end
end)
|> tap(&dbg/1)
# Filter status ok and map to {op, op_data}
|> Enum.filter(fn {status, _} -> status == :ok end)
|> Enum.map(fn {_, data} -> data end)

dbg(operators)

# Insert in db
Enum.map(operators, fn {op, op_data} ->
Operator.changeset(op, op_data) |> Repo.insert_or_update()
end)
end
:ok
end
end
2 changes: 1 addition & 1 deletion telemetry_api/lib/telemetry_api/operators.ex
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ defmodule TelemetryApi.Operators do
# iex> add_operator_metadata(operator)
# {:error, string}
#
defp add_operator_metadata(op_data) do
def add_operator_metadata(op_data) do
with {:ok, url} <- DelegationManager.get_operator_url(op_data.address),
{:ok, metadata} <- TelemetryApi.Utils.fetch_json_data(url) do
operator = %{
Expand Down
17 changes: 17 additions & 0 deletions telemetry_api/scripts/fetch_operators_metadata.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

source .env

export ENVIRONMENT=$ENVIRONMENT
export RPC_URL=$RPC_URL
ELIXIR_HOSTNAME=$(elixir -e 'IO.puts(:inet.gethostname() |> elem(1))')
export ELIXIR_HOSTNAME=$ELIXIR_HOSTNAME
export ALIGNED_CONFIG_FILE=$ALIGNED_CONFIG_FILE
export OPERATOR_FETCHER_WAIT_TIME_MS=$OPERATOR_FETCHER_WAIT_TIME_MS

mix compile --force #force recompile to get the latest .env values

echo "You will now connect to the Telemetry Node, make sure you run the following command inside it:"
echo "Scripts.FetchOperatorsMetadata.run()"

iex --sname fetch_operators_metadata --remsh telemetry@$ELIXIR_HOSTNAME
Loading