Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inomurko/merge unspent output bugfix to master v2 #1823

Merged
merged 99 commits into from
Mar 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
6ba53bd
/block.validate endpoint (#1668)
Aug 10, 2020
cb3659f
feat: configurable DB pool size, queue target and queue interval (#1689)
unnawut Aug 10, 2020
cbbc2dc
feat: auto trigger chart version bump (#1695)
boolafish Aug 18, 2020
a7b4188
Block Validation: New Checks (#1693)
Aug 21, 2020
733aab2
feat: block queue metrics and stalled submission alarm (#1649)
unnawut Aug 26, 2020
b3081f8
feat: handle in-flight exits deletions (#1701)
pgebal Aug 28, 2020
f62dc06
move omg_performance json rpc tests to perf project (#1691)
ayrat555 Aug 28, 2020
1992805
chore: add feefeed docker to elixir-omg setup (#1700)
boolafish Sep 2, 2020
536059c
feat: reintroduce automated changelog (#1708)
unnawut Sep 2, 2020
fd1beac
fix: ignore block_submitting that are above mined blocks (#1703)
unnawut Sep 2, 2020
f302553
fix: fix in-flight exit deleted bug and add tests (#1714)
pgebal Sep 3, 2020
ed8b0f7
revert: reverts ife deletion commits (#1725)
pgebal Sep 4, 2020
a69e22c
Allow to run docker-compose without feefeed docker (#1726)
boolafish Sep 9, 2020
3d75118
add test for 64_000 txs block hash (#1729)
ayrat555 Sep 9, 2020
3206e4c
rm mix based chch (#1716)
Sep 15, 2020
27379ec
Inomurko/remove child chain (#1737)
Sep 16, 2020
6227b79
feat: handle in-flight exits deletions
pgebal Sep 16, 2020
a428fa1
move dev env deployment job to helm repo (#1738)
boolafish Sep 18, 2020
7d6415b
fix: handle metrics for in flight exit deleted processor (#1742)
pgebal Sep 18, 2020
ff66dd2
Kevsul/standard exit perf test (#1732)
kevsul Sep 18, 2020
37ca58f
Chore: try to fix flaky reorg tests (#1739)
ayrat555 Sep 21, 2020
b54eb17
update change log v1.0.4 (#1731)
jarindr Sep 29, 2020
722949a
Chore: parallelize tests by tags (#1744)
ayrat555 Sep 29, 2020
85c5fc0
Chore: use exexec from upstream (#1743)
ayrat555 Oct 1, 2020
b8631c5
fix: recheck PR label on synchronize and reopen (#1748)
unnawut Oct 14, 2020
1d8ea8e
feat: add deposits performance tests bot (#1745)
ayrat555 Oct 19, 2020
ad007ca
feat: transaction.create optimisation (#1683)
Oct 20, 2020
c6cb81f
chore: bump version to 1.0.4 (#1751)
boolafish Oct 21, 2020
34b9d54
feat: comply with new Infura API (#1754)
pgebal Oct 26, 2020
54305bb
chore: changelog/version bump for v1.0.5 (#1747)
achiurizo Oct 27, 2020
a49a33a
Publish the perf project (#1753)
ayrat555 Oct 27, 2020
ed74da2
Utxo perf test (#1756)
ayrat555 Oct 29, 2020
251cfc0
Add cli help command for the perf project (#1757)
ayrat555 Oct 29, 2020
33c3300
feat : transaction.merge endpoint (#1715)
nicholasmueller Nov 2, 2020
d60fc03
add perf cli smoke test (#1762)
ayrat555 Nov 10, 2020
a10ef42
feat: send web telemetry events to Datadog
Nov 11, 2020
6a30d47
fix: move env var fetch into Configuration module
Nov 12, 2020
3a6b6c4
fix: ensure current_route doesn't throw an exception
Nov 12, 2020
bbfff29
fix: allow nil release and current_version env vars
Nov 12, 2020
3e02d1c
Merge pull request #1766 from omgnetwork/add-datadog-error-metrics
Nov 13, 2020
a94baf8
Chore: fix feefeed container healthcheck (#1768)
ayrat555 Nov 13, 2020
2ec3903
feat: add new metadata to Datadog traces
Nov 16, 2020
46036bc
refactor: move configuration helpers to new module
Nov 18, 2020
d348983
refactor: remove unused app field in Application
Nov 18, 2020
3665ec1
fix: failing tracer and response tests
Nov 18, 2020
d8e4431
fix: aggressive test fix (#1772)
Nov 18, 2020
dcc2d3d
Collect metrics through datadog for the perf project (#1765)
ayrat555 Nov 19, 2020
7f57d39
Merge branch 'master' into add-metadata-to-dd-traces-2
Nov 20, 2020
4f5756b
retry datadog errors (#1774)
ayrat555 Nov 20, 2020
35a2f51
fix: run tests that alter globals consecutively
Nov 20, 2020
4df5f4d
Merge branch 'master' into add-metadata-to-dd-traces-2
Nov 20, 2020
1f73eb5
refactor: atom to string with interpolation
Nov 20, 2020
0a7a6e8
Merge pull request #1770 from omgnetwork/add-metadata-to-dd-traces-2
Nov 20, 2020
8acfb91
ignore known errors - Sentry spike protection (#1775)
Nov 20, 2020
97bbb49
Fix readme docker docs (#1773)
ayrat555 Nov 20, 2020
7043d16
config filter sentry (#1778)
Nov 20, 2020
71e51b1
add docker-compose for `test_docker_compose_release` (#1777)
ayrat555 Nov 23, 2020
cd6ecc4
extract geth command, remove childchain only code paths (#1781)
Nov 23, 2020
dfca58b
#1588 phx exception caused by invalid accept header is now ignored
DanielaIvanova Nov 23, 2020
fe59481
#1588 added a test
DanielaIvanova Nov 24, 2020
525b80f
ignore RequestTooLarge for Sentry (#1779)
achiurizo Nov 25, 2020
b90fdc9
set remote_ip from cf-connecting-ip header (#1679)
ayrat555 Nov 25, 2020
0c562c5
#1588 minor adjustmen
DanielaIvanova Nov 25, 2020
8a8ba61
Merge branch 'master' into v1.0.5
unnawut Nov 25, 2020
e4a4aa0
feat: add X-Watcher-Version header to http requests (#1767)
pgebal Nov 25, 2020
2ccb80d
#1588 minor fix
DanielaIvanova Nov 25, 2020
7da0801
Merge branch 'master' into danielaivanova/ignore-invalid-header
DanielaIvanova Nov 25, 2020
4c9bed9
Merge pull request #1783 from omgnetwork/danielaivanova/ignore-invali…
DanielaIvanova Nov 25, 2020
f2e71d4
fix: set service name as a tag in metrics
Nov 25, 2020
4f26803
Merge branch 'master' into dd-metrics-service-tag
Nov 25, 2020
9571ac0
Merge pull request #1786 from omgnetwork/dd-metrics-service-tag
Nov 25, 2020
822b033
fix: limit matching for ethereumex responses (#1782)
souradeep-das Nov 25, 2020
d0b86c8
just the one thing to turn into a warn (#1784)
achiurizo Nov 26, 2020
568ea4b
Renamed all occurrences of omisego to omgnetwork (#1788)
DanielaIvanova Nov 30, 2020
8629ad0
Merge branch 'master' into v1.0.5
boolafish Dec 1, 2020
f205fd3
chore: changelog/version bump for v1.0.5 (#1747) (#1785)
unnawut Dec 1, 2020
73749ca
Merge branch 'master' into v1.0.5
boolafish Dec 4, 2020
9abc6c7
Merge pull request #1790 from omgnetwork/v1.0.5
boolafish Dec 4, 2020
e88809a
chore: add sem release automation (#1791)
boolafish Dec 4, 2020
09efc26
bump elixir (#1789)
Dec 7, 2020
f0a8a05
align rust version to 1.46 (#1793)
Dec 7, 2020
fef32f8
trace reorg tests (#1796)
Dec 7, 2020
f116c63
fix: make sem release ignore PR check (#1797)
boolafish Dec 8, 2020
eff6352
chore: use git tag version instead (#1798)
boolafish Dec 11, 2020
4f2c63b
simplify event pulling (#1801)
Dec 11, 2020
bb7ecf5
fix: git tag (#1804)
boolafish Dec 14, 2020
35bf68d
Update CODEOWNERS (#1805)
InoMurko Jan 11, 2021
0e96ddd
Watcher_Info events race cause spent output presented unspent (#1769)
pnowosie Jan 19, 2021
bc0151f
Merge remote-tracking branch 'origin/master' into master-v2
ayrat555 Jan 19, 2021
fa7ffd9
fix ex_plasma reference
ayrat555 Jan 20, 2021
6666ae8
fix linter
ayrat555 Jan 20, 2021
7ad6a27
merge from masterv2
InoMurko Mar 12, 2021
ea1262c
merge from masterv2
InoMurko Mar 12, 2021
18004d7
merge from masterv2
InoMurko Mar 12, 2021
e2bd1de
ci fixes
InoMurko Mar 12, 2021
de0c5cf
test fixes
InoMurko Mar 12, 2021
edc4408
test fixes
InoMurko Mar 12, 2021
304a527
missing events for PG
InoMurko Mar 12, 2021
73952fb
missing events for PG
InoMurko Mar 12, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
383 changes: 207 additions & 176 deletions .circleci/config.yml

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions apps/omg/lib/omg/state.ex
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ defmodule OMG.State do
end

def handle_call({:deposit, deposits}, _from, state) do
if Code.ensure_loaded?(OMG.WatcherInfo.DB.EthEvent) do
:ok = Kernel.apply(OMG.WatcherInfo.DB.EthEvent, :insert_deposits!, [deposits])
end

{:ok, db_updates, new_state} = Core.deposit(deposits, state)

{:reply, {:ok, db_updates}, new_state}
Expand Down
18 changes: 17 additions & 1 deletion apps/omg/test/omg/state/persistence_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ defmodule OMG.State.PersistenceTest do

require OMG.Utxo

alias Ecto.Adapters.SQL.Sandbox
alias OMG.Block
alias OMG.Eth.Configuration
alias OMG.State.Transaction
Expand Down Expand Up @@ -57,6 +58,20 @@ defmodule OMG.State.PersistenceTest do
strategy: :one_for_one
)

Application.ensure_all_started(:postgrex)
Application.ensure_all_started(:spandex_ecto)
Application.ensure_all_started(:ecto)

{:ok, _} =
Supervisor.start_link(
[%{id: OMG.WatcherInfo.DB.Repo, start: {OMG.WatcherInfo.DB.Repo, :start_link, []}, type: :supervisor}],
strategy: :one_for_one,
name: WatcherInfo.Supervisor
)

:ok = Sandbox.checkout(OMG.WatcherInfo.DB.Repo)
Sandbox.mode(OMG.WatcherInfo.DB.Repo, {:shared, self()})

on_exit(fn ->
Application.put_env(:omg_db, :path, nil)

Expand Down Expand Up @@ -226,7 +241,8 @@ defmodule OMG.State.PersistenceTest do
owner: owner.addr,
currency: currency,
amount: amount,
blknum: blknum
blknum: blknum,
eth_height: 1
}
end)
end
Expand Down
29 changes: 28 additions & 1 deletion apps/omg/test/omg/state_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ defmodule OMG.StateTest do

use OMG.DB.Fixtures

alias Ecto.Adapters.SQL.Sandbox
alias OMG.State
alias OMG.TestHelper
alias OMG.Utxo
Expand All @@ -38,6 +39,20 @@ defmodule OMG.StateTest do
# the pubsub is required, because `OMG.State` is broadcasting to the `OMG.Bus`
{:ok, bus_apps} = Application.ensure_all_started(:omg_bus)

Application.ensure_all_started(:postgrex)
Application.ensure_all_started(:spandex_ecto)
Application.ensure_all_started(:ecto)

{:ok, _} =
Supervisor.start_link(
[%{id: OMG.WatcherInfo.DB.Repo, start: {OMG.WatcherInfo.DB.Repo, :start_link, []}, type: :supervisor}],
strategy: :one_for_one,
name: WatcherInfo.Supervisor
)

:ok = Sandbox.checkout(OMG.WatcherInfo.DB.Repo)
Sandbox.mode(OMG.WatcherInfo.DB.Repo, {:shared, self()})

on_exit(fn ->
(started_apps ++ bus_apps)
|> Enum.reverse()
Expand Down Expand Up @@ -68,7 +83,19 @@ defmodule OMG.StateTest do
fee = %{@eth => [1]}

# deposits, transactions, utxo existence
assert {:ok, _} = State.deposit([%{owner: alice.addr, currency: @eth, amount: 10, blknum: 1}])
assert {:ok, _} =
State.deposit([
%{
owner: alice.addr,
currency: @eth,
amount: 10,
blknum: 1,
root_chain_txhash: <<1::256>>,
eth_height: 1,
log_index: 0
}
])

assert true == State.utxo_exists?(Utxo.position(1, 0, 0))

assert {:ok, _} = State.exec(TestHelper.create_recovered([{1, 0, 0, alice}], @eth, [{alice, 9}]), fee)
Expand Down
4 changes: 2 additions & 2 deletions apps/omg_status/lib/omg_status/metric/event.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ defmodule OMG.Status.Metric.Event do
:ife_exit_finalizer,
:in_flight_exit,
:in_flight_exit_processor,
:in_flight_exit_deleted_processor,
:piggyback,
:piggyback_challenges_processor,
:piggyback_processor,
Expand All @@ -54,7 +55,6 @@ defmodule OMG.Status.Metric.Event do
:watcher_exit_processor_message_queue_len - OMG.Watcher.ExitProcessor message queue length
:eventer_message_queue_len - OMG.Watcher.Eventer message queue length
:db_message_queue_len - OMG.DB server implementation (OMG.DB.LevelDB.Server, or OMG.DB.RocksDB.Server,) message queue length
:pending_block_queue_length - OMG.WatcherInfo.DB.PendingBlock queue length
:write - OMG.DB KV layer has three types of actions: write, read, multiread
:read - OMG.DB KV layer has three types of actions: write, read, multiread
:multiread - OMG.DB KV layer has three types of actions: write, read, multiread
Expand All @@ -78,7 +78,6 @@ defmodule OMG.Status.Metric.Event do
def name(:watcher_exit_processor_message_queue_len), do: "watcher_exit_processor_message_queue_len"
def name(:eventer_message_queue_len), do: "eventer_message_queue_len"
def name(:db_message_queue_len), do: "db_message_queue_len"
def name(:pending_block_queue_length), do: "pending_block_queue_length"
def name(:write), do: "db_write"
def name(:read), do: "db_read"
def name(:multiread), do: "db_multiread"
Expand All @@ -100,6 +99,7 @@ defmodule OMG.Status.Metric.Event do
defp events_name(:exit_finalizer), do: "exit_finalizer_ethereum_events"
defp events_name(:exit_challenger), do: "exit_challenger_ethereum_events"
defp events_name(:in_flight_exit_processor), do: "in_flight_exit_processor_ethereum_events"
defp events_name(:in_flight_exit_deleted_processor), do: "in_flight_exit_deleted_processor_ethereum_events"
defp events_name(:piggyback_processor), do: "piggyback_processor_ethereum_events"
defp events_name(:competitor_processor), do: "competitor_processor_ethereum_events"
defp events_name(:challenges_responds_processor), do: "challenges_responds_processor_ethereum_events"
Expand Down
6 changes: 2 additions & 4 deletions apps/omg_watcher/lib/omg_watcher/block_getter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,8 @@ defmodule OMG.Watcher.BlockGetter do

case Core.validate_executions(tx_exec_results, block_application, state) do
{:ok, state} ->
:ok =
{:child_chain, "block.get"}
|> OMG.Bus.Event.new(:block_received, block_application)
|> OMG.Bus.direct_local_broadcast()
if Code.ensure_loaded?(OMG.WatcherInfo.DB.Block),
do: Kernel.apply(OMG.WatcherInfo.BlockApplicator, :insert_block!, [block_application])

{:noreply, state, {:continue, {:apply_block_step, :run_block_download_task, block_application}}}

Expand Down
41 changes: 30 additions & 11 deletions apps/omg_watcher/lib/omg_watcher/exit_processor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,9 @@ defmodule OMG.Watcher.ExitProcessor do
)
|> Enum.map(fn {:ok, result} -> result end)

if Code.ensure_loaded?(OMG.WatcherInfo.DB.EthEvent),
do: Kernel.apply(OMG.WatcherInfo.DB.EthEvent, :insert_exits!, [exits, :standard_exit, nil])

{new_state, db_updates} = Core.new_exits(state, exit_maps, exit_contract_statuses)
{:reply, {:ok, db_updates}, new_state}
end
Expand All @@ -404,13 +407,17 @@ defmodule OMG.Watcher.ExitProcessor do
end)

# Prepare events data for internal bus
:ok =
events =
exits
|> Enum.map(fn %{input_utxos_pos: inputs} = event ->
{event, inputs}
end)
|> Tools.to_bus_events_data()
|> publish_internal_bus_events("InFlightExitStarted")

:ok = publish_internal_bus_events(events, :InFlightExitStarted)

if Code.ensure_loaded?(OMG.WatcherInfo.DB.EthEvent),
do: Kernel.apply(OMG.WatcherInfo.DB.EthEvent, :insert_exits!, [events, :in_flight_exit, :InFlightExitStarted])

{:ok, statuses} = Eth.RootChain.get_in_flight_exit_structs(contract_ife_ids)

Expand Down Expand Up @@ -446,10 +453,16 @@ defmodule OMG.Watcher.ExitProcessor do
_ = if not Enum.empty?(exits), do: Logger.info("Recognized #{Enum.count(exits)} piggybacks: #{inspect(exits)}")
{new_state, db_updates} = Core.new_piggybacks(state, exits)

:ok =
exits
|> Tools.to_bus_events_data()
|> publish_internal_bus_events("InFlightTxOutputPiggybacked")
events = Tools.to_bus_events_data(exits)
:ok = publish_internal_bus_events(events, :InFlightTxOutputPiggybacked)

if Code.ensure_loaded?(OMG.WatcherInfo.DB.EthEvent),
do:
Kernel.apply(
OMG.WatcherInfo.DB.EthEvent,
:insert_exits!,
[events, :in_flight_exit, :InFlightTxOutputPiggybacked]
)

{:reply, {:ok, db_updates}, new_state}
end
Expand Down Expand Up @@ -503,10 +516,16 @@ defmodule OMG.Watcher.ExitProcessor do

{:ok, state3, db_updates} = Core.finalize_in_flight_exits(state2, finalizations, invalidities)

:ok =
events_with_utxos
|> Tools.to_bus_events_data()
|> publish_internal_bus_events("InFlightExitOutputWithdrawn")
events = Tools.to_bus_events_data(events_with_utxos)
:ok = publish_internal_bus_events(events, :InFlightExitOutputWithdrawn)

if Code.ensure_loaded?(OMG.WatcherInfo.DB.EthEvent),
do:
Kernel.apply(
OMG.WatcherInfo.DB.EthEvent,
:insert_exits!,
[events, :in_flight_exit, :InFlightExitOutputWithdrawn]
)

{:reply, {:ok, state_db_updates ++ db_updates}, state3}
end
Expand Down Expand Up @@ -709,7 +728,7 @@ defmodule OMG.Watcher.ExitProcessor do

defp publish_internal_bus_events([], _), do: :ok

defp publish_internal_bus_events(events_data, topic) when is_list(events_data) and is_binary(topic) do
defp publish_internal_bus_events(events_data, topic) when is_list(events_data) and is_atom(topic) do
{:watcher, topic}
|> OMG.Bus.Event.new(:data, events_data)
|> OMG.Bus.direct_local_broadcast()
Expand Down
15 changes: 13 additions & 2 deletions apps/omg_watcher/test/omg_watcher/integration/monitor_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ defmodule OMG.Watcher.MonitorTest do

test "that a child process gets restarted after alarm is cleared" do
child = ChildProcess.prepare_child()
{:ok, monitor_pid} = Monitor.start_link([Alarm, child])
{:ok, monitor_pid} = start_and_attach_a_child([Alarm, child])
app_alarm = Alarm.ethereum_connection_error(__MODULE__)

# the monitor is now started, we raise an alarm and kill it's child
Expand Down Expand Up @@ -85,7 +85,7 @@ defmodule OMG.Watcher.MonitorTest do

test "that a child process does not get restarted if an alarm is cleared but it was not down" do
child = ChildProcess.prepare_child()
{:ok, monitor_pid} = Monitor.start_link([Alarm, child])
{:ok, monitor_pid} = start_and_attach_a_child([Alarm, child])
app_alarm = Alarm.ethereum_connection_error(__MODULE__)
:ok = :alarm_handler.set_alarm(app_alarm)
:erlang.trace(monitor_pid, true, [:receive])
Expand All @@ -102,6 +102,17 @@ defmodule OMG.Watcher.MonitorTest do
assert Process.info(monitor_pid, :links) == {:links, links}
end

defp start_and_attach_a_child(opts) do
case Monitor.start_link(opts) do
{:ok, monitor_pid} ->
{:ok, monitor_pid}

{:error, {{:badmatch, {:error, {:already_started, _}}}, _}} ->
Process.sleep(500)
start_and_attach_a_child(opts)
end
end

defmodule ChildProcess do
@moduledoc """
Mocking a child process to Monitor
Expand Down

This file was deleted.

48 changes: 48 additions & 0 deletions apps/omg_watcher_info/lib/omg_watcher_info/block_applicator.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright 2019-2020 OMG Network Pte Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

defmodule OMG.WatcherInfo.BlockApplicator do
@moduledoc """
Handles new block applications from Watcher's `BlockGetter` and persists them for further processing
"""

alias OMG.WatcherInfo.DB

@type block_application_t :: %{
eth_height: pos_integer(),
hash: binary(),
number: pos_integer(),
timestamp: pos_integer(),
transactions: [OMG.State.Transaction.Recovered.t()]
}

@doc """
Inserts a block along with transactions and outputs, does not break when block already exists.
"""
@spec insert_block!(block_application_t()) :: :ok
def insert_block!(block) do
block
|> DB.Block.insert_from_block_application()
|> case do
{:ok, _} ->
:ok

# Ensures insert idempotency. Trying to add block with the same `blknum` that already exists takes no effect.
# See also [comment](https://github.com/omgnetwork/elixir-omg/pull/1769#discussion_r528700434)
{:error, "current_block", changeset, _explain} ->
[{:blknum, {_msg, [constraint: :unique, constraint_name: _name]}}] = changeset.errors()
:ok
end
end
end
Loading