-
Notifications
You must be signed in to change notification settings - Fork 35
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
Conversation
There was a problem hiding this 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 -> |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
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 theGenServer
calls.Additionally, it adds some metrics on store persisting and fetching:
Closes #1116
Closes #1117