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

feat: ping metadata #516

Merged
merged 46 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
a297e4d
metadata
karasakalmt Dec 11, 2023
abf1dc4
metadata genserver
karasakalmt Dec 12, 2023
415e7b8
metadata impl
karasakalmt Dec 12, 2023
ad900bd
bild
karasakalmt Dec 12, 2023
8d59c86
refactor
karasakalmt Dec 12, 2023
d6e2120
tossz added
karasakalmt Dec 12, 2023
ebc38b5
ping fix
karasakalmt Dec 12, 2023
936668e
Merge branch 'main' into feat/ping_metadata
karasakalmt Dec 12, 2023
a734a67
encode seq number
karasakalmt Dec 12, 2023
d13626e
build issue
karasakalmt Dec 13, 2023
48abd59
Merge branch 'main' into feat/ping_metadata
karasakalmt Dec 13, 2023
a7f3319
build issue
karasakalmt Dec 13, 2023
4d64bf9
comment fix
karasakalmt Dec 14, 2023
5e736bd
supervisor added
karasakalmt Dec 14, 2023
89ff9de
Merge branch 'main' into feat/ping_metadata
karasakalmt Dec 14, 2023
5f99330
comment removed
karasakalmt Dec 14, 2023
271137b
build issur
karasakalmt Dec 14, 2023
4573713
set functions and new init
karasakalmt Jan 1, 2024
163276e
format
karasakalmt Jan 2, 2024
4fdf181
added constatnt
karasakalmt Jan 3, 2024
a96883f
comment removed
karasakalmt Jan 3, 2024
7cac16a
Merge branch 'main' into feat/ping_metadata
karasakalmt Jan 3, 2024
3fd665c
lint
karasakalmt Jan 3, 2024
2d9e7df
build issue
karasakalmt Jan 3, 2024
e4eb0d3
build issue
karasakalmt Jan 3, 2024
7bce9b1
build issue
karasakalmt Jan 3, 2024
915d638
build issue
karasakalmt Jan 3, 2024
c1ed672
build issue
karasakalmt Jan 3, 2024
e2e558e
build issue
karasakalmt Jan 3, 2024
11241dd
build issue
karasakalmt Jan 3, 2024
0d7952c
added network config
karasakalmt Jan 4, 2024
a7fb945
Merge branch 'main' into feat/ping_metadata
karasakalmt Jan 4, 2024
d32e584
Merge branch 'main' into feat/ping_metadata
karasakalmt Jan 8, 2024
f1c2687
fixed the conflicting part
karasakalmt Jan 8, 2024
0d26378
made private func
karasakalmt Jan 9, 2024
9f1f707
changed to getseq number
karasakalmt Jan 9, 2024
5dbabb0
Merge branch 'main' into feat/ping_metadata
karasakalmt Jan 10, 2024
7063e22
fix:lint
karasakalmt Jan 10, 2024
d1fdc8f
fix: build
karasakalmt Jan 10, 2024
db2769f
fix: change genserver init
karasakalmt Jan 10, 2024
16cb04d
fix: build
karasakalmt Jan 10, 2024
afe873f
fix: typo
karasakalmt Jan 11, 2024
20857c9
fix: return to old version
karasakalmt Jan 11, 2024
9aed705
Merge branch 'main' into feat/ping_metadata
karasakalmt Jan 11, 2024
7839060
Merge branch 'main' into feat/ping_metadata
karasakalmt Jan 11, 2024
433d08e
Merge branch 'main' into feat/ping_metadata
Arkenan Jan 12, 2024
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
2 changes: 2 additions & 0 deletions lib/lambda_ethereum_consensus/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ defmodule LambdaEthereumConsensus.Application do
{LambdaEthereumConsensus.Beacon.PendingBlocks, []},
{LambdaEthereumConsensus.Beacon.SyncBlocks, []},
{LambdaEthereumConsensus.P2P.GossipSub, []},
{LambdaEthereumConsensus.P2P.Metadata, []},
# Start the Endpoint (http/https)
karasakalmt marked this conversation as resolved.
Show resolved Hide resolved
{BeaconApi.Endpoint, []}
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ defmodule LambdaEthereumConsensus.P2P.IncomingRequests.Handler do
@moduledoc """
This module handles Req/Resp domain requests.
"""
require Logger

alias LambdaEthereumConsensus.ForkChoice
alias LambdaEthereumConsensus.Store.BlockStore
alias LambdaEthereumConsensus.{Libp2pPort, P2P}
require Logger
alias LambdaEthereumConsensus.Store.BlockStore

# This is the `ForkDigest` for mainnet in the capella fork
# TODO: compute this at runtime
Expand Down Expand Up @@ -85,9 +85,8 @@ defmodule LambdaEthereumConsensus.P2P.IncomingRequests.Handler do

defp handle_req("metadata/2/ssz_snappy", message_id, _message) do
# Values are hardcoded
with {:ok, payload} <-
<<0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0>>
|> Snappy.compress() do
with metadata <- P2P.Metadata.get_metadata(),
karasakalmt marked this conversation as resolved.
Show resolved Hide resolved
{:ok, payload} <- Ssz.to_ssz(metadata) |> Snappy.compress() do
Libp2pPort.send_response(message_id, <<0, 17>> <> payload)
end
end
Expand Down
58 changes: 58 additions & 0 deletions lib/lambda_ethereum_consensus/p2p/metadata.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
defmodule LambdaEthereumConsensus.P2P.Metadata do

Check warning on line 1 in lib/lambda_ethereum_consensus/p2p/metadata.ex

View workflow job for this annotation

GitHub Actions / Build project

conflicting behaviours found. function init/1 is required by GenServer and Supervisor (in module LambdaEthereumConsensus.P2P.Metadata)

Check warning on line 1 in lib/lambda_ethereum_consensus/p2p/metadata.ex

View workflow job for this annotation

GitHub Actions / Test

conflicting behaviours found. function init/1 is required by GenServer and Supervisor (in module LambdaEthereumConsensus.P2P.Metadata)

Check warning on line 1 in lib/lambda_ethereum_consensus/p2p/metadata.ex

View workflow job for this annotation

GitHub Actions / Run spec-tests (general)

conflicting behaviours found. function init/1 is required by GenServer and Supervisor (in module LambdaEthereumConsensus.P2P.Metadata)

Check warning on line 1 in lib/lambda_ethereum_consensus/p2p/metadata.ex

View workflow job for this annotation

GitHub Actions / Run spec-tests (general)

conflicting behaviours found. function init/1 is required by GenServer and Supervisor (in module LambdaEthereumConsensus.P2P.Metadata)

Check warning on line 1 in lib/lambda_ethereum_consensus/p2p/metadata.ex

View workflow job for this annotation

GitHub Actions / Run spec-tests (minimal)

conflicting behaviours found. function init/1 is required by GenServer and Supervisor (in module LambdaEthereumConsensus.P2P.Metadata)

Check warning on line 1 in lib/lambda_ethereum_consensus/p2p/metadata.ex

View workflow job for this annotation

GitHub Actions / Run spec-tests (minimal)

conflicting behaviours found. function init/1 is required by GenServer and Supervisor (in module LambdaEthereumConsensus.P2P.Metadata)

Check warning on line 1 in lib/lambda_ethereum_consensus/p2p/metadata.ex

View workflow job for this annotation

GitHub Actions / Run spec-tests (mainnet)

conflicting behaviours found. function init/1 is required by GenServer and Supervisor (in module LambdaEthereumConsensus.P2P.Metadata)

Check warning on line 1 in lib/lambda_ethereum_consensus/p2p/metadata.ex

View workflow job for this annotation

GitHub Actions / Run spec-tests (mainnet)

conflicting behaviours found. function init/1 is required by GenServer and Supervisor (in module LambdaEthereumConsensus.P2P.Metadata)
karasakalmt marked this conversation as resolved.
Show resolved Hide resolved
@moduledoc """
karasakalmt marked this conversation as resolved.
Show resolved Hide resolved
This module handles Metadata's genserver to fetch and edit.
"""

use GenServer
use Supervisor

alias SszTypes.Metadata

##########################
### Public API
##########################

def start_link(arg) do
Supervisor.start_link(__MODULE__, arg, name: __MODULE__)
end

@spec get_seq_number() :: SszTypes.uint64()
def get_seq_number do
[seq_number] = get_metadata_attrs([:seq_number])
seq_number
end

@spec get_metadata() :: Metadata.t()
def get_metadata do
GenServer.call(__MODULE__, :get_metadata)
end

##########################
### GenServer Callbacks
##########################

@impl GenServer
def init(metadata) do

Check warning on line 35 in lib/lambda_ethereum_consensus/p2p/metadata.ex

View workflow job for this annotation

GitHub Actions / Build project

module attribute @impl was not set for function init/1 callback (specified in Supervisor). This either means you forgot to add the "@impl true" annotation before the definition or that you are accidentally overriding this callback

Check warning on line 35 in lib/lambda_ethereum_consensus/p2p/metadata.ex

View workflow job for this annotation

GitHub Actions / Test

module attribute @impl was not set for function init/1 callback (specified in Supervisor). This either means you forgot to add the "@impl true" annotation before the definition or that you are accidentally overriding this callback

Check warning on line 35 in lib/lambda_ethereum_consensus/p2p/metadata.ex

View workflow job for this annotation

GitHub Actions / Run spec-tests (general)

module attribute @impl was not set for function init/1 callback (specified in Supervisor). This either means you forgot to add the "@impl true" annotation before the definition or that you are accidentally overriding this callback

Check warning on line 35 in lib/lambda_ethereum_consensus/p2p/metadata.ex

View workflow job for this annotation

GitHub Actions / Run spec-tests (general)

module attribute @impl was not set for function init/1 callback (specified in Supervisor). This either means you forgot to add the "@impl true" annotation before the definition or that you are accidentally overriding this callback

Check warning on line 35 in lib/lambda_ethereum_consensus/p2p/metadata.ex

View workflow job for this annotation

GitHub Actions / Run spec-tests (minimal)

module attribute @impl was not set for function init/1 callback (specified in Supervisor). This either means you forgot to add the "@impl true" annotation before the definition or that you are accidentally overriding this callback

Check warning on line 35 in lib/lambda_ethereum_consensus/p2p/metadata.ex

View workflow job for this annotation

GitHub Actions / Run spec-tests (minimal)

module attribute @impl was not set for function init/1 callback (specified in Supervisor). This either means you forgot to add the "@impl true" annotation before the definition or that you are accidentally overriding this callback

Check warning on line 35 in lib/lambda_ethereum_consensus/p2p/metadata.ex

View workflow job for this annotation

GitHub Actions / Run spec-tests (mainnet)

module attribute @impl was not set for function init/1 callback (specified in Supervisor). This either means you forgot to add the "@impl true" annotation before the definition or that you are accidentally overriding this callback

Check warning on line 35 in lib/lambda_ethereum_consensus/p2p/metadata.ex

View workflow job for this annotation

GitHub Actions / Run spec-tests (mainnet)

module attribute @impl was not set for function init/1 callback (specified in Supervisor). This either means you forgot to add the "@impl true" annotation before the definition or that you are accidentally overriding this callback
{:ok, metadata}
end

@impl GenServer
def handle_call({:get_metadata_attrs, attrs}, _from, metadata) do
values = Enum.map(attrs, &Map.fetch!(metadata, &1))
{:reply, values, metadata}
end
karasakalmt marked this conversation as resolved.
Show resolved Hide resolved

@impl GenServer
def handle_call(:get_metadata, _from, metadata) do
{:reply, metadata}
end

##########################
### Private Functions
##########################

@spec get_metadata_attrs([atom()]) :: [any()]
defp get_metadata_attrs(attrs) do
GenServer.call(__MODULE__, {:get_metadata_attrs, attrs})
end
karasakalmt marked this conversation as resolved.
Show resolved Hide resolved
end
Loading