From a297e4d9b410e1f5e7635d097a3dbf0015136303 Mon Sep 17 00:00:00 2001 From: karasakalmt Date: Mon, 11 Dec 2023 13:24:28 +0200 Subject: [PATCH 01/36] metadata --- lib/lambda_ethereum_consensus/p2p/metadata.ex | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 lib/lambda_ethereum_consensus/p2p/metadata.ex diff --git a/lib/lambda_ethereum_consensus/p2p/metadata.ex b/lib/lambda_ethereum_consensus/p2p/metadata.ex new file mode 100644 index 000000000..d4c9c5529 --- /dev/null +++ b/lib/lambda_ethereum_consensus/p2p/metadata.ex @@ -0,0 +1,16 @@ +defmodule LambdaEthereumConsensus.P2P.Metadata do + use Genserver + + ########################## + ### Public API + ########################## + + ########################## + ### GenServer Callbacks + ########################## + + ########################## + ### Private Functions + ########################## + +end From abf1dc48f50ce248aba74b118124097aeb83bb60 Mon Sep 17 00:00:00 2001 From: karasakalmt Date: Tue, 12 Dec 2023 11:53:38 +0200 Subject: [PATCH 02/36] metadata genserver --- lib/lambda_ethereum_consensus/p2p/metadata.ex | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/lib/lambda_ethereum_consensus/p2p/metadata.ex b/lib/lambda_ethereum_consensus/p2p/metadata.ex index d4c9c5529..39cba9415 100644 --- a/lib/lambda_ethereum_consensus/p2p/metadata.ex +++ b/lib/lambda_ethereum_consensus/p2p/metadata.ex @@ -1,16 +1,52 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do - use Genserver + use GenServer + + alias SszTypes.Metadata + + @default_timeout 10_000 ########################## ### Public API ########################## + @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, @default_timeout) + end + ########################## ### GenServer Callbacks ########################## + @impl GenServer + def init(metadata) do + {: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 + + @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}, @default_timeout) + end + end From 415e7b87ba3cce0401a87a22e79a8e889744787c Mon Sep 17 00:00:00 2001 From: karasakalmt Date: Tue, 12 Dec 2023 12:08:28 +0200 Subject: [PATCH 03/36] metadata impl --- .../p2p/incoming_requests/handler.ex | 5 +++-- lib/lambda_ethereum_consensus/p2p/metadata.ex | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex b/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex index bb8614183..540c41651 100644 --- a/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex +++ b/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex @@ -4,6 +4,7 @@ defmodule LambdaEthereumConsensus.P2P.IncomingRequests.Handler do """ require Logger alias LambdaEthereumConsensus.{Libp2pPort, P2P} + alias LambdaEthereumConsensus.P2P.Metadata alias LambdaEthereumConsensus.Store.BlockStore # This is the `ForkDigest` for mainnet in the capella fork @@ -85,7 +86,7 @@ defmodule LambdaEthereumConsensus.P2P.IncomingRequests.Handler do |> then(&"[Ping] seq_number: #{&1}") |> Logger.debug(), {:ok, payload} <- - <<0, 0, 0, 0, 0, 0, 0, 0>> + Metadata.get_seq_number() |> Snappy.compress() do Libp2pPort.send_response(message_id, <<0, 8>> <> payload) end @@ -94,7 +95,7 @@ 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>> + Metadata.get_metadata() |> Snappy.compress() do Libp2pPort.send_response(message_id, <<0, 17>> <> payload) end diff --git a/lib/lambda_ethereum_consensus/p2p/metadata.ex b/lib/lambda_ethereum_consensus/p2p/metadata.ex index 39cba9415..958e711cb 100644 --- a/lib/lambda_ethereum_consensus/p2p/metadata.ex +++ b/lib/lambda_ethereum_consensus/p2p/metadata.ex @@ -1,4 +1,8 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do + @moduledoc """ + This module handles Metadata's genserver to fetch and edit. + """ + use GenServer alias SszTypes.Metadata @@ -9,7 +13,7 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do ### Public API ########################## - @spec get_seq_number() :: SszTypes.uint64 + @spec get_seq_number() :: SszTypes.uint64() def get_seq_number do [seq_number] = get_metadata_attrs([:seq_number]) seq_number @@ -48,5 +52,4 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do defp get_metadata_attrs(attrs) do GenServer.call(__MODULE__, {:get_metadata_attrs, attrs}, @default_timeout) end - end From ad900bdeaecf7affe311876bed216b17cd441b24 Mon Sep 17 00:00:00 2001 From: karasakalmt Date: Tue, 12 Dec 2023 12:23:13 +0200 Subject: [PATCH 04/36] bild --- lib/lambda_ethereum_consensus/p2p/metadata.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/lambda_ethereum_consensus/p2p/metadata.ex b/lib/lambda_ethereum_consensus/p2p/metadata.ex index 958e711cb..0c1a97558 100644 --- a/lib/lambda_ethereum_consensus/p2p/metadata.ex +++ b/lib/lambda_ethereum_consensus/p2p/metadata.ex @@ -19,7 +19,7 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do seq_number end - @spec get_metadata() :: MetaData.t() + @spec get_metadata() :: SszTypes.Metadata.t() def get_metadata do GenServer.call(__MODULE__, :get_metadata, @default_timeout) end From 8d59c86e2e1e4ddf68124f4441d630872dda5a73 Mon Sep 17 00:00:00 2001 From: karasakalmt Date: Tue, 12 Dec 2023 12:23:38 +0200 Subject: [PATCH 05/36] refactor --- lib/lambda_ethereum_consensus/p2p/metadata.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/lambda_ethereum_consensus/p2p/metadata.ex b/lib/lambda_ethereum_consensus/p2p/metadata.ex index 0c1a97558..d737d8b04 100644 --- a/lib/lambda_ethereum_consensus/p2p/metadata.ex +++ b/lib/lambda_ethereum_consensus/p2p/metadata.ex @@ -19,7 +19,7 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do seq_number end - @spec get_metadata() :: SszTypes.Metadata.t() + @spec get_metadata() :: Metadata.t() def get_metadata do GenServer.call(__MODULE__, :get_metadata, @default_timeout) end From d6e2120567ecf4efe314b3ed0b1b1dcf2f5a62fa Mon Sep 17 00:00:00 2001 From: karasakalmt Date: Tue, 12 Dec 2023 12:34:56 +0200 Subject: [PATCH 06/36] tossz added --- .../p2p/incoming_requests/handler.ex | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex b/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex index 540c41651..80a8a327b 100644 --- a/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex +++ b/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex @@ -94,9 +94,9 @@ defmodule LambdaEthereumConsensus.P2P.IncomingRequests.Handler do defp handle_req("metadata/2/ssz_snappy", message_id, _message) do # Values are hardcoded - with {:ok, payload} <- - Metadata.get_metadata() - |> Snappy.compress() do + with metadata <- Metadata.get_metadata(), + {:ok, payload} <- Ssz.to_ssz(metadata), + {:ok, payload} <- Snappy.compress(payload) do Libp2pPort.send_response(message_id, <<0, 17>> <> payload) end end From ebc38b51937b8358116564fd907e6bf67b2830b4 Mon Sep 17 00:00:00 2001 From: karasakalmt Date: Tue, 12 Dec 2023 12:43:48 +0200 Subject: [PATCH 07/36] ping fix --- .../p2p/incoming_requests/handler.ex | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex b/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex index 80a8a327b..920c003a8 100644 --- a/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex +++ b/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex @@ -85,9 +85,9 @@ defmodule LambdaEthereumConsensus.P2P.IncomingRequests.Handler do |> :binary.decode_unsigned(:little) |> then(&"[Ping] seq_number: #{&1}") |> Logger.debug(), - {:ok, payload} <- - Metadata.get_seq_number() - |> Snappy.compress() do + seq_number <- Metadata.get_seq_number(), + {:ok, payload} <- Ssz.to_ssz(seq_number), + {:ok, payload} <- Snappy.compress(payload) do Libp2pPort.send_response(message_id, <<0, 8>> <> payload) end end From a734a67f9c865a6943cafd55dc7dd31d17efe815 Mon Sep 17 00:00:00 2001 From: karasakalmt Date: Tue, 12 Dec 2023 14:36:54 +0200 Subject: [PATCH 08/36] encode seq number --- lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex b/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex index 920c003a8..3134c4bc8 100644 --- a/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex +++ b/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex @@ -5,6 +5,7 @@ defmodule LambdaEthereumConsensus.P2P.IncomingRequests.Handler do require Logger alias LambdaEthereumConsensus.{Libp2pPort, P2P} alias LambdaEthereumConsensus.P2P.Metadata + alias LambdaEthereumConsensus.SszEx alias LambdaEthereumConsensus.Store.BlockStore # This is the `ForkDigest` for mainnet in the capella fork @@ -86,7 +87,7 @@ defmodule LambdaEthereumConsensus.P2P.IncomingRequests.Handler do |> then(&"[Ping] seq_number: #{&1}") |> Logger.debug(), seq_number <- Metadata.get_seq_number(), - {:ok, payload} <- Ssz.to_ssz(seq_number), + {:ok, payload} <- SszEx.encode(seq_number), {:ok, payload} <- Snappy.compress(payload) do Libp2pPort.send_response(message_id, <<0, 8>> <> payload) end From d13626e03de663bdf4552418e31e89165d17f017 Mon Sep 17 00:00:00 2001 From: karasakalmt Date: Wed, 13 Dec 2023 14:38:48 +0200 Subject: [PATCH 09/36] build issue --- .../p2p/incoming_requests/handler.ex | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex b/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex index 3134c4bc8..dc298de84 100644 --- a/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex +++ b/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex @@ -86,9 +86,9 @@ defmodule LambdaEthereumConsensus.P2P.IncomingRequests.Handler do |> :binary.decode_unsigned(:little) |> then(&"[Ping] seq_number: #{&1}") |> Logger.debug(), - seq_number <- Metadata.get_seq_number(), - {:ok, payload} <- SszEx.encode(seq_number), - {:ok, payload} <- Snappy.compress(payload) do + {:ok, payload} <- + <<0, 0, 0, 0, 0, 0, 0, 0>> + |> Snappy.compress() do Libp2pPort.send_response(message_id, <<0, 8>> <> payload) end end From a7f3319ed2cfdc4790e9bec61fe0b15dea2ff70a Mon Sep 17 00:00:00 2001 From: karasakalmt Date: Wed, 13 Dec 2023 14:51:34 +0200 Subject: [PATCH 10/36] build issue --- lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex b/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex index ffbf44f3f..65724eccf 100644 --- a/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex +++ b/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex @@ -6,7 +6,6 @@ defmodule LambdaEthereumConsensus.P2P.IncomingRequests.Handler do alias LambdaEthereumConsensus.ForkChoice alias LambdaEthereumConsensus.{Libp2pPort, P2P} - alias LambdaEthereumConsensus.SszEx alias LambdaEthereumConsensus.Store.BlockStore # This is the `ForkDigest` for mainnet in the capella fork From 4d64bf97c72996c8a4ae6cc89086955c8059e788 Mon Sep 17 00:00:00 2001 From: karasakalmt Date: Thu, 14 Dec 2023 13:17:52 +0200 Subject: [PATCH 11/36] comment fix --- lib/lambda_ethereum_consensus/application.ex | 1 + .../p2p/incoming_requests/handler.ex | 3 +-- lib/lambda_ethereum_consensus/p2p/metadata.ex | 10 ++++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/lambda_ethereum_consensus/application.ex b/lib/lambda_ethereum_consensus/application.ex index 3256a2242..d2150487f 100644 --- a/lib/lambda_ethereum_consensus/application.ex +++ b/lib/lambda_ethereum_consensus/application.ex @@ -33,6 +33,7 @@ defmodule LambdaEthereumConsensus.Application do {LambdaEthereumConsensus.Beacon.PendingBlocks, []}, {LambdaEthereumConsensus.Beacon.SyncBlocks, []}, {LambdaEthereumConsensus.P2P.GossipSub, []}, + {LambdaEthereumConsensus.P2P.Metadata, []}, # Start the Endpoint (http/https) {BeaconApi.Endpoint, []} ] diff --git a/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex b/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex index 65724eccf..ad3fbc0ed 100644 --- a/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex +++ b/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex @@ -86,8 +86,7 @@ defmodule LambdaEthereumConsensus.P2P.IncomingRequests.Handler do defp handle_req("metadata/2/ssz_snappy", message_id, _message) do # Values are hardcoded with metadata <- P2P.Metadata.get_metadata(), - {:ok, payload} <- Ssz.to_ssz(metadata), - {:ok, payload} <- Snappy.compress(payload) do + {:ok, payload} <- Ssz.to_ssz(metadata) |> Snappy.compress() do Libp2pPort.send_response(message_id, <<0, 17>> <> payload) end end diff --git a/lib/lambda_ethereum_consensus/p2p/metadata.ex b/lib/lambda_ethereum_consensus/p2p/metadata.ex index d737d8b04..7cbbe4f2e 100644 --- a/lib/lambda_ethereum_consensus/p2p/metadata.ex +++ b/lib/lambda_ethereum_consensus/p2p/metadata.ex @@ -7,12 +7,14 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do alias SszTypes.Metadata - @default_timeout 10_000 - ########################## ### 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]) @@ -21,7 +23,7 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do @spec get_metadata() :: Metadata.t() def get_metadata do - GenServer.call(__MODULE__, :get_metadata, @default_timeout) + GenServer.call(__MODULE__, :get_metadata) end ########################## @@ -50,6 +52,6 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do @spec get_metadata_attrs([atom()]) :: [any()] defp get_metadata_attrs(attrs) do - GenServer.call(__MODULE__, {:get_metadata_attrs, attrs}, @default_timeout) + GenServer.call(__MODULE__, {:get_metadata_attrs, attrs}) end end From 5e736bd47157076cd7798f7b0cbf2c48f2b661e7 Mon Sep 17 00:00:00 2001 From: karasakalmt Date: Thu, 14 Dec 2023 13:19:44 +0200 Subject: [PATCH 12/36] supervisor added --- lib/lambda_ethereum_consensus/p2p/metadata.ex | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/lambda_ethereum_consensus/p2p/metadata.ex b/lib/lambda_ethereum_consensus/p2p/metadata.ex index 7cbbe4f2e..0df56eca3 100644 --- a/lib/lambda_ethereum_consensus/p2p/metadata.ex +++ b/lib/lambda_ethereum_consensus/p2p/metadata.ex @@ -4,6 +4,7 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do """ use GenServer + use Supervisor alias SszTypes.Metadata From 5f9933063c227ef0a416d038e9c58404cf42dc9b Mon Sep 17 00:00:00 2001 From: karasakalmt Date: Thu, 14 Dec 2023 14:16:02 +0200 Subject: [PATCH 13/36] comment removed --- lib/lambda_ethereum_consensus/application.ex | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/lambda_ethereum_consensus/application.ex b/lib/lambda_ethereum_consensus/application.ex index 8dbeae4d8..a7216271f 100644 --- a/lib/lambda_ethereum_consensus/application.ex +++ b/lib/lambda_ethereum_consensus/application.ex @@ -35,7 +35,6 @@ defmodule LambdaEthereumConsensus.Application do {LambdaEthereumConsensus.Beacon.SyncBlocks, []}, {LambdaEthereumConsensus.P2P.GossipSub, []}, {LambdaEthereumConsensus.P2P.Metadata, []}, - # Start the Endpoint (http/https) {BeaconApi.Endpoint, []} ] From 271137bd0a8966549e91312aca9352e88efa0901 Mon Sep 17 00:00:00 2001 From: karasakalmt Date: Thu, 14 Dec 2023 14:31:16 +0200 Subject: [PATCH 14/36] build issur --- lib/lambda_ethereum_consensus/p2p/metadata.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/lambda_ethereum_consensus/p2p/metadata.ex b/lib/lambda_ethereum_consensus/p2p/metadata.ex index 0df56eca3..df21a3369 100644 --- a/lib/lambda_ethereum_consensus/p2p/metadata.ex +++ b/lib/lambda_ethereum_consensus/p2p/metadata.ex @@ -31,7 +31,7 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do ### GenServer Callbacks ########################## - @impl GenServer + @impl true def init(metadata) do {:ok, metadata} end From 4573713eb747dc690dd4eb2fe0559a1e55c87b27 Mon Sep 17 00:00:00 2001 From: karasakalmt Date: Mon, 1 Jan 2024 16:56:22 +0300 Subject: [PATCH 15/36] set functions and new init --- lib/lambda_ethereum_consensus/p2p/metadata.ex | 42 ++++++++++++++++--- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/lib/lambda_ethereum_consensus/p2p/metadata.ex b/lib/lambda_ethereum_consensus/p2p/metadata.ex index df21a3369..9ac30870e 100644 --- a/lib/lambda_ethereum_consensus/p2p/metadata.ex +++ b/lib/lambda_ethereum_consensus/p2p/metadata.ex @@ -6,14 +6,15 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do use GenServer use Supervisor + alias LambdaEthereumConsensus.Utils.BitVector alias SszTypes.Metadata ########################## ### Public API ########################## - def start_link(arg) do - Supervisor.start_link(__MODULE__, arg, name: __MODULE__) + def start_link(opts) do + Supervisor.start_link(__MODULE__, opts, name: __MODULE__) end @spec get_seq_number() :: SszTypes.uint64() @@ -31,9 +32,16 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do ### GenServer Callbacks ########################## - @impl true - def init(metadata) do - {:ok, metadata} + @impl GenServer + def init(_opts) do + {:ok, + %Metadata{ + seq_number: 0, + #get values from config + attnets: BitVector.new(0,), + syncnets: BitVector.new(0,) + } + } end @impl GenServer @@ -47,6 +55,20 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do {:reply, metadata} end + @impl GenServer + def handle_cast({:set_attestation_subnet, i, set}, _from, metadata) do + metadata.attnets = if set, do: BitVector.set(metadata.attnets, i), else: BitVector.clear(metadata.attnets, i) + metadata.seq_number = metadata.seq_number + 1 + {:noreply, metadata} + end + + @impl GenServer + def handle_cast({:set_sync_committee, i, set}, _from, metadata) do + metadata.syncnets = if set, do: BitVector.set(metadata.syncnets, i), else: BitVector.clear(metadata.syncnets, i) + metadata.seq_number = metadata.seq_number + 1 + {:noreply, metadata} + end + ########################## ### Private Functions ########################## @@ -55,4 +77,14 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do defp get_metadata_attrs(attrs) do GenServer.call(__MODULE__, {:get_metadata_attrs, attrs}) end + + @spec set_attestation_subnet(integer(), boolean()) + defp set_attestation_subnet(i, set) do + GenServer.call(__MODULE__, {:set_attestation_subnet, i, set}) + end + + @spec set_sync_committee(integer(), boolean()) + defp set_sync_committee(i, set) do + GenServer.call(__MODULE__, {:set_sync_committee, i, set}) + end end From 163276e211dbfa5134327675e2929fe8a068498a Mon Sep 17 00:00:00 2001 From: karasakalmt Date: Tue, 2 Jan 2024 16:35:17 +0300 Subject: [PATCH 16/36] format --- lib/lambda_ethereum_consensus/p2p/metadata.ex | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/lambda_ethereum_consensus/p2p/metadata.ex b/lib/lambda_ethereum_consensus/p2p/metadata.ex index 9ac30870e..7189f024a 100644 --- a/lib/lambda_ethereum_consensus/p2p/metadata.ex +++ b/lib/lambda_ethereum_consensus/p2p/metadata.ex @@ -35,13 +35,12 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do @impl GenServer def init(_opts) do {:ok, - %Metadata{ - seq_number: 0, - #get values from config - attnets: BitVector.new(0,), - syncnets: BitVector.new(0,) - } - } + %Metadata{ + seq_number: 0 + # get values from config + attnets: BitVector.new(0,), + syncnets: BitVector.new(0,) + }} end @impl GenServer @@ -57,14 +56,18 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do @impl GenServer def handle_cast({:set_attestation_subnet, i, set}, _from, metadata) do - metadata.attnets = if set, do: BitVector.set(metadata.attnets, i), else: BitVector.clear(metadata.attnets, i) + metadata.attnets = + if set, do: BitVector.set(metadata.attnets, i), else: BitVector.clear(metadata.attnets, i) + metadata.seq_number = metadata.seq_number + 1 {:noreply, metadata} end @impl GenServer def handle_cast({:set_sync_committee, i, set}, _from, metadata) do - metadata.syncnets = if set, do: BitVector.set(metadata.syncnets, i), else: BitVector.clear(metadata.syncnets, i) + metadata.syncnets = + if set, do: BitVector.set(metadata.syncnets, i), else: BitVector.clear(metadata.syncnets, i) + metadata.seq_number = metadata.seq_number + 1 {:noreply, metadata} end From 4fdf181afba16d538d7f4a5fae04b29c53b848c8 Mon Sep 17 00:00:00 2001 From: karasakalmt Date: Wed, 3 Jan 2024 12:41:09 +0200 Subject: [PATCH 17/36] added constatnt --- lib/constants.ex | 6 ++++++ lib/lambda_ethereum_consensus/p2p/metadata.ex | 7 +++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/constants.ex b/lib/constants.ex index 7430d13f6..3eddd6406 100644 --- a/lib/constants.ex +++ b/lib/constants.ex @@ -117,4 +117,10 @@ defmodule Constants do @spec proposer_score_boost() :: non_neg_integer() def proposer_score_boost, do: 3 + + @spec attestation_subnet_count() :: non_neg_integer() + def attestation_subnet_count, do: 2 ** 6 + + @spec sync_committee_subnet_count() :: non_neg_integer() + def sync_committee_subnet_count, do: 4 end diff --git a/lib/lambda_ethereum_consensus/p2p/metadata.ex b/lib/lambda_ethereum_consensus/p2p/metadata.ex index 7189f024a..5d4ab14af 100644 --- a/lib/lambda_ethereum_consensus/p2p/metadata.ex +++ b/lib/lambda_ethereum_consensus/p2p/metadata.ex @@ -36,10 +36,9 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do def init(_opts) do {:ok, %Metadata{ - seq_number: 0 - # get values from config - attnets: BitVector.new(0,), - syncnets: BitVector.new(0,) + seq_number: 0, + attnets: BitVector.new(0, Constants.attestation_subnet_count()), + syncnets: BitVector.new(0, Constants.sync_committee_subnet_count()) }} end From a96883f833c260f68267598502b1457dca761549 Mon Sep 17 00:00:00 2001 From: karasakalmt Date: Wed, 3 Jan 2024 12:56:53 +0200 Subject: [PATCH 18/36] comment removed --- lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex b/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex index ad3fbc0ed..b34b19baf 100644 --- a/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex +++ b/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex @@ -84,7 +84,6 @@ defmodule LambdaEthereumConsensus.P2P.IncomingRequests.Handler do end defp handle_req("metadata/2/ssz_snappy", message_id, _message) do - # Values are hardcoded with metadata <- P2P.Metadata.get_metadata(), {:ok, payload} <- Ssz.to_ssz(metadata) |> Snappy.compress() do Libp2pPort.send_response(message_id, <<0, 17>> <> payload) From 3fd665c87c06e74a26d3be5772b3b01aed71e20e Mon Sep 17 00:00:00 2001 From: karasakalmt Date: Wed, 3 Jan 2024 13:06:50 +0200 Subject: [PATCH 19/36] lint --- lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex b/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex index 3d8b42177..19d15976d 100644 --- a/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex +++ b/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex @@ -4,9 +4,9 @@ defmodule LambdaEthereumConsensus.P2P.IncomingRequests.Handler do """ require Logger - alias LambdaEthereumConsensus.Store.BlockStore alias LambdaEthereumConsensus.ForkChoice alias LambdaEthereumConsensus.{Libp2pPort, P2P} + alias LambdaEthereumConsensus.Store.BlockStore require Logger From 2d9e7df5c771095428b20aee0bba08c18eee3e44 Mon Sep 17 00:00:00 2001 From: karasakalmt Date: Wed, 3 Jan 2024 13:18:46 +0200 Subject: [PATCH 20/36] build issue --- lib/lambda_ethereum_consensus/p2p/metadata.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/lambda_ethereum_consensus/p2p/metadata.ex b/lib/lambda_ethereum_consensus/p2p/metadata.ex index 5d4ab14af..1f36d03e7 100644 --- a/lib/lambda_ethereum_consensus/p2p/metadata.ex +++ b/lib/lambda_ethereum_consensus/p2p/metadata.ex @@ -7,7 +7,7 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do use Supervisor alias LambdaEthereumConsensus.Utils.BitVector - alias SszTypes.Metadata + alias Types.Metadata ########################## ### Public API @@ -17,7 +17,7 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do Supervisor.start_link(__MODULE__, opts, name: __MODULE__) end - @spec get_seq_number() :: SszTypes.uint64() + @spec get_seq_number() :: Types.uint64() def get_seq_number do [seq_number] = get_metadata_attrs([:seq_number]) seq_number From e4eb0d338e07de8827c08b36d0c274d067636cf0 Mon Sep 17 00:00:00 2001 From: karasakalmt Date: Wed, 3 Jan 2024 13:25:36 +0200 Subject: [PATCH 21/36] build issue --- lib/lambda_ethereum_consensus/p2p/metadata.ex | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/lambda_ethereum_consensus/p2p/metadata.ex b/lib/lambda_ethereum_consensus/p2p/metadata.ex index 1f36d03e7..d7e3edaf7 100644 --- a/lib/lambda_ethereum_consensus/p2p/metadata.ex +++ b/lib/lambda_ethereum_consensus/p2p/metadata.ex @@ -28,6 +28,16 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do GenServer.call(__MODULE__, :get_metadata) end + @spec set_attestation_subnet(integer(), boolean()) + def set_attestation_subnet(i, set) do + GenServer.call(__MODULE__, {:set_attestation_subnet, i, set}) + end + + @spec set_sync_committee(integer(), boolean()) + def set_sync_committee(i, set) do + GenServer.call(__MODULE__, {:set_sync_committee, i, set}) + end + ########################## ### GenServer Callbacks ########################## @@ -79,14 +89,4 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do defp get_metadata_attrs(attrs) do GenServer.call(__MODULE__, {:get_metadata_attrs, attrs}) end - - @spec set_attestation_subnet(integer(), boolean()) - defp set_attestation_subnet(i, set) do - GenServer.call(__MODULE__, {:set_attestation_subnet, i, set}) - end - - @spec set_sync_committee(integer(), boolean()) - defp set_sync_committee(i, set) do - GenServer.call(__MODULE__, {:set_sync_committee, i, set}) - end end From 7bce9b18c972d701266b457bd4227ae206fbb1b4 Mon Sep 17 00:00:00 2001 From: karasakalmt Date: Wed, 3 Jan 2024 13:38:13 +0200 Subject: [PATCH 22/36] build issue --- lib/lambda_ethereum_consensus/p2p/metadata.ex | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/lambda_ethereum_consensus/p2p/metadata.ex b/lib/lambda_ethereum_consensus/p2p/metadata.ex index d7e3edaf7..0964511e8 100644 --- a/lib/lambda_ethereum_consensus/p2p/metadata.ex +++ b/lib/lambda_ethereum_consensus/p2p/metadata.ex @@ -65,19 +65,21 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do @impl GenServer def handle_cast({:set_attestation_subnet, i, set}, _from, metadata) do - metadata.attnets = - if set, do: BitVector.set(metadata.attnets, i), else: BitVector.clear(metadata.attnets, i) - - metadata.seq_number = metadata.seq_number + 1 + metadata = %Metadata{ + metadata | + attnets: if set, do: BitVector.set(metadata.attnets, i), else: BitVector.clear(metadata.attnets, i) + seq_number: metadata.seq_number + 1 + } {:noreply, metadata} end @impl GenServer def handle_cast({:set_sync_committee, i, set}, _from, metadata) do - metadata.syncnets = - if set, do: BitVector.set(metadata.syncnets, i), else: BitVector.clear(metadata.syncnets, i) - - metadata.seq_number = metadata.seq_number + 1 + metadata = %Metadata{ + metadata | + syncnets: if set, do: BitVector.set(metadata.syncnets, i), else: BitVector.clear(metadata.syncnets, i) + seq_number: metadata.seq_number + 1 + } {:noreply, metadata} end From 915d638525e0b58f3b0907cf178c4d717458dfdb Mon Sep 17 00:00:00 2001 From: karasakalmt Date: Wed, 3 Jan 2024 13:42:00 +0200 Subject: [PATCH 23/36] build issue --- lib/lambda_ethereum_consensus/p2p/metadata.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/lambda_ethereum_consensus/p2p/metadata.ex b/lib/lambda_ethereum_consensus/p2p/metadata.ex index 0964511e8..da9382fd9 100644 --- a/lib/lambda_ethereum_consensus/p2p/metadata.ex +++ b/lib/lambda_ethereum_consensus/p2p/metadata.ex @@ -67,7 +67,7 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do def handle_cast({:set_attestation_subnet, i, set}, _from, metadata) do metadata = %Metadata{ metadata | - attnets: if set, do: BitVector.set(metadata.attnets, i), else: BitVector.clear(metadata.attnets, i) + attnets: if set, do: BitVector.set(metadata.attnets, i), else: BitVector.clear(metadata.attnets, i), seq_number: metadata.seq_number + 1 } {:noreply, metadata} @@ -77,7 +77,7 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do def handle_cast({:set_sync_committee, i, set}, _from, metadata) do metadata = %Metadata{ metadata | - syncnets: if set, do: BitVector.set(metadata.syncnets, i), else: BitVector.clear(metadata.syncnets, i) + syncnets: if set, do: BitVector.set(metadata.syncnets, i), else: BitVector.clear(metadata.syncnets, i), seq_number: metadata.seq_number + 1 } {:noreply, metadata} From c1ed672fe64691fb51e9c44013a4ddba7a8b45f9 Mon Sep 17 00:00:00 2001 From: karasakalmt Date: Wed, 3 Jan 2024 13:44:22 +0200 Subject: [PATCH 24/36] build issue --- lib/lambda_ethereum_consensus/p2p/metadata.ex | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/lib/lambda_ethereum_consensus/p2p/metadata.ex b/lib/lambda_ethereum_consensus/p2p/metadata.ex index da9382fd9..8ec860c99 100644 --- a/lib/lambda_ethereum_consensus/p2p/metadata.ex +++ b/lib/lambda_ethereum_consensus/p2p/metadata.ex @@ -65,22 +65,28 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do @impl GenServer def handle_cast({:set_attestation_subnet, i, set}, _from, metadata) do - metadata = %Metadata{ - metadata | - attnets: if set, do: BitVector.set(metadata.attnets, i), else: BitVector.clear(metadata.attnets, i), - seq_number: metadata.seq_number + 1 - } - {:noreply, metadata} + attnets = + if set, do: BitVector.set(metadata.attnets, i), else: BitVector.clear(metadata.attnets, i) + + {:noreply, + %Metadata{ + metadata + | attnets: attnets, + seq_number: metadata.seq_number + 1 + }} end @impl GenServer def handle_cast({:set_sync_committee, i, set}, _from, metadata) do - metadata = %Metadata{ - metadata | - syncnets: if set, do: BitVector.set(metadata.syncnets, i), else: BitVector.clear(metadata.syncnets, i), - seq_number: metadata.seq_number + 1 - } - {:noreply, metadata} + syncnets = + if set, do: BitVector.set(metadata.syncnets, i), else: BitVector.clear(metadata.syncnets, i) + + {:noreply, + %Metadata{ + metadata + | syncnets: syncnets, + seq_number: metadata.seq_number + 1 + }} end ########################## From e2e558ebe043b2b0663cae28d350f8b58eaf5081 Mon Sep 17 00:00:00 2001 From: karasakalmt Date: Wed, 3 Jan 2024 13:56:29 +0200 Subject: [PATCH 25/36] build issue --- lib/lambda_ethereum_consensus/p2p/metadata.ex | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/lambda_ethereum_consensus/p2p/metadata.ex b/lib/lambda_ethereum_consensus/p2p/metadata.ex index 8ec860c99..51961d8bd 100644 --- a/lib/lambda_ethereum_consensus/p2p/metadata.ex +++ b/lib/lambda_ethereum_consensus/p2p/metadata.ex @@ -4,7 +4,6 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do """ use GenServer - use Supervisor alias LambdaEthereumConsensus.Utils.BitVector alias Types.Metadata @@ -28,12 +27,12 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do GenServer.call(__MODULE__, :get_metadata) end - @spec set_attestation_subnet(integer(), boolean()) + @spec set_attestation_subnet(integer(), boolean()) :: none() def set_attestation_subnet(i, set) do GenServer.call(__MODULE__, {:set_attestation_subnet, i, set}) end - @spec set_sync_committee(integer(), boolean()) + @spec set_sync_committee(integer(), boolean()) :: none() def set_sync_committee(i, set) do GenServer.call(__MODULE__, {:set_sync_committee, i, set}) end @@ -42,7 +41,8 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do ### GenServer Callbacks ########################## - @impl GenServer + @impl true + @spec init(any) :: Metadata.t() def init(_opts) do {:ok, %Metadata{ @@ -52,19 +52,19 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do }} end - @impl GenServer + @impl true def handle_call({:get_metadata_attrs, attrs}, _from, metadata) do values = Enum.map(attrs, &Map.fetch!(metadata, &1)) {:reply, values, metadata} end - @impl GenServer + @impl true def handle_call(:get_metadata, _from, metadata) do {:reply, metadata} end - @impl GenServer - def handle_cast({:set_attestation_subnet, i, set}, _from, metadata) do + @impl true + def handle_cast({:set_attestation_subnet, i, set}, metadata) do attnets = if set, do: BitVector.set(metadata.attnets, i), else: BitVector.clear(metadata.attnets, i) @@ -76,8 +76,8 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do }} end - @impl GenServer - def handle_cast({:set_sync_committee, i, set}, _from, metadata) do + @impl true + def handle_cast({:set_sync_committee, i, set}, metadata) do syncnets = if set, do: BitVector.set(metadata.syncnets, i), else: BitVector.clear(metadata.syncnets, i) From 11241dd0cfac6b53332d0cc0eaffcaa6b0c25902 Mon Sep 17 00:00:00 2001 From: karasakalmt Date: Wed, 3 Jan 2024 14:09:41 +0200 Subject: [PATCH 26/36] build issue --- .../p2p/incoming_requests/handler.ex | 3 ++- lib/lambda_ethereum_consensus/p2p/metadata.ex | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex b/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex index 19d15976d..64804c429 100644 --- a/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex +++ b/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex @@ -87,7 +87,8 @@ defmodule LambdaEthereumConsensus.P2P.IncomingRequests.Handler do defp handle_req("metadata/2/ssz_snappy", message_id, _message) do with metadata <- P2P.Metadata.get_metadata(), - {:ok, payload} <- Ssz.to_ssz(metadata) |> Snappy.compress() do + {:ok, metadata_ssz} <- Ssz.to_ssz(metadata), + {:ok, payload} <- Snappy.compress(metadata_ssz) do Libp2pPort.send_response(message_id, <<0, 17>> <> payload) end end diff --git a/lib/lambda_ethereum_consensus/p2p/metadata.ex b/lib/lambda_ethereum_consensus/p2p/metadata.ex index 51961d8bd..3a9312854 100644 --- a/lib/lambda_ethereum_consensus/p2p/metadata.ex +++ b/lib/lambda_ethereum_consensus/p2p/metadata.ex @@ -27,12 +27,12 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do GenServer.call(__MODULE__, :get_metadata) end - @spec set_attestation_subnet(integer(), boolean()) :: none() + @spec set_attestation_subnet(integer(), boolean()) :: any() def set_attestation_subnet(i, set) do GenServer.call(__MODULE__, {:set_attestation_subnet, i, set}) end - @spec set_sync_committee(integer(), boolean()) :: none() + @spec set_sync_committee(integer(), boolean()) :: any() def set_sync_committee(i, set) do GenServer.call(__MODULE__, {:set_sync_committee, i, set}) end @@ -42,7 +42,7 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do ########################## @impl true - @spec init(any) :: Metadata.t() + @spec init(any) :: {:ok, Metadata.t()} def init(_opts) do {:ok, %Metadata{ From 0d7952c9a5a8265cfa94e2986d334fcdf2b5b048 Mon Sep 17 00:00:00 2001 From: karasakalmt Date: Thu, 4 Jan 2024 21:07:57 +0200 Subject: [PATCH 27/36] added network config --- config/networks/mainnet/config.yaml | 44 +++++++++++++------ config/networks/minimal/config.yaml | 37 +++++++++++----- lib/constants.ex | 3 -- lib/lambda_ethereum_consensus/p2p/metadata.ex | 2 +- 4 files changed, 58 insertions(+), 28 deletions(-) diff --git a/config/networks/mainnet/config.yaml b/config/networks/mainnet/config.yaml index 39e08ef39..8df491df6 100644 --- a/config/networks/mainnet/config.yaml +++ b/config/networks/mainnet/config.yaml @@ -1,14 +1,14 @@ # Mainnet config # Extends the mainnet preset -PRESET_BASE: 'mainnet' +PRESET_BASE: "mainnet" # Free-form short name of the network that this configuration applies to - known # canonical network names include: # * 'mainnet' - there can be only one # * 'prater' - testnet # Must match the regex: [a-z0-9\-] -CONFIG_NAME: 'mainnet' +CONFIG_NAME: "mainnet" # Transition # --------------------------------------------------------------- @@ -18,8 +18,6 @@ TERMINAL_TOTAL_DIFFICULTY: 58750000000000000000000 TERMINAL_BLOCK_HASH: 0x0000000000000000000000000000000000000000000000000000000000000000 TERMINAL_BLOCK_HASH_ACTIVATION_EPOCH: 18446744073709551615 - - # Genesis # --------------------------------------------------------------- # `2**14` (= 16,384) @@ -31,7 +29,6 @@ GENESIS_FORK_VERSION: 0x00000000 # 604800 seconds (7 days) GENESIS_DELAY: 604800 - # Forking # --------------------------------------------------------------- # Some forks are disabled for now: @@ -40,20 +37,17 @@ GENESIS_DELAY: 604800 # Altair ALTAIR_FORK_VERSION: 0x01000000 -ALTAIR_FORK_EPOCH: 74240 # Oct 27, 2021, 10:56:23am UTC +ALTAIR_FORK_EPOCH: 74240 # Oct 27, 2021, 10:56:23am UTC # Bellatrix BELLATRIX_FORK_VERSION: 0x02000000 -BELLATRIX_FORK_EPOCH: 144896 # Sept 6, 2022, 11:34:47am UTC +BELLATRIX_FORK_EPOCH: 144896 # Sept 6, 2022, 11:34:47am UTC # Capella CAPELLA_FORK_VERSION: 0x03000000 -CAPELLA_FORK_EPOCH: 194048 # April 12, 2023, 10:27:35pm UTC +CAPELLA_FORK_EPOCH: 194048 # April 12, 2023, 10:27:35pm UTC # Deneb DENEB_FORK_VERSION: 0x04000000 DENEB_FORK_EPOCH: 18446744073709551615 - - - # Time parameters # --------------------------------------------------------------- # 12 seconds @@ -67,7 +61,6 @@ SHARD_COMMITTEE_PERIOD: 256 # 2**11 (= 2,048) Eth1 blocks ~8 hours ETH1_FOLLOW_DISTANCE: 2048 - # Validator cycle # --------------------------------------------------------------- # 2**2 (= 4) @@ -81,7 +74,6 @@ MIN_PER_EPOCH_CHURN_LIMIT: 4 # 2**16 (= 65,536) CHURN_LIMIT_QUOTIENT: 65536 - # Fork choice # --------------------------------------------------------------- # 40% @@ -96,5 +88,29 @@ DEPOSIT_CONTRACT_ADDRESS: 0x00000000219ab540356cBB839Cbe05303d7705Fa # Networking # --------------------------------------------------------------- +# `10 * 2**20` (= 10485760, 10 MiB) +GOSSIP_MAX_SIZE: 10485760 # `2**10` (= 1024) -MAX_REQUEST_BLOCKS: 1024 \ No newline at end of file +MAX_REQUEST_BLOCKS: 1024 +# `2**8` (= 256) +EPOCHS_PER_SUBNET_SUBSCRIPTION: 256 +# `MIN_VALIDATOR_WITHDRAWABILITY_DELAY + CHURN_LIMIT_QUOTIENT // 2` (= 33024, ~5 months) +MIN_EPOCHS_FOR_BLOCK_REQUESTS: 33024 +# `10 * 2**20` (=10485760, 10 MiB) +MAX_CHUNK_SIZE: 10485760 +# 5s +TTFB_TIMEOUT: 5 +# 10s +RESP_TIMEOUT: 10 +ATTESTATION_PROPAGATION_SLOT_RANGE: 32 +# 500ms +MAXIMUM_GOSSIP_CLOCK_DISPARITY: 500 +MESSAGE_DOMAIN_INVALID_SNAPPY: 0x00000000 +MESSAGE_DOMAIN_VALID_SNAPPY: 0x01000000 +# 2 subnets per node +SUBNETS_PER_NODE: 2 +# 2**8 (= 64) +ATTESTATION_SUBNET_COUNT: 64 +ATTESTATION_SUBNET_EXTRA_BITS: 0 +# ceillog2(ATTESTATION_SUBNET_COUNT) + ATTESTATION_SUBNET_EXTRA_BITS +ATTESTATION_SUBNET_PREFIX_BITS: 6 diff --git a/config/networks/minimal/config.yaml b/config/networks/minimal/config.yaml index df1451501..fe5b6fc03 100644 --- a/config/networks/minimal/config.yaml +++ b/config/networks/minimal/config.yaml @@ -1,14 +1,14 @@ # Minimal config # Extends the minimal preset -PRESET_BASE: 'minimal' +PRESET_BASE: "minimal" # Free-form short name of the network that this configuration applies to - known # canonical network names include: # * 'mainnet' - there can be only one # * 'prater' - testnet # Must match the regex: [a-z0-9\-] -CONFIG_NAME: 'minimal' +CONFIG_NAME: "minimal" # Transition # --------------------------------------------------------------- @@ -18,8 +18,6 @@ TERMINAL_TOTAL_DIFFICULTY: 11579208923731619542357098500868790785326998466564056 TERMINAL_BLOCK_HASH: 0x0000000000000000000000000000000000000000000000000000000000000000 TERMINAL_BLOCK_HASH_ACTIVATION_EPOCH: 18446744073709551615 - - # Genesis # --------------------------------------------------------------- # [customized] @@ -31,7 +29,6 @@ GENESIS_FORK_VERSION: 0x00000001 # [customized] Faster to spin up testnets, but does not give validator reasonable warning time for genesis GENESIS_DELAY: 300 - # Forking # --------------------------------------------------------------- # Values provided for illustrative purposes. @@ -50,7 +47,6 @@ CAPELLA_FORK_EPOCH: 18446744073709551615 DENEB_FORK_VERSION: 0x04000001 DENEB_FORK_EPOCH: 18446744073709551615 - # Time parameters # --------------------------------------------------------------- # [customized] Faster for testing purposes @@ -64,7 +60,6 @@ SHARD_COMMITTEE_PERIOD: 64 # [customized] process deposits more quickly, but insecure ETH1_FOLLOW_DISTANCE: 16 - # Validator cycle # --------------------------------------------------------------- # 2**2 (= 4) @@ -78,13 +73,11 @@ MIN_PER_EPOCH_CHURN_LIMIT: 4 # [customized] scale queue churn at much lower validator counts for testing CHURN_LIMIT_QUOTIENT: 32 - # Fork choice # --------------------------------------------------------------- # 40% PROPOSER_SCORE_BOOST: 40 - # Deposit contract # --------------------------------------------------------------- # Ethereum Goerli testnet @@ -95,5 +88,29 @@ DEPOSIT_CONTRACT_ADDRESS: 0x1234567890123456789012345678901234567890 # Networking # --------------------------------------------------------------- +# `10 * 2**20` (= 10485760, 10 MiB) +GOSSIP_MAX_SIZE: 10485760 # `2**10` (= 1024) -MAX_REQUEST_BLOCKS: 1024 \ No newline at end of file +MAX_REQUEST_BLOCKS: 1024 +# `2**8` (= 256) +EPOCHS_PER_SUBNET_SUBSCRIPTION: 256 +# [customized] `MIN_VALIDATOR_WITHDRAWABILITY_DELAY + CHURN_LIMIT_QUOTIENT // 2` (= 272) +MIN_EPOCHS_FOR_BLOCK_REQUESTS: 272 +# `10 * 2**20` (=10485760, 10 MiB) +MAX_CHUNK_SIZE: 10485760 +# 5s +TTFB_TIMEOUT: 5 +# 10s +RESP_TIMEOUT: 10 +ATTESTATION_PROPAGATION_SLOT_RANGE: 32 +# 500ms +MAXIMUM_GOSSIP_CLOCK_DISPARITY: 500 +MESSAGE_DOMAIN_INVALID_SNAPPY: 0x00000000 +MESSAGE_DOMAIN_VALID_SNAPPY: 0x01000000 +# 2 subnets per node +SUBNETS_PER_NODE: 2 +# 2**8 (= 64) +ATTESTATION_SUBNET_COUNT: 64 +ATTESTATION_SUBNET_EXTRA_BITS: 0 +# ceillog2(ATTESTATION_SUBNET_COUNT) + ATTESTATION_SUBNET_EXTRA_BITS +ATTESTATION_SUBNET_PREFIX_BITS: 6 diff --git a/lib/constants.ex b/lib/constants.ex index 37b1079ac..15cd366a6 100644 --- a/lib/constants.ex +++ b/lib/constants.ex @@ -118,9 +118,6 @@ defmodule Constants do @spec proposer_score_boost() :: non_neg_integer() def proposer_score_boost, do: 3 - @spec attestation_subnet_count() :: non_neg_integer() - def attestation_subnet_count, do: 2 ** 6 - @spec sync_committee_subnet_count() :: non_neg_integer() def sync_committee_subnet_count, do: 4 end diff --git a/lib/lambda_ethereum_consensus/p2p/metadata.ex b/lib/lambda_ethereum_consensus/p2p/metadata.ex index 3a9312854..aa8758737 100644 --- a/lib/lambda_ethereum_consensus/p2p/metadata.ex +++ b/lib/lambda_ethereum_consensus/p2p/metadata.ex @@ -47,7 +47,7 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do {:ok, %Metadata{ seq_number: 0, - attnets: BitVector.new(0, Constants.attestation_subnet_count()), + attnets: BitVector.new(0, ChainSpec.get("ATTESTATION_SUBNET_COUNT")), syncnets: BitVector.new(0, Constants.sync_committee_subnet_count()) }} end From f1c268775813c8d060cf45383fef6929568c4ce7 Mon Sep 17 00:00:00 2001 From: karasakalmt Date: Mon, 8 Jan 2024 19:01:46 +0300 Subject: [PATCH 28/36] fixed the conflicting part --- lib/lambda_ethereum_consensus/application.ex | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/lambda_ethereum_consensus/application.ex b/lib/lambda_ethereum_consensus/application.ex index 01edafd27..d354cd589 100644 --- a/lib/lambda_ethereum_consensus/application.ex +++ b/lib/lambda_ethereum_consensus/application.ex @@ -29,13 +29,8 @@ defmodule LambdaEthereumConsensus.Application do {LambdaEthereumConsensus.Libp2pPort, libp2p_opts}, {LambdaEthereumConsensus.Store.Db, []}, {LambdaEthereumConsensus.P2P.Peerbook, []}, - {LambdaEthereumConsensus.ForkChoice, [checkpoint_sync]}, - {LambdaEthereumConsensus.P2P.IncomingRequests, []}, - {LambdaEthereumConsensus.Beacon.PendingBlocks, []}, - {LambdaEthereumConsensus.Beacon.SyncBlocks, []}, - {LambdaEthereumConsensus.P2P.GossipSub, []}, - {LambdaEthereumConsensus.P2P.Metadata, []}, {LambdaEthereumConsensus.Beacon.BeaconNode, [checkpoint_sync]}, + {LambdaEthereumConsensus.P2P.Metadata, []}, {BeaconApi.Endpoint, []} ] From 0d263787596dcc44ae6d5e00804b79e570216597 Mon Sep 17 00:00:00 2001 From: karasakalmt Date: Wed, 10 Jan 2024 00:36:03 +0300 Subject: [PATCH 29/36] made private func --- lib/lambda_ethereum_consensus/p2p/metadata.ex | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/lambda_ethereum_consensus/p2p/metadata.ex b/lib/lambda_ethereum_consensus/p2p/metadata.ex index aa8758737..79ce81491 100644 --- a/lib/lambda_ethereum_consensus/p2p/metadata.ex +++ b/lib/lambda_ethereum_consensus/p2p/metadata.ex @@ -65,8 +65,7 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do @impl true def handle_cast({:set_attestation_subnet, i, set}, metadata) do - attnets = - if set, do: BitVector.set(metadata.attnets, i), else: BitVector.clear(metadata.attnets, i) + attnets = set_or_clear(metadata.attnets, i, set) {:noreply, %Metadata{ @@ -78,8 +77,7 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do @impl true def handle_cast({:set_sync_committee, i, set}, metadata) do - syncnets = - if set, do: BitVector.set(metadata.syncnets, i), else: BitVector.clear(metadata.syncnets, i) + syncnets = set_or_clear(metadata.syncnets, i, set) {:noreply, %Metadata{ @@ -97,4 +95,13 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do defp get_metadata_attrs(attrs) do GenServer.call(__MODULE__, {:get_metadata_attrs, attrs}) end + + @spec set_or_clear(BitVector.t(), integer(), boolean()) :: BitVector.t() + defp set_or_clear(bitvector, i, set) do + if set do + BitVector.set(bitvector, i) + else + BitVector.clear(bitvector, i) + end + end end From 9f1f707d1877e0fb7cd5fbfa160ceb6407fcab54 Mon Sep 17 00:00:00 2001 From: karasakalmt Date: Wed, 10 Jan 2024 01:00:35 +0300 Subject: [PATCH 30/36] changed to getseq number --- lib/lambda_ethereum_consensus/p2p/metadata.ex | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/lib/lambda_ethereum_consensus/p2p/metadata.ex b/lib/lambda_ethereum_consensus/p2p/metadata.ex index 79ce81491..06e65cec5 100644 --- a/lib/lambda_ethereum_consensus/p2p/metadata.ex +++ b/lib/lambda_ethereum_consensus/p2p/metadata.ex @@ -18,8 +18,7 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do @spec get_seq_number() :: Types.uint64() def get_seq_number do - [seq_number] = get_metadata_attrs([:seq_number]) - seq_number + GenServer.call(__MODULE__, {:get_seq_number}) end @spec get_metadata() :: Metadata.t() @@ -53,9 +52,9 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do end @impl true - def handle_call({:get_metadata_attrs, attrs}, _from, metadata) do - values = Enum.map(attrs, &Map.fetch!(metadata, &1)) - {:reply, values, metadata} + def handle_call({:get_seq_number, attrs}, _from, metadata) do + seq_number = Map.fetch!(metadata, :seq_number) + {:reply, seq_number, metadata} end @impl true @@ -91,11 +90,6 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do ### Private Functions ########################## - @spec get_metadata_attrs([atom()]) :: [any()] - defp get_metadata_attrs(attrs) do - GenServer.call(__MODULE__, {:get_metadata_attrs, attrs}) - end - @spec set_or_clear(BitVector.t(), integer(), boolean()) :: BitVector.t() defp set_or_clear(bitvector, i, set) do if set do From 7063e22cb4528c2863a15caf1ef4c154936d7b92 Mon Sep 17 00:00:00 2001 From: karasakalmt Date: Wed, 10 Jan 2024 15:09:16 +0300 Subject: [PATCH 31/36] fix:lint --- lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex b/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex index 9a1d159ab..1cc49762c 100644 --- a/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex +++ b/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex @@ -4,8 +4,8 @@ defmodule LambdaEthereumConsensus.P2P.IncomingRequests.Handler do """ require Logger - alias LambdaEthereumConsensus.ForkChoice alias LambdaEthereumConsensus.Beacon.BeaconChain + alias LambdaEthereumConsensus.ForkChoice alias LambdaEthereumConsensus.{Libp2pPort, P2P} alias LambdaEthereumConsensus.Store.BlockStore From d1fdc8f6775027777c02e904b424eb73822d6d7c Mon Sep 17 00:00:00 2001 From: karasakalmt Date: Wed, 10 Jan 2024 15:23:16 +0300 Subject: [PATCH 32/36] fix: build --- lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex | 1 - lib/lambda_ethereum_consensus/p2p/metadata.ex | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex b/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex index 1cc49762c..995cd0c9b 100644 --- a/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex +++ b/lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex @@ -5,7 +5,6 @@ defmodule LambdaEthereumConsensus.P2P.IncomingRequests.Handler do require Logger alias LambdaEthereumConsensus.Beacon.BeaconChain - alias LambdaEthereumConsensus.ForkChoice alias LambdaEthereumConsensus.{Libp2pPort, P2P} alias LambdaEthereumConsensus.Store.BlockStore diff --git a/lib/lambda_ethereum_consensus/p2p/metadata.ex b/lib/lambda_ethereum_consensus/p2p/metadata.ex index 06e65cec5..f0c2034bd 100644 --- a/lib/lambda_ethereum_consensus/p2p/metadata.ex +++ b/lib/lambda_ethereum_consensus/p2p/metadata.ex @@ -52,7 +52,7 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do end @impl true - def handle_call({:get_seq_number, attrs}, _from, metadata) do + def handle_call({:get_seq_number}, _from, metadata) do seq_number = Map.fetch!(metadata, :seq_number) {:reply, seq_number, metadata} end From db2769f80bc4ff6bc756f261c830494adbcafd5b Mon Sep 17 00:00:00 2001 From: karasakalmt Date: Thu, 11 Jan 2024 00:37:02 +0300 Subject: [PATCH 33/36] fix: change genserver init --- lib/lambda_ethereum_consensus/p2p/metadata.ex | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/lambda_ethereum_consensus/p2p/metadata.ex b/lib/lambda_ethereum_consensus/p2p/metadata.ex index f0c2034bd..2d3752ed9 100644 --- a/lib/lambda_ethereum_consensus/p2p/metadata.ex +++ b/lib/lambda_ethereum_consensus/p2p/metadata.ex @@ -44,7 +44,7 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do @spec init(any) :: {:ok, Metadata.t()} def init(_opts) do {:ok, - %Metadata{ + %{ seq_number: 0, attnets: BitVector.new(0, ChainSpec.get("ATTESTATION_SUBNET_COUNT")), syncnets: BitVector.new(0, Constants.sync_committee_subnet_count()) @@ -59,7 +59,13 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do @impl true def handle_call(:get_metadata, _from, metadata) do - {:reply, metadata} + {:reply, + %Metadata{ + seq_number: metadata.seq_number + attnets: metadata.attnets + syncnets: metadata.syncnets + } + } end @impl true @@ -67,7 +73,7 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do attnets = set_or_clear(metadata.attnets, i, set) {:noreply, - %Metadata{ + %{ metadata | attnets: attnets, seq_number: metadata.seq_number + 1 @@ -79,7 +85,7 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do syncnets = set_or_clear(metadata.syncnets, i, set) {:noreply, - %Metadata{ + %{ metadata | syncnets: syncnets, seq_number: metadata.seq_number + 1 From 16cb04deaa66d7f00915481705799199146fa249 Mon Sep 17 00:00:00 2001 From: karasakalmt Date: Thu, 11 Jan 2024 00:47:52 +0300 Subject: [PATCH 34/36] fix: build --- lib/lambda_ethereum_consensus/p2p/metadata.ex | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/lambda_ethereum_consensus/p2p/metadata.ex b/lib/lambda_ethereum_consensus/p2p/metadata.ex index 2d3752ed9..13e3799c3 100644 --- a/lib/lambda_ethereum_consensus/p2p/metadata.ex +++ b/lib/lambda_ethereum_consensus/p2p/metadata.ex @@ -41,7 +41,6 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do ########################## @impl true - @spec init(any) :: {:ok, Metadata.t()} def init(_opts) do {:ok, %{ @@ -60,12 +59,11 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do @impl true def handle_call(:get_metadata, _from, metadata) do {:reply, - %Metadata{ - seq_number: metadata.seq_number - attnets: metadata.attnets - syncnets: metadata.syncnets - } - } + %Metadata{ + seq_number: metadata.seq_number, + attnets: metadata.attnets, + syncnets: metadata.syncnets + }} end @impl true From afe873fd54075a58c827dd5db03c2360b0b4813b Mon Sep 17 00:00:00 2001 From: karasakalmt Date: Thu, 11 Jan 2024 21:58:31 +0300 Subject: [PATCH 35/36] fix: typo --- lib/lambda_ethereum_consensus/p2p/metadata.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/lambda_ethereum_consensus/p2p/metadata.ex b/lib/lambda_ethereum_consensus/p2p/metadata.ex index 13e3799c3..17fc909f1 100644 --- a/lib/lambda_ethereum_consensus/p2p/metadata.ex +++ b/lib/lambda_ethereum_consensus/p2p/metadata.ex @@ -13,7 +13,7 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do ########################## def start_link(opts) do - Supervisor.start_link(__MODULE__, opts, name: __MODULE__) + GenServer.start_link(__MODULE__, opts, name: __MODULE__) end @spec get_seq_number() :: Types.uint64() From 20857c94e2cedf27545d0fb213da517020373bc8 Mon Sep 17 00:00:00 2001 From: karasakalmt Date: Thu, 11 Jan 2024 21:59:37 +0300 Subject: [PATCH 36/36] fix: return to old version --- lib/lambda_ethereum_consensus/p2p/metadata.ex | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/lambda_ethereum_consensus/p2p/metadata.ex b/lib/lambda_ethereum_consensus/p2p/metadata.ex index 17fc909f1..a5cec0c04 100644 --- a/lib/lambda_ethereum_consensus/p2p/metadata.ex +++ b/lib/lambda_ethereum_consensus/p2p/metadata.ex @@ -43,7 +43,7 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do @impl true def init(_opts) do {:ok, - %{ + %Metadata{ seq_number: 0, attnets: BitVector.new(0, ChainSpec.get("ATTESTATION_SUBNET_COUNT")), syncnets: BitVector.new(0, Constants.sync_committee_subnet_count()) @@ -58,12 +58,7 @@ defmodule LambdaEthereumConsensus.P2P.Metadata do @impl true def handle_call(:get_metadata, _from, metadata) do - {:reply, - %Metadata{ - seq_number: metadata.seq_number, - attnets: metadata.attnets, - syncnets: metadata.syncnets - }} + {:reply, metadata} end @impl true