Skip to content

Commit f3ea4b4

Browse files
authored
chore: prepare wealth to be updated on block basis (#1556)
1 parent 5fd3bd3 commit f3ea4b4

File tree

3 files changed

+0
-58
lines changed

3 files changed

+0
-58
lines changed

lib/ae_mdw/application.ex

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,6 @@ defmodule AeMdw.Application do
223223
:ok
224224
end
225225

226-
def start_phase(:dedup_accounts, _start_type, []) do
227-
AeMdw.Sync.AsyncTasks.WealthRankAccounts.dedup_pending_accounts()
228-
:ok
229-
end
230-
231226
def start_phase(:load_obj_keys, _start_type, []) do
232227
ObjectKeys.init(State.new())
233228
end

lib/ae_mdw/sync/async_tasks/wealth_rank_accounts.ex

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3,51 +3,13 @@ defmodule AeMdw.Sync.AsyncTasks.WealthRankAccounts do
33

44
@typep micro_block :: term()
55

6-
alias AeMdw.Collection
76
alias AeMdw.Db.Model
8-
alias AeMdw.Db.State
97
alias AeMdw.Db.Mutation
108
alias AeMdw.Db.IntCallsMutation
11-
alias AeMdw.Db.DeleteKeysMutation
12-
alias AeMdw.Db.WriteMutation
139
alias AeMdw.Sync.Transaction
1410

1511
require Model
1612

17-
@spec dedup_pending_accounts() :: :ok
18-
def dedup_pending_accounts do
19-
state = State.new()
20-
21-
{delete_keys, pubkeys_set} =
22-
state
23-
|> Collection.stream(Model.AsyncTask, nil)
24-
|> Stream.filter(fn {_ts, type} -> type == :store_acc_balance end)
25-
|> Stream.map(&State.fetch!(state, Model.AsyncTask, &1))
26-
|> Enum.map_reduce(MapSet.new(), fn
27-
Model.async_task(index: index, extra_args: []), acc ->
28-
{index, acc}
29-
30-
Model.async_task(index: index, extra_args: [extra_args]), acc ->
31-
{index, MapSet.union(acc, extra_args)}
32-
end)
33-
34-
with args when args != [] <- last_mb(state, nil) do
35-
task_index = {System.system_time(), :store_acc_balance}
36-
m_task = Model.async_task(index: task_index, args: args, extra_args: [pubkeys_set])
37-
38-
State.commit_db(
39-
state,
40-
[
41-
DeleteKeysMutation.new(%{Model.AsyncTask => delete_keys}),
42-
WriteMutation.new(Model.AsyncTask, m_task)
43-
],
44-
false
45-
)
46-
end
47-
48-
:ok
49-
end
50-
5113
@spec micro_block_accounts(micro_block(), [Mutation.t()]) :: MapSet.t()
5214
def micro_block_accounts(micro_block, mutations) do
5315
txs_pubkeys =
@@ -93,18 +55,4 @@ defmodule AeMdw.Sync.AsyncTasks.WealthRankAccounts do
9355
_other -> []
9456
end)
9557
end
96-
97-
defp last_mb(state, key) do
98-
case State.prev(state, Model.Block, key) do
99-
{:ok, {_height, -1} = prev_key} ->
100-
last_mb(state, prev_key)
101-
102-
{:ok, block_index} ->
103-
Model.block(hash: mb_hash) = State.fetch!(state, Model.Block, block_index)
104-
[mb_hash, block_index]
105-
106-
:none ->
107-
[]
108-
end
109-
end
11058
end

mix.exs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ defmodule AeMdw.MixProject do
125125
start_phases: [
126126
migrate_db: [],
127127
hardforks_presets: [],
128-
dedup_accounts: [],
129128
load_obj_keys: [],
130129
start_sync: []
131130
],

0 commit comments

Comments
 (0)