Skip to content

Commit

Permalink
Merge keystore api branch
Browse files Browse the repository at this point in the history
  • Loading branch information
avilagaston9 committed Aug 9, 2024
1 parent ae42589 commit 5209ab7
Show file tree
Hide file tree
Showing 42 changed files with 2,493 additions and 430 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,4 @@ callgrind.out.*

# beacon node oapi json file
beacon-node-oapi.json
flamegraphs/
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ lint:
mix recode --no-autocorrect
mix format --check-formatted
mix credo --strict
mix dialyzer --no-check

#✅ fmt: @ Format all code (Go, rust and elixir).
fmt:
Expand Down
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ Some public endpoints can be found in [eth-clients.github.io/checkpoint-sync-end
> The data retrieved from the URL is stored in the DB once the node is initiated (i.e. the iex prompt shows).
> Once this happens, following runs of `make iex` will start the node using that data.
### Beacon API
### APIs
#### Beacon API

You can start the application with the Beacon API on the default port `4000` running:
```shell
Expand All @@ -100,7 +101,27 @@ make start
You can also specify a port with the "--beacon-api-port" flag:

```shell
iex -S mix run -- --beacon-api --beacon-api-port <your_port_here>
iex -S mix run -- --beacon-api-port <your_port_here>
```
> [!WARNING]
> In case checkpoint-sync is needed, following the instructions above will end immediately with an error (see [Checkpoint Sync](#checkpoint-sync)).
>
#### Key-Manager API

Implemented following the [Ethereum specification](https://ethereum.github.io/keymanager-APIs/#/).

You can start the application with the key manager API on the default port `5000` running:

```shell
iex -S mix run -- --validator-api
```


You can also specify a port with the "--validator-api-port" flag:

```shell
iex -S mix run -- --validator-api-port <your_port_here>
```
> [!WARNING]
> In case checkpoint-sync is needed, following the instructions above will end immediately with an error (see [Checkpoint Sync](#checkpoint-sync)).
Expand Down Expand Up @@ -250,6 +271,7 @@ participants:
use_separate_vc: false
count: 1
cl_max_mem: 4096
keymanager_enabled: true
```
### Kurtosis Execution and Make tasks
Expand Down
29 changes: 14 additions & 15 deletions bench/block_processing.exs
Original file line number Diff line number Diff line change
@@ -1,43 +1,42 @@
alias LambdaEthereumConsensus.ForkChoice
alias LambdaEthereumConsensus.ForkChoice.Handlers
alias LambdaEthereumConsensus.StateTransition.Cache
alias LambdaEthereumConsensus.Store
alias LambdaEthereumConsensus.Store.BlockBySlot
alias LambdaEthereumConsensus.Store.BlockDb
alias LambdaEthereumConsensus.Store.StateDb
alias Types.BeaconState
alias Types.BlockInfo
alias Types.SignedBeaconBlock
alias Types.StateInfo
alias Utils.Date

Logger.configure(level: :warning)
Cache.initialize_cache()

# NOTE: this slot must be at the beginning of an epoch (i.e. a multiple of 32)
slot = 9_591_424
slot = 9_649_056

IO.puts("fetching blocks...")
IO.puts("Fetching state and blocks...")
{:ok, %StateInfo{beacon_state: state}} = StateDb.get_state_by_slot(slot)
{:ok, %BlockInfo{signed_block: block}} = BlockDb.get_block_info_by_slot(slot)
{:ok, %BlockInfo{signed_block: new_block} = block_info} = BlockDb.get_block_info_by_slot(slot + 1)
{:ok, %BlockInfo{} = block_info} = BlockDb.get_block_info_by_slot(slot + 1)
{:ok, %BlockInfo{} = block_info_2} = BlockDb.get_block_info_by_slot(slot + 2)

IO.puts("initializing store...")
IO.puts("Initializing store...")
{:ok, store} = Types.Store.get_forkchoice_store(state, block)
store = Handlers.on_tick(store, store.time + 30)

{:ok, root} = BlockBySlot.get(slot)
IO.puts("Processing the block 1...")

IO.puts("about to process block: #{slot + 1}, with root: #{Base.encode16(root)}...")
IO.puts("#{length(attestations)} attestations ; #{length(attester_slashings)} attester slashings")
IO.puts("")
{:ok, new_store} = ForkChoice.process_block(block_info, store)
IO.puts("Processing the block 2...")

if System.get_env("FLAMA") do
Flama.run({ForkChoice, :process_block, [block_info, store]})
filename = "flamegraphs/stacks.#{Date.now_str()}.out"
Flama.run({ForkChoice, :process_block, [block_info_2, new_store]}, output_file: filename)
IO.puts("Flamegraph saved to #{filename}")
else
Benchee.run(
%{
"block (full cache)" => fn ->
ForkChoice.process_block(block_info, store)
ForkChoice.process_block(block_info_2, new_store)
end
},
time: 30
Expand All @@ -46,7 +45,7 @@ else
Benchee.run(
%{
"block (empty cache)" => fn _ ->
ForkChoice.process_block(block_info, store)
ForkChoice.process_block(block_info_2, new_store)
end
},
time: 30,
Expand Down
16 changes: 15 additions & 1 deletion config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ switches = [
log_file: :string,
beacon_api: :boolean,
beacon_api_port: :integer,
validator_api: :boolean,
validator_api_port: :integer,
listen_address: [:string, :keep],
discovery_port: :integer,
boot_nodes: :string,
Expand Down Expand Up @@ -47,6 +49,8 @@ metrics_port = Keyword.get(args, :metrics_port, nil)
enable_metrics = Keyword.get(args, :metrics, not is_nil(metrics_port))
beacon_api_port = Keyword.get(args, :beacon_api_port, nil)
enable_beacon_api = Keyword.get(args, :beacon_api, not is_nil(beacon_api_port))
validator_api_port = Keyword.get(args, :validator_api_port, nil)
enable_validator_api = Keyword.get(args, :validator_api, not is_nil(validator_api_port))
listen_addresses = Keyword.get_values(args, :listen_address)
discovery_port = Keyword.get(args, :discovery_port, 9000)
cli_bootnodes = Keyword.get(args, :boot_nodes, "")
Expand Down Expand Up @@ -153,6 +157,16 @@ config :lambda_ethereum_consensus, BeaconApi.Endpoint,
layout: false
]

# KeyStore API
config :lambda_ethereum_consensus, KeyStoreApi.Endpoint,
server: enable_validator_api,
http: [port: validator_api_port || 5000],
url: [host: "localhost"],
render_errors: [
formats: [json: KeyStoreApi.ErrorJSON],
layout: false
]

# Validator setup

if (keystore_dir != nil and keystore_pass_dir == nil) or
Expand All @@ -171,7 +185,7 @@ if keystore_pass_dir != nil and not File.dir?(keystore_pass_dir) do
System.halt(2)
end

config :lambda_ethereum_consensus, LambdaEthereumConsensus.Validator.ValidatorManager,
config :lambda_ethereum_consensus, LambdaEthereumConsensus.Validator.Setup,
keystore_dir: keystore_dir,
keystore_pass_dir: keystore_pass_dir

Expand Down
Loading

0 comments on commit 5209ab7

Please sign in to comment.