Skip to content

Commit

Permalink
Merge branch 'main' into initial-assertoor-implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigo-o authored Jan 20, 2025
2 parents 6919410 + 65d0573 commit b370534
Show file tree
Hide file tree
Showing 11 changed files with 894 additions and 152 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/assertoor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ jobs:
- name: Setup kurtosis testnet and run assertoor tests
uses: ethpandaops/kurtosis-assertoor-github-action@v1
with:
kurtosis_version: "1.4.2"
ethereum_package_url: 'github.com/lambdaclass/ethereum-package'
ethereum_package_branch: 'lecc-integration-and-assertoor'
ethereum_package_args: './assertoor-config.yml'
# Additional configurations as needed
# Additional configurations as needed
2 changes: 1 addition & 1 deletion .tool-versions
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
rust 1.71.1
rust 1.81.0
protoc 24.3
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ RUN go build -o libp2p_port

# Precompile rust crates
# bls nif
FROM rust:1.71.1 AS bls_nif_builder
FROM rust:1.81.0 AS bls_nif_builder
LABEL stage=builder

RUN mkdir /bls_nif
Expand All @@ -31,7 +31,7 @@ RUN cargo build --release && \
rm -rf target/

# kzg nif
FROM rust:1.71.1 AS kzg_nif_builder
FROM rust:1.81.0 AS kzg_nif_builder
LABEL stage=builder

RUN mkdir /kzg_nif
Expand All @@ -43,7 +43,7 @@ RUN cargo build --release && \
rm -rf target/

# snappy nif
FROM rust:1.71.1 AS snappy_nif_builder
FROM rust:1.81.0 AS snappy_nif_builder
LABEL stage=builder

RUN mkdir /snappy_nif
Expand All @@ -55,7 +55,7 @@ RUN cargo build --release && \
rm -rf target/

# ssz nif
FROM rust:1.71.1 AS ssz_nif_builder
FROM rust:1.81.0 AS ssz_nif_builder
LABEL stage=builder

RUN mkdir /ssz_nif
Expand Down
7 changes: 4 additions & 3 deletions assertoor-config.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
participants:
- el_type: nethermind
cl_type: prysm
- el_type: reth
- el_type: geth
el_image: ethereum/client-go:v1.14.12
cl_type: lighthouse
cl_image: sigp/lighthouse:v5.3.0
- el_type: geth
el_image: ethereum/client-go:v1.14.12
cl_type: lambda
cl_image: lambda_ethereum_consensus:latest
use_separate_vc: false
Expand Down
6 changes: 3 additions & 3 deletions lib/lambda_ethereum_consensus/store/blob_db.ex
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ defmodule LambdaEthereumConsensus.Store.BlobDb do

with {:ok, it} <- Db.iterate(),
{:ok, @block_root_prefix <> _, _value} <-
Exleveldb.iterator_move(it, last_finalized_key),
Db.iterator_move(it, last_finalized_key),
{:ok, keys_to_remove} <- get_block_root_keys_to_remove(it),
:ok <- Exleveldb.iterator_close(it) do
:ok <- Db.iterator_close(it) do
total_removed =
keys_to_remove
|> Enum.reduce_while(0, fn
Expand All @@ -111,7 +111,7 @@ defmodule LambdaEthereumConsensus.Store.BlobDb do
@spec get_block_root_keys_to_remove(list(binary()), :eleveldb.itr_ref()) ::
{:ok, list(binary())}
defp get_block_root_keys_to_remove(keys_to_remove \\ [], iterator) do
case Exleveldb.iterator_move(iterator, :prev) do
case Db.iterator_move(iterator, :prev) do
{:ok, <<@block_root_prefix, _rest::binary>> = block_root_key, _root} ->
[block_root_key | keys_to_remove] |> get_block_root_keys_to_remove(iterator)

Expand Down
40 changes: 26 additions & 14 deletions lib/lambda_ethereum_consensus/store/db.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,49 @@ defmodule LambdaEthereumConsensus.Store.Db do

@spec put(binary, binary) :: :ok
def put(key, value) do
ref = GenServer.call(@registered_name, :get_ref)
Exleveldb.put(ref, key, value)
Exleveldb.put(ref(), key, value)
end

@spec delete(binary) :: :ok
def delete(key) do
ref = GenServer.call(@registered_name, :get_ref)
Exleveldb.delete(ref, key)
Exleveldb.delete(ref(), key)
end

@spec get(binary) :: {:ok, binary} | :not_found
def get(key) do
ref = GenServer.call(@registered_name, :get_ref)
Exleveldb.get(ref, key)
Exleveldb.get(ref(), key)
end

@spec size() :: non_neg_integer()
def size() do
ref = GenServer.call(@registered_name, :get_ref)
{:ok, size} = :eleveldb.status(ref, "leveldb.total-bytes")
{:ok, size} = :eleveldb.status(ref(), "leveldb.total-bytes")
String.to_integer(size)
end

@spec iterate() :: {:ok, :eleveldb.itr_ref()} | {:error, any()}
def iterate() do
ref = GenServer.call(@registered_name, :get_ref)
# TODO: wrap cursor to make it DB-agnostic
Exleveldb.iterator(ref, [])
Exleveldb.iterator(ref(), [])
end

@spec iterate_keys() :: {:ok, :eleveldb.itr_ref()} | {:error, any()}
def iterate_keys() do
ref = GenServer.call(@registered_name, :get_ref)
# TODO: wrap cursor to make it DB-agnostic
Exleveldb.iterator(ref, [], :keys_only)
Exleveldb.iterator(ref(), [], :keys_only)
end

@spec iterator_close(:eleveldb.itr_ref()) :: :ok
def iterator_close(iter_ref) do
Exleveldb.iterator_close(iter_ref)
end

@spec iterator_move(
:eleveldb.itr_ref(),
:first | :last | :next | :prefetch | :prefetch_stop | :prev | binary()
) ::
{:error, :invalid_iterator | :iterator_closed}
| {:ok, binary()}
| {:ok, binary(), binary()}
def iterator_move(iter_ref, action) do
Exleveldb.iterator_move(iter_ref, action)
end

@impl true
Expand All @@ -74,4 +82,8 @@ defmodule LambdaEthereumConsensus.Store.Db do
Application.fetch_env!(:lambda_ethereum_consensus, __MODULE__)
|> Keyword.fetch!(:dir)
end

defp ref() do
GenServer.call(__MODULE__, :get_ref)
end
end
14 changes: 7 additions & 7 deletions lib/lambda_ethereum_consensus/store/kv_schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ defmodule LambdaEthereumConsensus.Store.KvSchema do

with {:ok, it} <- Db.iterate_keys(),
{:ok, encoded_start} <- do_encode_key(start_key),
{:ok, ^encoded_start} <- Exleveldb.iterator_move(it, encoded_start) do
{:ok, ^encoded_start} <- Db.iterator_move(it, encoded_start) do
res = iterate(it, starting_value, f, direction, encoded_start, include_first?)
Exleveldb.iterator_close(it)
Db.iterator_close(it)
{:ok, res}
else
# The iterator moved for the first time to a place where it wasn't expected.
Expand Down Expand Up @@ -109,7 +109,7 @@ defmodule LambdaEthereumConsensus.Store.KvSchema do
def first_key() do
{:ok, it} = Db.iterate_keys()

case Exleveldb.iterator_move(it, @prefix) do
case Db.iterator_move(it, @prefix) do
{:ok, @prefix <> _k = full_key} -> do_decode_key(full_key)
{:ok, _other} -> :not_found
{:error, :invalid_iterator} -> :not_found
Expand All @@ -135,7 +135,7 @@ defmodule LambdaEthereumConsensus.Store.KvSchema do
defp key_iterator(key) do
with {:ok, it} <- Db.iterate_keys(),
{:ok, encoded_start} <- do_encode_key(key),
{:ok, ^encoded_start} <- Exleveldb.iterator_move(it, encoded_start) do
{:ok, ^encoded_start} <- Db.iterator_move(it, encoded_start) do
{:first, it, key}
else
# The iterator moved for the first time to a place where it wasn't expected.
Expand All @@ -154,7 +154,7 @@ defmodule LambdaEthereumConsensus.Store.KvSchema do
defp next_key({:first, it, key}, direction), do: {[key], {:next, it}}

defp move_iterator(it, direction) do
case Exleveldb.iterator_move(it, direction) do
case Db.iterator_move(it, direction) do
{:ok, @prefix <> _ = k} ->
{:ok, decoded_key} = do_decode_key(k)
{[decoded_key], {:next, it}}
Expand All @@ -168,7 +168,7 @@ defmodule LambdaEthereumConsensus.Store.KvSchema do
defp next_key({:error, _}, _direction), do: nil

defp close(nil), do: :ok
defp close(it), do: :ok == Exleveldb.iterator_close(it)
defp close(it), do: :ok == Db.iterator_close(it)

defp iterate(it, acc, f, direction, _first_key, false) do
iterate(it, acc, f, direction)
Expand All @@ -189,7 +189,7 @@ defmodule LambdaEthereumConsensus.Store.KvSchema do
end

defp accumulate(it, acc, f, direction) do
case Exleveldb.iterator_move(it, direction) do
case Db.iterator_move(it, direction) do
{:ok, @prefix <> _ = k} ->
{:ok, decoded_key} = do_decode_key(k)
{:cont, f.(decoded_key, acc)}
Expand Down
8 changes: 4 additions & 4 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,21 @@ defmodule LambdaEthereumConsensus.MixProject do
{:recase, "~> 0.7"},
{:rexbug, "~> 1.0"},
{:eep, git: "https://github.com/virtan/eep", branch: "master"},
{:protobuf, "~> 0.13.0"},
{:protobuf, "~> 0.14.0"},
{:aja, "~> 0.6"},
{:logfmt_ex, "~> 0.4.2"},
{:ex2ms, "~> 1.6", runtime: false},
{:eflambe, "~> 0.3.1"},
{:patch, "~> 0.13.0", only: [:test]},
{:patch, "~> 0.15.0", only: [:test]},
{:stream_data, "~> 1.0", only: [:test]},
{:benchee, "~> 1.2", only: [:dev]},
{:dialyxir, "~> 1.1", only: [:dev, :test], runtime: false},
{:credo, "~> 1.7", only: [:dev, :test], runtime: false},
{:open_api_spex, "~> 3.18"},
{:crc32c, git: "https://github.com/lambdaclass/crc32c", branch: "bump-rustler-32"},
{:recode, "~> 0.7", only: [:dev, :test]},
{:sentry, "~> 10.7.0"},
{:prom_ex, "~> 1.10.0"},
{:sentry, "~> 10.8.0"},
{:prom_ex, "~> 1.11.0"},
{:flama, git: "https://github.com/lambdaclass/ht1223_tracer"},
{:uuid, "~> 1.1"}
]
Expand Down
Loading

0 comments on commit b370534

Please sign in to comment.