Skip to content

Commit

Permalink
refactor: fix node configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
avilagaston9 committed Jul 12, 2024
1 parent 770993d commit 76c2702
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 113 deletions.
44 changes: 40 additions & 4 deletions lib/lambda_ethereum_consensus/beacon/pending_blocks.ex
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ defmodule LambdaEthereumConsensus.Beacon.PendingBlocks do

if Enum.empty?(missing_blobs) do
Blocks.new_block_info(block_info)

Metrics.block_status(
block_info.root,
block_info.signed_block.message.slot,
:pending
)

Metrics.block_relationship(
block_info.signed_block.message.parent_root,
block_info.root
)

process_block_and_check_children(block_info)
else
BlobDownloader.request_blobs_by_root(missing_blobs, &process_blobs/1, 30)
Expand All @@ -53,10 +65,10 @@ defmodule LambdaEthereumConsensus.Beacon.PendingBlocks do
end
end

Metrics.block_relationship(
block_info.signed_block.message.parent_root,
block_info.root
)
# Metrics.block_relationship(
# block_info.signed_block.message.parent_root,
# block_info.root
# )
end

##########################
Expand Down Expand Up @@ -108,6 +120,19 @@ defmodule LambdaEthereumConsensus.Beacon.PendingBlocks do
case ForkChoice.on_block(block_info) do
:ok ->
Blocks.change_status(block_info, :transitioned)

Metrics.block_status(
block_info.root,
block_info.signed_block.message.slot,
:pending,
:transitioned
)

Metrics.block_relationship(
block_info.signed_block.message.parent_root,
block_info.root
)

:transitioned

{:error, reason} ->
Expand Down Expand Up @@ -143,6 +168,17 @@ defmodule LambdaEthereumConsensus.Beacon.PendingBlocks do
with %BlockInfo{} = block_info <- Blocks.get_block_info(root) do
# TODO: add a new missing blobs call if some blobs are still missing for a block.
if Enum.empty?(missing_blobs(block_info)) do
Metrics.block_status(
block_info.root,
block_info.signed_block.message.slot,
:pending
)

Metrics.block_relationship(
block_info.signed_block.message.parent_root,
block_info.root
)

block_info
|> Blocks.change_status(:pending)
|> process_block_and_check_children()
Expand Down
39 changes: 19 additions & 20 deletions lib/lambda_ethereum_consensus/metrics.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ defmodule LambdaEthereumConsensus.Metrics do
@moduledoc """
Basic telemetry metric generation to be used across the node.
"""
alias LambdaEthereumConsensus.Store.Blocks
alias Types.BlockInfo
require Logger

def tracer({:add_peer, %{}}) do
:telemetry.execute([:network, :pubsub_peers], %{}, %{result: "add"})
Expand Down Expand Up @@ -69,27 +71,22 @@ defmodule LambdaEthereumConsensus.Metrics do
end
end

def block_status(%BlockInfo{root: root, status: new_status, signed_block: nil}, old_status),
do: block_status(root, nil, old_status, new_status)

def block_status(
%BlockInfo{root: root, status: new_status, signed_block: signed_block},
old_status
),
do: block_status(root, signed_block.message.slot, old_status, new_status)

def block_status(root, slot, old_status, new_status) do
block_status_execute(root, old_status, slot, 0)
def block_status(root, slot, new_status) do
block_status_execute(root, new_status, slot, 1)
end

def block_status(root, slot, new_status) do
def block_status(root, slot, old_status, new_status) do
block_status_execute(root, old_status, slot, 0)
block_status_execute(root, new_status, slot, 1)
end

defp block_status_execute(root, status, slot, value) do
hex_root = Base.encode16(root)

Logger.info(
"[Metrics] slot = #{inspect(slot)}, status = #{inspect(status)}, value = #{inspect(value)}"
)

:telemetry.execute([:blocks, :status], %{total: value}, %{
id: hex_root,
mainstat: status,
Expand All @@ -100,14 +97,16 @@ defmodule LambdaEthereumConsensus.Metrics do
end

def block_relationship(parent_id, child_id) do
hex_parent_id = parent_id |> Base.encode16()
hex_child_id = child_id |> Base.encode16()

:telemetry.execute([:blocks, :relationship], %{total: 1}, %{
id: hex_child_id <> hex_parent_id,
source: hex_parent_id,
target: hex_child_id
})
if Blocks.get_block_info(parent_id) do
hex_parent_id = parent_id |> Base.encode16()
hex_child_id = child_id |> Base.encode16()

:telemetry.execute([:blocks, :relationship], %{total: 1}, %{
id: hex_child_id <> hex_parent_id,
source: hex_parent_id,
target: hex_child_id
})
end
end

defp map_color(:transitioned), do: "blue"
Expand Down
1 change: 0 additions & 1 deletion lib/lambda_ethereum_consensus/store/block_db.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ defmodule LambdaEthereumConsensus.Store.BlockDb do
Storage and retrieval of blocks.
"""
require Logger
# alias LambdaEthereumConsensus.Metrics
alias LambdaEthereumConsensus.Store.Db
alias LambdaEthereumConsensus.Store.Utils
alias Types.BlockInfo
Expand Down
6 changes: 4 additions & 2 deletions lib/lambda_ethereum_consensus/store/blocks.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ defmodule LambdaEthereumConsensus.Store.Blocks do
@spec add_block_to_download(Types.root()) :: :ok
def add_block_to_download(root) do
%BlockInfo{root: root, status: :download, signed_block: nil}
# |> Metrics.block_status(:download)
|> new_block_info()
end

Expand Down Expand Up @@ -82,7 +83,8 @@ defmodule LambdaEthereumConsensus.Store.Blocks do
# list. If it's not in the list, the operation is equivalent to only adding it in the correct
# one.
BlockDb.change_root_status(block_info.root, :download, block_info.status)
Metrics.block_status(block_info, :download)

# Metrics.block_status(block_info, :download)
end

@doc """
Expand All @@ -95,7 +97,7 @@ defmodule LambdaEthereumConsensus.Store.Blocks do

old_status = block_info.status
BlockDb.change_root_status(block_info.root, old_status, status)
Metrics.block_status(new_block_info, old_status)
# Metrics.block_status(new_block_info, old_status)
new_block_info
end

Expand Down
120 changes: 34 additions & 86 deletions metrics/grafana/provisioning/dashboards/home.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,60 +29,61 @@
"liveNow": false,
"panels": [
{
"type": "nodeGraph",
"title": "Blocks Statuses",
"gridPos": {
"x": 0,
"y": 0,
"w": 12,
"h": 8
},
"datasource": {
"uid": "PBFA97CFB590B2093",
"type": "prometheus"
},
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 0
},
"id": 31,
"options": {
"nodes": {},
"edges": {}
},
"targets": [
{
"refId": "A",
"expr": "blocks_status_total",
"range": true,
"instant": false,
"datasource": {
"type": "prometheus",
"uid": "PBFA97CFB590B2093"
},
"editorMode": "builder",
"legendFormat": "__auto",
"useBackend": false,
"disableTextWrap": false,
"editorMode": "builder",
"expr": "blocks_status_total",
"format": "table",
"fullMetaSearch": false,
"includeNullMetadata": true,
"format": "table"
"instant": true,
"legendFormat": "__auto",
"range": false,
"refId": "A",
"useBackend": false,
"exemplar": false
},
{
"refId": "B",
"expr": "blocks_relationship_total",
"range": true,
"instant": false,
"datasource": {
"uid": "PBFA97CFB590B2093",
"type": "prometheus"
"type": "prometheus",
"uid": "PBFA97CFB590B2093"
},
"hide": false,
"editorMode": "builder",
"legendFormat": "__auto",
"useBackend": false,
"disableTextWrap": false,
"editorMode": "builder",
"expr": "blocks_relationship_total",
"format": "table",
"fullMetaSearch": false,
"hide": false,
"includeNullMetadata": true,
"format": "table"
"instant": true,
"legendFormat": "__auto",
"range": false,
"refId": "B",
"useBackend": false,
"exemplar": false
}
],
"options": {
"nodes": {},
"edges": {}
},
"title": "Blocks Statuses",
"transformations": [
{
"id": "filterByValue",
Expand All @@ -106,62 +107,9 @@
"options": "A"
},
"topic": "series"
},
{
"id": "groupBy",
"options": {
"fields": {
"id": {
"aggregations": [],
"operation": "groupby"
},
"source": {
"aggregations": [],
"operation": "groupby"
},
"target": {
"aggregations": [],
"operation": "groupby"
}
}
},
"filter": {
"id": "byRefId",
"options": "B"
}
},
{
"id": "groupBy",
"options": {
"fields": {
"id": {
"aggregations": [],
"operation": "groupby"
},
"mainstat": {
"aggregations": [],
"operation": "groupby"
},
"title": {
"aggregations": [],
"operation": "groupby"
},
"Value #A": {
"aggregations": [],
"operation": "groupby"
},
"color": {
"aggregations": [],
"operation": "groupby"
}
}
},
"filter": {
"id": "byRefId",
"options": "A"
}
}
]
],
"type": "nodeGraph"
},
{
"datasource": {
Expand Down

0 comments on commit 76c2702

Please sign in to comment.