Skip to content

Commit

Permalink
formatting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
guha-rahul committed Apr 23, 2024
1 parent e920dd8 commit b404ff9
Show file tree
Hide file tree
Showing 17 changed files with 102 additions and 120 deletions.
13 changes: 6 additions & 7 deletions lib/lambda_ethereum_consensus/execution/rpc.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ defmodule LambdaEthereumConsensus.Execution.RPC do
{Tesla.Middleware.Headers, [{"authorization", "Bearer #{jwt}"}]}
])

request_body =
%{
"jsonrpc" => version,
"method" => method,
"params" => params,
"id" => 1
}
request_body = %{
"jsonrpc" => version,
"method" => method,
"params" => params,
"id" => 1
}

with {:ok, result} <- post(client, endpoint, request_body) do
result |> validate_rpc_response()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,7 @@ defmodule LambdaEthereumConsensus.StateTransition.EpochProcessing do

slots_per_historical_root = ChainSpec.get("SLOTS_PER_HISTORICAL_ROOT")

epochs_per_historical_root =
div(slots_per_historical_root, ChainSpec.get("SLOTS_PER_EPOCH"))
epochs_per_historical_root = div(slots_per_historical_root, ChainSpec.get("SLOTS_PER_EPOCH"))

if rem(next_epoch, epochs_per_historical_root) == 0 do
with {:ok, block_summary_root} <-
Expand All @@ -279,8 +278,7 @@ defmodule LambdaEthereumConsensus.StateTransition.EpochProcessing do
state_summary_root: state_summary_root
}

new_state =
Map.update!(state, :historical_summaries, &(&1 ++ [historical_summary]))
new_state = Map.update!(state, :historical_summaries, &(&1 ++ [historical_summary]))

{:ok, new_state}
end
Expand All @@ -303,8 +301,7 @@ defmodule LambdaEthereumConsensus.StateTransition.EpochProcessing do
previous_target_balance =
get_total_participating_balance(state, target_index, previous_epoch)

current_target_balance =
get_total_participating_balance(state, target_index, current_epoch)
current_target_balance = get_total_participating_balance(state, target_index, current_epoch)

total_active_balance = Accessors.get_total_active_balance(state)

Expand Down
3 changes: 1 addition & 2 deletions lib/lambda_ethereum_consensus/state_transition/shuffling.ex
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ defmodule LambdaEthereumConsensus.StateTransition.Shuffling do
defp shuffle_list(input, round, seed) do
input_size = Aja.Enum.count(input)

round_bytes =
:binary.encode_unsigned(round, :little)
round_bytes = :binary.encode_unsigned(round, :little)

pivot =
(seed <> round_bytes)
Expand Down
3 changes: 1 addition & 2 deletions lib/lambda_ethereum_consensus/store/lru_cache.ex
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ defmodule LambdaEthereumConsensus.Store.LRUCache do
to_prune = :ets.info(data_table, :size) - max_entries

if to_prune > 0 do
{elems, _cont} =
:ets.select(ttl_table, [{:_, [], [:"$_"]}], to_prune + batch_prune_size)
{elems, _cont} = :ets.select(ttl_table, [{:_, [], [:"$_"]}], to_prune + batch_prune_size)

elems
|> Enum.each(fn {uniq, root} ->
Expand Down
3 changes: 1 addition & 2 deletions lib/utils/bit_list.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ defmodule LambdaEthereumConsensus.Utils.BitList do
num_bits = bit_size(bitstring)

<<pre::integer-little-size(num_bits - @bits_per_byte),
last_byte::integer-little-size(@bits_per_byte)>> =
bitstring
last_byte::integer-little-size(@bits_per_byte)>> = bitstring

<<remove_trailing_bit(<<last_byte>>)::bitstring,
pre::integer-size(num_bits - @bits_per_byte)>>
Expand Down
6 changes: 2 additions & 4 deletions lib/utils/diff.ex
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,9 @@ defmodule LambdaEthereumConsensus.Utils.Diff do
a_keys = a |> Map.keys() |> MapSet.new()
b_keys = b |> Map.keys() |> MapSet.new()

a_extra =
MapSet.difference(a_keys, b_keys) |> Enum.map(fn k -> {k, Map.fetch!(a, k)} end)
a_extra = MapSet.difference(a_keys, b_keys) |> Enum.map(fn k -> {k, Map.fetch!(a, k)} end)

b_extra =
MapSet.difference(b_keys, a_keys) |> Enum.map(fn k -> {k, Map.fetch!(b, k)} end)
b_extra = MapSet.difference(b_keys, a_keys) |> Enum.map(fn k -> {k, Map.fetch!(b, k)} end)

d
|> add_if_not_empty(:added_left, a_extra)
Expand Down
2 changes: 1 addition & 1 deletion native/bls_nif/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ fn key_validate<'env>(public_key: Binary) -> Result<bool, String> {
let _pubkey =
PublicKey::deserialize(public_key.as_slice()).map_err(|err| format!("{:?}", err))?;

Ok(true)
Ok(true)
}

rustler::init!(
Expand Down
107 changes: 52 additions & 55 deletions test/fixtures/block.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,20 @@ defmodule Fixtures.Block do

@spec beacon_block_body :: BeaconBlockBody.t()
def beacon_block_body do
fields =
[
randao_reveal: Random.bls_signature(),
eth1_data: eth1_data(),
graffiti: Random.hash32(),
proposer_slashings: [],
attester_slashings: [],
attestations: [],
deposits: [],
voluntary_exits: [],
sync_aggregate: sync_aggregate(),
execution_payload: execution_payload(),
bls_to_execution_changes: [],
blob_kzg_commitments: []
]
fields = [
randao_reveal: Random.bls_signature(),
eth1_data: eth1_data(),
graffiti: Random.hash32(),
proposer_slashings: [],
attester_slashings: [],
attestations: [],
deposits: [],
voluntary_exits: [],
sync_aggregate: sync_aggregate(),
execution_payload: execution_payload(),
bls_to_execution_changes: [],
blob_kzg_commitments: []
]

struct!(BeaconBlockBody, fields)
end
Expand All @@ -72,26 +71,25 @@ defmodule Fixtures.Block do

@spec execution_payload :: ExecutionPayload.t()
def execution_payload do
fields =
[
parent_hash: Random.hash32(),
fee_recipient: Random.execution_address(),
state_root: Random.root(),
receipts_root: Random.root(),
logs_bloom: Random.binary(256),
prev_randao: Random.hash32(),
block_number: Random.uint64(),
gas_limit: Random.uint64(),
gas_used: Random.uint64(),
timestamp: Random.uint64(),
extra_data: Random.binary(30),
base_fee_per_gas: Random.uint64(),
block_hash: Random.binary(32),
transactions: [],
withdrawals: [],
blob_gas_used: 0,
excess_blob_gas: 0
]
fields = [
parent_hash: Random.hash32(),
fee_recipient: Random.execution_address(),
state_root: Random.root(),
receipts_root: Random.root(),
logs_bloom: Random.binary(256),
prev_randao: Random.hash32(),
block_number: Random.uint64(),
gas_limit: Random.uint64(),
gas_used: Random.uint64(),
timestamp: Random.uint64(),
extra_data: Random.binary(30),
base_fee_per_gas: Random.uint64(),
block_hash: Random.binary(32),
transactions: [],
withdrawals: [],
blob_gas_used: 0,
excess_blob_gas: 0
]

struct!(ExecutionPayload, fields)
end
Expand Down Expand Up @@ -142,26 +140,25 @@ defmodule Fixtures.Block do

@spec execution_payload_header :: ExecutionPayloadHeader.t()
def execution_payload_header do
fields =
[
parent_hash: Random.binary(32),
fee_recipient: Random.binary(20),
state_root: Random.root(),
receipts_root: Random.root(),
logs_bloom: Random.binary(256),
prev_randao: Random.binary(32),
block_number: Random.uint64(),
gas_limit: Random.uint64(),
gas_used: Random.uint64(),
timestamp: Random.uint64(),
extra_data: Random.binary(30),
base_fee_per_gas: Random.uint256(),
block_hash: Random.binary(32),
transactions_root: Random.root(),
withdrawals_root: Random.root(),
blob_gas_used: 0,
excess_blob_gas: 0
]
fields = [
parent_hash: Random.binary(32),
fee_recipient: Random.binary(20),
state_root: Random.root(),
receipts_root: Random.root(),
logs_bloom: Random.binary(256),
prev_randao: Random.binary(32),
block_number: Random.uint64(),
gas_limit: Random.uint64(),
gas_used: Random.uint64(),
timestamp: Random.uint64(),
extra_data: Random.binary(30),
base_fee_per_gas: Random.uint256(),
block_hash: Random.binary(32),
transactions_root: Random.root(),
withdrawals_root: Random.root(),
blob_gas_used: 0,
excess_blob_gas: 0
]

struct!(ExecutionPayloadHeader, fields)
end
Expand Down
1 change: 0 additions & 1 deletion test/spec/runners/bls.ex
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,4 @@ defmodule BlsTestRunner do
assert not output, reason
end
end

end
6 changes: 2 additions & 4 deletions test/spec/runners/fork_choice.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ defmodule ForkChoiceTestRunner do
anchor_block =
SpecTestUtils.read_ssz_from_file!(case_dir <> "/anchor_block.ssz_snappy", BeaconBlock)

steps =
YamlElixir.read_from_file!(case_dir <> "/steps.yaml") |> SpecTestUtils.sanitize_yaml()
steps = YamlElixir.read_from_file!(case_dir <> "/steps.yaml") |> SpecTestUtils.sanitize_yaml()

signed_block = %SignedBeaconBlock{message: anchor_block, signature: <<0::768>>}

Expand Down Expand Up @@ -170,8 +169,7 @@ defmodule ForkChoiceTestRunner do
defp load_blob_data(case_dir, block, %{blobs: "blobs_0x" <> _hash = blobs_file, proofs: proofs}) do
schema = {:list, TypeAliases.blob(), ChainSpec.get("MAX_BLOBS_PER_BLOCK")}

blobs =
SpecTestUtils.read_ssz_ex_from_file!(case_dir <> "/#{blobs_file}.ssz_snappy", schema)
blobs = SpecTestUtils.read_ssz_ex_from_file!(case_dir <> "/#{blobs_file}.ssz_snappy", schema)

block_root = Ssz.hash_tree_root!(block.message)

Expand Down
3 changes: 1 addition & 2 deletions test/spec/runners/helpers/process_blocks.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ defmodule Helpers.ProcessBlocks do
pre = SpecTestUtils.read_ssz_from_file!(case_dir <> "/pre.ssz_snappy", BeaconState)
post = SpecTestUtils.read_ssz_from_optional_file!(case_dir <> "/post.ssz_snappy", BeaconState)

meta =
YamlElixir.read_from_file!(case_dir <> "/meta.yaml") |> SpecTestUtils.sanitize_yaml()
meta = YamlElixir.read_from_file!(case_dir <> "/meta.yaml") |> SpecTestUtils.sanitize_yaml()

%{blocks_count: blocks_count} = meta

Expand Down
3 changes: 1 addition & 2 deletions test/spec/runners/operations.ex
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ defmodule OperationsTestRunner do
# We're skipping the tests where execution_valid is false since we make the execution client call
# outside of the `process_execution_payload` function for performance reasons.
if execution_valid do
result =
Operations.process_execution_payload(pre, body)
result = Operations.process_execution_payload(pre, body)

case post do
nil ->
Expand Down
3 changes: 1 addition & 2 deletions test/spec/runners/ssz_static.ex
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ defmodule SszStaticTestRunner do
YamlElixir.read_from_file!(case_dir <> "/value.yaml")
|> SpecTestUtils.sanitize_yaml()

expected_sanitized =
SpecTestUtils.sanitize_ssz(sanitize_yaml, schema)
expected_sanitized = SpecTestUtils.sanitize_ssz(sanitize_yaml, schema)

%{"root" => expected_root} = YamlElixir.read_from_file!(case_dir <> "/roots.yaml")
expected_root = expected_root |> SpecTestUtils.sanitize_yaml()
Expand Down
3 changes: 1 addition & 2 deletions test/spec/runners/sync.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ defmodule SyncTestRunner do

@impl TestRunner
def run_test_case(%SpecTestCase{} = testcase) do
original_engine_api_config =
Application.fetch_env!(:lambda_ethereum_consensus, EngineApi)
original_engine_api_config = Application.fetch_env!(:lambda_ethereum_consensus, EngineApi)

Application.put_env(
:lambda_ethereum_consensus,
Expand Down
12 changes: 8 additions & 4 deletions test/unit/bls_test.exs
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
defmodule BlsTest do

use ExUnit.Case

describe "validate_key" do
test "returns true for valid public key" do
valid_public_key = Base.decode16!("8afc8f134790914b4a15d2fa73b07cafd0d30884fd80ca220c8b9503f5f69c33dd27275b129543d2f7f8f635a81867a0",case: :mixed)
valid_public_key =
Base.decode16!(
"8afc8f134790914b4a15d2fa73b07cafd0d30884fd80ca220c8b9503f5f69c33dd27275b129543d2f7f8f635a81867a0",
case: :mixed
)

assert Bls.key_validate(valid_public_key) == {:ok, true}
end

test "returns false for invalid public key" do
invalid_public_key = <<0::384>>
assert Bls.key_validate(invalid_public_key) == {:error, "BlstError(BLST_BAD_ENCODING)"}
invalid_public_key = <<0::384>>
assert Bls.key_validate(invalid_public_key) == {:error, "BlstError(BLST_BAD_ENCODING)"}
end
end
end
42 changes: 20 additions & 22 deletions test/unit/req_resp_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,16 @@ defmodule Unit.ReqRespTest do
request = %BeaconBlocksByRangeRequest{start_slot: 15_125, count: count}

# TODO: generate randomly
response =
[
%Types.BlobSidecar{
index: 1,
blob: <<152_521_252::(4096*32)*8>>,
kzg_commitment: <<57_888::48*8>>,
kzg_proof: <<6122::48*8>>,
signed_block_header: Block.signed_beacon_block_header(),
kzg_commitment_inclusion_proof: [<<1551::32*8>>] |> Stream.cycle() |> Enum.take(17)
}
]
response = [
%Types.BlobSidecar{
index: 1,
blob: <<152_521_252::(4096*32)*8>>,
kzg_commitment: <<57_888::48*8>>,
kzg_proof: <<6122::48*8>>,
signed_block_header: Block.signed_beacon_block_header(),
kzg_commitment_inclusion_proof: [<<1551::32*8>>] |> Stream.cycle() |> Enum.take(17)
}
]

assert_complex_request_roundtrip(request, BeaconBlocksByRangeRequest, response)
end
Expand All @@ -145,17 +144,16 @@ defmodule Unit.ReqRespTest do
request = Enum.map(1..count, &%BlobIdentifier{block_root: <<&1::256>>, index: &1})

# TODO: generate randomly
response =
[
%Types.BlobSidecar{
index: 1,
blob: <<152_521_252::(4096*32)*8>>,
kzg_commitment: <<57_888::48*8>>,
kzg_proof: <<6122::48*8>>,
signed_block_header: Block.signed_beacon_block_header(),
kzg_commitment_inclusion_proof: [<<1551::32*8>>] |> Stream.cycle() |> Enum.take(17)
}
]
response = [
%Types.BlobSidecar{
index: 1,
blob: <<152_521_252::(4096*32)*8>>,
kzg_commitment: <<57_888::48*8>>,
kzg_proof: <<6122::48*8>>,
signed_block_header: Block.signed_beacon_block_header(),
kzg_commitment_inclusion_proof: [<<1551::32*8>>] |> Stream.cycle() |> Enum.take(17)
}
]

assert_complex_request_roundtrip(
request,
Expand Down
3 changes: 1 addition & 2 deletions test/unit/snappy_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ defmodule Unit.SnappyTest do
test "compress binary" do
expected = Base.decode16!("FF060000734E61507059000A0000B3A056EA1100003E0100")

got =
Snappy.compress(Base.decode16!("0000000000000000000000000000000000"))
got = Snappy.compress(Base.decode16!("0000000000000000000000000000000000"))

assert got == {:ok, expected}
end
Expand Down

0 comments on commit b404ff9

Please sign in to comment.