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 all 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
44 changes: 30 additions & 14 deletions config/networks/mainnet/config.yaml
Original file line number Diff line number Diff line change
@@ -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
# ---------------------------------------------------------------
Expand All @@ -18,8 +18,6 @@ TERMINAL_TOTAL_DIFFICULTY: 58750000000000000000000
TERMINAL_BLOCK_HASH: 0x0000000000000000000000000000000000000000000000000000000000000000
TERMINAL_BLOCK_HASH_ACTIVATION_EPOCH: 18446744073709551615



# Genesis
# ---------------------------------------------------------------
# `2**14` (= 16,384)
Expand All @@ -31,7 +29,6 @@ GENESIS_FORK_VERSION: 0x00000000
# 604800 seconds (7 days)
GENESIS_DELAY: 604800


# Forking
# ---------------------------------------------------------------
# Some forks are disabled for now:
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -81,7 +74,6 @@ MIN_PER_EPOCH_CHURN_LIMIT: 4
# 2**16 (= 65,536)
CHURN_LIMIT_QUOTIENT: 65536


# Fork choice
# ---------------------------------------------------------------
# 40%
Expand All @@ -96,5 +88,29 @@ DEPOSIT_CONTRACT_ADDRESS: 0x00000000219ab540356cBB839Cbe05303d7705Fa

# Networking
# ---------------------------------------------------------------
# `10 * 2**20` (= 10485760, 10 MiB)
GOSSIP_MAX_SIZE: 10485760
karasakalmt marked this conversation as resolved.
Show resolved Hide resolved
# `2**10` (= 1024)
MAX_REQUEST_BLOCKS: 1024
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
37 changes: 27 additions & 10 deletions config/networks/minimal/config.yaml
Original file line number Diff line number Diff line change
@@ -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
# ---------------------------------------------------------------
Expand All @@ -18,8 +18,6 @@ TERMINAL_TOTAL_DIFFICULTY: 11579208923731619542357098500868790785326998466564056
TERMINAL_BLOCK_HASH: 0x0000000000000000000000000000000000000000000000000000000000000000
TERMINAL_BLOCK_HASH_ACTIVATION_EPOCH: 18446744073709551615



# Genesis
# ---------------------------------------------------------------
# [customized]
Expand All @@ -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.
Expand All @@ -50,7 +47,6 @@ CAPELLA_FORK_EPOCH: 18446744073709551615
DENEB_FORK_VERSION: 0x04000001
DENEB_FORK_EPOCH: 18446744073709551615


# Time parameters
# ---------------------------------------------------------------
# [customized] Faster for testing purposes
Expand All @@ -64,7 +60,6 @@ SHARD_COMMITTEE_PERIOD: 64
# [customized] process deposits more quickly, but insecure
ETH1_FOLLOW_DISTANCE: 16


# Validator cycle
# ---------------------------------------------------------------
# 2**2 (= 4)
Expand All @@ -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
Expand All @@ -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
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
3 changes: 3 additions & 0 deletions lib/constants.ex
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,7 @@ defmodule Constants do

@spec proposer_score_boost() :: non_neg_integer()
def proposer_score_boost, do: 3

@spec sync_committee_subnet_count() :: non_neg_integer()
def sync_committee_subnet_count, do: 4
end
1 change: 1 addition & 0 deletions lib/lambda_ethereum_consensus/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ defmodule LambdaEthereumConsensus.Application do
{LambdaEthereumConsensus.Telemetry, []},
{LambdaEthereumConsensus.Store.Db, []},
{LambdaEthereumConsensus.Beacon.BeaconNode, [checkpoint_sync]},
{LambdaEthereumConsensus.P2P.Metadata, []},
{BeaconApi.Endpoint, []}
]

Expand Down
10 changes: 5 additions & 5 deletions lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ defmodule LambdaEthereumConsensus.P2P.IncomingRequests.Handler do
@moduledoc """
This module handles Req/Resp domain requests.
"""
require Logger

alias LambdaEthereumConsensus.Beacon.BeaconChain
alias LambdaEthereumConsensus.Store.BlockStore
alias LambdaEthereumConsensus.{Libp2pPort, P2P}
alias LambdaEthereumConsensus.Store.BlockStore

require Logger

Expand Down Expand Up @@ -86,10 +87,9 @@ defmodule LambdaEthereumConsensus.P2P.IncomingRequests.Handler do
end

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, metadata_ssz} <- Ssz.to_ssz(metadata),
{:ok, payload} <- Snappy.compress(metadata_ssz) do
Libp2pPort.send_response(message_id, <<0, 17>> <> payload)
end
end
Expand Down
100 changes: 100 additions & 0 deletions lib/lambda_ethereum_consensus/p2p/metadata.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
defmodule LambdaEthereumConsensus.P2P.Metadata do
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

alias LambdaEthereumConsensus.Utils.BitVector
alias Types.Metadata

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

def start_link(opts) do
GenServer.start_link(__MODULE__, opts, name: __MODULE__)
end

@spec get_seq_number() :: Types.uint64()
def get_seq_number do
GenServer.call(__MODULE__, {:get_seq_number})
end

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

@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()) :: any()
def set_sync_committee(i, set) do
GenServer.call(__MODULE__, {:set_sync_committee, i, set})
end

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

@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())
}}
end

@impl true
def handle_call({:get_seq_number}, _from, metadata) do
seq_number = Map.fetch!(metadata, :seq_number)
{:reply, seq_number, metadata}
end

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

@impl true
def handle_cast({:set_attestation_subnet, i, set}, metadata) do
attnets = set_or_clear(metadata.attnets, i, set)

{:noreply,
%{
metadata
| attnets: attnets,
seq_number: metadata.seq_number + 1
}}
end

@impl true
def handle_cast({:set_sync_committee, i, set}, metadata) do
syncnets = set_or_clear(metadata.syncnets, i, set)

{:noreply,
%{
metadata
| syncnets: syncnets,
seq_number: metadata.seq_number + 1
}}
end

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

@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
Loading