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", []}, pools_likelihood: {:staking, "getPoolsLikelihood", []},
validators: {:validator_set, "getValidators", []}, validators: {:validator_set, "getValidators", []},
unremovable_validator: {:validator_set, "unremovableValidator", []}, unremovable_validator: {:validator_set, "unremovableValidator", []},
pending_validators: {:validator_set, "getPendingValidators", []}, # pending_validators: {:validator_set, "getPendingValidators", []},
be_finalized_validators: {:validator_set, "validatorsToBeFinalized", []}, # be_finalized_validators: {:validator_set, "validatorsToBeFinalized", []},
validator_set_apply_block: {:validator_set, "validatorSetApplyBlock", []} validator_set_apply_block: {:validator_set, "validatorSetApplyBlock", []}
] ]
end end

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

@ -7,22 +7,24 @@ defmodule Explorer.Staking.StakeSnapshotting do
import Ecto.Query, only: [from: 2] import Ecto.Query, only: [from: 2]
require Logger
alias Explorer.Chain alias Explorer.Chain
alias Explorer.Chain.{StakingPool, StakingPoolsDelegator} alias Explorer.Chain.{StakingPool, StakingPoolsDelegator}
alias Explorer.SmartContract.Reader alias Explorer.SmartContract.Reader
alias Explorer.Staking.ContractReader 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]}, "getPendingValidators" => {:ok, [pending_validators]},
"validatorsToBeFinalized" => {:ok, [be_finalized_validators_mining_addresses]} "validatorsToBeFinalized" => {:ok, [to_be_finalized_validators]}
} = } =
Reader.query_contract(contracts.validator_set, abi, %{ Reader.query_contract(contracts.validator_set, abi, %{
"getPendingValidators" => [], "getPendingValidators" => [],
"validatorsToBeFinalized" => [] "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_staking_addresses =
pool_mining_addresses pool_mining_addresses

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

Loading…
Cancel
Save