-
Notifications
You must be signed in to change notification settings - Fork 11
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
feat: index miners count and total rewards from fees #854
Conversation
Includes a migration that takes 15-30mins to index the already processed generation miners.
073a65c
to
26702d1
Compare
The reason for this is that miner's pks always change, so for every new key block there will almost always be a new miner.
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.
No operational issues, only refactoring opportunities.
case State.get(state, Model.Miner, beneficiary_pk) do | ||
{:ok, Model.miner(total_reward: old_reward) = miner} -> | ||
{State.put(state, Model.Miner, Model.miner(miner, total_reward: old_reward + reward)), | ||
false} | ||
|
||
:not_found -> | ||
{State.put( | ||
state, | ||
Model.Miner, | ||
Model.miner(index: beneficiary_pk, total_reward: reward) | ||
), true} | ||
end |
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.
It's already readable but might convey the idea at a glance by giving a name to this case
block with a function (sth like increment_total_reward
)
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
State.update(state, Model.Stat, Stats.miners_count_key(), fn | ||
Model.stat(payload: count) = stat -> | ||
Model.stat(stat, payload: count + 1) | ||
|
||
nil -> | ||
Model.stat(index: Stats.miners_count_key(), payload: 1) | ||
end) |
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.
same here with increment_payload
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
def fetch_miner!(state, miner_pk), | ||
do: render_miner(State.fetch!(state, Model.Miner, miner_pk)) | ||
|
||
defp build_streamer(state, cursor), do: &Collection.stream(state, Model.Miner, &1, nil, cursor) |
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.
👍
def run(_from_start?) do | ||
state = State.new() | ||
|
||
case state |> Collection.stream(Model.DeltaStat, :backward, nil, nil) |> Enum.take(1) 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.
maybe Database.last_key
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
refs #844
Includes a migration that takes 15-30mins to index the already processed generation miners.