|
|
@ -233,8 +233,6 @@ defmodule Explorer.Staking.ContractState do |
|
|
|
|
|
|
|
|
|
|
|
epoch_very_beginning = global_responses.epoch_start_block == block_number + 1 |
|
|
|
epoch_very_beginning = global_responses.epoch_start_block == block_number + 1 |
|
|
|
|
|
|
|
|
|
|
|
start_snapshotting = start_snapshotting?(global_responses, state, block_number) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# determine if something changed in contracts state since the previous seen block. |
|
|
|
# determine if something changed in contracts state since the previous seen block. |
|
|
|
# if something changed or the `fetch_state` function is called for the first time |
|
|
|
# if something changed or the `fetch_state` function is called for the first time |
|
|
|
# or we are at the beginning of staking epoch or snapshotting recently finished |
|
|
|
# or we are at the beginning of staking epoch or snapshotting recently finished |
|
|
@ -242,6 +240,8 @@ defmodule Explorer.Staking.ContractState do |
|
|
|
last_change_block = |
|
|
|
last_change_block = |
|
|
|
max(global_responses.staking_last_change_block, global_responses.validator_set_last_change_block) |
|
|
|
max(global_responses.staking_last_change_block, global_responses.validator_set_last_change_block) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
start_snapshotting = start_snapshotting?(global_responses, state, block_number, last_change_block) |
|
|
|
|
|
|
|
|
|
|
|
first_fetch = get(:epoch_end_block, 0) == 0 |
|
|
|
first_fetch = get(:epoch_end_block, 0) == 0 |
|
|
|
|
|
|
|
|
|
|
|
should_update_db = |
|
|
|
should_update_db = |
|
|
@ -350,7 +350,7 @@ defmodule Explorer.Staking.ContractState do |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp start_snapshotting?(global_responses, state, block_number) do |
|
|
|
defp start_snapshotting?(global_responses, state, block_number, last_change_block) do |
|
|
|
if global_responses.epoch_number == 0 do |
|
|
|
if global_responses.epoch_number == 0 do |
|
|
|
# we never snapshot at initial staking epoch |
|
|
|
# we never snapshot at initial staking epoch |
|
|
|
false |
|
|
|
false |
|
|
@ -365,6 +365,8 @@ defmodule Explorer.Staking.ContractState do |
|
|
|
:ets.insert(@table_name, snapshotting_scheduled: false) |
|
|
|
:ets.insert(@table_name, snapshotting_scheduled: false) |
|
|
|
true |
|
|
|
true |
|
|
|
else |
|
|
|
else |
|
|
|
|
|
|
|
change_pool_address_events = |
|
|
|
|
|
|
|
if last_change_block > get(:last_change_block) do |
|
|
|
# check for ChangedMiningAddress and ChangedStakingAddress events |
|
|
|
# check for ChangedMiningAddress and ChangedStakingAddress events |
|
|
|
# from the ValidatorSetAuRa contract: if one of these events |
|
|
|
# from the ValidatorSetAuRa contract: if one of these events |
|
|
|
# emitted, we need to do snapshotting |
|
|
|
# emitted, we need to do snapshotting |
|
|
@ -377,7 +379,6 @@ defmodule Explorer.Staking.ContractState do |
|
|
|
block_number |
|
|
|
block_number |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
change_pool_address_events = |
|
|
|
|
|
|
|
ContractReader.get_contract_events( |
|
|
|
ContractReader.get_contract_events( |
|
|
|
state.contracts.validator_set, |
|
|
|
state.contracts.validator_set, |
|
|
|
from_block, |
|
|
|
from_block, |
|
|
@ -389,6 +390,9 @@ defmodule Explorer.Staking.ContractState do |
|
|
|
"0x5c44164828293bba0353472e907f7ee26a8659f916e6311fe826a7c70510e352" |
|
|
|
"0x5c44164828293bba0353472e907f7ee26a8659f916e6311fe826a7c70510e352" |
|
|
|
] |
|
|
|
] |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
[] |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
if Enum.count(change_pool_address_events) > 0 do |
|
|
|
if Enum.count(change_pool_address_events) > 0 do |
|
|
|
# we see at least one of the events, so start snapshotting |
|
|
|
# we see at least one of the events, so start snapshotting |
|
|
|