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

refactor: persist forkchoice state #1125

Merged
merged 4 commits into from
Jun 3, 2024
Merged

Conversation

avilagaston9
Copy link
Contributor

@avilagaston9 avilagaston9 commented May 30, 2024

Motivation

In order to reduce complexity, we need to reduce concurrency as much as possible.

Description

This PR removes the use of the GenServer state, storing it into the db, taking the first step towards removing the GenServer calls.

Additionally, it adds some metrics on store persisting and fetching:
image

Closes #1116
Closes #1117

@avilagaston9 avilagaston9 marked this pull request as ready for review May 30, 2024 18:55
@avilagaston9 avilagaston9 requested a review from a team as a code owner May 30, 2024 18:55
Copy link
Collaborator

@Arkenan Arkenan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with some small comments.

@spec persist_store(Types.Store.t()) :: :ok
def persist_store(%Types.Store{} = store) do
put(@store_prefix, store)
end

@spec persist_fork_choice_store(Types.Store.t()) :: :ok
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need a separate table? Is it not the same store we're saving?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merged into a single table!

@@ -93,6 +95,7 @@ defmodule LambdaEthereumConsensus.ForkChoice do
prune_old_states(last_finalized_checkpoint.epoch, new_finalized_checkpoint.epoch)

GenServer.cast(from, {:block_processed, block_root, true})
persist_fork_choice_store(new_store)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would persist before calling the cast. As a general rule it's useful that the state is stored and consistent before others are made aware of it. As a matter of fact, if we persist it before launching the recompute_head async task, we can remove the persist call in recompute-head.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true. Done!

@@ -219,4 +228,19 @@ defmodule LambdaEthereumConsensus.ForkChoice do
Logger.debug("[Fork choice] Store persisted")
end)
end

defp persist_fork_choice_store(store) do
:telemetry.span([:fork_choice, :persist], %{}, fn ->
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's have the telemetry call on the db methods directly, so they are called no matter who is storing/fetching the store.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@avilagaston9 avilagaston9 merged commit b469fd8 into main Jun 3, 2024
19 checks passed
@avilagaston9 avilagaston9 deleted the persist-forkchoice-store branch June 3, 2024 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
2 participants