Fix start_snapshotting function

staking
Vadim 5 years ago committed by Victor Baranov
parent 954d3dc96d
commit dcdb353bd4
  1. 4
      apps/explorer/lib/explorer/staking/contract_reader.ex
  2. 8
      apps/explorer/lib/explorer/staking/contract_state.ex
  3. 10
      apps/explorer/lib/explorer/staking/stake_snapshotting.ex
  4. 4
      apps/explorer/priv/contracts_abi/posdao/ValidatorSetAuRa.json

@ -20,8 +20,8 @@ defmodule Explorer.Staking.ContractReader do
pools_likelihood: {:staking, "getPoolsLikelihood", []},
validators: {:validator_set, "getValidators", []},
unremovable_validator: {:validator_set, "unremovableValidator", []},
pending_validators: {:validator_set, "getPendingValidators", []},
be_finalized_validators: {:validator_set, "validatorsToBeFinalized", []},
# pending_validators: {:validator_set, "getPendingValidators", []},
# be_finalized_validators: {:validator_set, "validatorsToBeFinalized", []},
validator_set_apply_block: {:validator_set, "validatorSetApplyBlock", []}
]
end

@ -7,6 +7,8 @@ defmodule Explorer.Staking.ContractState do
use GenServer
require Logger
alias Explorer.Chain
alias Explorer.Chain.Events.{Publisher, Subscriber}
alias Explorer.SmartContract.Reader
@ -118,8 +120,6 @@ defmodule Explorer.Staking.ContractState do
end
defp fetch_state(contracts, abi, block_number) do
previous_epoch = get(:epoch_number, 0)
global_responses = ContractReader.perform_requests(ContractReader.global_requests(), contracts, abi)
token = get_token(global_responses.token_contract_address)
@ -268,11 +268,11 @@ defmodule Explorer.Staking.ContractState do
timeout: :infinity
})
if previous_epoch && previous_epoch != 0 && previous_epoch != global_responses.epoch_number do
if global_responses.epoch_start_block == block_number + 1 do
with(
true <- :ets.insert(@table_name, is_snapshotted: false),
{:ok, _} <-
StakeSnapshotting.start_snapshoting(
StakeSnapshotting.start_snapshotting(
%{contracts: contracts, abi: abi, global_responses: global_responses},
block_number
)

@ -7,22 +7,24 @@ defmodule Explorer.Staking.StakeSnapshotting do
import Ecto.Query, only: [from: 2]
require Logger
alias Explorer.Chain
alias Explorer.Chain.{StakingPool, StakingPoolsDelegator}
alias Explorer.SmartContract.Reader
alias Explorer.Staking.ContractReader
def start_snapshoting(%{contracts: contracts, abi: abi, global_responses: global_responses}, block_number) do
def start_snapshotting(%{contracts: contracts, abi: abi, global_responses: global_responses}, block_number) do
%{
"getPendingValidators" => {:ok, [pending_validators_mining_addresses]},
"validatorsToBeFinalized" => {:ok, [be_finalized_validators_mining_addresses]}
"getPendingValidators" => {:ok, [pending_validators]},
"validatorsToBeFinalized" => {:ok, [to_be_finalized_validators]}
} =
Reader.query_contract(contracts.validator_set, abi, %{
"getPendingValidators" => [],
"validatorsToBeFinalized" => []
})
pool_mining_addresses = Enum.uniq(pending_validators_mining_addresses ++ be_finalized_validators_mining_addresses)
pool_mining_addresses = Enum.uniq(pending_validators ++ to_be_finalized_validators)
pool_staking_addresses =
pool_mining_addresses

@ -557,7 +557,7 @@
"name": "getPendingValidators",
"outputs": [
{
"name": "_miningAddress",
"name": "",
"type": "address[]"
}
],
@ -571,7 +571,7 @@
"name": "validatorsToBeFinalized",
"outputs": [
{
"name": "_miningAddress",
"name": "miningAddresses",
"type": "address[]"
}
],

Loading…
Cancel
Save