-
Notifications
You must be signed in to change notification settings - Fork 42
refactor: move blob operations to blobs module #1404
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
52b6ef1
move blob operations to blobs.ex
LeanSerra 11c1377
moduledoc
LeanSerra 07ca6fe
try ci fix
LeanSerra 08d5975
bump go version to 1.22
LeanSerra 6c92637
blobs unit tests
LeanSerra 138bcb5
Merge branch 'main' into refactor/blob_module
LeanSerra 03f5816
fix path in blob tests
LeanSerra ad8de24
move blob downloads to blob module
LeanSerra 954fef3
rename missing_blobs to missing_for_block
LeanSerra 72ca1ef
dont process blocks in blobs module
LeanSerra 001953e
fix status change from :download_blobs to :pending was not being saved
LeanSerra 5724e6a
move process_blob back to pending_blocks, process the block if possible
LeanSerra b03cdd4
try fix for test
LeanSerra 216ec15
fix lint
LeanSerra ed08c27
add todo for #1406
LeanSerra e4c8bc3
refactor pass blobs with pipe
LeanSerra 21f705f
remove unused add_blob fn
LeanSerra 6b04c7f
add @spec and @docs for public functions
LeanSerra f133462
fix test file was being loaded with wrong ChainSpec
LeanSerra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| erlang 26.2 | ||
| elixir 1.16.2-otp-26 | ||
| golang 1.21.3 | ||
| golang 1.22 | ||
| rust 1.81.0 | ||
| protoc 24.3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| defmodule LambdaEthereumConsensus.Store.Blobs do | ||
| @moduledoc """ | ||
| Interface to `Store.Blobs`. | ||
| """ | ||
| require Logger | ||
|
|
||
| alias LambdaEthereumConsensus.Store.BlobDb | ||
| alias Types.BlobSidecar | ||
| alias Types.BlockInfo | ||
|
|
||
| @doc """ | ||
| To be used when a series of blobs are downloaded. Stores each blob. | ||
| """ | ||
| @spec add_blobs([BlobSidecar.t()]) :: [Types.root()] | ||
| def add_blobs(blobs) do | ||
rodrigo-o marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| blobs | ||
| |> Enum.map(&BlobDb.store_blob/1) | ||
| |> Enum.uniq() | ||
| end | ||
|
|
||
| @spec missing_for_block(BlockInfo.t()) :: [Types.BlobIdentifier.t()] | ||
| def missing_for_block(%BlockInfo{root: root, signed_block: signed_block}) do | ||
| signed_block.message.body.blob_kzg_commitments | ||
| |> Stream.with_index() | ||
| |> Enum.filter(&present?(&1, root)) | ||
| |> Enum.map(&%Types.BlobIdentifier{block_root: root, index: elem(&1, 1)}) | ||
| end | ||
|
|
||
| defp present?({commitment, index}, block_root) do | ||
| case BlobDb.get_blob_sidecar(block_root, index) do | ||
| {:ok, %{kzg_commitment: ^commitment}} -> | ||
| false | ||
|
|
||
| _ -> | ||
| true | ||
| end | ||
| end | ||
| end | ||
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| defmodule Unit.BlobsTest do | ||
| use ExUnit.Case | ||
| alias Fixtures.Block | ||
| alias LambdaEthereumConsensus.Store.BlobDb | ||
| alias LambdaEthereumConsensus.Store.Blobs | ||
| alias SpecTestUtils | ||
| alias Types.BlobSidecar | ||
| alias Types.BlockInfo | ||
|
|
||
| setup %{tmp_dir: tmp_dir} do | ||
| start_link_supervised!({LambdaEthereumConsensus.Store.Db, dir: tmp_dir}) | ||
| start_link_supervised!(LambdaEthereumConsensus.Store.Blocks) | ||
|
|
||
| Application.fetch_env!(:lambda_ethereum_consensus, ChainSpec) | ||
| |> Keyword.put(:config, MainnetConfig) | ||
| |> then(&Application.put_env(:lambda_ethereum_consensus, ChainSpec, &1)) | ||
|
Comment on lines
+14
to
+16
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! |
||
|
|
||
| # Blob sidecar from spec test | ||
| blob_sidecar = | ||
| SpecTestUtils.read_ssz_from_file!( | ||
| "test/fixtures/blobs/blob_sidecar.ssz_snappy", | ||
| BlobSidecar | ||
| ) | ||
|
|
||
| {:ok, blob_sidecar: blob_sidecar} | ||
| end | ||
|
|
||
| defp new_block_info() do | ||
| Block.signed_beacon_block() |> BlockInfo.from_block() | ||
| end | ||
|
|
||
| describe "Blobs unit tests" do | ||
| @tag :tmp_dir | ||
| test "Basic blobs saving and loading", %{blob_sidecar: blob_sidecar} do | ||
| Blobs.add_blobs([blob_sidecar]) | ||
| block_root = Ssz.hash_tree_root!(blob_sidecar.signed_block_header.message) | ||
| index = blob_sidecar.index | ||
| {:ok, recovered_blob} = BlobDb.get_blob_sidecar(block_root, index) | ||
|
|
||
| assert(blob_sidecar == recovered_blob) | ||
| end | ||
|
|
||
| @tag :tmp_dir | ||
| test "One missing blob from block, then add, then no missing blobs", %{ | ||
| blob_sidecar: blob_sidecar | ||
| } do | ||
| blob_sidecar = %BlobSidecar{blob_sidecar | index: 0} | ||
|
|
||
| # Create random block info | ||
| block_info = new_block_info() | ||
| # add blob_sidecar kzg_commitment to the block_info | ||
| block_info = | ||
| put_in( | ||
| block_info.signed_block.message.body.blob_kzg_commitments, | ||
| [blob_sidecar.kzg_commitment] | ||
| ) | ||
|
|
||
| # change block root to the one from the blob | ||
| block_info = %BlockInfo{ | ||
| block_info | ||
| | root: Ssz.hash_tree_root!(blob_sidecar.signed_block_header.message) | ||
| } | ||
|
|
||
| # check that the blob is detetected as missing | ||
| missing = Blobs.missing_for_block(block_info) | ||
| assert(length(missing) == 1) | ||
| # add blob to db | ||
| Blobs.add_blobs([blob_sidecar]) | ||
| # check that the blob is not missing | ||
| missing = Blobs.missing_for_block(block_info) | ||
| assert(Enum.empty?(missing)) | ||
| end | ||
| end | ||
| end | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.