-
Notifications
You must be signed in to change notification settings - Fork 40
fix: trigger pruning on tick #1086
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
Conversation
last_finalized_key = slot |> root_by_slot_key() | ||
|
||
with {:ok, it} <- Db.iterate(), | ||
{:ok, @stateslot_prefix <> _slot, _value} <- | ||
Exleveldb.iterator_move(it, last_finalized_key), | ||
{:ok, slots_to_remove} <- get_slots_to_remove(it), | ||
:ok <- Exleveldb.iterator_close(it) do | ||
slots_to_remove |> Enum.map(&remove_by_slot/1) | ||
slots_to_remove |> Enum.each(&remove_by_slot/1) | ||
Logger.info("[StateDb] Pruning finished. #{length(slots_to_remove)} slots removed.") | ||
end | ||
end | ||
|
||
defp get_slots_to_remove(slots_to_remove \\ [], iterator) do |
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.
can you add typespec here? I am confused if slots are integers or binaries
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.
Maybe I can create an issue to refactor this for clarity.
end | ||
end | ||
|
||
defp get_slots_to_remove(slots_to_remove \\ [], iterator) do | ||
case Exleveldb.iterator_move(iterator, :prev) do | ||
{:ok, @stateslot_prefix <> slot, _root} -> | ||
[slot | slots_to_remove] |> get_slots_to_remove(iterator) | ||
[slot |> :binary.decode_unsigned() | slots_to_remove] |> get_slots_to_remove(iterator) |
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.
You can match this here by doing:
{:ok, @stateslot_prefix <> <<slot::unsigned-size(64)>>, _root} ->
end | ||
end | ||
|
||
@spec get_slots_to_remove(list(), :eleveldb.itr_ref()) :: {:ok, list(non_neg_integer())} |
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.
list of what?
State pruning was not being triggered because checkpoint updates were occurring within the
on_tick
function, while only updates within theon_block
function had been considered.