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: implement BeaconBlocksByRoot libp2p handler #471

Merged
merged 57 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
953002e
feat: implement BeaconBlocksByRoot libp2p handler
h3lio5 Nov 29, 2023
2f9bc77
Merge branch 'main' into p2p-beacon-blocks-by-root
h3lio5 Nov 29, 2023
c9e47dc
fix lint error
h3lio5 Nov 29, 2023
97e6707
remove logs
h3lio5 Nov 30, 2023
a0b7c23
Merge branch 'main' into p2p-beacon-blocks-by-root
h3lio5 Nov 30, 2023
fd2b09e
fixed a minor bug
h3lio5 Nov 30, 2023
4917cf3
Merge branch 'main' into p2p-beacon-blocks-by-root
h3lio5 Dec 8, 2023
961e746
add beacon_blocks_by_root to the list for discovery
h3lio5 Dec 8, 2023
d50cf7b
add unit test to BeaconBlocksByRoot handler
h3lio5 Dec 10, 2023
5c2a4f8
fix some bugs
h3lio5 Dec 10, 2023
9a13e4d
minor bug fix
h3lio5 Dec 10, 2023
8830785
fix some bugs
h3lio5 Dec 13, 2023
8952ec5
add type in match_schema
h3lio5 Dec 15, 2023
27ad0fa
Update lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex
h3lio5 Jan 5, 2024
76044fb
Update lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex
h3lio5 Jan 5, 2024
ccbf119
error handling empty messages
h3lio5 Jan 5, 2024
cd457c8
feat: implement `ssz_generic` spec tests (#490)
f3r10 Dec 11, 2023
7cafe21
fix: errors in `compute_proposer_index` (#503)
MegaRedHand Dec 11, 2023
c2e55e4
fix: errors "mismatched aggregation bits length" and "invalid signatu…
MegaRedHand Dec 11, 2023
aed341b
feat: ssz support nested containers (#509)
f3r10 Dec 12, 2023
61eae51
docs: fix spec-test runner command (#517)
Godspower-Eze Dec 12, 2023
9cc2be1
feat: merklelization of basic types (#514)
Godspower-Eze Dec 12, 2023
321fe39
feat: status req res (#492)
karasakalmt Dec 12, 2023
3dfdf01
perf: optimize `Misc.compute_committee` a bit (#515)
MegaRedHand Dec 12, 2023
c5e2d2c
perf: reduce `get_beacon_committee` calls (#518)
MegaRedHand Dec 12, 2023
92da9ef
fix: status message handler (#522)
Godspower-Eze Dec 13, 2023
44d23b2
feat: add integration to engine api. (#521)
mpaulucci Dec 13, 2023
9a39c5d
perf: small optimization on `increase_balance` and `decrease_balance`…
MegaRedHand Dec 13, 2023
a318fc0
docs: helper functionality for the makefile (#519)
Arkenan Dec 13, 2023
4ad4252
feat: added functions to handle empty slots (#495)
Godspower-Eze Dec 14, 2023
e644543
feat: add `Ssz` vs `SszEx` benchmark (w `Checkpoint`) (#527)
MegaRedHand Dec 15, 2023
44137ac
perf: add `StateTransition.Cache` module (#525)
MegaRedHand Dec 18, 2023
7555b1f
perf: use ordered list indexing instead of `MapSet` (#529)
MegaRedHand Dec 18, 2023
fc6b673
fix: rename cli options related to execution client. (#537)
mpaulucci Dec 19, 2023
cbaaa0e
chore: rename `SszTypes` to `Types` (#539)
mpaulucci Dec 19, 2023
027c82c
docs: add `GetMetadata` example (#538)
MegaRedHand Dec 19, 2023
0a3c7e8
fix: allow not passing `--execution-jwt` flag (#542)
MegaRedHand Dec 21, 2023
b558b39
perf: batched attestation processing (#533)
MegaRedHand Dec 21, 2023
6c534c3
fix: bitvector creation and serialization (#547)
Arkenan Dec 22, 2023
3047560
refactor: allow for more networks apart from mainnet (#546)
mpaulucci Dec 22, 2023
09261d0
refactor: move config to runtime.exs. (#548)
mpaulucci Dec 22, 2023
af37663
feat: implement rewards spec test runner (#536)
f3r10 Dec 22, 2023
992f591
fix: was using `SszTypes` in `rewards` spec-test runner (#551)
MegaRedHand Dec 27, 2023
f435301
feat: download anchor block from checkpoint sync api instead of peers…
mpaulucci Jan 2, 2024
c3e7c73
perf: store validators in array (#544)
MegaRedHand Jan 2, 2024
058a951
perf: store `X_epoch_participation` and `balances` in vectors (#550)
MegaRedHand Jan 4, 2024
61280ac
perf: optimize `process_justification_and_finalization` (#555)
MegaRedHand Jan 4, 2024
62cbc9a
refactor: add beacon node supervisor. (#566)
mpaulucci Jan 4, 2024
1920bf7
feat: add bitlist and bitvector ssz support (#494)
f3r10 Jan 4, 2024
dcd6261
fix: process block attestations and slashings (#567)
MegaRedHand Jan 4, 2024
817633c
fix: run `mix clean` on `clean` target (#575)
MegaRedHand Jan 4, 2024
b3a2a8d
Merge branch 'main' into p2p-beacon-blocks-by-root
h3lio5 Jan 5, 2024
ce81aad
Merge branch 'main' into p2p-beacon-blocks-by-root
h3lio5 Jan 8, 2024
ffee49f
replace SszTypes with Types
h3lio5 Jan 8, 2024
f1b5e61
Merge branch 'main' into p2p-beacon-blocks-by-root
MegaRedHand Jan 12, 2024
c9b8c72
refactor
h3lio5 Jan 15, 2024
ef13ecf
fix lint errors
h3lio5 Jan 16, 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
29 changes: 29 additions & 0 deletions lib/lambda_ethereum_consensus/p2p/incoming_requests/handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,35 @@ defmodule LambdaEthereumConsensus.P2P.IncomingRequests.Handler do
end
end

defp handle_req("beacon_blocks_by_root/2/ssz_snappy", message_id, message) do
MegaRedHand marked this conversation as resolved.
Show resolved Hide resolved
with <<24, snappy_blocks_by_root_request::binary>> <- message,
MegaRedHand marked this conversation as resolved.
Show resolved Hide resolved
{:ok, ssz_blocks_by_root_request} <- Snappy.decompress(snappy_blocks_by_root_request),
{:ok, blocks_by_root_request} <-
Ssz.from_ssz(ssz_blocks_by_root_request, SszTypes.BeaconBlocksByRootRequest) do
## TODO: there should be check that the `start_slot` is not older than the `oldest_slot_with_block`
%SszTypes.BeaconBlocksByRootRequest{body: body} =
MegaRedHand marked this conversation as resolved.
Show resolved Hide resolved
blocks_by_root_request

count = length(body)

count = min(count, ChainSpec.get("MAX_REQUEST_BLOCKS"))
MegaRedHand marked this conversation as resolved.
Show resolved Hide resolved
h3lio5 marked this conversation as resolved.
Show resolved Hide resolved

"[Received BlocksByRoot Request] requested #{count} number of blocks"
|> Logger.info()

blocks =
body
|> Enum.slice(0..(count - 1))
|> Enum.map(&BlockStore.get_block/1)

response_chunk =
blocks
|> Enum.map_join(&create_block_response_chunk/1)
h3lio5 marked this conversation as resolved.
Show resolved Hide resolved

Libp2pPort.send_response(message_id, response_chunk)
end
end

defp handle_req(protocol, _message_id, _message) do
# This should never happen, since Libp2p only accepts registered protocols
Logger.error("Unsupported protocol: #{protocol}")
Expand Down
17 changes: 17 additions & 0 deletions lib/ssz_types/p2p/beacon_blocks_ by_root_response.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
defmodule SszTypes.BeaconBlocksByRootRequest do
@moduledoc """
Struct definition for `BeaconBlocksByRootRequest`.
Related definitions in `native/ssz_nif/src/types/`.
"""

fields = [
:body
]

@enforce_keys fields
defstruct fields

@type t :: %__MODULE__{
body: list(SszTypes.SignedBeaconBlock.t())
MegaRedHand marked this conversation as resolved.
Show resolved Hide resolved
}
end
17 changes: 17 additions & 0 deletions lib/ssz_types/p2p/beacon_blocks_by_root_request.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
defmodule SszTypes.BeaconBlocksByRootResponse do
@moduledoc """
Struct definition for `BeaconBlocksByRootResponse`.
Related definitions in `native/ssz_nif/src/types/`.
"""

fields = [
:body
]

@enforce_keys fields
defstruct fields

@type t :: %__MODULE__{
body: list(SszTypes.root())
MegaRedHand marked this conversation as resolved.
Show resolved Hide resolved
}
end
18 changes: 17 additions & 1 deletion native/ssz_nif/src/elx_types/p2p.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,28 @@ gen_struct!(

gen_struct_with_config!(
#[derive(NifStruct)]
#[module = "SszTypes.BeaconBlocksByRangeRequest"]
#[module = "SszTypes.BeaconBlocksByRangeResponse"]
h3lio5 marked this conversation as resolved.
Show resolved Hide resolved
MegaRedHand marked this conversation as resolved.
Show resolved Hide resolved
pub(crate) struct BeaconBlocksByRangeResponse<'a> {
body: Vec<SignedBeaconBlock<'a>>,
}
);

gen_struct!(
#[derive(NifStruct)]
#[module = "SszTypes.BeaconBlocksByRootRequest"]
pub(crate) struct BeaconBlocksByRootRequest<'a> {
body: Vec<Root<'a>>,
}
);

gen_struct_with_config!(
#[derive(NifStruct)]
#[module = "SszTypes.BeaconBlocksByRootResponse"]
pub(crate) struct BeaconBlocksByRootResponse<'a> {
MegaRedHand marked this conversation as resolved.
Show resolved Hide resolved
body: Vec<SignedBeaconBlock<'a>>,
}
);

gen_struct_with_config!(
#[derive(NifStruct)]
#[module = "SszTypes.Metadata"]
Expand Down
10 changes: 10 additions & 0 deletions native/ssz_nif/src/ssz_types/p2p.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ pub(crate) struct BeaconBlocksByRangeResponse<C: Config> {
pub(crate) body: VariableList<SignedBeaconBlock<C>, MaxRequestBlocks>,
}

#[derive(Encode, Decode, TreeHash)]
pub(crate) struct BeaconBlocksByRootRequest {
pub(crate) body: VariableList<Root, MaxRequestBlocks>,
}

#[derive(Encode, Decode, TreeHash)]
pub(crate) struct BeaconBlocksByRootResponse<C: Config> {
pub(crate) body: VariableList<SignedBeaconBlock<C>, MaxRequestBlocks>,
}

#[derive(Encode, Decode, TreeHash)]
pub(crate) struct Metadata<C: Config> {
pub(crate) seq_number: u64,
Expand Down
Loading