Skip to content

Commit d9e84f1

Browse files
committed
filterhash builder
1 parent 43482f6 commit d9e84f1

File tree

6 files changed

+64
-3
lines changed

6 files changed

+64
-3
lines changed

ex/lib/api/api_tx.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ defmodule API.TX do
1818
end
1919
end
2020

21-
# e44225070
21+
# e 44225212
2222
def get_by_filter(filters = %{}) do
2323
signer = filters[:signer] || filters[:sender] || filters[:pk] || <<0>>
2424
arg0 = filters[:arg0] || filters[:receiver] || <<0>>

ex/lib/api/db_entry.ex

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,33 @@ defmodule DB.Entry do
176176
end)
177177
end
178178

179+
def build_filter_hashes() do
180+
rebuilt_up_to = RocksDB.get("filter_hashes_rebuilt_up_to", db_handle(%{}, :sysconf, %{})) || EntryGenesis.get().hash
181+
entry = by_hash(rebuilt_up_to)
182+
if rem(entry.header.height, 10_000) == 0 do
183+
IO.inspect {:rebuilt_filter_hashes_up_to, entry.header.height}
184+
end
185+
txs = entry.txs
186+
txs = Enum.map(txs, fn(txu)->
187+
txu = if !is_binary(txu) do txu else
188+
txu = VanillaSer.decode!(txu)
189+
tx = VanillaSer.decode!(txu.tx_encoded)
190+
Map.put(txu, :tx, tx)
191+
end
192+
action = TX.action(txu)
193+
args = case action.args do
194+
[n|t] when is_integer(n) -> [:erlang.integer_to_binary(n) | t]
195+
args -> args
196+
end
197+
198+
txu = put_in(txu, [:tx, :action], action)
199+
put_in(txu, [:tx, :action, :args], args)
200+
end)
201+
202+
tx_filters = RDB.build_tx_hashfilters(txs)
203+
Enum.each(tx_filters, fn {key, hash} ->
204+
RocksDB.put(key, hash, db_handle(%{}, :tx_filter, %{}))
205+
end)
206+
rebuilt_up_to = RocksDB.put("filter_hashes_rebuilt_up_to", next(rebuilt_up_to), db_handle(%{}, :sysconf, %{})) || EntryGenesis.get().hash
207+
end
179208
end

ex/lib/api/db_entry_hashbuilder.ex

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
defmodule DB.Entry.Hashbuilder do
2+
use GenServer
3+
4+
def start_link() do
5+
GenServer.start_link(__MODULE__, %{}, name: __MODULE__)
6+
end
7+
8+
def init(state) do
9+
case RocksDB.get("filter_hashes_start", DB.API.db_handle(%{}, :sysconf, %{})) do
10+
nil ->
11+
IO.inspect "starting hashfilter builder"
12+
RocksDB.put("filter_hashes_end_hash", DB.Chain.tip(), DB.API.db_handle(%{}, :sysconf, %{}))
13+
_ -> nil
14+
end
15+
16+
:erlang.send_after(1000, self(), :tick)
17+
{:ok, state}
18+
end
19+
20+
def handle_info(:tick, state) do
21+
rebuilt_up_to = RocksDB.get("filter_hashes_rebuilt_up_to", DB.API.db_handle(%{}, :sysconf, %{})) || EntryGenesis.get().hash
22+
rebuilt_up_to_height = DB.Entry.by_hash(rebuilt_up_to).header.height
23+
rebuilt_end = RocksDB.get("filter_hashes_end_hash", DB.API.db_handle(%{}, :sysconf, %{}))
24+
rebuilt_end_height = DB.Entry.by_hash(rebuilt_end).header.height
25+
if rebuilt_up_to_height <= rebuilt_end_height do
26+
Enum.each(0..100_000, fn(_)-> DB.Entry.build_filter_hashes() end)
27+
end
28+
:erlang.send_after(1000, self(), :tick)
29+
{:noreply, state}
30+
end
31+
end

ex/lib/consensus/fabric_gen.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ defmodule FabricGen do
303303

304304
took_contract_exec = :os.system_time(1000) - start_contract_exec
305305
if took_contract_exec > 100 do
306-
IO.puts "Contract Exec took #{took_contract_exec}ms"
306+
IO.puts "Contract Exec took #{took_contract_exec}ms #{next_entry.header.height}"
307307
end
308308

309309
rebuild_m_fn = fn(m)->

ex/lib/consensus/models/tx.ex

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ defmodule TX do
142142
case {c,f,a} do
143143
{"Coin", "transfer", [receiver, _amount, _symbol]} -> valid_pk(receiver) && [receiver]
144144
{"Epoch", "slash_trainer", [malicious_pk, _epoch, _signature, _mask_size, _mask]} when byte_size(malicious_pk) == 48 -> valid_pk(malicious_pk) && [malicious_pk]
145-
{"Epoch", "slash_trainer", [_epoch, malicious_pk, _signature, _mask_size, _mask]} when byte_size(malicious_pk) == 48 -> valid_pk(malicious_pk) && [malicious_pk]
146145
_ -> nil
147146
end || []
148147
end

ex/lib/ex.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ defmodule Ama do
9696
if !Application.fetch_env!(:ama, :testnet) do
9797
{:ok, _} = DynamicSupervisor.start_child(Ama.Supervisor, %{id: FabricSyncAttestGen, start: {FabricSyncAttestGen, :start_link, []}})
9898
{:ok, _} = DynamicSupervisor.start_child(Ama.Supervisor, %{id: FabricSyncGen, start: {FabricSyncGen, :start_link, []}})
99+
#TODO: remove it later
100+
{:ok, _} = DynamicSupervisor.start_child(Ama.Supervisor, %{id: DB.Entry.Hashbuilder, start: {DB.Entry.Hashbuilder, :start_link, []}})
99101
end
100102

101103
{:ok, _} = DynamicSupervisor.start_child(Ama.Supervisor, %{id: ComputorGen, start: {ComputorGen, :start_link, []}})

0 commit comments

Comments
 (0)