Explicit block number in snapshotting

staking
Vadim 5 years ago committed by Victor Baranov
parent 2c7cb93f16
commit 29faa57c9b
  1. 8
      apps/explorer/lib/explorer/staking/contract_reader.ex
  2. 6
      apps/explorer/lib/explorer/staking/contract_state.ex
  3. 8
      apps/explorer/lib/explorer/staking/stake_snapshotting.ex

@ -24,15 +24,15 @@ defmodule Explorer.Staking.ContractReader do
]
end
def active_delegators_request(staking_address) do
def active_delegators_request(staking_address, block_number) do
[
active_delegators: {:staking, "poolDelegators", [staking_address]}
active_delegators: {:staking, "poolDelegators", [staking_address], block_number}
]
end
def pool_staking_requests(staking_address) do
def pool_staking_requests(staking_address, block_number) do
[
active_delegators: active_delegators_request(staking_address)[:active_delegators],
active_delegators: active_delegators_request(staking_address, block_number)[:active_delegators],
inactive_delegators: {:staking, "poolDelegatorsInactive", [staking_address]},
is_active: {:staking, "isPoolActive", [staking_address]},
mining_address_hash: {:validator_set, "miningByStakingAddress", [staking_address]},

@ -199,7 +199,9 @@ defmodule Explorer.Staking.ContractState do
# read pool info from the contracts by its staking address
pool_staking_responses =
pools
|> Enum.map(&ContractReader.pool_staking_requests/1)
|> Enum.map(fn staking_address_hash ->
ContractReader.pool_staking_requests(staking_address_hash, block_number)
end)
|> ContractReader.perform_grouped_requests(pools, contracts, abi)
# read pool info from the contracts by its mining address
@ -395,7 +397,7 @@ defmodule Explorer.Staking.ContractState do
pool_staking_responses,
validators.pending, # mining addresses of pending validators
mining_to_staking_address,
block_number # the last block of the finished staking epoch
global_responses.epoch_start_block - 1 # the last block of the finished staking epoch
])
end

@ -31,7 +31,7 @@ defmodule Explorer.Staking.StakeSnapshotting do
|> Enum.zip(pending_validators_mining_addresses)
|> Map.new()
# get snapshotted amounts and other pool info for each
# get snapshotted amounts and active delegator list for the pool for each
# pending validator by their staking address.
# use `cached_pool_staking_responses` when possible
pool_staking_responses =
@ -42,7 +42,7 @@ defmodule Explorer.Staking.StakeSnapshotting do
Map.merge(resp, ContractReader.perform_requests(snapshotted_pool_amounts_requests(staking_address_hash, block_number), contracts, abi))
:error ->
ContractReader.perform_requests(
ContractReader.active_delegators_request(staking_address_hash) ++
ContractReader.active_delegators_request(staking_address_hash, block_number) ++
snapshotted_pool_amounts_requests(staking_address_hash, block_number),
contracts,
abi
@ -60,7 +60,7 @@ defmodule Explorer.Staking.StakeSnapshotting do
Enum.map(resp.active_delegators, &{pool_staking_address, &1})
end)
# read info of each staker from the contracts
# read info about each staker from the contracts
staker_responses =
stakers
|> Enum.map(fn {pool_staking_address, staker_address} ->
@ -161,7 +161,7 @@ defmodule Explorer.Staking.StakeSnapshotting do
timeout: :infinity
}) do
{:ok, _} -> :ets.insert(ets_table_name, is_snapshotted: true)
_ -> Logger.error("Cannot finish snapshotting started at block #{block_number}")
_ -> Logger.error("Cannot successfully finish snapshotting for the epoch #{epoch_number - 1}")
end
end

Loading…
Cancel
Save