Remove an excess code from snapshotting

staking
Vadim 5 years ago committed by Victor Baranov
parent bca2bfd5e2
commit 4486d5865c
  1. 2
      apps/explorer/lib/explorer/staking/contract_state.ex
  2. 32
      apps/explorer/lib/explorer/staking/stake_snapshotting.ex

@ -109,7 +109,6 @@ defmodule Explorer.Staking.ContractState do
end end
def handle_continue(_, state) do def handle_continue(_, state) do
fetch_state(state.contracts, state.abi, state.seen_block)
{:noreply, state} {:noreply, state}
end end
@ -394,7 +393,6 @@ defmodule Explorer.Staking.ContractState do
%{contracts: contracts, abi: abi, ets_table_name: @table_name}, %{contracts: contracts, abi: abi, ets_table_name: @table_name},
global_responses.epoch_number, global_responses.epoch_number,
pool_staking_responses, pool_staking_responses,
pool_mining_responses,
Map.new(Enum.map(staker_responses, fn {key, resp} -> {pool_staking_address, staker_address, _} = key; {{pool_staking_address, staker_address}, resp} end)), Map.new(Enum.map(staker_responses, fn {key, resp} -> {pool_staking_address, staker_address, _} = key; {{pool_staking_address, staker_address}, resp} end)),
validators.pending, # mining addresses of pending validators validators.pending, # mining addresses of pending validators
mining_to_staking_address, mining_to_staking_address,

@ -15,7 +15,6 @@ defmodule Explorer.Staking.StakeSnapshotting do
%{contracts: contracts, abi: abi, ets_table_name: ets_table_name}, %{contracts: contracts, abi: abi, ets_table_name: ets_table_name},
epoch_number, epoch_number,
cached_pool_staking_responses, cached_pool_staking_responses,
cached_pool_mining_responses,
cached_staker_responses, cached_staker_responses,
pending_validators_mining_addresses, pending_validators_mining_addresses,
mining_to_staking_address, mining_to_staking_address,
@ -48,23 +47,6 @@ defmodule Explorer.Staking.StakeSnapshotting do
|> Enum.zip(pool_staking_addresses) |> Enum.zip(pool_staking_addresses)
|> Map.new(fn {key, val} -> {val, key} end) |> Map.new(fn {key, val} -> {val, key} end)
# read pool info from the contracts by its mining address.
# use `cached_pool_mining_responses` when possible
pool_mining_responses =
pool_staking_addresses
|> Enum.map(fn staking_address_hash ->
case Map.fetch(cached_pool_mining_responses, staking_address_hash) do
{:ok, resp} ->
resp
:error ->
pool_staking_responses[staking_address_hash].mining_address_hash
|> ContractReader.pool_mining_requests()
|> ContractReader.perform_requests(contracts, abi)
end
end)
|> Enum.zip(pool_staking_addresses)
|> Map.new(fn {key, val} -> {val, key} end)
# get a flat list of all stakers of each validator # get a flat list of all stakers of each validator
# in the form of {pool_staking_address, staker_address} # in the form of {pool_staking_address, staker_address}
stakers = stakers =
@ -140,7 +122,6 @@ defmodule Explorer.Staking.StakeSnapshotting do
pool_entries = pool_entries =
Enum.map(pool_staking_addresses, fn pool_staking_address -> Enum.map(pool_staking_addresses, fn pool_staking_address ->
staking_resp = pool_staking_responses[pool_staking_address] staking_resp = pool_staking_responses[pool_staking_address]
mining_resp = pool_mining_responses[pool_staking_address]
validator_reward_resp = validator_reward_responses[pool_staking_address] validator_reward_resp = validator_reward_responses[pool_staking_address]
%{ %{
@ -157,13 +138,11 @@ defmodule Explorer.Staking.StakeSnapshotting do
:total_staked_amount :total_staked_amount
]) ])
) )
|> Map.merge( |> Map.merge(%{
Map.take(mining_resp, [ banned_until: 0,
:banned_until, was_banned_count: 0,
:was_banned_count, was_validator_count: 0
:was_validator_count })
])
)
end) end)
# form entries for updating the `staking_pools_delegators` table in DB # form entries for updating the `staking_pools_delegators` table in DB
@ -174,6 +153,7 @@ defmodule Explorer.Staking.StakeSnapshotting do
Map.merge(resp, %{ Map.merge(resp, %{
address_hash: staker_address, address_hash: staker_address,
staking_address_hash: pool_staking_address, staking_address_hash: pool_staking_address,
is_active: false,
snapshotted_reward_ratio: Float.floor(delegator_reward_resp.delegator_share / 10_000, 2) snapshotted_reward_ratio: Float.floor(delegator_reward_resp.delegator_share / 10_000, 2)
}) })
end) end)

Loading…
Cancel
Save