From deab148154a79aba05ec2b3d2aeb5d28ec39e851 Mon Sep 17 00:00:00 2001 From: souradeep-das Date: Tue, 28 Apr 2020 03:19:24 +0530 Subject: [PATCH 01/28] change EXIT_PROCESSOR_SLA_MARGIN to EXIT_PROCESSOR_SLA_SECONDS --- .../lib/omg_watcher/api/configuration.ex | 2 +- .../lib/omg_watcher/configuration.ex | 4 +-- .../lib/omg_watcher/exit_processor.ex | 17 +++++----- .../lib/omg_watcher/exit_processor/core.ex | 34 +++++++++---------- .../exit_processor/standard_exit.ex | 7 ++-- .../set_exit_processor_sla_margin.ex | 8 ++--- .../lib/omg_watcher/sync_supervisor.ex | 4 +-- .../omg_watcher/exit_processor/core_test.exs | 8 ++--- .../integration/block_getter_test.exs | 13 +++---- .../integration/invalid_exit_test.exs | 10 +++--- .../set_exit_processor_sla_margin_test.exs | 18 +++++----- .../priv/swagger/info_api_specs.yaml | 4 +-- .../configuration/configuration_schema.yml | 2 +- .../configuration/response_schemas.yaml | 2 +- .../info_api_specs/configuration/schemas.yaml | 2 +- .../swagger/security_critical_api_specs.yaml | 2 +- .../configuration/configuration_schema.yml | 2 +- .../configuration/schemas.yaml | 2 +- bin/variables | 2 +- bin/variables_test_barebone | 2 +- config/config.exs | 6 ++-- config/dev.exs | 6 ++-- config/test.exs | 2 +- docker-compose-watcher.yml | 4 +-- docker-compose.yml | 4 +-- docs/deployment_configuration.md | 2 +- docs/details.md | 6 ++-- docs/exit_validation.md | 32 ++++++++--------- ...watcher_security_critical_configuration.ex | 6 ++-- .../test/itest/configuration_api_test.exs | 2 +- priv/cabbage/docker-compose-cabbage.yml | 4 +-- 31 files changed, 112 insertions(+), 107 deletions(-) diff --git a/apps/omg_watcher/lib/omg_watcher/api/configuration.ex b/apps/omg_watcher/lib/omg_watcher/api/configuration.ex index 6afdb84be4..65d0be043f 100644 --- a/apps/omg_watcher/lib/omg_watcher/api/configuration.ex +++ b/apps/omg_watcher/lib/omg_watcher/api/configuration.ex @@ -22,7 +22,7 @@ defmodule OMG.Watcher.API.Configuration do @spec get_configuration() :: {:ok, map()} def get_configuration() do configuration = %{ - exit_processor_sla_margin: Configuration.exit_processor_sla_margin(), + exit_processor_sla_seconds: Configuration.exit_processor_sla_seconds(), deposit_finality_margin: OMG.Configuration.deposit_finality_margin(), contract_semver: OMG.Eth.Configuration.contract_semver(), network: OMG.Eth.Configuration.network() diff --git a/apps/omg_watcher/lib/omg_watcher/configuration.ex b/apps/omg_watcher/lib/omg_watcher/configuration.ex index fc579d010f..21c94669e1 100644 --- a/apps/omg_watcher/lib/omg_watcher/configuration.ex +++ b/apps/omg_watcher/lib/omg_watcher/configuration.ex @@ -17,8 +17,8 @@ defmodule OMG.Watcher.Configuration do Provides access to applications configuration """ @app :omg_watcher - def exit_processor_sla_margin() do - Application.fetch_env!(@app, :exit_processor_sla_margin) + def exit_processor_sla_seconds() do + Application.fetch_env!(@app, :exit_processor_sla_seconds) end def exit_processor_sla_margin_forced() do diff --git a/apps/omg_watcher/lib/omg_watcher/exit_processor.ex b/apps/omg_watcher/lib/omg_watcher/exit_processor.ex index 87ef0fe03f..dcb8e4c8f0 100644 --- a/apps/omg_watcher/lib/omg_watcher/exit_processor.ex +++ b/apps/omg_watcher/lib/omg_watcher/exit_processor.ex @@ -247,16 +247,16 @@ defmodule OMG.Watcher.ExitProcessor do Reads the exit data from `OMG.DB`. Options: - - `exit_processor_sla_margin`: number of blocks after exit start before it's considered late (and potentially: + - `exit_processor_sla_seconds`: seconds after exit start before it's considered late (and potentially: unchallenged) - - `exit_processor_sla_margin_forced`: if `true` will override the check of `exit_processor_sla_margin` against + - `exit_processor_sla_margin_forced`: if `true` will override the check of `exit_processor_sla_seconds` against `min_exit_period_seconds` - `min_exit_period_seconds`: should reflect the value of this parameter for the specific child chain watched, - - `ethereum_block_time_seconds`: just to relate blocks to seconds for the `exit_processor_sla_margin` check + - `ethereum_block_time_seconds`: relate blocks to seconds - `metrics_collection_interval`: how often are the metrics sent to `telemetry` (in milliseconds) """ def init( - exit_processor_sla_margin: exit_processor_sla_margin, + exit_processor_sla_seconds: exit_processor_sla_seconds, exit_processor_sla_margin_forced: exit_processor_sla_margin_forced, metrics_collection_interval: metrics_collection_interval, min_exit_period_seconds: min_exit_period_seconds, @@ -267,14 +267,13 @@ defmodule OMG.Watcher.ExitProcessor do {:ok, db_competitors} = DB.competitors_info() :ok = - Core.check_sla_margin( - exit_processor_sla_margin, + Core.check_sla_seconds( + exit_processor_sla_seconds, exit_processor_sla_margin_forced, - min_exit_period_seconds, - ethereum_block_time_seconds + min_exit_period_seconds ) - {:ok, processor} = Core.init(db_exits, db_ifes, db_competitors, exit_processor_sla_margin) + {:ok, processor} = Core.init(db_exits, db_ifes, db_competitors, exit_processor_sla_seconds) {:ok, _} = :timer.send_interval(metrics_collection_interval, self(), :send_metrics) _ = Logger.info("Initializing with: #{inspect(processor)}") diff --git a/apps/omg_watcher/lib/omg_watcher/exit_processor/core.ex b/apps/omg_watcher/lib/omg_watcher/exit_processor/core.ex index 129e4cabae..eceb9b0de6 100644 --- a/apps/omg_watcher/lib/omg_watcher/exit_processor/core.ex +++ b/apps/omg_watcher/lib/omg_watcher/exit_processor/core.ex @@ -44,7 +44,7 @@ defmodule OMG.Watcher.ExitProcessor.Core do use OMG.Utils.LoggerExt - @default_sla_margin 10 + @default_sla_seconds 10 @zero_address OMG.Eth.zero_address() @max_inputs Transaction.Payment.max_inputs() @@ -68,10 +68,10 @@ defmodule OMG.Watcher.ExitProcessor.Core do @type new_piggyback_event_t() :: new_piggyback_input_event_t() | new_piggyback_output_event_t() - defstruct [:sla_margin, exits: %{}, in_flight_exits: %{}, exit_ids: %{}, competitors: %{}] + defstruct [:sla_seconds, exits: %{}, in_flight_exits: %{}, exit_ids: %{}, competitors: %{}] @type t :: %__MODULE__{ - sla_margin: non_neg_integer(), + sla_seconds: non_neg_integer(), exits: %{Utxo.Position.t() => ExitInfo.t()}, in_flight_exits: %{Transaction.tx_hash() => InFlightExitInfo.t()}, # NOTE: maps only standard exit_ids to the natural keys of standard exits (input pointers/utxo_pos) @@ -101,9 +101,9 @@ defmodule OMG.Watcher.ExitProcessor.Core do db_exits :: [{{pos_integer, non_neg_integer, non_neg_integer}, map}], db_in_flight_exits :: [{Transaction.tx_hash(), InFlightExitInfo.t()}], db_competitors :: [{Transaction.tx_hash(), CompetitorInfo.t()}], - sla_margin :: non_neg_integer + sla_seconds :: non_neg_integer ) :: {:ok, t()} - def init(db_exits, db_in_flight_exits, db_competitors, sla_margin \\ @default_sla_margin) do + def init(db_exits, db_in_flight_exits, db_competitors, sla_seconds \\ @default_sla_seconds) do exits = db_exits |> Enum.map(&ExitInfo.from_db_kv/1) |> Map.new() exit_ids = exits |> Enum.into(%{}, fn {utxo_pos, %ExitInfo{exit_id: exit_id}} -> {exit_id, utxo_pos} end) @@ -113,30 +113,30 @@ defmodule OMG.Watcher.ExitProcessor.Core do in_flight_exits: db_in_flight_exits |> Enum.map(&InFlightExitInfo.from_db_kv/1) |> Map.new(), exit_ids: exit_ids, competitors: db_competitors |> Enum.map(&CompetitorInfo.from_db_kv/1) |> Map.new(), - sla_margin: sla_margin + sla_seconds: sla_seconds }} end @doc """ - Use to check if the settings regarding the `:exit_processor_sla_margin` config of `:omg_watcher` are OK. + Use to check if the settings regarding the `:exit_processor_sla_seconds` config of `:omg_watcher` are OK. Since there are combinations of our configuration that may lead to a dangerous setup of the Watcher - (in particular - muting the reports of unchallenged_exits), we're enforcing that the `exit_processor_sla_margin` + (in particular - muting the reports of unchallenged_exits), we're enforcing that the `exit_processor_sla_seconds` be not larger than `min_exit_period`. """ - @spec check_sla_margin(pos_integer(), boolean(), pos_integer(), pos_integer()) :: :ok | {:error, :sla_margin_too_big} - def check_sla_margin(sla_margin, sla_margin_forced, min_exit_period_seconds, ethereum_block_time_seconds) + @spec check_sla_seconds(pos_integer(), boolean(), pos_integer()) :: :ok | {:error, :sla_margin_too_big} + def check_sla_seconds(sla_seconds, sla_margin_forced, min_exit_period_seconds) - def check_sla_margin(sla_margin, true, min_exit_period_seconds, ethereum_block_time_seconds) do + def check_sla_seconds(sla_seconds, true, min_exit_period_seconds) do _ = - if !sla_margin_safe?(sla_margin, min_exit_period_seconds, ethereum_block_time_seconds), - do: Logger.warn("Allowing unsafe sla margin of #{sla_margin} blocks") + if !sla_seconds_safe?(sla_seconds, min_exit_period_seconds), + do: Logger.warn("Allowing unsafe sla margin of #{sla_seconds} seconds") :ok end - def check_sla_margin(sla_margin, false, min_exit_period_seconds, ethereum_block_time_seconds) do - if sla_margin_safe?(sla_margin, min_exit_period_seconds, ethereum_block_time_seconds), + def check_sla_seconds(sla_seconds, false, min_exit_period_seconds) do + if sla_seconds_safe?(sla_seconds, min_exit_period_seconds), do: :ok, else: {:error, :sla_margin_too_big} end @@ -587,6 +587,6 @@ defmodule OMG.Watcher.ExitProcessor.Core do address != @zero_address end - defp sla_margin_safe?(exit_processor_sla_margin, min_exit_period_seconds, ethereum_block_time_seconds), - do: exit_processor_sla_margin * ethereum_block_time_seconds < min_exit_period_seconds + defp sla_seconds_safe?(exit_processor_sla_seconds, min_exit_period_seconds), + do: exit_processor_sla_seconds < min_exit_period_seconds end diff --git a/apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex b/apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex index 6ebe2ef7ad..398901ebb4 100644 --- a/apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex +++ b/apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex @@ -67,7 +67,7 @@ defmodule OMG.Watcher.ExitProcessor.StandardExit do """ @spec get_invalid(Core.t(), %{Utxo.Position.t() => boolean}, pos_integer()) :: {%{Utxo.Position.t() => ExitInfo.t()}, %{Utxo.Position.t() => ExitInfo.t()}} - def get_invalid(%Core{sla_margin: sla_margin} = state, utxo_exists?, eth_height_now) do + def get_invalid(%Core{sla_seconds: sla_seconds} = state, utxo_exists?, eth_height_now) do active_exits = active_exits(state) invalid_exit_positions = @@ -79,10 +79,13 @@ defmodule OMG.Watcher.ExitProcessor.StandardExit do exits_invalid_by_ife = get_invalid_exits_based_on_ifes(active_exits, tx_appendix) invalid_exits = active_exits |> Map.take(invalid_exit_positions) |> Enum.concat(exits_invalid_by_ife) |> Enum.uniq() + ethereum_block_time_seconds = OMG.Eth.Configuration.ethereum_block_time_seconds() # get exits which are still invalid and after the SLA margin late_invalid_exits = invalid_exits - |> Enum.filter(fn {_, %ExitInfo{eth_height: eth_height}} -> eth_height + sla_margin <= eth_height_now end) + |> Enum.filter(fn {_, %ExitInfo{eth_height: eth_height}} -> + eth_height + sla_seconds / ethereum_block_time_seconds <= eth_height_now + end) {Map.new(invalid_exits), Map.new(late_invalid_exits)} end diff --git a/apps/omg_watcher/lib/omg_watcher/release_tasks/set_exit_processor_sla_margin.ex b/apps/omg_watcher/lib/omg_watcher/release_tasks/set_exit_processor_sla_margin.ex index a0c32ca97d..9737d24cb5 100644 --- a/apps/omg_watcher/lib/omg_watcher/release_tasks/set_exit_processor_sla_margin.ex +++ b/apps/omg_watcher/lib/omg_watcher/release_tasks/set_exit_processor_sla_margin.ex @@ -18,8 +18,8 @@ defmodule OMG.Watcher.ReleaseTasks.SetExitProcessorSLAMargin do require Logger @app :omg_watcher - @system_env_name_margin "EXIT_PROCESSOR_SLA_MARGIN" - @app_env_name_margin :exit_processor_sla_margin + @system_env_name_margin "EXIT_PROCESSOR_SLA_SECONDS" + @app_env_name_margin :exit_processor_sla_seconds @system_env_name_force "EXIT_PROCESSOR_SLA_MARGIN_FORCED" @app_env_name_force :exit_processor_sla_margin_forced @@ -33,13 +33,13 @@ defmodule OMG.Watcher.ReleaseTasks.SetExitProcessorSLAMargin do Config.Reader.merge(config, omg_watcher: [ - exit_processor_sla_margin: get_exit_processor_sla_margin(), + exit_processor_sla_seconds: get_exit_processor_sla_seconds(), exit_processor_sla_margin_forced: get_exit_processor_sla_forced() ] ) end - defp get_exit_processor_sla_margin() do + defp get_exit_processor_sla_seconds() do config_value = validate_int(get_env(@system_env_name_margin), Application.get_env(@app, @app_env_name_margin)) _ = Logger.info("CONFIGURATION: App: #{@app} Key: #{@system_env_name_margin} Value: #{inspect(config_value)}.") config_value diff --git a/apps/omg_watcher/lib/omg_watcher/sync_supervisor.ex b/apps/omg_watcher/lib/omg_watcher/sync_supervisor.ex index 52a63b0505..04a5cda691 100644 --- a/apps/omg_watcher/lib/omg_watcher/sync_supervisor.ex +++ b/apps/omg_watcher/lib/omg_watcher/sync_supervisor.ex @@ -45,7 +45,7 @@ defmodule OMG.Watcher.SyncSupervisor do defp children(args) do contract_deployment_height = Keyword.fetch!(args, :contract_deployment_height) - exit_processor_sla_margin = Configuration.exit_processor_sla_margin() + exit_processor_sla_seconds = Configuration.exit_processor_sla_seconds() exit_processor_sla_margin_forced = Configuration.exit_processor_sla_margin_forced() metrics_collection_interval = Configuration.metrics_collection_interval() finality_margin = Configuration.exit_finality_margin() @@ -59,7 +59,7 @@ defmodule OMG.Watcher.SyncSupervisor do [ {ExitProcessor, [ - exit_processor_sla_margin: exit_processor_sla_margin, + exit_processor_sla_seconds: exit_processor_sla_seconds, exit_processor_sla_margin_forced: exit_processor_sla_margin_forced, metrics_collection_interval: metrics_collection_interval, min_exit_period_seconds: min_exit_period_seconds, diff --git a/apps/omg_watcher/test/omg_watcher/exit_processor/core_test.exs b/apps/omg_watcher/test/omg_watcher/exit_processor/core_test.exs index fc7a4067ad..1bb0e5b69e 100644 --- a/apps/omg_watcher/test/omg_watcher/exit_processor/core_test.exs +++ b/apps/omg_watcher/test/omg_watcher/exit_processor/core_test.exs @@ -118,13 +118,13 @@ defmodule OMG.Watcher.ExitProcessor.CoreTest do describe "check_sla_margin/4" do test "allows only safe margins if not forcing" do - assert {:error, :sla_margin_too_big} = Core.check_sla_margin(10, false, 100, 15) - assert :ok = Core.check_sla_margin(10, false, 300, 15) + assert {:error, :sla_margin_too_big} = Core.check_sla_seconds(150, false, 100) + assert :ok = Core.check_sla_seconds(150, false, 300) end test "allows anything if forcing" do - capture_log(fn -> assert :ok = Core.check_sla_margin(10, true, 100, 15) end) - assert :ok = Core.check_sla_margin(10, true, 300, 15) + capture_log(fn -> assert :ok = Core.check_sla_seconds(150, true, 100) end) + assert :ok = Core.check_sla_seconds(150, true, 300) end end diff --git a/apps/omg_watcher/test/omg_watcher/integration/block_getter_test.exs b/apps/omg_watcher/test/omg_watcher/integration/block_getter_test.exs index 3961efe1f9..a14eb93687 100644 --- a/apps/omg_watcher/test/omg_watcher/integration/block_getter_test.exs +++ b/apps/omg_watcher/test/omg_watcher/integration/block_getter_test.exs @@ -183,7 +183,7 @@ defmodule OMG.Watcher.Integration.BlockGetterTest do end @tag fixtures: [:in_beam_watcher, :stable_alice, :mix_based_child_chain, :token, :stable_alice_deposits, :test_server] - test "transaction which is spending an exiting output before the `sla_margin` causes an invalid_exit event only", + test "transaction which is spending an exiting output before the `sla_seconds` causes an invalid_exit event only", %{stable_alice: alice, stable_alice_deposits: {deposit_blknum, _}, test_server: context} do tx = OMG.TestHelper.create_encoded([{deposit_blknum, 0, 0, alice}], @eth, [{alice, 9}]) %{"blknum" => exit_blknum} = WatcherHelper.submit(tx) @@ -223,14 +223,14 @@ defmodule OMG.Watcher.Integration.BlockGetterTest do # Here we're manually submitting invalid block to the root chain # NOTE: this **must** come after `start_exit` is mined (see just above) but still not later than - # `sla_margin` after exit start, hence the `config/test.exs` entry for the margin is rather high + # `sla_seconds` after exit start, hence the `config/test.exs` entry for the margin is rather high {:ok, _} = Eth.submit_block(bad_block_hash, 2, 1) IntegrationTest.wait_for_byzantine_events([%Event.InvalidExit{}.name], @timeout) end @tag fixtures: [:in_beam_watcher, :stable_alice, :mix_based_child_chain, :token, :stable_alice_deposits, :test_server] - test "transaction which is spending an exiting output after the `sla_margin` causes an unchallenged_exit event", + test "transaction which is spending an exiting output after the `sla_seconds` causes an unchallenged_exit event", %{stable_alice: alice, stable_alice_deposits: {deposit_blknum, _}, test_server: context} do tx = OMG.TestHelper.create_encoded([{deposit_blknum, 0, 0, alice}], @eth, [{alice, 9}]) %{"blknum" => exit_blknum} = WatcherHelper.submit(tx) @@ -259,7 +259,7 @@ defmodule OMG.Watcher.Integration.BlockGetterTest do "utxo_pos" => utxo_pos } = WatcherHelper.get_exit_data(exit_blknum, 0, 0) - {:ok, %{"status" => "0x1", "blockNumber" => eth_height}} = + {:ok, %{"status" => "0x1"}} = RootChainHelper.start_exit( utxo_pos, txbytes, @@ -268,8 +268,9 @@ defmodule OMG.Watcher.Integration.BlockGetterTest do ) |> DevHelper.transact_sync!() - exit_processor_sla_margin = Application.fetch_env!(:omg_watcher, :exit_processor_sla_margin) - DevHelper.wait_for_root_chain_block(eth_height + exit_processor_sla_margin, @timeout) + exit_processor_sla_seconds = Application.fetch_env!(:omg_watcher, :exit_processor_sla_seconds) + exit_processor_sla_ms = exit_processor_sla_seconds * 1000 + Process.sleep(exit_processor_sla_ms) # checking if both machines and humans learn about the byzantine condition assert WatcherHelper.capture_log(fn -> diff --git a/apps/omg_watcher/test/omg_watcher/integration/invalid_exit_test.exs b/apps/omg_watcher/test/omg_watcher/integration/invalid_exit_test.exs index b13e2ee53f..3b4efdf190 100644 --- a/apps/omg_watcher/test/omg_watcher/integration/invalid_exit_test.exs +++ b/apps/omg_watcher/test/omg_watcher/integration/invalid_exit_test.exs @@ -96,7 +96,7 @@ defmodule OMG.Watcher.Integration.InvalidExitTest do end @tag fixtures: [:in_beam_watcher, :stable_alice, :mix_based_child_chain, :token, :stable_alice_deposits] - test "invalid_exit without a challenge raises unchallenged_exit after sla_margin had passed, can be challenged", + test "invalid_exit without a challenge raises unchallenged_exit after sla_seconds had passed, can be challenged", %{stable_alice: alice, stable_alice_deposits: {deposit_blknum, _}} do %{"blknum" => first_tx_blknum} = OMG.TestHelper.create_encoded([{deposit_blknum, 0, 0, alice}], @eth, [{alice, 9}]) |> WatcherHelper.submit() @@ -109,14 +109,16 @@ defmodule OMG.Watcher.Integration.InvalidExitTest do %{"txbytes" => txbytes, "proof" => proof, "utxo_pos" => tx_utxo_pos} = WatcherHelper.get_exit_data(first_tx_blknum, 0, 0) - {:ok, %{"status" => "0x1", "blockNumber" => eth_height}} = + {:ok, %{"status" => "0x1"}} = RootChainHelper.start_exit(tx_utxo_pos, txbytes, proof, alice.addr) |> DevHelper.transact_sync!() IntegrationTest.wait_for_byzantine_events([%Event.InvalidExit{}.name], @timeout) - exit_processor_sla_margin = Application.fetch_env!(:omg_watcher, :exit_processor_sla_margin) - DevHelper.wait_for_root_chain_block(eth_height + exit_processor_sla_margin, @timeout) + exit_processor_sla_seconds = Application.fetch_env!(:omg_watcher, :exit_processor_sla_seconds) + exit_processor_sla_ms = exit_processor_sla_seconds * 1000 + # after exit, the event fetch time + waiting for sla_margin goes beyond the required time + Process.sleep(exit_processor_sla_ms) IntegrationTest.wait_for_byzantine_events([%Event.InvalidExit{}.name, %Event.UnchallengedExit{}.name], @timeout) # after the notification has been received, a challenged is composed and sent, regardless of it being late diff --git a/apps/omg_watcher/test/omg_watcher/release_tasks/set_exit_processor_sla_margin_test.exs b/apps/omg_watcher/test/omg_watcher/release_tasks/set_exit_processor_sla_margin_test.exs index 5c98e76c4d..4ebbcb4557 100644 --- a/apps/omg_watcher/test/omg_watcher/release_tasks/set_exit_processor_sla_margin_test.exs +++ b/apps/omg_watcher/test/omg_watcher/release_tasks/set_exit_processor_sla_margin_test.exs @@ -19,37 +19,37 @@ defmodule OMG.Watcher.ReleaseTasks.SetExitProcessorSLAMarginTest do @app :omg_watcher test "if environment variables get applied in the configuration" do - :ok = System.put_env("EXIT_PROCESSOR_SLA_MARGIN", "15") + :ok = System.put_env("EXIT_PROCESSOR_SLA_SECONDS", "15") :ok = System.put_env("EXIT_PROCESSOR_SLA_MARGIN_FORCED", "TRUE") config = SetExitProcessorSLAMargin.load([], []) - exit_processor_sla_margin = config |> Keyword.fetch!(@app) |> Keyword.fetch!(:exit_processor_sla_margin) + exit_processor_sla_seconds = config |> Keyword.fetch!(@app) |> Keyword.fetch!(:exit_processor_sla_seconds) exit_processor_sla_margin_forced = config |> Keyword.fetch!(@app) |> Keyword.fetch!(:exit_processor_sla_margin_forced) - assert exit_processor_sla_margin == 15 + assert exit_processor_sla_seconds == 15 assert exit_processor_sla_margin_forced == true end test "if default configuration is used when there's no environment variables" do - :ok = System.delete_env("EXIT_PROCESSOR_SLA_MARGIN") + :ok = System.delete_env("EXIT_PROCESSOR_SLA_SECONDS") :ok = System.delete_env("EXIT_PROCESSOR_SLA_MARGIN_FORCED") config = SetExitProcessorSLAMargin.load([], []) - exit_processor_sla_margin = config |> Keyword.fetch!(@app) |> Keyword.fetch!(:exit_processor_sla_margin) + exit_processor_sla_seconds = config |> Keyword.fetch!(@app) |> Keyword.fetch!(:exit_processor_sla_seconds) exit_processor_sla_margin_forced = config |> Keyword.fetch!(@app) |> Keyword.fetch!(:exit_processor_sla_margin_forced) - exit_processor_sla_margin_updated = Application.get_env(@app, :exit_processor_sla_margin) + exit_processor_sla_seconds_updated = Application.get_env(@app, :exit_processor_sla_seconds) exit_processor_sla_margin_forced_updated = Application.get_env(@app, :exit_processor_sla_margin_forced) - assert exit_processor_sla_margin == exit_processor_sla_margin_updated + assert exit_processor_sla_seconds == exit_processor_sla_seconds_updated assert exit_processor_sla_margin_forced == exit_processor_sla_margin_forced_updated end test "if exit is thrown when faulty margin configuration is used" do - :ok = System.put_env("EXIT_PROCESSOR_SLA_MARGIN", "15a") + :ok = System.put_env("EXIT_PROCESSOR_SLA_SECONDS", "15a") catch_exit(SetExitProcessorSLAMargin.load([], [])) - :ok = System.delete_env("EXIT_PROCESSOR_SLA_MARGIN") + :ok = System.delete_env("EXIT_PROCESSOR_SLA_SECONDS") end test "if exit is thrown when faulty margin force configuration is used" do diff --git a/apps/omg_watcher_rpc/priv/swagger/info_api_specs.yaml b/apps/omg_watcher_rpc/priv/swagger/info_api_specs.yaml index a6995afba9..3996478048 100644 --- a/apps/omg_watcher_rpc/priv/swagger/info_api_specs.yaml +++ b/apps/omg_watcher_rpc/priv/swagger/info_api_specs.yaml @@ -232,7 +232,7 @@ paths: format: int256 contract_semver: type: string - exit_processor_sla_margin: + exit_processor_sla_seconds: type: integer format: int256 network: @@ -241,7 +241,7 @@ paths: data: - deposit_finality_margin: 10 contract_semver: 1.0.0.1+a1s29s8 - exit_processor_sla_margin: 5520 + exit_processor_sla_seconds: 5520 network: RINKEBY '500': description: Returns an internal server error diff --git a/apps/omg_watcher_rpc/priv/swagger/info_api_specs/configuration/configuration_schema.yml b/apps/omg_watcher_rpc/priv/swagger/info_api_specs/configuration/configuration_schema.yml index a58c232b09..702aa3ed0e 100644 --- a/apps/omg_watcher_rpc/priv/swagger/info_api_specs/configuration/configuration_schema.yml +++ b/apps/omg_watcher_rpc/priv/swagger/info_api_specs/configuration/configuration_schema.yml @@ -7,6 +7,6 @@ components: type: string network: type: string - exit_processor_sla_margin: + exit_processor_sla_seconds: type: integer format: int256 \ No newline at end of file diff --git a/apps/omg_watcher_rpc/priv/swagger/info_api_specs/configuration/response_schemas.yaml b/apps/omg_watcher_rpc/priv/swagger/info_api_specs/configuration/response_schemas.yaml index ae84108a80..ab5ebc3a01 100644 --- a/apps/omg_watcher_rpc/priv/swagger/info_api_specs/configuration/response_schemas.yaml +++ b/apps/omg_watcher_rpc/priv/swagger/info_api_specs/configuration/response_schemas.yaml @@ -12,5 +12,5 @@ ConfigurationResponseSchema: - deposit_finality_margin: 10 contract_semver: "1.0.0.1+a1s29s8" - exit_processor_sla_margin: 5520 + exit_processor_sla_seconds: 82800 network: "RINKEBY" diff --git a/apps/omg_watcher_rpc/priv/swagger/info_api_specs/configuration/schemas.yaml b/apps/omg_watcher_rpc/priv/swagger/info_api_specs/configuration/schemas.yaml index 62d50a372e..eaf6b21566 100644 --- a/apps/omg_watcher_rpc/priv/swagger/info_api_specs/configuration/schemas.yaml +++ b/apps/omg_watcher_rpc/priv/swagger/info_api_specs/configuration/schemas.yaml @@ -7,7 +7,7 @@ ConfigurationSchema: contract_semver: type: string - exit_processor_sla_margin: + exit_processor_sla_seconds: type: integer format: int256 network: diff --git a/apps/omg_watcher_rpc/priv/swagger/security_critical_api_specs.yaml b/apps/omg_watcher_rpc/priv/swagger/security_critical_api_specs.yaml index 70dc6f8e9b..916f5b6b02 100644 --- a/apps/omg_watcher_rpc/priv/swagger/security_critical_api_specs.yaml +++ b/apps/omg_watcher_rpc/priv/swagger/security_critical_api_specs.yaml @@ -233,7 +233,7 @@ paths: format: int256 contract_semver: type: string - exit_processor_sla_margin: + exit_processor_sla_seconds: type: integer format: int256 network: diff --git a/apps/omg_watcher_rpc/priv/swagger/security_critical_api_specs/configuration/configuration_schema.yml b/apps/omg_watcher_rpc/priv/swagger/security_critical_api_specs/configuration/configuration_schema.yml index be4e0508ce..bf1419fe75 100644 --- a/apps/omg_watcher_rpc/priv/swagger/security_critical_api_specs/configuration/configuration_schema.yml +++ b/apps/omg_watcher_rpc/priv/swagger/security_critical_api_specs/configuration/configuration_schema.yml @@ -4,7 +4,7 @@ components: type: integer contract_semver: type: string - exit_processor_sla_margin: + exit_processor_sla_seconds: type: integer network: type: string diff --git a/apps/omg_watcher_rpc/priv/swagger/security_critical_api_specs/configuration/schemas.yaml b/apps/omg_watcher_rpc/priv/swagger/security_critical_api_specs/configuration/schemas.yaml index 62d50a372e..eaf6b21566 100644 --- a/apps/omg_watcher_rpc/priv/swagger/security_critical_api_specs/configuration/schemas.yaml +++ b/apps/omg_watcher_rpc/priv/swagger/security_critical_api_specs/configuration/schemas.yaml @@ -7,7 +7,7 @@ ConfigurationSchema: contract_semver: type: string - exit_processor_sla_margin: + exit_processor_sla_seconds: type: integer format: int256 network: diff --git a/bin/variables b/bin/variables index 5e23c036c5..15ab0e4aba 100755 --- a/bin/variables +++ b/bin/variables @@ -10,7 +10,7 @@ export CHILD_CHAIN_URL=http://127.0.0.1:9656 export ETHEREUM_HEIGHT_CHECK_INTERVAL_MS=800 export ETHEREUM_EVENTS_CHECK_INTERVAL_MS=800 export ETHEREUM_STALLED_SYNC_THRESHOLD_MS=20000 -export EXIT_PROCESSOR_SLA_MARGIN=5520 +export EXIT_PROCESSOR_SLA_SECONDS=5520 export FEE_CLAIMER_ADDRESS=0x3b9f4c1dd26e0be593373b1d36cee2008cbeb837 export FEE_ADAPTER=file export FEE_SPECS_FILE_PATH=./priv/dev-artifacts/fee_specs.dev.json diff --git a/bin/variables_test_barebone b/bin/variables_test_barebone index 25c1392a5f..d410c40ed7 100755 --- a/bin/variables_test_barebone +++ b/bin/variables_test_barebone @@ -4,7 +4,7 @@ # setup of our services # test_barebone_release taylored values. Compare also with priv/cabbage/docker-compose-cabbage.yml -export EXIT_PROCESSOR_SLA_MARGIN=30 +export EXIT_PROCESSOR_SLA_SECONDS=30 # the rest stays same as bin/variables export APP_ENV=local-development diff --git a/config/config.exs b/config/config.exs index 4a65211c78..edf834ff82 100644 --- a/config/config.exs +++ b/config/config.exs @@ -152,9 +152,9 @@ config :os_mon, config :omg_watcher, child_chain_url: "http://localhost:9656" config :omg_watcher, - # 23 hours worth of blocks - this is how long the child chain server has to block spends from exiting utxos - exit_processor_sla_margin: 23 * 60 * 4, - # this means we don't want the `sla_margin` above be larger than the `min_exit_period` + # 23 hours - this is how long the child chain server has to block spends from exiting utxos + exit_processor_sla_seconds: 23 * 60 * 60, + # this means we don't want the `sla_seconds` above be larger than the `min_exit_period` exit_processor_sla_margin_forced: false, maximum_block_withholding_time_ms: 15 * 60 * 60 * 1000, block_getter_loops_interval_ms: 500, diff --git a/config/dev.exs b/config/dev.exs index 081fb5e2c4..696cb941fd 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -44,9 +44,9 @@ config :omg_watcher_info, OMG.WatcherInfo.Tracer, config :omg_watcher, environment: :dev config :omg_watcher, - # 1 hour of Ethereum blocks - exit_processor_sla_margin: 60 * 4, - # this means we allow the `sla_margin` above be larger than the `min_exit_period` + # 1 hour + exit_processor_sla_seconds: 60 * 60, + # this means we allow the `sla_seconds` above be larger than the `min_exit_period` exit_processor_sla_margin_forced: true config :omg_watcher, OMG.Watcher.Tracer, diff --git a/config/test.exs b/config/test.exs index fa9902478e..dab08bbce7 100644 --- a/config/test.exs +++ b/config/test.exs @@ -138,7 +138,7 @@ config :omg_watcher, block_getter_loops_interval_ms: 50, # NOTE `exit_processor_sla_margin` can't be made shorter. At 3 it sometimes # causes :unchallenged_exit because `geth --dev` is too fast - exit_processor_sla_margin: 5, + exit_processor_sla_seconds: 75, # this means we allow the `sla_margin` above be larger than the `min_exit_period` exit_processor_sla_margin_forced: true, # NOTE: `maximum_block_withholding_time_ms` must be here - one of our integration tests diff --git a/docker-compose-watcher.yml b/docker-compose-watcher.yml index 7e7496420b..03ea455c74 100644 --- a/docker-compose-watcher.yml +++ b/docker-compose-watcher.yml @@ -36,7 +36,7 @@ services: - ETHEREUM_EVENTS_CHECK_INTERVAL_MS=8000 - ETHEREUM_STALLED_SYNC_THRESHOLD_MS=300000 - ETHEREUM_BLOCK_TIME_SECONDS=15 - - EXIT_PROCESSOR_SLA_MARGIN=5520 + - EXIT_PROCESSOR_SLA_SECONDS=82800 - EXIT_PROCESSOR_SLA_MARGIN_FORCED=TRUE - LOGGER_BACKEND=console - DD_HOSTNAME=datadog @@ -69,7 +69,7 @@ services: - ETHEREUM_EVENTS_CHECK_INTERVAL_MS=8000 - ETHEREUM_STALLED_SYNC_THRESHOLD_MS=300000 - ETHEREUM_BLOCK_TIME_SECONDS=15 - - EXIT_PROCESSOR_SLA_MARGIN=5520 + - EXIT_PROCESSOR_SLA_SECONDS=82800 - EXIT_PROCESSOR_SLA_MARGIN_FORCED=TRUE - LOGGER_BACKEND=console - DD_HOSTNAME=datadog diff --git a/docker-compose.yml b/docker-compose.yml index 4a5ae849dc..c0d7c705cd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -118,7 +118,7 @@ services: - ETHEREUM_EVENTS_CHECK_INTERVAL_MS=800 - ETHEREUM_STALLED_SYNC_THRESHOLD_MS=20000 - ETHEREUM_BLOCK_TIME_SECONDS=1 - - EXIT_PROCESSOR_SLA_MARGIN=5520 + - EXIT_PROCESSOR_SLA_SECONDS=5520 - EXIT_PROCESSOR_SLA_MARGIN_FORCED=TRUE - LOGGER_BACKEND=console - RELEASE_COOKIE=development @@ -158,7 +158,7 @@ services: - DB_PATH=/data - ETHEREUM_EVENTS_CHECK_INTERVAL_MS=800 - ETHEREUM_BLOCK_TIME_SECONDS=1 - - EXIT_PROCESSOR_SLA_MARGIN=5520 + - EXIT_PROCESSOR_SLA_SECONDS=5520 - EXIT_PROCESSOR_SLA_MARGIN_FORCED=TRUE - LOGGER_BACKEND=console - RELEASE_COOKIE=development diff --git a/docs/deployment_configuration.md b/docs/deployment_configuration.md index 823377c5e5..9a2038bff9 100644 --- a/docs/deployment_configuration.md +++ b/docs/deployment_configuration.md @@ -33,7 +33,7 @@ ***Watcher and Watcher Info only*** - "CHILD_CHAIN_URL" - Location of the Child Chain API. *mandatory* -- "EXIT_PROCESSOR_SLA_MARGIN" - Number of Ethereum blocks since start of an invalid exit, before `unchallenged_exit` is reported to prompt to mass exit. Must be smaller than "MIN_EXIT_PERIOD_SECONDS", unless "EXIT_PROCESSOR_SLA_MARGIN_FORCED=TRUE". +- "EXIT_PROCESSOR_SLA_SECONDS" - Seconds since start of an invalid exit, before `unchallenged_exit` is reported to prompt to mass exit. Must be smaller than "MIN_EXIT_PERIOD_SECONDS", unless "EXIT_PROCESSOR_SLA_MARGIN_FORCED=TRUE". ***Watcher Info only*** diff --git a/docs/details.md b/docs/details.md index fbe591508f..97f259b9fb 100644 --- a/docs/details.md +++ b/docs/details.md @@ -214,14 +214,14 @@ Options of the fee adapter, depends on adapter ## Watcher configuration - `:omg_watcher` app -* **`exit_processor_sla_margin`** - the margin to define the notion of a "late", invalid exit. +* **`exit_processor_sla_seconds`** - the margin to define the notion of a "late", invalid exit. After this margin passes, every invalid exit is deemed a critical failure of the child chain (`unchallenged_exit`). Such event will prompt a mass exit and stop processing new blocks. See [exit validation documentation](docs/exit_validation.md) for details. Cannot be larger than `min_exit_period_seconds` because otherwise it leads to a dangerous setup of the Watcher (in particular - muting the reports of unchallenged_exits). -Override using the `EXIT_PROCESSOR_SLA_MARGIN` system environment variable. +Override using the `EXIT_PROCESSOR_SLA_SECONDS` system environment variable. -* **`exit_processor_sla_margin_forced`** - if set to `true`, will allow one to set a `exit_processor_sla_margin` that is larger than the `min_exit_period_seconds` of the child chain we're running for. +* **`exit_processor_sla_margin_forced`** - if set to `true`, will allow one to set a `exit_processor_sla_seconds` that is larger than the `min_exit_period_seconds` of the child chain we're running for. Set to `true` only when you know what you are doing. Defaults to `false`, override using the `EXIT_PROCESSOR_SLA_MARGIN_FORCED` system environment variable. diff --git a/docs/exit_validation.md b/docs/exit_validation.md index 550fde2a0c..20a2509382 100644 --- a/docs/exit_validation.md +++ b/docs/exit_validation.md @@ -10,9 +10,9 @@ This document describes the exit validation (processing) done by the Watcher in * **unchallenged exit tolerance** - a Watcher's tolerance to an invalid exit not having a challenge for a long time since its start. - **NOTE**: in practice, violation of the child chain exit recognition SLA and violation of the unchallenged exit tolerance are similar. The correct reaction to both is a prompt to mass exit and a challenge of the invalid exit. - Because of this, only `sla_margin` is used as a configurable setting on the Watcher, covering for both conditions. -* **`sla_margin`** - margin of the child chain exit recognition SLA (in Ethereum blocks). -This is a number of blocks after the start of an exit (or piggyback), during which a Child Chain Server still might include a transaction invalidating a previously valid exit, without violating the child chain exit recognition SLA. + Because of this, only `sla_seconds` is used as a configurable setting on the Watcher, covering for both conditions. +* **`sla_seconds`** - margin of the child chain exit recognition SLA (in seconds). +This is the time in seconds after the start of an exit (or piggyback), during which a Child Chain Server still might include a transaction invalidating a previously valid exit, without violating the child chain exit recognition SLA. Similarly, this is a number of blocks after the start of an exit (or piggyback), during which the Watcher will not report [unchallenged exits](#unchallenged_exit-condition). ## Notes on the Child Chain Server @@ -31,34 +31,34 @@ The child chain becomes insolvent if any invalid exit gets finalized, which lead - **NOTE**: This immediacy is limited because the server must process deposits before exits and deposits _must_ wait for finality on the root chain. There are scenarios, when a race condition/reorg on the root chain might make the Child Chain Server prohibit spending of a particular UTXO **late**, regardless of the immediacy mentioned above. -This is acceptable as long as the delay doesn't exceed the `sla_margin`. +This is acceptable as long as the delay doesn't exceed the `sla_seconds`. ## Watcher -### Choice of the `sla_margin` setting value +### Choice of the `sla_seconds` setting value -`sla_margin` is a set on the Watcher (via [`exit_processor_sla_margin`/`EXIT_PROCESSOR_SLA_MARGIN`](./details.md#configuration-parameters)), which needs to be determined correctly for various deployments and environments. +`sla_seconds` is a set on the Watcher (via [`exit_processor_sla_seconds`/`EXIT_PROCESSOR_SLA_SECONDS`](./details.md#configuration-parameters)), which needs to be determined correctly for various deployments and environments. It should reflect the exit period and the intended usage patterns and security requirements of the environment. -`sla margin` should be large enough: +`sla_seconds` should be large enough: - for the Child Chain Server (that runs the child chain the Watcher validates), to recognize exiting UTXOs, to prevent an invalidating transaction going through - for anyone concerned with challenging to challenge invalid exits. -`sla_margin` should be tight enough: +`sla_seconds` should be tight enough: - to allow a successful mass exit in case of an [`unchallenged_exit` condition](#unchallenged_exit-condition). -**NOTE** The `sla_margin` is usually much larger and unrelated to any margins that the Child Chain Server may wait before recognizing exits. -So, if everything is functioning correctly, the spending of exiting UTXOs is blocked _much_ earlier than the `sla_margin`. -In other words, `sla_margin` is usually picked to be ample (to avoid spurious mass exit prompts), and this doesn't impact the immediacy of the Child Chain Server's reaction to exits. +**NOTE** The `sla_seconds` is usually much larger and unrelated to any margins that the Child Chain Server may wait before recognizing exits. +So, if everything is functioning correctly, the spending of exiting UTXOs is blocked _much_ earlier than the `sla_seconds`. +In other words, `sla_seconds` is usually picked to be ample (to avoid spurious mass exit prompts), and this doesn't impact the immediacy of the Child Chain Server's reaction to exits. ### Standard Exits #### Actions that the Watcher should prompt 1. If an exit is known to be invalid it should be challenged. The Watcher prompts by an `:invalid_exit` event. -2. If an exit is invalidated with a transaction submitted *before* `start_eth_height + sla_margin` it must be challenged (`:invalid_exit` event) -3. If an exit is invalidated with a transaction submitted *after* `start_eth_height + sla_margin` it must be challenged **AND** the Watcher prompts to exit. The Watcher prompts by both `:invalid_exit` and `:unchallenged_exit` events. Users should not deposit or spend -4. If an exit is invalid and remains unchallenged *after* `start_eth_height + sla_margin` it must be challenged **AND** the Watcher prompts to exit. The Watcher prompts by both `:invalid_exit` and `:unchallenged_exit` events. Users should not deposit or spend. +2. If an exit is invalidated with a transaction submitted *before* `sla_seconds` it must be challenged (`:invalid_exit` event) +3. If an exit is invalidated with a transaction submitted *after* `sla_seconds` it must be challenged **AND** the Watcher prompts to exit. The Watcher prompts by both `:invalid_exit` and `:unchallenged_exit` events. Users should not deposit or spend +4. If an exit is invalid and remains unchallenged *after* `sla_seconds` it must be challenged **AND** the Watcher prompts to exit. The Watcher prompts by both `:invalid_exit` and `:unchallenged_exit` events. Users should not deposit or spend. 5. The `unchallenged_exit` event also covers the case where the invalid exit finalizes, causing an insolvent chain until [issue #1318 is solved](github.com/omisego/elixir-omg/issues/1318). More on the [`unchallenged_exit` condition](#unchallenged_exit-condition). @@ -75,7 +75,7 @@ Assumptions: 3. For every open exit request run `OMG.State.utxo_exists?` method * if `true` -> noop, * if `false` -> emit `:invalid_exit` event prompts to challenge - * if `false` and exit is older than `sla_margin` -> emit additionally an `:unchallenged_exit` event which promts mass exit + * if `false` and exit is older than `sla_seconds` -> emit additionally an `:unchallenged_exit` event which promts mass exit 4. Spend UTXOs in `OMG.State` on exit finalization * if the spent UTXO is present at the moment, forget the exit from validation - this is a valid finalization * if the spent UTXO is missing, keep on emitting `:unchallenged_exit` (until [issue #1318 is solved](github.com/omisego/elixir-omg/issues/1318)) - this is an invalid finalization. @@ -127,5 +127,5 @@ An alternative is to always check the current status of every exit, before takin All the above rules will apply analogically to in-flight exits. See [MoreVP](./morevp.md) for specs and introduction to in-flight exits. Invalid attempts to do an in-flight related action prompt challenges. -Absence of challenges within the `sla_margin`, as well as invalid finalization, should result in client prompting to mass exit (to be implemented in [issue #1275](github.com/omisego/elixir-omg/issues/1275)). +Absence of challenges within the `sla_seconds`, as well as invalid finalization, should result in client prompting to mass exit (to be implemented in [issue #1275](github.com/omisego/elixir-omg/issues/1275)). `OMG.State` is modified on IFE finalization. diff --git a/priv/cabbage/apps/itest/lib/api_model/watcher_security_critical_configuration.ex b/priv/cabbage/apps/itest/lib/api_model/watcher_security_critical_configuration.ex index a059f439ab..f834fe06da 100644 --- a/priv/cabbage/apps/itest/lib/api_model/watcher_security_critical_configuration.ex +++ b/priv/cabbage/apps/itest/lib/api_model/watcher_security_critical_configuration.ex @@ -15,13 +15,13 @@ defmodule Itest.ApiModel.WatcherSecurityCriticalConfiguration do @moduledoc """ The purpose of this module is to represent a specific API response as a struct and validates it's response """ - defstruct [:contract_semver, :deposit_finality_margin, :network, :exit_processor_sla_margin] + defstruct [:contract_semver, :deposit_finality_margin, :network, :exit_processor_sla_seconds] @type t() :: %__MODULE__{ deposit_finality_margin: non_neg_integer(), contract_semver: binary(), network: binary(), - exit_processor_sla_margin: non_neg_integer() + exit_processor_sla_seconds: non_neg_integer() } def to_struct(attrs) do @@ -42,7 +42,7 @@ defmodule Itest.ApiModel.WatcherSecurityCriticalConfiguration do defp is_valid(struct) do is_integer(struct.deposit_finality_margin) && is_binary(struct.contract_semver) && - is_integer(struct.exit_processor_sla_margin) && + is_integer(struct.exit_processor_sla_seconds) && is_binary(struct.network) end end diff --git a/priv/cabbage/apps/itest/test/itest/configuration_api_test.exs b/priv/cabbage/apps/itest/test/itest/configuration_api_test.exs index 70581b7c01..cae73ca91b 100644 --- a/priv/cabbage/apps/itest/test/itest/configuration_api_test.exs +++ b/priv/cabbage/apps/itest/test/itest/configuration_api_test.exs @@ -32,7 +32,7 @@ defmodule ConfigurationRetrievalTests do "contract_semver" => contract_semver, "deposit_finality_margin" => 10, "network" => "LOCALCHAIN", - "exit_processor_sla_margin" => 30 + "exit_processor_sla_seconds" => 30 }, child_chain_assert_response: %{ "contract_semver" => contract_semver, diff --git a/priv/cabbage/docker-compose-cabbage.yml b/priv/cabbage/docker-compose-cabbage.yml index d692c22c5a..d51274beb7 100644 --- a/priv/cabbage/docker-compose-cabbage.yml +++ b/priv/cabbage/docker-compose-cabbage.yml @@ -4,7 +4,7 @@ version: "2.3" services: watcher: environment: - - EXIT_PROCESSOR_SLA_MARGIN=30 + - EXIT_PROCESSOR_SLA_SECONDS=30 watcher_info: environment: - - EXIT_PROCESSOR_SLA_MARGIN=30 + - EXIT_PROCESSOR_SLA_SECONDS=30 From 617427124e14f5e6871a1ae3180fd2044c30d67e Mon Sep 17 00:00:00 2001 From: souradeep-das Date: Tue, 28 Apr 2020 04:22:33 +0530 Subject: [PATCH 02/28] remove eth-block-time and credo fix --- .../test/omg_status/monitor/memory_monitor_test.exs | 2 +- apps/omg_watcher/lib/omg_watcher/exit_processor.ex | 4 +--- apps/omg_watcher/lib/omg_watcher/sync_supervisor.ex | 4 +--- config/dev.exs | 2 +- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/apps/omg_status/test/omg_status/monitor/memory_monitor_test.exs b/apps/omg_status/test/omg_status/monitor/memory_monitor_test.exs index 83ee117ec1..e6c1938a60 100644 --- a/apps/omg_status/test/omg_status/monitor/memory_monitor_test.exs +++ b/apps/omg_status/test/omg_status/monitor/memory_monitor_test.exs @@ -58,7 +58,7 @@ defmodule OMG.Status.Monitor.MemoryMonitorTest do assert_receive :got_clear_alarm end - test "works with :buffered_memory and :cached_memory values are not provided", context do + test "works with :buffered_memory and :cached_memory values are not provided" do set_memsup(total_memory: 1000, free_memory: 100) assert_receive :got_raise_alarm end diff --git a/apps/omg_watcher/lib/omg_watcher/exit_processor.ex b/apps/omg_watcher/lib/omg_watcher/exit_processor.ex index dcb8e4c8f0..410b86c950 100644 --- a/apps/omg_watcher/lib/omg_watcher/exit_processor.ex +++ b/apps/omg_watcher/lib/omg_watcher/exit_processor.ex @@ -252,15 +252,13 @@ defmodule OMG.Watcher.ExitProcessor do - `exit_processor_sla_margin_forced`: if `true` will override the check of `exit_processor_sla_seconds` against `min_exit_period_seconds` - `min_exit_period_seconds`: should reflect the value of this parameter for the specific child chain watched, - - `ethereum_block_time_seconds`: relate blocks to seconds - `metrics_collection_interval`: how often are the metrics sent to `telemetry` (in milliseconds) """ def init( exit_processor_sla_seconds: exit_processor_sla_seconds, exit_processor_sla_margin_forced: exit_processor_sla_margin_forced, metrics_collection_interval: metrics_collection_interval, - min_exit_period_seconds: min_exit_period_seconds, - ethereum_block_time_seconds: ethereum_block_time_seconds + min_exit_period_seconds: min_exit_period_seconds ) do {:ok, db_exits} = DB.exit_infos() {:ok, db_ifes} = DB.in_flight_exits_info() diff --git a/apps/omg_watcher/lib/omg_watcher/sync_supervisor.ex b/apps/omg_watcher/lib/omg_watcher/sync_supervisor.ex index 04a5cda691..8471752d1b 100644 --- a/apps/omg_watcher/lib/omg_watcher/sync_supervisor.ex +++ b/apps/omg_watcher/lib/omg_watcher/sync_supervisor.ex @@ -53,7 +53,6 @@ defmodule OMG.Watcher.SyncSupervisor do ethereum_events_check_interval_ms = OMG.Configuration.ethereum_events_check_interval_ms() coordinator_eth_height_check_interval_ms = OMG.Configuration.coordinator_eth_height_check_interval_ms() min_exit_period_seconds = OMG.Eth.Configuration.min_exit_period_seconds() - ethereum_block_time_seconds = OMG.Eth.Configuration.ethereum_block_time_seconds() contracts = OMG.Eth.Configuration.contracts() [ @@ -62,8 +61,7 @@ defmodule OMG.Watcher.SyncSupervisor do exit_processor_sla_seconds: exit_processor_sla_seconds, exit_processor_sla_margin_forced: exit_processor_sla_margin_forced, metrics_collection_interval: metrics_collection_interval, - min_exit_period_seconds: min_exit_period_seconds, - ethereum_block_time_seconds: ethereum_block_time_seconds + min_exit_period_seconds: min_exit_period_seconds ]}, %{ id: OMG.Watcher.BlockGetter.Supervisor, diff --git a/config/dev.exs b/config/dev.exs index 696cb941fd..69f929b220 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -44,7 +44,7 @@ config :omg_watcher_info, OMG.WatcherInfo.Tracer, config :omg_watcher, environment: :dev config :omg_watcher, - # 1 hour + # 1 hour exit_processor_sla_seconds: 60 * 60, # this means we allow the `sla_seconds` above be larger than the `min_exit_period` exit_processor_sla_margin_forced: true From db4f1a226121a2651d98db97c73957127928c0a5 Mon Sep 17 00:00:00 2001 From: souradeep-das Date: Tue, 28 Apr 2020 05:21:36 +0530 Subject: [PATCH 03/28] update- change cabbage sla_sec --- .../omg_watcher/test/omg_watcher/exit_processor/core_test.exs | 2 +- priv/cabbage/docker-compose-cabbage.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/omg_watcher/test/omg_watcher/exit_processor/core_test.exs b/apps/omg_watcher/test/omg_watcher/exit_processor/core_test.exs index 1bb0e5b69e..e06ad4d618 100644 --- a/apps/omg_watcher/test/omg_watcher/exit_processor/core_test.exs +++ b/apps/omg_watcher/test/omg_watcher/exit_processor/core_test.exs @@ -116,7 +116,7 @@ defmodule OMG.Watcher.ExitProcessor.CoreTest do end end - describe "check_sla_margin/4" do + describe "check_sla_margin/3" do test "allows only safe margins if not forcing" do assert {:error, :sla_margin_too_big} = Core.check_sla_seconds(150, false, 100) assert :ok = Core.check_sla_seconds(150, false, 300) diff --git a/priv/cabbage/docker-compose-cabbage.yml b/priv/cabbage/docker-compose-cabbage.yml index d51274beb7..64b79217c9 100644 --- a/priv/cabbage/docker-compose-cabbage.yml +++ b/priv/cabbage/docker-compose-cabbage.yml @@ -4,7 +4,7 @@ version: "2.3" services: watcher: environment: - - EXIT_PROCESSOR_SLA_SECONDS=30 + - EXIT_PROCESSOR_SLA_SECONDS=450 watcher_info: environment: - - EXIT_PROCESSOR_SLA_SECONDS=30 + - EXIT_PROCESSOR_SLA_SECONDS=450 From 85fc0f5c41a58ed3cbc123f1806eb94ce4065612 Mon Sep 17 00:00:00 2001 From: souradeep-das Date: Tue, 28 Apr 2020 12:53:29 +0530 Subject: [PATCH 04/28] fixed- configuration_api_test --- priv/cabbage/apps/itest/test/itest/configuration_api_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/priv/cabbage/apps/itest/test/itest/configuration_api_test.exs b/priv/cabbage/apps/itest/test/itest/configuration_api_test.exs index cae73ca91b..f9ab3267ed 100644 --- a/priv/cabbage/apps/itest/test/itest/configuration_api_test.exs +++ b/priv/cabbage/apps/itest/test/itest/configuration_api_test.exs @@ -32,7 +32,7 @@ defmodule ConfigurationRetrievalTests do "contract_semver" => contract_semver, "deposit_finality_margin" => 10, "network" => "LOCALCHAIN", - "exit_processor_sla_seconds" => 30 + "exit_processor_sla_seconds" => 450 }, child_chain_assert_response: %{ "contract_semver" => contract_semver, From da7964a9ec563c9d006d7153de577a0a0fd5da19 Mon Sep 17 00:00:00 2001 From: souradeep-das Date: Tue, 28 Apr 2020 14:04:03 +0530 Subject: [PATCH 05/28] fix barebone test --- bin/variables_test_barebone | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/variables_test_barebone b/bin/variables_test_barebone index d410c40ed7..b7388f1977 100755 --- a/bin/variables_test_barebone +++ b/bin/variables_test_barebone @@ -4,7 +4,7 @@ # setup of our services # test_barebone_release taylored values. Compare also with priv/cabbage/docker-compose-cabbage.yml -export EXIT_PROCESSOR_SLA_SECONDS=30 +export EXIT_PROCESSOR_SLA_SECONDS=450 # the rest stays same as bin/variables export APP_ENV=local-development From 8e9a5378f8e15e7f7c5f8dd4a1fff77be2c9ffde Mon Sep 17 00:00:00 2001 From: souradeep-das Date: Tue, 28 Apr 2020 15:12:34 +0530 Subject: [PATCH 06/28] dummy --- docs/exit_validation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/exit_validation.md b/docs/exit_validation.md index 20a2509382..c99a00304a 100644 --- a/docs/exit_validation.md +++ b/docs/exit_validation.md @@ -12,7 +12,7 @@ This document describes the exit validation (processing) done by the Watcher in The correct reaction to both is a prompt to mass exit and a challenge of the invalid exit. Because of this, only `sla_seconds` is used as a configurable setting on the Watcher, covering for both conditions. * **`sla_seconds`** - margin of the child chain exit recognition SLA (in seconds). -This is the time in seconds after the start of an exit (or piggyback), during which a Child Chain Server still might include a transaction invalidating a previously valid exit, without violating the child chain exit recognition SLA. +This is the time (in seconds) after the start of an exit (or piggyback), during which a Child Chain Server still might include a transaction invalidating a previously valid exit, without violating the child chain exit recognition SLA. Similarly, this is a number of blocks after the start of an exit (or piggyback), during which the Watcher will not report [unchallenged exits](#unchallenged_exit-condition). ## Notes on the Child Chain Server From a250c9314d7b9e4a981dd746a259c718604ed392 Mon Sep 17 00:00:00 2001 From: souradeep-das Date: Wed, 29 Apr 2020 15:58:42 +0530 Subject: [PATCH 07/28] add ETHEREUM_BLOCK_TIME_SECONDS to variables_test_barebone --- bin/variables_test_barebone | 3 ++- .../apps/itest/test/itest/configuration_api_test.exs | 2 +- priv/cabbage/docker-compose-cabbage.yml | 4 ++-- priv/cabbage/mix.lock | 12 ++++++------ 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/bin/variables_test_barebone b/bin/variables_test_barebone index b7388f1977..efa27d913b 100755 --- a/bin/variables_test_barebone +++ b/bin/variables_test_barebone @@ -4,7 +4,7 @@ # setup of our services # test_barebone_release taylored values. Compare also with priv/cabbage/docker-compose-cabbage.yml -export EXIT_PROCESSOR_SLA_SECONDS=450 +export EXIT_PROCESSOR_SLA_SECONDS=30 # the rest stays same as bin/variables export APP_ENV=local-development @@ -18,6 +18,7 @@ export CHILD_CHAIN_URL=http://127.0.0.1:9656 export ETHEREUM_HEIGHT_CHECK_INTERVAL_MS=800 export ETHEREUM_EVENTS_CHECK_INTERVAL_MS=800 export ETHEREUM_STALLED_SYNC_THRESHOLD_MS=20000 +export ETHEREUM_BLOCK_TIME_SECONDS=1 export FEE_CLAIMER_ADDRESS=0x3b9f4c1dd26e0be593373b1d36cee2008cbeb837 export FEE_ADAPTER=file # Fee specs file path needs to be an absolute path as the childchain will start deep in the _build subdirectory diff --git a/priv/cabbage/apps/itest/test/itest/configuration_api_test.exs b/priv/cabbage/apps/itest/test/itest/configuration_api_test.exs index f9ab3267ed..cae73ca91b 100644 --- a/priv/cabbage/apps/itest/test/itest/configuration_api_test.exs +++ b/priv/cabbage/apps/itest/test/itest/configuration_api_test.exs @@ -32,7 +32,7 @@ defmodule ConfigurationRetrievalTests do "contract_semver" => contract_semver, "deposit_finality_margin" => 10, "network" => "LOCALCHAIN", - "exit_processor_sla_seconds" => 450 + "exit_processor_sla_seconds" => 30 }, child_chain_assert_response: %{ "contract_semver" => contract_semver, diff --git a/priv/cabbage/docker-compose-cabbage.yml b/priv/cabbage/docker-compose-cabbage.yml index 64b79217c9..d51274beb7 100644 --- a/priv/cabbage/docker-compose-cabbage.yml +++ b/priv/cabbage/docker-compose-cabbage.yml @@ -4,7 +4,7 @@ version: "2.3" services: watcher: environment: - - EXIT_PROCESSOR_SLA_SECONDS=450 + - EXIT_PROCESSOR_SLA_SECONDS=30 watcher_info: environment: - - EXIT_PROCESSOR_SLA_SECONDS=450 + - EXIT_PROCESSOR_SLA_SECONDS=30 diff --git a/priv/cabbage/mix.lock b/priv/cabbage/mix.lock index a2625ee00b..f54c249643 100644 --- a/priv/cabbage/mix.lock +++ b/priv/cabbage/mix.lock @@ -3,19 +3,19 @@ "bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"}, "cabbage": {:hex, :cabbage, "0.3.6", "5348ced2f8dd7c940a9becd3df26b32750cdeedf72baa262bd3361c7476f47bc", [:mix], [{:gherkin, "~> 1.4", [hex: :gherkin, repo: "hexpm", optional: false]}], "hexpm", "691218ffc05a13ae3b0bba9d05dd52b1c8502548a919016ddc68818a1ebe6f49"}, "certifi": {:hex, :certifi, "2.5.1", "867ce347f7c7d78563450a18a6a28a8090331e77fa02380b4a21962a65d36ee5", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm", "805abd97539caf89ec6d4732c91e62ba9da0cda51ac462380bbd28ee697a8c42"}, - "credo": {:hex, :credo, "1.3.2", "08d456dcf3c24da162d02953fb07267e444469d8dad3a2ae47794938ea467b3a", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "b11d28cce1f1f399dddffd42d8e21dcad783309e230f84b70267b1a5546468b6"}, + "credo": {:hex, :credo, "1.4.0", "92339d4cbadd1e88b5ee43d427b639b68a11071b6f73854e33638e30a0ea11f5", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "1fd3b70dce216574ce3c18bdf510b57e7c4c85c2ec9cad4bff854abaf7e58658"}, "eip_55": {:hex, :eip_55, "0.1.0", "ca0b4bb4276ab58787144a2f5d9d62abc58708be78b58ff51d8a9b9165088a74", [:mix], [{:ex_sha3, "~> 0.1", [hex: :ex_sha3, repo: "hexpm", optional: false]}], "hexpm", "6613ba20070ecec70e42c525151b8ac7645b0e83ea42fa47231d3b4de772d916"}, - "ethereumex": {:hex, :ethereumex, "0.6.0", "6c3a8f7ac09aa390db5c7d79678c1833948725c4c157946e86a7f4a1a6d03ce2", [:mix], [{:httpoison, "~> 1.4.0", [hex: :httpoison, repo: "hexpm", optional: false]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5.1", [hex: :poolboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "b221e989962a3a9e9d8d40af212ca86d3ee72800493a432a54426c807517f237"}, + "ethereumex": {:hex, :ethereumex, "0.6.1", "d4497a2f66cb2deba582652e93135daec28426b195f92883b37086e56bdea9a5", [:mix], [{:httpoison, "~> 1.6", [hex: :httpoison, repo: "hexpm", optional: false]}, {:jason, "~> 1.2", [hex: :jason, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5.1", [hex: :poolboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "79be0659a8978eb0ae5184ade13878f1f1133fb402ce5ac697bf2afa08bba7e7"}, "ex_abi": {:hex, :ex_abi, "0.2.2", "805c19edccb98ecd02a2eee1851d49f625ae036953ae45b3349468333b19870e", [:mix], [{:exth_crypto, "~> 0.1.6", [hex: :exth_crypto, repo: "hexpm", optional: false]}], "hexpm", "649688a53dde9c676f6a760cc0c1e43cb246010a7f83b13b9e5bd75aa04cc409"}, - "ex_plasma": {:git, "https://github.com/omisego/ex_plasma.git", "1e322870cb0e9f28650089110a18a556821b167c", []}, + "ex_plasma": {:git, "https://github.com/omisego/ex_plasma.git", "fb0a9b0c00995bbf3d36983a16135ebf9bd51aab", []}, "ex_rlp": {:hex, :ex_rlp, "0.5.3", "9055bddade545ee3e734aaad62c4b4d08211834da3beb43ae269b75785909e5e", [:mix], [], "hexpm", "a755a5f8f9f66079f3ecbe021536b949077fac0df963d9e59a20321bab28722d"}, "ex_sha3": {:hex, :ex_sha3, "0.1.1", "8972638de7ded220cb885d6a8889c0df9da0d581d25c3b1b94a85a226b6fe874", [:mix], [], "hexpm", "3c0da4d7ca4c31dd1c7c4077b394f1fe113fbcdd8ae597683896570dcdb06841"}, "exth_crypto": {:hex, :exth_crypto, "0.1.6", "8e636a9bcb75d8e32451be96e547a495121ed2178d078db294edb0f81f7cf2e8", [:mix], [{:binary, "~> 0.0.4", [hex: :binary, repo: "hexpm", optional: false]}, {:keccakf1600, "~> 2.0.0", [hex: :keccakf1600_orig, repo: "hexpm", optional: false]}, {:libsecp256k1, "~> 0.1.9", [hex: :libsecp256k1, repo: "hexpm", optional: false]}], "hexpm", "45d6faf4b889f8fc526deba059e0c7947423784ab1e7fa85be8db4c46cf4416b"}, "gherkin": {:hex, :gherkin, "1.6.0", "a7a2925e6153b7f475646e411e45eed657eb8648ae4bec4222334bf46d37798e", [:mix], [], "hexpm", "9631845a23f3dbde97ae576c1e67e928392b12fb0d0e976acb0ec5d4b5fd1881"}, "hackney": {:hex, :hackney, "1.15.2", "07e33c794f8f8964ee86cebec1a8ed88db5070e52e904b8f12209773c1036085", [:rebar3], [{:certifi, "2.5.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "6.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.5", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm", "e0100f8ef7d1124222c11ad362c857d3df7cb5f4204054f9f0f4a728666591fc"}, - "httpoison": {:hex, :httpoison, "1.4.0", "e0b3c2ad6fa573134e42194d13e925acfa8f89d138bc621ffb7b1989e6d22e73", [:mix], [{:hackney, "~> 1.8", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "37b6f39cb92136ee72276f4bf4da81495e7935d720c3a15daf1553953153e3f7"}, + "httpoison": {:hex, :httpoison, "1.6.2", "ace7c8d3a361cebccbed19c283c349b3d26991eff73a1eaaa8abae2e3c8089b6", [:mix], [{:hackney, "~> 1.15 and >= 1.15.2", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "aa2c74bd271af34239a3948779612f87df2422c2fdcfdbcec28d9c105f0773fe"}, "idna": {:hex, :idna, "6.0.0", "689c46cbcdf3524c44d5f3dde8001f364cd7608a99556d8fbd8239a5798d4c10", [:rebar3], [{:unicode_util_compat, "0.4.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "4bdd305eb64e18b0273864920695cb18d7a2021f31a11b9c5fbcd9a253f936e2"}, - "jason": {:hex, :jason, "1.1.2", "b03dedea67a99223a2eaf9f1264ce37154564de899fd3d8b9a21b1a6fd64afe7", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fdf843bca858203ae1de16da2ee206f53416bbda5dc8c9e78f43243de4bc3afe"}, + "jason": {:hex, :jason, "1.2.0", "10043418c42d2493d0ee212d3fddd25d7ffe484380afad769a0a38795938e448", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "116747dbe057794c3a3e4e143b7c8390b29f634e16c78a7f59ba75bfa6852e7f"}, "keccakf1600": {:hex, :keccakf1600_orig, "2.0.0", "0a7217ddb3ee8220d449bbf7575ec39d4e967099f220a91e3dfca4dbaef91963", [:rebar3], [], "hexpm", "bdbbb02d67bea35605f95d4e3de48203347374e414da7945c4f2f7fd13ffe632"}, "libsecp256k1": {:git, "https://github.com/omisego/libsecp256k1.git", "83d4c91b7b5ad79fdd3c020be8c57ff6e2212780", [branch: "elixir-only"]}, "libsecp256k1_source": {:git, "https://github.com/bitcoin-core/secp256k1.git", "d33352151699bd7598b868369dace092f7855740", [ref: "d33352151699bd7598b868369dace092f7855740"]}, @@ -28,7 +28,7 @@ "poolboy": {:hex, :poolboy, "1.5.2", "392b007a1693a64540cead79830443abf5762f5d30cf50bc95cb2c1aaafa006b", [:rebar3], [], "hexpm", "dad79704ce5440f3d5a3681c8590b9dc25d1a561e8f5a9c995281012860901e3"}, "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.5", "6eaf7ad16cb568bb01753dbbd7a95ff8b91c7979482b95f38443fe2c8852a79b", [:make, :mix, :rebar3], [], "hexpm", "13104d7897e38ed7f044c4de953a6c28597d1c952075eb2e328bc6d6f2bfc496"}, "telemetry": {:hex, :telemetry, "0.4.1", "ae2718484892448a24470e6aa341bc847c3277bfb8d4e9289f7474d752c09c7f", [:rebar3], [], "hexpm", "4738382e36a0a9a2b6e25d67c960e40e1a2c95560b9f936d8e29de8cd858480f"}, - "tesla": {:hex, :tesla, "1.3.2", "deb92c5c9ce35e747a395ba413ca78593a4f75bf0e1545630ee2e3d34264021e", [:mix], [{:castore, "~> 0.1", [hex: :castore, repo: "hexpm", optional: true]}, {:exjsx, ">= 3.0.0", [hex: :exjsx, repo: "hexpm", optional: true]}, {:fuse, "~> 2.4", [hex: :fuse, repo: "hexpm", optional: true]}, {:gun, "~> 1.3", [hex: :gun, repo: "hexpm", optional: true]}, {:hackney, "~> 1.6", [hex: :hackney, repo: "hexpm", optional: true]}, {:ibrowse, "~> 4.4.0", [hex: :ibrowse, repo: "hexpm", optional: true]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: true]}, {:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.0", [hex: :mint, repo: "hexpm", optional: true]}, {:poison, ">= 1.0.0", [hex: :poison, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.3", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "7567704c4790e21bd9a961b56d0b6a988ff68cc4dacfe6b2106e258da1d5cdda"}, + "tesla": {:hex, :tesla, "1.3.3", "26ae98627af5c406584aa6755ab5fc96315d70d69a24dd7f8369cfcb75094a45", [:mix], [{:castore, "~> 0.1", [hex: :castore, repo: "hexpm", optional: true]}, {:exjsx, ">= 3.0.0", [hex: :exjsx, repo: "hexpm", optional: true]}, {:fuse, "~> 2.4", [hex: :fuse, repo: "hexpm", optional: true]}, {:gun, "~> 1.3", [hex: :gun, repo: "hexpm", optional: true]}, {:hackney, "~> 1.6", [hex: :hackney, repo: "hexpm", optional: true]}, {:ibrowse, "~> 4.4.0", [hex: :ibrowse, repo: "hexpm", optional: true]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: true]}, {:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.0", [hex: :mint, repo: "hexpm", optional: true]}, {:poison, ">= 1.0.0", [hex: :poison, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "2648f1c276102f9250299e0b7b57f3071c67827349d9173f34c281756a1b124c"}, "unicode_util_compat": {:hex, :unicode_util_compat, "0.4.1", "d869e4c68901dd9531385bb0c8c40444ebf624e60b6962d95952775cac5e90cd", [:rebar3], [], "hexpm", "1d1848c40487cdb0b30e8ed975e34e025860c02e419cb615d255849f3427439d"}, "websockex": {:hex, :websockex, "0.4.2", "9a3b7dc25655517ecd3f8ff7109a77fce94956096b942836cdcfbc7c86603ecc", [:mix], [], "hexpm", "803cd76e91544b56f0e655e36790be797fa6436db9224f7c303db9b9df2a3df4"}, } From a0c7d4f6fed92f46e64f838bec9376078cda2de8 Mon Sep 17 00:00:00 2001 From: souradeep-das Date: Wed, 29 Apr 2020 16:05:41 +0530 Subject: [PATCH 08/28] revert mix lock --- priv/cabbage/mix.lock | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/priv/cabbage/mix.lock b/priv/cabbage/mix.lock index f54c249643..a0707543a1 100644 --- a/priv/cabbage/mix.lock +++ b/priv/cabbage/mix.lock @@ -3,19 +3,19 @@ "bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"}, "cabbage": {:hex, :cabbage, "0.3.6", "5348ced2f8dd7c940a9becd3df26b32750cdeedf72baa262bd3361c7476f47bc", [:mix], [{:gherkin, "~> 1.4", [hex: :gherkin, repo: "hexpm", optional: false]}], "hexpm", "691218ffc05a13ae3b0bba9d05dd52b1c8502548a919016ddc68818a1ebe6f49"}, "certifi": {:hex, :certifi, "2.5.1", "867ce347f7c7d78563450a18a6a28a8090331e77fa02380b4a21962a65d36ee5", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm", "805abd97539caf89ec6d4732c91e62ba9da0cda51ac462380bbd28ee697a8c42"}, - "credo": {:hex, :credo, "1.4.0", "92339d4cbadd1e88b5ee43d427b639b68a11071b6f73854e33638e30a0ea11f5", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "1fd3b70dce216574ce3c18bdf510b57e7c4c85c2ec9cad4bff854abaf7e58658"}, + "credo": {:hex, :credo, "1.3.2", "08d456dcf3c24da162d02953fb07267e444469d8dad3a2ae47794938ea467b3a", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "b11d28cce1f1f399dddffd42d8e21dcad783309e230f84b70267b1a5546468b6"}, "eip_55": {:hex, :eip_55, "0.1.0", "ca0b4bb4276ab58787144a2f5d9d62abc58708be78b58ff51d8a9b9165088a74", [:mix], [{:ex_sha3, "~> 0.1", [hex: :ex_sha3, repo: "hexpm", optional: false]}], "hexpm", "6613ba20070ecec70e42c525151b8ac7645b0e83ea42fa47231d3b4de772d916"}, - "ethereumex": {:hex, :ethereumex, "0.6.1", "d4497a2f66cb2deba582652e93135daec28426b195f92883b37086e56bdea9a5", [:mix], [{:httpoison, "~> 1.6", [hex: :httpoison, repo: "hexpm", optional: false]}, {:jason, "~> 1.2", [hex: :jason, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5.1", [hex: :poolboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "79be0659a8978eb0ae5184ade13878f1f1133fb402ce5ac697bf2afa08bba7e7"}, + "ethereumex": {:hex, :ethereumex, "0.6.0", "6c3a8f7ac09aa390db5c7d79678c1833948725c4c157946e86a7f4a1a6d03ce2", [:mix], [{:httpoison, "~> 1.4.0", [hex: :httpoison, repo: "hexpm", optional: false]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5.1", [hex: :poolboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "b221e989962a3a9e9d8d40af212ca86d3ee72800493a432a54426c807517f237"}, "ex_abi": {:hex, :ex_abi, "0.2.2", "805c19edccb98ecd02a2eee1851d49f625ae036953ae45b3349468333b19870e", [:mix], [{:exth_crypto, "~> 0.1.6", [hex: :exth_crypto, repo: "hexpm", optional: false]}], "hexpm", "649688a53dde9c676f6a760cc0c1e43cb246010a7f83b13b9e5bd75aa04cc409"}, - "ex_plasma": {:git, "https://github.com/omisego/ex_plasma.git", "fb0a9b0c00995bbf3d36983a16135ebf9bd51aab", []}, + "ex_plasma": {:git, "https://github.com/omisego/ex_plasma.git", "1e322870cb0e9f28650089110a18a556821b167c", []}, "ex_rlp": {:hex, :ex_rlp, "0.5.3", "9055bddade545ee3e734aaad62c4b4d08211834da3beb43ae269b75785909e5e", [:mix], [], "hexpm", "a755a5f8f9f66079f3ecbe021536b949077fac0df963d9e59a20321bab28722d"}, "ex_sha3": {:hex, :ex_sha3, "0.1.1", "8972638de7ded220cb885d6a8889c0df9da0d581d25c3b1b94a85a226b6fe874", [:mix], [], "hexpm", "3c0da4d7ca4c31dd1c7c4077b394f1fe113fbcdd8ae597683896570dcdb06841"}, "exth_crypto": {:hex, :exth_crypto, "0.1.6", "8e636a9bcb75d8e32451be96e547a495121ed2178d078db294edb0f81f7cf2e8", [:mix], [{:binary, "~> 0.0.4", [hex: :binary, repo: "hexpm", optional: false]}, {:keccakf1600, "~> 2.0.0", [hex: :keccakf1600_orig, repo: "hexpm", optional: false]}, {:libsecp256k1, "~> 0.1.9", [hex: :libsecp256k1, repo: "hexpm", optional: false]}], "hexpm", "45d6faf4b889f8fc526deba059e0c7947423784ab1e7fa85be8db4c46cf4416b"}, "gherkin": {:hex, :gherkin, "1.6.0", "a7a2925e6153b7f475646e411e45eed657eb8648ae4bec4222334bf46d37798e", [:mix], [], "hexpm", "9631845a23f3dbde97ae576c1e67e928392b12fb0d0e976acb0ec5d4b5fd1881"}, "hackney": {:hex, :hackney, "1.15.2", "07e33c794f8f8964ee86cebec1a8ed88db5070e52e904b8f12209773c1036085", [:rebar3], [{:certifi, "2.5.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "6.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.5", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm", "e0100f8ef7d1124222c11ad362c857d3df7cb5f4204054f9f0f4a728666591fc"}, - "httpoison": {:hex, :httpoison, "1.6.2", "ace7c8d3a361cebccbed19c283c349b3d26991eff73a1eaaa8abae2e3c8089b6", [:mix], [{:hackney, "~> 1.15 and >= 1.15.2", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "aa2c74bd271af34239a3948779612f87df2422c2fdcfdbcec28d9c105f0773fe"}, + "httpoison": {:hex, :httpoison, "1.4.0", "e0b3c2ad6fa573134e42194d13e925acfa8f89d138bc621ffb7b1989e6d22e73", [:mix], [{:hackney, "~> 1.8", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "37b6f39cb92136ee72276f4bf4da81495e7935d720c3a15daf1553953153e3f7"}, "idna": {:hex, :idna, "6.0.0", "689c46cbcdf3524c44d5f3dde8001f364cd7608a99556d8fbd8239a5798d4c10", [:rebar3], [{:unicode_util_compat, "0.4.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "4bdd305eb64e18b0273864920695cb18d7a2021f31a11b9c5fbcd9a253f936e2"}, - "jason": {:hex, :jason, "1.2.0", "10043418c42d2493d0ee212d3fddd25d7ffe484380afad769a0a38795938e448", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "116747dbe057794c3a3e4e143b7c8390b29f634e16c78a7f59ba75bfa6852e7f"}, + "jason": {:hex, :jason, "1.1.2", "b03dedea67a99223a2eaf9f1264ce37154564de899fd3d8b9a21b1a6fd64afe7", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fdf843bca858203ae1de16da2ee206f53416bbda5dc8c9e78f43243de4bc3afe"}, "keccakf1600": {:hex, :keccakf1600_orig, "2.0.0", "0a7217ddb3ee8220d449bbf7575ec39d4e967099f220a91e3dfca4dbaef91963", [:rebar3], [], "hexpm", "bdbbb02d67bea35605f95d4e3de48203347374e414da7945c4f2f7fd13ffe632"}, "libsecp256k1": {:git, "https://github.com/omisego/libsecp256k1.git", "83d4c91b7b5ad79fdd3c020be8c57ff6e2212780", [branch: "elixir-only"]}, "libsecp256k1_source": {:git, "https://github.com/bitcoin-core/secp256k1.git", "d33352151699bd7598b868369dace092f7855740", [ref: "d33352151699bd7598b868369dace092f7855740"]}, @@ -28,7 +28,7 @@ "poolboy": {:hex, :poolboy, "1.5.2", "392b007a1693a64540cead79830443abf5762f5d30cf50bc95cb2c1aaafa006b", [:rebar3], [], "hexpm", "dad79704ce5440f3d5a3681c8590b9dc25d1a561e8f5a9c995281012860901e3"}, "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.5", "6eaf7ad16cb568bb01753dbbd7a95ff8b91c7979482b95f38443fe2c8852a79b", [:make, :mix, :rebar3], [], "hexpm", "13104d7897e38ed7f044c4de953a6c28597d1c952075eb2e328bc6d6f2bfc496"}, "telemetry": {:hex, :telemetry, "0.4.1", "ae2718484892448a24470e6aa341bc847c3277bfb8d4e9289f7474d752c09c7f", [:rebar3], [], "hexpm", "4738382e36a0a9a2b6e25d67c960e40e1a2c95560b9f936d8e29de8cd858480f"}, - "tesla": {:hex, :tesla, "1.3.3", "26ae98627af5c406584aa6755ab5fc96315d70d69a24dd7f8369cfcb75094a45", [:mix], [{:castore, "~> 0.1", [hex: :castore, repo: "hexpm", optional: true]}, {:exjsx, ">= 3.0.0", [hex: :exjsx, repo: "hexpm", optional: true]}, {:fuse, "~> 2.4", [hex: :fuse, repo: "hexpm", optional: true]}, {:gun, "~> 1.3", [hex: :gun, repo: "hexpm", optional: true]}, {:hackney, "~> 1.6", [hex: :hackney, repo: "hexpm", optional: true]}, {:ibrowse, "~> 4.4.0", [hex: :ibrowse, repo: "hexpm", optional: true]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: true]}, {:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.0", [hex: :mint, repo: "hexpm", optional: true]}, {:poison, ">= 1.0.0", [hex: :poison, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "2648f1c276102f9250299e0b7b57f3071c67827349d9173f34c281756a1b124c"}, + "tesla": {:hex, :tesla, "1.3.2", "deb92c5c9ce35e747a395ba413ca78593a4f75bf0e1545630ee2e3d34264021e", [:mix], [{:castore, "~> 0.1", [hex: :castore, repo: "hexpm", optional: true]}, {:exjsx, ">= 3.0.0", [hex: :exjsx, repo: "hexpm", optional: true]}, {:fuse, "~> 2.4", [hex: :fuse, repo: "hexpm", optional: true]}, {:gun, "~> 1.3", [hex: :gun, repo: "hexpm", optional: true]}, {:hackney, "~> 1.6", [hex: :hackney, repo: "hexpm", optional: true]}, {:ibrowse, "~> 4.4.0", [hex: :ibrowse, repo: "hexpm", optional: true]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: true]}, {:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.0", [hex: :mint, repo: "hexpm", optional: true]}, {:poison, ">= 1.0.0", [hex: :poison, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.3", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "7567704c4790e21bd9a961b56d0b6a988ff68cc4dacfe6b2106e258da1d5cdda"}, "unicode_util_compat": {:hex, :unicode_util_compat, "0.4.1", "d869e4c68901dd9531385bb0c8c40444ebf624e60b6962d95952775cac5e90cd", [:rebar3], [], "hexpm", "1d1848c40487cdb0b30e8ed975e34e025860c02e419cb615d255849f3427439d"}, "websockex": {:hex, :websockex, "0.4.2", "9a3b7dc25655517ecd3f8ff7109a77fce94956096b942836cdcfbc7c86603ecc", [:mix], [], "hexpm", "803cd76e91544b56f0e655e36790be797fa6436db9224f7c303db9b9df2a3df4"}, -} +} \ No newline at end of file From e074347fbdbc5a439c26112472ff5afa8776d21b Mon Sep 17 00:00:00 2001 From: souradeep-das Date: Mon, 4 May 2020 20:33:18 +0530 Subject: [PATCH 09/28] temp assigning ethereum_block_time_seconds which wont be used later --- .../lib/omg_watcher/exit_processor/standard_exit.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex b/apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex index 398901ebb4..92672794c2 100644 --- a/apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex +++ b/apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex @@ -81,10 +81,11 @@ defmodule OMG.Watcher.ExitProcessor.StandardExit do ethereum_block_time_seconds = OMG.Eth.Configuration.ethereum_block_time_seconds() # get exits which are still invalid and after the SLA margin + # temporarily assigning ethereum_block_time_seconds= 1, will be removed on merge of #1495 late_invalid_exits = invalid_exits |> Enum.filter(fn {_, %ExitInfo{eth_height: eth_height}} -> - eth_height + sla_seconds / ethereum_block_time_seconds <= eth_height_now + eth_height + sla_seconds / 1 <= eth_height_now end) {Map.new(invalid_exits), Map.new(late_invalid_exits)} From b2157c9e1056dc9b62d67fb836abdcf21dd175cc Mon Sep 17 00:00:00 2001 From: souradeep-das Date: Mon, 4 May 2020 20:57:31 +0530 Subject: [PATCH 10/28] credo fix --- .../omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex b/apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex index 92672794c2..157b618abb 100644 --- a/apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex +++ b/apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex @@ -79,7 +79,7 @@ defmodule OMG.Watcher.ExitProcessor.StandardExit do exits_invalid_by_ife = get_invalid_exits_based_on_ifes(active_exits, tx_appendix) invalid_exits = active_exits |> Map.take(invalid_exit_positions) |> Enum.concat(exits_invalid_by_ife) |> Enum.uniq() - ethereum_block_time_seconds = OMG.Eth.Configuration.ethereum_block_time_seconds() + _ethereum_block_time_seconds = OMG.Eth.Configuration.ethereum_block_time_seconds() # get exits which are still invalid and after the SLA margin # temporarily assigning ethereum_block_time_seconds= 1, will be removed on merge of #1495 late_invalid_exits = From dc32c7dd840db2815392eb8391c6af94fabe93e8 Mon Sep 17 00:00:00 2001 From: souradeep-das Date: Mon, 4 May 2020 21:10:57 +0530 Subject: [PATCH 11/28] lint fix --- .../omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex b/apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex index 157b618abb..59375e7a0f 100644 --- a/apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex +++ b/apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex @@ -81,7 +81,7 @@ defmodule OMG.Watcher.ExitProcessor.StandardExit do _ethereum_block_time_seconds = OMG.Eth.Configuration.ethereum_block_time_seconds() # get exits which are still invalid and after the SLA margin - # temporarily assigning ethereum_block_time_seconds= 1, will be removed on merge of #1495 + # temporarily assigning ethereum_block_time_seconds= 1, will be removed on merge of #1495 late_invalid_exits = invalid_exits |> Enum.filter(fn {_, %ExitInfo{eth_height: eth_height}} -> From 9e4263070a4751204956b0fc4aae1a61d7cd3b62 Mon Sep 17 00:00:00 2001 From: souradeep-das Date: Tue, 5 May 2020 12:32:18 +0530 Subject: [PATCH 12/28] update sla_seconds for test.exs --- config/test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/test.exs b/config/test.exs index dab08bbce7..02f5266212 100644 --- a/config/test.exs +++ b/config/test.exs @@ -138,7 +138,7 @@ config :omg_watcher, block_getter_loops_interval_ms: 50, # NOTE `exit_processor_sla_margin` can't be made shorter. At 3 it sometimes # causes :unchallenged_exit because `geth --dev` is too fast - exit_processor_sla_seconds: 75, + exit_processor_sla_seconds: 5, # this means we allow the `sla_margin` above be larger than the `min_exit_period` exit_processor_sla_margin_forced: true, # NOTE: `maximum_block_withholding_time_ms` must be here - one of our integration tests From 43bd892ec62337d4d48e3e1f96310d86d7b9b52a Mon Sep 17 00:00:00 2001 From: souradeep-das Date: Tue, 5 May 2020 12:42:32 +0530 Subject: [PATCH 13/28] change: @system_env_name_margin to @system_env_name and @app_env_name_margin to @app_env_name --- .../release_tasks/set_exit_processor_sla_margin.ex | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/omg_watcher/lib/omg_watcher/release_tasks/set_exit_processor_sla_margin.ex b/apps/omg_watcher/lib/omg_watcher/release_tasks/set_exit_processor_sla_margin.ex index 9737d24cb5..5e3cda1a13 100644 --- a/apps/omg_watcher/lib/omg_watcher/release_tasks/set_exit_processor_sla_margin.ex +++ b/apps/omg_watcher/lib/omg_watcher/release_tasks/set_exit_processor_sla_margin.ex @@ -18,8 +18,8 @@ defmodule OMG.Watcher.ReleaseTasks.SetExitProcessorSLAMargin do require Logger @app :omg_watcher - @system_env_name_margin "EXIT_PROCESSOR_SLA_SECONDS" - @app_env_name_margin :exit_processor_sla_seconds + @system_env_name "EXIT_PROCESSOR_SLA_SECONDS" + @app_env_name :exit_processor_sla_seconds @system_env_name_force "EXIT_PROCESSOR_SLA_MARGIN_FORCED" @app_env_name_force :exit_processor_sla_margin_forced @@ -40,8 +40,8 @@ defmodule OMG.Watcher.ReleaseTasks.SetExitProcessorSLAMargin do end defp get_exit_processor_sla_seconds() do - config_value = validate_int(get_env(@system_env_name_margin), Application.get_env(@app, @app_env_name_margin)) - _ = Logger.info("CONFIGURATION: App: #{@app} Key: #{@system_env_name_margin} Value: #{inspect(config_value)}.") + config_value = validate_int(get_env(@system_env_name), Application.get_env(@app, @app_env_name)) + _ = Logger.info("CONFIGURATION: App: #{@app} Key: #{@system_env_name} Value: #{inspect(config_value)}.") config_value end @@ -66,7 +66,7 @@ defmodule OMG.Watcher.ReleaseTasks.SetExitProcessorSLAMargin do defp to_int(value) do case Integer.parse(value) do {result, ""} -> result - _ -> exit("#{@system_env_name_margin} must be an integer.") + _ -> exit("#{@system_env_name} must be an integer.") end end end From b4c53429eda93c9fb3c4a8b10bc7c881500ad26c Mon Sep 17 00:00:00 2001 From: souradeep-das Date: Tue, 5 May 2020 12:52:48 +0530 Subject: [PATCH 14/28] remove single pipeline --- .../lib/omg_watcher/exit_processor/standard_exit.ex | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex b/apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex index 59375e7a0f..20eb1a2d7f 100644 --- a/apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex +++ b/apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex @@ -83,8 +83,7 @@ defmodule OMG.Watcher.ExitProcessor.StandardExit do # get exits which are still invalid and after the SLA margin # temporarily assigning ethereum_block_time_seconds= 1, will be removed on merge of #1495 late_invalid_exits = - invalid_exits - |> Enum.filter(fn {_, %ExitInfo{eth_height: eth_height}} -> + Enum.filter(invalid_exits, fn {_, %ExitInfo{eth_height: eth_height}} -> eth_height + sla_seconds / 1 <= eth_height_now end) From 545034d0cf5d2c61140d7b7f0b316c9f9d74213f Mon Sep 17 00:00:00 2001 From: souradeep-das Date: Tue, 5 May 2020 13:03:19 +0530 Subject: [PATCH 15/28] revert mix lock --- priv/cabbage/mix.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/priv/cabbage/mix.lock b/priv/cabbage/mix.lock index a0707543a1..a2625ee00b 100644 --- a/priv/cabbage/mix.lock +++ b/priv/cabbage/mix.lock @@ -31,4 +31,4 @@ "tesla": {:hex, :tesla, "1.3.2", "deb92c5c9ce35e747a395ba413ca78593a4f75bf0e1545630ee2e3d34264021e", [:mix], [{:castore, "~> 0.1", [hex: :castore, repo: "hexpm", optional: true]}, {:exjsx, ">= 3.0.0", [hex: :exjsx, repo: "hexpm", optional: true]}, {:fuse, "~> 2.4", [hex: :fuse, repo: "hexpm", optional: true]}, {:gun, "~> 1.3", [hex: :gun, repo: "hexpm", optional: true]}, {:hackney, "~> 1.6", [hex: :hackney, repo: "hexpm", optional: true]}, {:ibrowse, "~> 4.4.0", [hex: :ibrowse, repo: "hexpm", optional: true]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: true]}, {:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.0", [hex: :mint, repo: "hexpm", optional: true]}, {:poison, ">= 1.0.0", [hex: :poison, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.3", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "7567704c4790e21bd9a961b56d0b6a988ff68cc4dacfe6b2106e258da1d5cdda"}, "unicode_util_compat": {:hex, :unicode_util_compat, "0.4.1", "d869e4c68901dd9531385bb0c8c40444ebf624e60b6962d95952775cac5e90cd", [:rebar3], [], "hexpm", "1d1848c40487cdb0b30e8ed975e34e025860c02e419cb615d255849f3427439d"}, "websockex": {:hex, :websockex, "0.4.2", "9a3b7dc25655517ecd3f8ff7109a77fce94956096b942836cdcfbc7c86603ecc", [:mix], [], "hexpm", "803cd76e91544b56f0e655e36790be797fa6436db9224f7c303db9b9df2a3df4"}, -} \ No newline at end of file +} From c8ea7aa053d22ae591a1b861279c21468df586ed Mon Sep 17 00:00:00 2001 From: souradeep-das Date: Mon, 18 May 2020 01:01:42 +0530 Subject: [PATCH 16/28] merge changes from master --- .../lib/omg_watcher/exit_processor/core.ex | 22 ++++--------------- 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/apps/omg_watcher/lib/omg_watcher/exit_processor/core.ex b/apps/omg_watcher/lib/omg_watcher/exit_processor/core.ex index b538435d56..31dcb5423d 100644 --- a/apps/omg_watcher/lib/omg_watcher/exit_processor/core.ex +++ b/apps/omg_watcher/lib/omg_watcher/exit_processor/core.ex @@ -68,11 +68,8 @@ defmodule OMG.Watcher.ExitProcessor.Core do @type new_piggyback_event_t() :: new_piggyback_input_event_t() | new_piggyback_output_event_t() -<<<<<<< HEAD - defstruct [:sla_seconds, exits: %{}, in_flight_exits: %{}, exit_ids: %{}, competitors: %{}] -======= defstruct [ - :sla_margin, + :sla_seconds, :min_exit_period_seconds, :child_block_interval, exits: %{}, @@ -80,7 +77,6 @@ defmodule OMG.Watcher.ExitProcessor.Core do exit_ids: %{}, competitors: %{} ] ->>>>>>> master @type t :: %__MODULE__{ sla_seconds: non_neg_integer(), @@ -115,14 +111,9 @@ defmodule OMG.Watcher.ExitProcessor.Core do db_exits :: [{{pos_integer, non_neg_integer, non_neg_integer}, map}], db_in_flight_exits :: [{Transaction.tx_hash(), InFlightExitInfo.t()}], db_competitors :: [{Transaction.tx_hash(), CompetitorInfo.t()}], -<<<<<<< HEAD - sla_seconds :: non_neg_integer - ) :: {:ok, t()} - def init(db_exits, db_in_flight_exits, db_competitors, sla_seconds \\ @default_sla_seconds) do -======= min_exit_period_seconds :: non_neg_integer(), child_block_interval :: non_neg_integer, - sla_margin :: non_neg_integer + sla_seconds :: non_neg_integer ) :: {:ok, t()} def init( db_exits, @@ -130,9 +121,8 @@ defmodule OMG.Watcher.ExitProcessor.Core do db_competitors, min_exit_period_seconds, child_block_interval, - sla_margin \\ @default_sla_margin + sla_seconds \\ @default_sla_seconds ) do ->>>>>>> master exits = db_exits |> Enum.map(&ExitInfo.from_db_kv/1) |> Map.new() exit_ids = Enum.into(exits, %{}, fn {utxo_pos, %ExitInfo{exit_id: exit_id}} -> {exit_id, utxo_pos} end) @@ -143,13 +133,9 @@ defmodule OMG.Watcher.ExitProcessor.Core do in_flight_exits: db_in_flight_exits |> Enum.map(&InFlightExitInfo.from_db_kv/1) |> Map.new(), exit_ids: exit_ids, competitors: db_competitors |> Enum.map(&CompetitorInfo.from_db_kv/1) |> Map.new(), -<<<<<<< HEAD - sla_seconds: sla_seconds -======= - sla_margin: sla_margin, + sla_seconds: sla_seconds, min_exit_period_seconds: min_exit_period_seconds, child_block_interval: child_block_interval ->>>>>>> master }} end From b25e4dc029993b33cbc82d0c070ec87126ba1906 Mon Sep 17 00:00:00 2001 From: souradeep-das Date: Mon, 18 May 2020 22:05:40 +0530 Subject: [PATCH 17/28] get timestamp from eth_height --- .../omg_watcher/lib/omg_watcher/exit_processor.ex | 3 +-- .../lib/omg_watcher/exit_processor/canonicity.ex | 11 +++++++---- .../lib/omg_watcher/exit_processor/piggyback.ex | 15 +++++++++------ .../omg_watcher/exit_processor/standard_exit.ex | 9 +++++---- .../exit_processor/canonicity_test.exs | 2 +- .../omg_watcher/exit_processor/piggyback_test.exs | 2 +- .../exit_processor/standard_exit_test.exs | 1 - .../omg_watcher/integration/invalid_exit_test.exs | 2 +- 8 files changed, 25 insertions(+), 20 deletions(-) diff --git a/apps/omg_watcher/lib/omg_watcher/exit_processor.ex b/apps/omg_watcher/lib/omg_watcher/exit_processor.ex index 0f6dfd8f90..41065fb9a9 100644 --- a/apps/omg_watcher/lib/omg_watcher/exit_processor.ex +++ b/apps/omg_watcher/lib/omg_watcher/exit_processor.ex @@ -610,7 +610,7 @@ defmodule OMG.Watcher.ExitProcessor do end defp run_status_gets(%ExitProcessor.Request{eth_height_now: nil, blknum_now: nil} = request) do - {:ok, eth_height_now} = EthereumHeight.get() + {:ok, eth_height_now} = Eth.get_block_timestamp_by_number(EthereumHeight.get()) {blknum_now, _} = State.get_status() _ = Logger.debug("eth_height_now: #{inspect(eth_height_now)}, blknum_now: #{inspect(blknum_now)}") @@ -686,7 +686,6 @@ defmodule OMG.Watcher.ExitProcessor do {:utxo_position, blknum, _, _} = Utxo.Position.decode!(utxo_pos_enc) {_block_hash, utxo_creation_block_timestamp} = RootChain.blocks(blknum) {:ok, exit_block_timestamp} = Eth.get_block_timestamp_by_number(eth_height) - {:ok, scheduled_finalization_time} = ExitInfo.calculate_sft( blknum, diff --git a/apps/omg_watcher/lib/omg_watcher/exit_processor/canonicity.ex b/apps/omg_watcher/lib/omg_watcher/exit_processor/canonicity.ex index 455f4781b3..4ec8b0f329 100644 --- a/apps/omg_watcher/lib/omg_watcher/exit_processor/canonicity.ex +++ b/apps/omg_watcher/lib/omg_watcher/exit_processor/canonicity.ex @@ -34,6 +34,7 @@ defmodule OMG.Watcher.ExitProcessor.Canonicity do alias OMG.Crypto alias OMG.State.Transaction alias OMG.Utxo + alias OMG.Eth alias OMG.Watcher.Event alias OMG.Watcher.ExitProcessor alias OMG.Watcher.ExitProcessor.Core @@ -67,7 +68,7 @@ defmodule OMG.Watcher.ExitProcessor.Canonicity do @doc """ Returns a tuple with byzantine events: first element is a list of events for ifes with competitor - and the second is the same list filtered for late ifes past sla margin + and the second is the same list filtered for late ifes past sla seconds """ @spec get_ife_txs_with_competitors(Core.t(), KnownTx.known_txs_by_input_t(), pos_integer()) :: {list(Event.NonCanonicalIFE.t()), list(Event.UnchallengedNonCanonicalIFE.t())} @@ -81,19 +82,21 @@ defmodule OMG.Watcher.ExitProcessor.Canonicity do InFlightExitInfo.is_viable_competitor?(ife, utxo_pos) end) + {:ok, time_now} = Eth.get_block_timestamp_by_number(eth_height_now) + non_canonical_ife_events = non_canonical_ifes |> Stream.map(fn {ife, _double_spend} -> Transaction.raw_txbytes(ife.tx) end) |> Enum.uniq() |> Enum.map(fn txbytes -> %Event.NonCanonicalIFE{txbytes: txbytes} end) - past_sla_margin = fn {ife, _double_spend} -> - ife.eth_height + state.sla_margin <= eth_height_now + past_sla_seconds = fn {ife, _double_spend} -> + ife.timestamp + state.sla_seconds <= time_now end late_non_canonical_ife_events = non_canonical_ifes - |> Stream.filter(past_sla_margin) + |> Stream.filter(past_sla_seconds) |> Stream.map(fn {ife, _double_spend} -> Transaction.raw_txbytes(ife.tx) end) |> Enum.uniq() |> Enum.map(fn txbytes -> %Event.UnchallengedNonCanonicalIFE{txbytes: txbytes} end) diff --git a/apps/omg_watcher/lib/omg_watcher/exit_processor/piggyback.ex b/apps/omg_watcher/lib/omg_watcher/exit_processor/piggyback.ex index ed16c2ece1..ae10d52483 100644 --- a/apps/omg_watcher/lib/omg_watcher/exit_processor/piggyback.ex +++ b/apps/omg_watcher/lib/omg_watcher/exit_processor/piggyback.ex @@ -32,6 +32,7 @@ defmodule OMG.Watcher.ExitProcessor.Piggyback do alias OMG.State.Transaction alias OMG.Utxo + alias OMG.Eth alias OMG.Watcher.Event alias OMG.Watcher.ExitProcessor alias OMG.Watcher.ExitProcessor.Core @@ -87,13 +88,13 @@ defmodule OMG.Watcher.ExitProcessor.Piggyback do end @doc """ - Returns a tuple of ivalid piggybacks and invalid piggybacks that are past SLA margin. - This is inclusive, invalid piggybacks past SLA margin are included in the invalid piggybacks list. + Returns a tuple of ivalid piggybacks and invalid piggybacks that are past SLA seconds. + This is inclusive, invalid piggybacks past SLA seconds are included in the invalid piggybacks list. """ @spec get_invalid_piggybacks_events(Core.t(), KnownTx.known_txs_by_input_t(), pos_integer()) :: {list(Event.InvalidPiggyback.t()), list(Event.UnchallengedPiggyback.t())} def get_invalid_piggybacks_events( - %Core{sla_margin: sla_margin, in_flight_exits: ifes}, + %Core{sla_seconds: sla_seconds, in_flight_exits: ifes}, known_txs_by_input, eth_height_now ) do @@ -102,15 +103,17 @@ defmodule OMG.Watcher.ExitProcessor.Piggyback do |> Map.values() |> all_invalid_piggybacks_by_ife(known_txs_by_input) + {:ok, time_now} = Eth.get_block_timestamp_by_number(eth_height_now) + invalid_piggybacks_events = to_events(invalid_piggybacks_by_ife, &to_invalid_piggyback_event/1) - past_sla_margin = fn {ife, _type, _materials} -> - ife.eth_height + sla_margin <= eth_height_now + past_sla_seconds = fn {ife, _type, _materials} -> + ife.timestamp + sla_seconds <= time_now end unchallenged_piggybacks_events = invalid_piggybacks_by_ife - |> Enum.filter(past_sla_margin) + |> Enum.filter(past_sla_seconds) |> to_events(&to_unchallenged_piggyback_event/1) {invalid_piggybacks_events, unchallenged_piggybacks_events} diff --git a/apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex b/apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex index 81593c3d65..902bde0d07 100644 --- a/apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex +++ b/apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex @@ -41,6 +41,7 @@ defmodule OMG.Watcher.ExitProcessor.StandardExit do alias OMG.Block alias OMG.State.Transaction alias OMG.Utxo + alias OMG.Eth alias OMG.Watcher.ExitProcessor alias OMG.Watcher.ExitProcessor.Core alias OMG.Watcher.ExitProcessor.DoubleSpend @@ -70,6 +71,7 @@ defmodule OMG.Watcher.ExitProcessor.StandardExit do def get_invalid(%Core{sla_seconds: sla_seconds} = state, utxo_exists?, eth_height_now) do active_exits = active_exits(state) + {:ok, time_now} = Eth.get_block_timestamp_by_number(eth_height_now) exits_invalid_by_ife = state |> TxAppendix.get_all() @@ -90,13 +92,12 @@ defmodule OMG.Watcher.ExitProcessor.StandardExit do end) invalid_exits = standard_invalid_exits |> Enum.concat(exits_invalid_by_ife) |> Enum.uniq() - + _ethereum_block_time_seconds = OMG.Eth.Configuration.ethereum_block_time_seconds() # get exits which are still invalid and after the SLA margin - # temporarily assigning ethereum_block_time_seconds= 1, will be removed on merge of #1495 late_invalid_exits = - Enum.filter(invalid_exits, fn {_, %ExitInfo{eth_height: eth_height}} -> - eth_height + sla_seconds / 1 <= eth_height_now + Enum.filter(invalid_exits, fn {_, %ExitInfo{block_timestamp: block_timestamp}} -> + block_timestamp + sla_seconds <= time_now end) {Map.new(invalid_exits), Map.new(late_invalid_exits)} diff --git a/apps/omg_watcher/test/omg_watcher/exit_processor/canonicity_test.exs b/apps/omg_watcher/test/omg_watcher/exit_processor/canonicity_test.exs index 117ac5d05b..4080a40367 100644 --- a/apps/omg_watcher/test/omg_watcher/exit_processor/canonicity_test.exs +++ b/apps/omg_watcher/test/omg_watcher/exit_processor/canonicity_test.exs @@ -330,7 +330,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_height_now: 5 + processor.sla_margin, + eth_height_now: 5 + processor.sla_seconds, blocks_result: [Block.hashed_txs_at([comp, tx1], other_blknum)], ife_input_spending_blocks_result: [Block.hashed_txs_at([comp, tx1], other_blknum)] } diff --git a/apps/omg_watcher/test/omg_watcher/exit_processor/piggyback_test.exs b/apps/omg_watcher/test/omg_watcher/exit_processor/piggyback_test.exs index 1d9432ef59..78e17f9d3a 100644 --- a/apps/omg_watcher/test/omg_watcher/exit_processor/piggyback_test.exs +++ b/apps/omg_watcher/test/omg_watcher/exit_processor/piggyback_test.exs @@ -440,7 +440,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_height_now: 5 + state.sla_margin, + eth_height_now: 5 + state.sla_seconds, ife_input_spending_blocks_result: [Block.hashed_txs_at([tx], tx_blknum)] } diff --git a/apps/omg_watcher/test/omg_watcher/exit_processor/standard_exit_test.exs b/apps/omg_watcher/test/omg_watcher/exit_processor/standard_exit_test.exs index cc8430b097..a4fc850c35 100644 --- a/apps/omg_watcher/test/omg_watcher/exit_processor/standard_exit_test.exs +++ b/apps/omg_watcher/test/omg_watcher/exit_processor/standard_exit_test.exs @@ -33,7 +33,6 @@ defmodule OMG.Watcher.ExitProcessor.StandardExitTest do only: [start_ife_from: 2, start_se_from: 3, start_se_from: 4, check_validity_filtered: 3] @eth OMG.Eth.zero_address() - @deposit_blknum 1 @deposit_blknum2 2 @early_blknum 1_000 diff --git a/apps/omg_watcher/test/omg_watcher/integration/invalid_exit_test.exs b/apps/omg_watcher/test/omg_watcher/integration/invalid_exit_test.exs index 3b4efdf190..c9636e30c6 100644 --- a/apps/omg_watcher/test/omg_watcher/integration/invalid_exit_test.exs +++ b/apps/omg_watcher/test/omg_watcher/integration/invalid_exit_test.exs @@ -117,7 +117,7 @@ defmodule OMG.Watcher.Integration.InvalidExitTest do exit_processor_sla_seconds = Application.fetch_env!(:omg_watcher, :exit_processor_sla_seconds) exit_processor_sla_ms = exit_processor_sla_seconds * 1000 - # after exit, the event fetch time + waiting for sla_margin goes beyond the required time + # after exit, the event fetch time + waiting for sla_seconds goes beyond the required time Process.sleep(exit_processor_sla_ms) IntegrationTest.wait_for_byzantine_events([%Event.InvalidExit{}.name, %Event.UnchallengedExit{}.name], @timeout) From 1ba1a3deec0396e1dba547a6f78d44459d3a3fb0 Mon Sep 17 00:00:00 2001 From: souradeep-das Date: Mon, 18 May 2020 22:14:41 +0530 Subject: [PATCH 18/28] revert to eth_height_now --- apps/omg_watcher/lib/omg_watcher/exit_processor.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/omg_watcher/lib/omg_watcher/exit_processor.ex b/apps/omg_watcher/lib/omg_watcher/exit_processor.ex index 41065fb9a9..b8cd15cf10 100644 --- a/apps/omg_watcher/lib/omg_watcher/exit_processor.ex +++ b/apps/omg_watcher/lib/omg_watcher/exit_processor.ex @@ -610,7 +610,7 @@ defmodule OMG.Watcher.ExitProcessor do end defp run_status_gets(%ExitProcessor.Request{eth_height_now: nil, blknum_now: nil} = request) do - {:ok, eth_height_now} = Eth.get_block_timestamp_by_number(EthereumHeight.get()) + {:ok, eth_height_now} = EthereumHeight.get() {blknum_now, _} = State.get_status() _ = Logger.debug("eth_height_now: #{inspect(eth_height_now)}, blknum_now: #{inspect(blknum_now)}") From 872f1b5fa8be6837fa41a214fa7415035ec2d1d3 Mon Sep 17 00:00:00 2001 From: souradeep-das Date: Thu, 28 May 2020 17:03:39 +0530 Subject: [PATCH 19/28] fix: change eth_height to eth_timestamp and fix tests --- .../lib/omg_watcher/exit_processor.ex | 8 +-- .../omg_watcher/exit_processor/canonicity.ex | 6 +- .../lib/omg_watcher/exit_processor/core.ex | 10 +-- .../exit_processor/in_flight_exit_info.ex | 1 - .../omg_watcher/exit_processor/piggyback.ex | 6 +- .../lib/omg_watcher/exit_processor/request.ex | 4 +- .../exit_processor/standard_exit.ex | 9 ++- .../exit_processor/canonicity_test.exs | 64 +++++++++---------- .../core/state_interaction_test.exs | 16 ++--- .../omg_watcher/exit_processor/core_test.exs | 8 +-- .../exit_processor/finalizations_test.exs | 6 +- .../exit_processor/piggyback_test.exs | 62 +++++++++--------- .../exit_processor/standard_exit_test.exs | 16 ++--- .../test/support/exit_processor/case.ex | 4 +- .../support/exit_processor/test_helper.ex | 2 +- 15 files changed, 110 insertions(+), 112 deletions(-) diff --git a/apps/omg_watcher/lib/omg_watcher/exit_processor.ex b/apps/omg_watcher/lib/omg_watcher/exit_processor.ex index b8cd15cf10..60c0a31365 100644 --- a/apps/omg_watcher/lib/omg_watcher/exit_processor.ex +++ b/apps/omg_watcher/lib/omg_watcher/exit_processor.ex @@ -609,12 +609,12 @@ defmodule OMG.Watcher.ExitProcessor do Core.find_ifes_in_blocks(state, prepared_request) end - defp run_status_gets(%ExitProcessor.Request{eth_height_now: nil, blknum_now: nil} = request) do - {:ok, eth_height_now} = EthereumHeight.get() + defp run_status_gets(%ExitProcessor.Request{eth_timestamp_now: nil, blknum_now: nil} = request) do + {:ok, eth_timestamp_now} = Eth.get_block_timestamp_by_number(EthereumHeight.get()) {blknum_now, _} = State.get_status() - _ = Logger.debug("eth_height_now: #{inspect(eth_height_now)}, blknum_now: #{inspect(blknum_now)}") - %{request | eth_height_now: eth_height_now, blknum_now: blknum_now} + _ = Logger.debug("eth_timestamp_now: #{inspect(eth_timestamp_now)}, blknum_now: #{inspect(blknum_now)}") + %{request | eth_timestamp_now: eth_timestamp_now, blknum_now: blknum_now} end defp get_utxo_existence(%ExitProcessor.Request{utxos_to_check: positions} = request), diff --git a/apps/omg_watcher/lib/omg_watcher/exit_processor/canonicity.ex b/apps/omg_watcher/lib/omg_watcher/exit_processor/canonicity.ex index 4ec8b0f329..8468cc2aac 100644 --- a/apps/omg_watcher/lib/omg_watcher/exit_processor/canonicity.ex +++ b/apps/omg_watcher/lib/omg_watcher/exit_processor/canonicity.ex @@ -72,7 +72,7 @@ defmodule OMG.Watcher.ExitProcessor.Canonicity do """ @spec get_ife_txs_with_competitors(Core.t(), KnownTx.known_txs_by_input_t(), pos_integer()) :: {list(Event.NonCanonicalIFE.t()), list(Event.UnchallengedNonCanonicalIFE.t())} - def get_ife_txs_with_competitors(state, known_txs_by_input, eth_height_now) do + def get_ife_txs_with_competitors(state, known_txs_by_input, eth_timestamp_now) do non_canonical_ifes = state.in_flight_exits |> Map.values() @@ -82,8 +82,6 @@ defmodule OMG.Watcher.ExitProcessor.Canonicity do InFlightExitInfo.is_viable_competitor?(ife, utxo_pos) end) - {:ok, time_now} = Eth.get_block_timestamp_by_number(eth_height_now) - non_canonical_ife_events = non_canonical_ifes |> Stream.map(fn {ife, _double_spend} -> Transaction.raw_txbytes(ife.tx) end) @@ -91,7 +89,7 @@ defmodule OMG.Watcher.ExitProcessor.Canonicity do |> Enum.map(fn txbytes -> %Event.NonCanonicalIFE{txbytes: txbytes} end) past_sla_seconds = fn {ife, _double_spend} -> - ife.timestamp + state.sla_seconds <= time_now + ife.timestamp + state.sla_seconds <= eth_timestamp_now end late_non_canonical_ife_events = diff --git a/apps/omg_watcher/lib/omg_watcher/exit_processor/core.ex b/apps/omg_watcher/lib/omg_watcher/exit_processor/core.ex index 31dcb5423d..076d868d96 100644 --- a/apps/omg_watcher/lib/omg_watcher/exit_processor/core.ex +++ b/apps/omg_watcher/lib/omg_watcher/exit_processor/core.ex @@ -459,17 +459,17 @@ defmodule OMG.Watcher.ExitProcessor.Core do @spec check_validity(ExitProcessor.Request.t(), t()) :: check_validity_result_t() def check_validity( %ExitProcessor.Request{ - eth_height_now: eth_height_now, + eth_timestamp_now: eth_timestamp_now, utxos_to_check: utxos_to_check, utxo_exists_result: utxo_exists_result, blocks_result: blocks }, %__MODULE__{} = state ) - when not is_nil(eth_height_now) do + when not is_nil(eth_timestamp_now) do utxo_exists? = Enum.zip(utxos_to_check, utxo_exists_result) |> Map.new() - {invalid_exits, late_invalid_exits} = StandardExit.get_invalid(state, utxo_exists?, eth_height_now) + {invalid_exits, late_invalid_exits} = StandardExit.get_invalid(state, utxo_exists?, eth_timestamp_now) invalid_exit_events = invalid_exits @@ -482,12 +482,12 @@ defmodule OMG.Watcher.ExitProcessor.Core do known_txs_by_input = KnownTx.get_all_from_blocks_appendix(blocks, state) {non_canonical_ife_events, late_non_canonical_ife_events} = - ExitProcessor.Canonicity.get_ife_txs_with_competitors(state, known_txs_by_input, eth_height_now) + ExitProcessor.Canonicity.get_ife_txs_with_competitors(state, known_txs_by_input, eth_timestamp_now) invalid_ife_challenges_events = ExitProcessor.Canonicity.get_invalid_ife_challenges(state) {invalid_piggybacks_events, late_invalid_piggybacks_events} = - ExitProcessor.Piggyback.get_invalid_piggybacks_events(state, known_txs_by_input, eth_height_now) + ExitProcessor.Piggyback.get_invalid_piggybacks_events(state, known_txs_by_input, eth_timestamp_now) available_piggybacks_events = state diff --git a/apps/omg_watcher/lib/omg_watcher/exit_processor/in_flight_exit_info.ex b/apps/omg_watcher/lib/omg_watcher/exit_processor/in_flight_exit_info.ex index 886a23f150..7e648e3512 100644 --- a/apps/omg_watcher/lib/omg_watcher/exit_processor/in_flight_exit_info.ex +++ b/apps/omg_watcher/lib/omg_watcher/exit_processor/in_flight_exit_info.ex @@ -121,7 +121,6 @@ defmodule OMG.Watcher.ExitProcessor.InFlightExitInfo do defp do_new(tx_bytes, tx_signatures, contract_status, fields) do {timestamp, is_active} = parse_contract_in_flight_exit_status(contract_status) - with {:ok, tx} <- prepare_tx(tx_bytes, tx_signatures) do # NOTE: in case of using output_id as the input pointer, getting the youngest will be entirely different Utxo.position(youngest_input_blknum, _, _) = diff --git a/apps/omg_watcher/lib/omg_watcher/exit_processor/piggyback.ex b/apps/omg_watcher/lib/omg_watcher/exit_processor/piggyback.ex index ae10d52483..ee59e331a7 100644 --- a/apps/omg_watcher/lib/omg_watcher/exit_processor/piggyback.ex +++ b/apps/omg_watcher/lib/omg_watcher/exit_processor/piggyback.ex @@ -96,19 +96,17 @@ defmodule OMG.Watcher.ExitProcessor.Piggyback do def get_invalid_piggybacks_events( %Core{sla_seconds: sla_seconds, in_flight_exits: ifes}, known_txs_by_input, - eth_height_now + eth_timestamp_now ) do invalid_piggybacks_by_ife = ifes |> Map.values() |> all_invalid_piggybacks_by_ife(known_txs_by_input) - {:ok, time_now} = Eth.get_block_timestamp_by_number(eth_height_now) - invalid_piggybacks_events = to_events(invalid_piggybacks_by_ife, &to_invalid_piggyback_event/1) past_sla_seconds = fn {ife, _type, _materials} -> - ife.timestamp + sla_seconds <= time_now + ife.timestamp + sla_seconds <= eth_timestamp_now end unchallenged_piggybacks_events = diff --git a/apps/omg_watcher/lib/omg_watcher/exit_processor/request.ex b/apps/omg_watcher/lib/omg_watcher/exit_processor/request.ex index 9c9c07f603..20d2107833 100644 --- a/apps/omg_watcher/lib/omg_watcher/exit_processor/request.ex +++ b/apps/omg_watcher/lib/omg_watcher/exit_processor/request.ex @@ -23,7 +23,7 @@ defmodule OMG.Watcher.ExitProcessor.Request do alias OMG.Utxo defstruct [ - :eth_height_now, + :eth_timestamp_now, :blknum_now, utxos_to_check: [], spends_to_get: [], @@ -41,7 +41,7 @@ defmodule OMG.Watcher.ExitProcessor.Request do ] @type t :: %__MODULE__{ - eth_height_now: nil | pos_integer, + eth_timestamp_now: nil | pos_integer, blknum_now: nil | pos_integer, utxos_to_check: list(Utxo.Position.t()), spends_to_get: list(Utxo.Position.t()), diff --git a/apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex b/apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex index 902bde0d07..9377227f42 100644 --- a/apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex +++ b/apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex @@ -68,10 +68,13 @@ defmodule OMG.Watcher.ExitProcessor.StandardExit do """ @spec get_invalid(Core.t(), %{Utxo.Position.t() => boolean}, pos_integer()) :: {%{Utxo.Position.t() => ExitInfo.t()}, %{Utxo.Position.t() => ExitInfo.t()}} - def get_invalid(%Core{sla_seconds: sla_seconds} = state, utxo_exists?, eth_height_now) do + def get_invalid( + %Core{sla_seconds: sla_seconds} = state, + utxo_exists?, + eth_timestamp_now + ) do active_exits = active_exits(state) - {:ok, time_now} = Eth.get_block_timestamp_by_number(eth_height_now) exits_invalid_by_ife = state |> TxAppendix.get_all() @@ -97,7 +100,7 @@ defmodule OMG.Watcher.ExitProcessor.StandardExit do # get exits which are still invalid and after the SLA margin late_invalid_exits = Enum.filter(invalid_exits, fn {_, %ExitInfo{block_timestamp: block_timestamp}} -> - block_timestamp + sla_seconds <= time_now + block_timestamp + sla_seconds <= eth_timestamp_now end) {Map.new(invalid_exits), Map.new(late_invalid_exits)} diff --git a/apps/omg_watcher/test/omg_watcher/exit_processor/canonicity_test.exs b/apps/omg_watcher/test/omg_watcher/exit_processor/canonicity_test.exs index 4080a40367..95acba3abb 100644 --- a/apps/omg_watcher/test/omg_watcher/exit_processor/canonicity_test.exs +++ b/apps/omg_watcher/test/omg_watcher/exit_processor/canonicity_test.exs @@ -48,7 +48,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do test "none if input never spent elsewhere", %{processor_filled: processor} do assert {:ok, []} = - %ExitProcessor.Request{blknum_now: 1000, eth_height_now: 5} + %ExitProcessor.Request{blknum_now: 1000, eth_timestamp_now: :os.system_time(:second) + 5} |> check_validity_filtered(processor, exclude: [Event.PiggybackAvailable]) end @@ -58,11 +58,11 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do processor = processor |> start_ife_from(comp) assert {:ok, []} = - %ExitProcessor.Request{blknum_now: 1000, eth_height_now: 5} + %ExitProcessor.Request{blknum_now: 1000, eth_timestamp_now: :os.system_time(:second) + 5} |> check_validity_filtered(processor, exclude: [Event.PiggybackAvailable]) assert {:error, :competitor_not_found} = - %ExitProcessor.Request{blknum_now: 5000, eth_height_now: 5} + %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: :os.system_time(:second) + 5} |> Core.get_competitor_for_ife(processor, txbytes) end @@ -72,7 +72,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do exit_processor_request = %ExitProcessor.Request{ blknum_now: 5000, - eth_height_now: 5, + eth_timestamp_now: :os.system_time(:second) + 5, blocks_result: [Block.hashed_txs_at([comp], 3000)] } @@ -88,7 +88,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do exit_processor_request = %ExitProcessor.Request{ blknum_now: 5000, - eth_height_now: 5, + eth_timestamp_now: :os.system_time(:second) + 5, blocks_result: [Block.hashed_txs_at([tx1], 3000)] } @@ -106,11 +106,11 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do processor = processor |> start_ife_from(tx) assert {:ok, []} = - %ExitProcessor.Request{blknum_now: 5000, eth_height_now: 5} + %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: :os.system_time(:second) + 5} |> check_validity_filtered(processor, exclude: [Event.PiggybackAvailable]) assert {:error, :competitor_not_found} = - %ExitProcessor.Request{blknum_now: 5000, eth_height_now: 5} + %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: :os.system_time(:second) + 5} |> Core.get_competitor_for_ife(processor, txbytes) end @@ -121,7 +121,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do processor = processor |> start_ife_from(comp) assert {:ok, events} = - %ExitProcessor.Request{blknum_now: 5000, eth_height_now: 5} + %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: :os.system_time(:second) + 5} |> check_validity_filtered(processor, only: [Event.NonCanonicalIFE]) assert_events(events, [%Event.NonCanonicalIFE{txbytes: txbytes}, %Event.NonCanonicalIFE{txbytes: comp_txbytes}]) @@ -136,7 +136,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do competing_tx_pos: Utxo.position(0, 0, 0), competing_proof: "" }} = - %ExitProcessor.Request{blknum_now: 5000, eth_height_now: 5} + %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: :os.system_time(:second) + 5} |> Core.get_competitor_for_ife(processor, txbytes) end @@ -150,7 +150,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do challenge_event = ife_challenge(tx2, comp) {processor, _} = Core.new_ife_challenges(processor, [challenge_event]) - exit_processor_request = %ExitProcessor.Request{blknum_now: 5000, eth_height_now: 5} + exit_processor_request = %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: :os.system_time(:second) + 5} assert {:ok, [%Event.NonCanonicalIFE{txbytes: ^txbytes}]} = exit_processor_request |> check_validity_filtered(processor, only: [Event.NonCanonicalIFE]) @@ -173,7 +173,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do exit_processor_request = %ExitProcessor.Request{ blknum_now: 5000, - eth_height_now: 5, + eth_timestamp_now: :os.system_time(:second) + 5, blocks_result: [Block.hashed_txs_at([comp], other_blknum)] } @@ -205,7 +205,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_height_now: 5, + eth_timestamp_now: :os.system_time(:second) + 5, blocks_result: [Block.hashed_txs_at([comp, comp], other_blknum)], ife_input_spending_blocks_result: [Block.hashed_txs_at([comp, comp], other_blknum)] } @@ -249,7 +249,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do comp1 = TestHelper.create_recovered([{1, 0, 0, alice}], [{alice, @eth, 1}]) comp2 = TestHelper.create_recovered([{1, 0, 0, alice}], [{alice, @eth, 2}]) txbytes = txbytes(tx1) - request = %ExitProcessor.Request{blknum_now: 5000, eth_height_now: 5} + request = %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: :os.system_time(:second) + 5} processor = processor |> start_ife_from(comp1) |> start_ife_from(comp2) # before any challenge @@ -272,7 +272,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_height_now: 5, + eth_timestamp_now: :os.system_time(:second) + 5, ife_input_spending_blocks_result: [Block.hashed_txs_at([tx1], other_blknum)] } @@ -292,7 +292,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_height_now: 5, + eth_timestamp_now: :os.system_time(:second) + 5, blocks_result: [Block.hashed_txs_at([tx1, comp], other_blknum)], ife_input_spending_blocks_result: [Block.hashed_txs_at([tx1, comp], other_blknum)] } @@ -310,7 +310,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_height_now: 5, + eth_timestamp_now: :os.system_time(:second) + 5, blocks_result: [Block.hashed_txs_at([comp, tx1], other_blknum)], ife_input_spending_blocks_result: [Block.hashed_txs_at([comp, tx1], other_blknum)] } @@ -330,7 +330,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_height_now: 5 + processor.sla_seconds, + eth_timestamp_now: :os.system_time(:second) + 5 + processor.sla_seconds, blocks_result: [Block.hashed_txs_at([comp, tx1], other_blknum)], ife_input_spending_blocks_result: [Block.hashed_txs_at([comp, tx1], other_blknum)] } @@ -349,7 +349,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_height_now: 5, + eth_timestamp_now: :os.system_time(:second) + 5, blocks_result: [block1, block2], # note the flipped order here, all still works as the blocks should be processed starting from oldest ife_input_spending_blocks_result: [block2, block1] @@ -370,7 +370,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_height_now: 5, + eth_timestamp_now: :os.system_time(:second) + 5, blocks_result: [Block.hashed_txs_at([comp], other_blknum)] } @@ -420,7 +420,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do exit_processor_request = %ExitProcessor.Request{ blknum_now: 5000, - eth_height_now: 5, + eth_timestamp_now: :os.system_time(:second) + 5, blocks_result: [Block.hashed_txs_at([other_recovered], 3000)] } @@ -448,7 +448,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do exit_processor_request = %ExitProcessor.Request{ blknum_now: 5000, - eth_height_now: 5, + eth_timestamp_now: :os.system_time(:second) + 5, blocks_result: [Block.hashed_txs_at([comp], 3000)] } @@ -471,7 +471,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do exit_processor_request = %ExitProcessor.Request{ blknum_now: 5000, - eth_height_now: 5, + eth_timestamp_now: :os.system_time(:second) + 5, blocks_result: [Block.hashed_txs_at([recovered_oldest], 2000), Block.hashed_txs_at([recovered_recent], 3000)] } @@ -552,7 +552,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do txbytes = txbytes(tx) processor = processor |> start_ife_from(comp) - request = %ExitProcessor.Request{blknum_now: 1000, eth_height_now: 5} + request = %ExitProcessor.Request{blknum_now: 1000, eth_timestamp_now: :os.system_time(:second) + 5} assert {:ok, %{input_tx: "input_tx", input_utxo_pos: Utxo.position(1, 0, 0)}} = Core.get_competitor_for_ife(request, processor, txbytes) @@ -568,7 +568,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do test "none if input not yet created during sync", %{processor_filled: processor} do assert %{utxos_to_check: to_check} = - %ExitProcessor.Request{blknum_now: 1000, eth_height_now: 13} + %ExitProcessor.Request{blknum_now: 1000, eth_timestamp_now: :os.system_time(:second) + 13} |> Core.determine_utxo_existence_to_get(processor) assert Utxo.position(9000, 0, 1) not in to_check @@ -579,14 +579,14 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do txbytes = Transaction.raw_txbytes(tx) assert {:error, :ife_not_known_for_tx} = - %ExitProcessor.Request{blknum_now: 5000, eth_height_now: 5} + %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: :os.system_time(:second) + 5} |> Core.get_competitor_for_ife(processor, txbytes) end test "for malformed input txbytes doesn't crash", %{processor_empty: processor} do assert {:error, :malformed_transaction} = - %ExitProcessor.Request{blknum_now: 5000, eth_height_now: 5} + %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: :os.system_time(:second) + 5} |> Core.get_competitor_for_ife(processor, <<0>>) end end @@ -600,7 +600,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_height_now: 5, + eth_timestamp_now: :os.system_time(:second) + 5, ife_input_spending_blocks_result: [Block.hashed_txs_at(txs, other_blknum)] } @@ -621,20 +621,20 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do test "proving canonical for nonexistent tx doesn't crash", %{processor_empty: processor, transactions: [tx | _]} do txbytes = Transaction.raw_txbytes(tx) - request = %ExitProcessor.Request{blknum_now: 5000, eth_height_now: 5} + request = %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: :os.system_time(:second) + 5} processor = processor |> Core.find_ifes_in_blocks(request) assert {:error, :ife_not_known_for_tx} = Core.prove_canonical_for_ife(processor, txbytes) end test "for malformed input txbytes doesn't crash", %{processor_empty: processor} do - request = %ExitProcessor.Request{blknum_now: 5000, eth_height_now: 5} + request = %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: :os.system_time(:second) + 5} processor = processor |> Core.find_ifes_in_blocks(request) assert {:error, :malformed_transaction} = Core.prove_canonical_for_ife(processor, <<0>>) end test "none if ifes are fresh and canonical by default", %{processor_filled: processor} do assert {:ok, []} = - %ExitProcessor.Request{blknum_now: 5000, eth_height_now: 5} + %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: :os.system_time(:second) + 5} |> check_validity_filtered(processor, exclude: [Event.PiggybackAvailable]) end @@ -650,7 +650,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_height_now: 5, + eth_timestamp_now: :os.system_time(:second) + 5, ife_input_spending_blocks_result: [Block.hashed_txs_at(txs, other_blknum)] } @@ -667,7 +667,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_height_now: 5, + eth_timestamp_now: :os.system_time(:second) + 5, # NOTE: `tx` is included twice ife_input_spending_blocks_result: [Block.hashed_txs_at([tx, tx], other_blknum)] } diff --git a/apps/omg_watcher/test/omg_watcher/exit_processor/core/state_interaction_test.exs b/apps/omg_watcher/test/omg_watcher/exit_processor/core/state_interaction_test.exs index 12b09c3955..592f961962 100644 --- a/apps/omg_watcher/test/omg_watcher/exit_processor/core/state_interaction_test.exs +++ b/apps/omg_watcher/test/omg_watcher/exit_processor/core/state_interaction_test.exs @@ -73,7 +73,7 @@ defmodule OMG.Watcher.ExitProcessor.Core.StateInteractionTest do processor = start_se_from(processor, standard_exit_tx, @utxo_pos1) assert {:ok, [%Event.InvalidExit{utxo_pos: ^exiting_position}]} = - %ExitProcessor.Request{eth_height_now: 5, blknum_now: @late_blknum} + %ExitProcessor.Request{eth_timestamp_now: 5 + :os.system_time(:second), blknum_now: @late_blknum} |> Core.determine_utxo_existence_to_get(processor) |> mock_utxo_exists(state) |> Core.check_validity(processor) @@ -85,7 +85,7 @@ defmodule OMG.Watcher.ExitProcessor.Core.StateInteractionTest do processor = start_se_from(processor, standard_exit_tx, Utxo.position(@late_blknum, 0, 0)) assert {:ok, []} = - %ExitProcessor.Request{eth_height_now: 13, blknum_now: @early_blknum} + %ExitProcessor.Request{eth_timestamp_now: 13 + :os.system_time(:second), blknum_now: @early_blknum} |> Core.determine_utxo_existence_to_get(processor) |> mock_utxo_exists(state) |> Core.check_validity(processor) @@ -111,7 +111,7 @@ defmodule OMG.Watcher.ExitProcessor.Core.StateInteractionTest do assert {processor, _} = Core.finalize_exits(processor, two_spend) assert {{:error, :unchallenged_exit}, [_event1, _event2, _event3]} = - %ExitProcessor.Request{eth_height_now: 12, blknum_now: @late_blknum} + %ExitProcessor.Request{eth_timestamp_now: 12 + :os.system_time(:second), blknum_now: @late_blknum} |> Core.determine_utxo_existence_to_get(processor) |> mock_utxo_exists(state_after_spend) |> Core.check_validity(processor) @@ -125,14 +125,14 @@ defmodule OMG.Watcher.ExitProcessor.Core.StateInteractionTest do processor = start_se_from(processor, standard_exit_tx, @utxo_pos1) assert {:ok, []} = - %ExitProcessor.Request{eth_height_now: 5, blknum_now: @late_blknum} + %ExitProcessor.Request{eth_timestamp_now: 5 + :os.system_time(:second), blknum_now: @late_blknum} |> Core.determine_utxo_existence_to_get(processor) |> mock_utxo_exists(state) |> Core.check_validity(processor) # go into the future - old exits work the same assert {:ok, []} = - %ExitProcessor.Request{eth_height_now: 105, blknum_now: @late_blknum} + %ExitProcessor.Request{eth_timestamp_now: 105 + :os.system_time(:second), blknum_now: @late_blknum} |> Core.determine_utxo_existence_to_get(processor) |> mock_utxo_exists(state) |> Core.check_validity(processor) @@ -196,7 +196,7 @@ defmodule OMG.Watcher.ExitProcessor.Core.StateInteractionTest do {:ok, {block, _}, state} = State.Core.form_block(state) - request = %ExitProcessor.Request{blknum_now: 5000, eth_height_now: 5, ife_input_spending_blocks_result: [block]} + request = %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: 5 + :os.system_time(:second), ife_input_spending_blocks_result: [block]} processor = processor @@ -229,7 +229,7 @@ defmodule OMG.Watcher.ExitProcessor.Core.StateInteractionTest do ife_id = 1 # ife tx cannot be found in blocks, hence `ife_input_spending_blocks_result: []` - request = %ExitProcessor.Request{blknum_now: 5000, eth_height_now: 5, ife_input_spending_blocks_result: []} + request = %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: 5 + :os.system_time(:second), ife_input_spending_blocks_result: []} processor = processor @@ -262,7 +262,7 @@ defmodule OMG.Watcher.ExitProcessor.Core.StateInteractionTest do {:ok, {_, _, _}, state} = State.Core.exec(state, spending_tx, @fee) {:ok, {block, _}, state} = State.Core.form_block(state) - request = %ExitProcessor.Request{blknum_now: 5000, eth_height_now: 5, ife_input_spending_blocks_result: [block]} + request = %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: 5 + :os.system_time(:second), ife_input_spending_blocks_result: [block]} processor = processor diff --git a/apps/omg_watcher/test/omg_watcher/exit_processor/core_test.exs b/apps/omg_watcher/test/omg_watcher/exit_processor/core_test.exs index e06ad4d618..d24384dcd9 100644 --- a/apps/omg_watcher/test/omg_watcher/exit_processor/core_test.exs +++ b/apps/omg_watcher/test/omg_watcher/exit_processor/core_test.exs @@ -204,7 +204,7 @@ defmodule OMG.Watcher.ExitProcessor.CoreTest do describe "finding IFE txs in blocks" do test "handles well situation when syncing is in progress", %{processor_filled: state} do assert %ExitProcessor.Request{utxos_to_check: [], ife_input_utxos_to_check: []} = - %ExitProcessor.Request{eth_height_now: 13, blknum_now: 0} + %ExitProcessor.Request{eth_timestamp_now: 13, blknum_now: 0} |> Core.determine_ife_input_utxos_existence_to_get(state) |> Core.determine_utxo_existence_to_get(state) end @@ -212,7 +212,7 @@ defmodule OMG.Watcher.ExitProcessor.CoreTest do test "seeks all IFE txs' inputs spends in blocks", %{processor_filled: processor, transactions: txs} do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_height_now: 5 + eth_timestamp_now: 5 } # for one piggybacked output, we're asking for its inputs positions to check utxo existence @@ -237,7 +237,7 @@ defmodule OMG.Watcher.ExitProcessor.CoreTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_height_now: 5 + eth_timestamp_now: 5 } # for one piggybacked output, we're asking for its inputs positions to check utxo existence @@ -251,7 +251,7 @@ defmodule OMG.Watcher.ExitProcessor.CoreTest do %{processor_filled: processor, transactions: [tx1, tx2]} do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_height_now: 5, + eth_timestamp_now: 5, ife_input_spending_blocks_result: [Block.hashed_txs_at([tx1], 3000)] } diff --git a/apps/omg_watcher/test/omg_watcher/exit_processor/finalizations_test.exs b/apps/omg_watcher/test/omg_watcher/exit_processor/finalizations_test.exs index 084d7a63d9..06d6da4969 100644 --- a/apps/omg_watcher/test/omg_watcher/exit_processor/finalizations_test.exs +++ b/apps/omg_watcher/test/omg_watcher/exit_processor/finalizations_test.exs @@ -51,7 +51,7 @@ defmodule OMG.Watcher.ExitProcessor.FinalizationsTest do # both IFE txs are inlcuded in one of the blocks and picked up by the `ExitProcessor` request = %ExitProcessor.Request{ blknum_now: 5000, - eth_height_now: 5, + eth_timestamp_now: 5, ife_input_spending_blocks_result: [Block.hashed_txs_at([tx1], tx1_blknum)] } @@ -85,7 +85,7 @@ defmodule OMG.Watcher.ExitProcessor.FinalizationsTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_height_now: 5, + eth_timestamp_now: 5, ife_input_spending_blocks_result: [] } @@ -118,7 +118,7 @@ defmodule OMG.Watcher.ExitProcessor.FinalizationsTest do # both IFE txs are inlcuded in one of the blocks and picked up by the `ExitProcessor` request = %ExitProcessor.Request{ blknum_now: 5000, - eth_height_now: 5, + eth_timestamp_now: 5, ife_input_spending_blocks_result: [Block.hashed_txs_at([tx1, tx2], tx2_blknum)] } diff --git a/apps/omg_watcher/test/omg_watcher/exit_processor/piggyback_test.exs b/apps/omg_watcher/test/omg_watcher/exit_processor/piggyback_test.exs index 78e17f9d3a..765a969f8f 100644 --- a/apps/omg_watcher/test/omg_watcher/exit_processor/piggyback_test.exs +++ b/apps/omg_watcher/test/omg_watcher/exit_processor/piggyback_test.exs @@ -108,7 +108,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do txbytes_2 = Transaction.raw_txbytes(tx2) assert {:ok, events} = - %ExitProcessor.Request{blknum_now: 5000, eth_height_now: 5} + %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: :os.system_time(:second) + 5} |> Core.check_validity(processor) assert_events(events, [ @@ -133,7 +133,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do processor = processor |> start_ife_from(tx) assert {:ok, [%Event.PiggybackAvailable{txbytes: ^txbytes}]} = - %ExitProcessor.Request{blknum_now: 5000, eth_height_now: 5} + %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: :os.system_time(:second) + 5} |> Core.check_validity(processor) end @@ -148,7 +148,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do processor = processor |> start_ife_from(signed_tx, sigs: sigs) assert {:ok, [%Event.PiggybackAvailable{txbytes: ^txbytes}]} = - %ExitProcessor.Request{blknum_now: 5000, eth_height_now: 5} + %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: :os.system_time(:second) + 5} |> Core.check_validity(processor) end @@ -158,7 +158,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_height_now: 5, + eth_timestamp_now: :os.system_time(:second) + 5, ife_input_spending_blocks_result: [Block.hashed_txs_at([tx1], 3000)] } @@ -183,7 +183,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do txbytes: ^txbytes } ]} = - check_validity_filtered(%ExitProcessor.Request{blknum_now: 1000, eth_height_now: 5}, processor, + check_validity_filtered(%ExitProcessor.Request{blknum_now: 1000, eth_timestamp_now: :os.system_time(:second) + 5}, processor, only: [Event.PiggybackAvailable] ) end @@ -201,7 +201,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do available_outputs: [%{index: 0}] } ]} = - check_validity_filtered(%ExitProcessor.Request{blknum_now: 1000, eth_height_now: 5}, processor, + check_validity_filtered(%ExitProcessor.Request{blknum_now: 1000, eth_timestamp_now: :os.system_time(:second) + 5}, processor, only: [Event.PiggybackAvailable] ) end @@ -219,7 +219,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do available_outputs: [] } ]} = - check_validity_filtered(%ExitProcessor.Request{blknum_now: 1000, eth_height_now: 5}, processor, + check_validity_filtered(%ExitProcessor.Request{blknum_now: 1000, eth_timestamp_now: :os.system_time(:second) + 5}, processor, only: [Event.PiggybackAvailable] ) end @@ -242,7 +242,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do available_outputs: [] } ]} = - check_validity_filtered(%ExitProcessor.Request{blknum_now: 1000, eth_height_now: 5}, processor, + check_validity_filtered(%ExitProcessor.Request{blknum_now: 1000, eth_timestamp_now: :os.system_time(:second) + 5}, processor, only: [Event.PiggybackAvailable] ) end @@ -256,7 +256,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do {:ok, processor, _} = Core.finalize_in_flight_exits(processor, [finalization], %{}) assert {:ok, []} = - check_validity_filtered(%ExitProcessor.Request{blknum_now: 1000, eth_height_now: 5}, processor, + check_validity_filtered(%ExitProcessor.Request{blknum_now: 1000, eth_timestamp_now: :os.system_time(:second) + 5}, processor, only: [Event.PiggybackAvailable] ) end @@ -264,12 +264,12 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do test "challenged IFEs emit the same piggybacks as canonical ones", %{processor_filled: processor, transactions: [tx | _], competing_tx: comp} do assert {:ok, events_canonical} = - Core.check_validity(%ExitProcessor.Request{blknum_now: 1000, eth_height_now: 5}, processor) + Core.check_validity(%ExitProcessor.Request{blknum_now: 1000, eth_timestamp_now: :os.system_time(:second) + 5}, processor) {challenged_processor, _} = Core.new_ife_challenges(processor, [ife_challenge(tx, comp)]) assert {:ok, events_challenged} = - Core.check_validity(%ExitProcessor.Request{blknum_now: 5000, eth_height_now: 5}, challenged_processor) + Core.check_validity(%ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: :os.system_time(:second) + 5}, challenged_processor) assert_events(events_canonical, events_challenged) end @@ -281,7 +281,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do processor = processor |> start_ife_from(comp) assert {:ok, []} = - %ExitProcessor.Request{blknum_now: 5000, eth_height_now: 5} + %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: :os.system_time(:second) + 5} |> check_validity_filtered(processor, only: [Event.InvalidPiggyback]) end @@ -294,7 +294,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_height_now: 5, + eth_timestamp_now: :os.system_time(:second) + 5, ife_input_spending_blocks_result: [Block.hashed_txs_at([tx], tx_blknum)] } @@ -302,7 +302,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do processor = processor |> start_ife_from(comp) |> Core.find_ifes_in_blocks(request) assert {:ok, []} = - %ExitProcessor.Request{blknum_now: 5000, eth_height_now: 5} + %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: :os.system_time(:second) + 5} |> check_validity_filtered(processor, only: [Event.InvalidPiggyback]) end @@ -311,7 +311,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do txbytes = txbytes(tx) {comp_txbytes, other_sig} = {txbytes(comp), sig(comp, 1)} state = state |> start_ife_from(comp) |> piggyback_ife_from(ife_id, 0, :input) - request = %ExitProcessor.Request{blknum_now: 1000, eth_height_now: 5} + request = %ExitProcessor.Request{blknum_now: 1000, eth_timestamp_now: :os.system_time(:second) + 5} assert {:ok, [%Event.InvalidPiggyback{txbytes: ^txbytes, inputs: [0], outputs: []}]} = check_validity_filtered(request, state, only: [Event.InvalidPiggyback]) @@ -341,7 +341,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do %{} ) - request = %ExitProcessor.Request{blknum_now: 1000, eth_height_now: 5} + request = %ExitProcessor.Request{blknum_now: 1000, eth_timestamp_now: :os.system_time(:second) + 5} assert {:ok, [%Event.InvalidPiggyback{txbytes: ^txbytes, inputs: [0], outputs: []}]} = check_validity_filtered(request, state, only: [Event.InvalidPiggyback]) @@ -357,7 +357,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do |> piggyback_ife_from(tx_hash, 0, :input) |> Core.challenge_piggybacks([%{tx_hash: tx_hash, output_index: 0, omg_data: %{piggyback_type: :input}}]) - request = %ExitProcessor.Request{blknum_now: 1000, eth_height_now: 5} + request = %ExitProcessor.Request{blknum_now: 1000, eth_timestamp_now: :os.system_time(:second) + 5} assert {:ok, []} = check_validity_filtered(request, state, only: [Event.InvalidPiggyback]) @@ -374,7 +374,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_height_now: 5, + eth_timestamp_now: :os.system_time(:second) + 5, blocks_result: [Block.hashed_txs_at([comp], comp_blknum)] } @@ -405,7 +405,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_height_now: 5, + eth_timestamp_now: :os.system_time(:second) + 5, ife_input_spending_blocks_result: [Block.hashed_txs_at([tx], tx_blknum)] } @@ -440,7 +440,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_height_now: 5 + state.sla_seconds, + eth_timestamp_now: :os.system_time(:second) + 5 + state.sla_seconds, ife_input_spending_blocks_result: [Block.hashed_txs_at([tx], tx_blknum)] } @@ -465,7 +465,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_height_now: 5, + eth_timestamp_now: :os.system_time(:second) + 5, ife_input_spending_blocks_result: [Block.hashed_txs_at([tx], tx_blknum)] } @@ -492,7 +492,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_height_now: 5, + eth_timestamp_now: :os.system_time(:second) + 5, ife_input_spending_blocks_result: [Block.hashed_txs_at([tx], tx_blknum)] } @@ -524,7 +524,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_height_now: 5, + eth_timestamp_now: :os.system_time(:second) + 5, ife_input_spending_blocks_result: [Block.hashed_txs_at([tx], tx_blknum)], blocks_result: [Block.hashed_txs_at([comp], comp_blknum)] } @@ -560,7 +560,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_height_now: 5, + eth_timestamp_now: :os.system_time(:second) + 5, ife_input_spending_blocks_result: [Block.hashed_txs_at([tx], tx_blknum)], blocks_result: [Block.hashed_txs_at([comp], comp_blknum)] } @@ -595,7 +595,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_height_now: 5, + eth_timestamp_now: :os.system_time(:second) + 5, ife_input_spending_blocks_result: [Block.hashed_txs_at([tx], tx_blknum)], blocks_result: [Block.hashed_txs_at([comp], comp_blknum)] } @@ -631,7 +631,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_height_now: 5, + eth_timestamp_now: :os.system_time(:second) + 5, ife_input_spending_blocks_result: [Block.hashed_txs_at([other_tx, tx], tx_blknum)], blocks_result: [Block.hashed_txs_at([comp], comp_blknum)] } @@ -659,7 +659,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do # NOTE: the piggybacked index is the second one, compared to the invalid piggyback situation request = %ExitProcessor.Request{ blknum_now: 5000, - eth_height_now: 5, + eth_timestamp_now: :os.system_time(:second) + 5, blocks_result: [Block.hashed_txs_at([comp], 4000)] } @@ -678,7 +678,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_height_now: 5, + eth_timestamp_now: :os.system_time(:second) + 5, ife_input_spending_blocks_result: [Block.hashed_txs_at([tx], tx_blknum)], blocks_result: [Block.hashed_txs_at([comp], 4000)] } @@ -692,7 +692,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do %{processor_filled: state, transactions: [tx | _], ife_tx_hashes: [ife_id | _]} do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_height_now: 5, + eth_timestamp_now: :os.system_time(:second) + 5, ife_input_spending_blocks_result: [Block.hashed_txs_at([tx], 3000)] } @@ -719,7 +719,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do request = %ExitProcessor.Request{ blknum_now: 4000, - eth_height_now: 5, + eth_timestamp_now: :os.system_time(:second) + 5, ife_input_spending_blocks_result: [Block.hashed_txs_at([tx], tx_blknum)] } @@ -771,7 +771,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do txbytes = txbytes(tx) state = state |> start_ife_from(comp) |> piggyback_ife_from(ife_id, 0, :input) - request = %ExitProcessor.Request{blknum_now: 1000, eth_height_now: 5} + request = %ExitProcessor.Request{blknum_now: 1000, eth_timestamp_now: :os.system_time(:second) + 5} assert {:ok, %{input_tx: "input_tx", input_utxo_pos: Utxo.position(1, 0, 0)}} = Core.get_input_challenge_data(request, state, txbytes, 0) diff --git a/apps/omg_watcher/test/omg_watcher/exit_processor/standard_exit_test.exs b/apps/omg_watcher/test/omg_watcher/exit_processor/standard_exit_test.exs index a4fc850c35..d80c0c70f8 100644 --- a/apps/omg_watcher/test/omg_watcher/exit_processor/standard_exit_test.exs +++ b/apps/omg_watcher/test/omg_watcher/exit_processor/standard_exit_test.exs @@ -366,7 +366,7 @@ defmodule OMG.Watcher.ExitProcessor.StandardExitTest do standard_exit_tx = TestHelper.create_recovered([{@blknum, 0, 0, alice}], @eth, [{alice, 10}]) request = %ExitProcessor.Request{ - eth_height_now: 5, + eth_timestamp_now: 5 + :os.system_time(:second), blknum_now: @late_blknum, utxos_to_check: [exiting_pos], utxo_exists_result: [false] @@ -393,7 +393,7 @@ defmodule OMG.Watcher.ExitProcessor.StandardExitTest do standard_exit_tx = TestHelper.create_recovered([{@blknum, 0, 0, alice}], @eth, [{alice, 10}]) request = %ExitProcessor.Request{ - eth_height_now: 50, + eth_timestamp_now: 50 + :os.system_time(:second), blknum_now: @late_blknum, utxos_to_check: [exiting_pos], utxo_exists_result: [false] @@ -418,7 +418,7 @@ defmodule OMG.Watcher.ExitProcessor.StandardExitTest do standard_exit_tx = TestHelper.create_recovered([{@deposit_blknum, 0, 0, alice}], @eth, [{alice, 10}]) request = %ExitProcessor.Request{ - eth_height_now: 13, + eth_timestamp_now: 13 + :os.system_time(:second), blknum_now: @late_blknum, utxos_to_check: [exiting_pos], utxo_exists_result: [false] @@ -436,7 +436,7 @@ defmodule OMG.Watcher.ExitProcessor.StandardExitTest do processor = processor |> start_se_from(standard_exit_tx, exiting_pos) assert %ExitProcessor.Request{utxos_to_check: []} = - %ExitProcessor.Request{eth_height_now: 13, blknum_now: @early_blknum} + %ExitProcessor.Request{eth_timestamp_now: 13 + :os.system_time(:second), blknum_now: @early_blknum} |> Core.determine_utxo_existence_to_get(processor) end @@ -449,7 +449,7 @@ defmodule OMG.Watcher.ExitProcessor.StandardExitTest do processor = processor |> start_se_from(standard_exit_tx, exiting_pos) |> start_ife_from(tx) assert {:ok, [%Event.InvalidExit{utxo_pos: ^exiting_pos_enc, spending_txhash: ^tx_hash}]} = - check_validity_filtered(%ExitProcessor.Request{eth_height_now: 5, blknum_now: @late_blknum}, processor, + check_validity_filtered(%ExitProcessor.Request{eth_timestamp_now: 5 + :os.system_time(:second), blknum_now: @late_blknum}, processor, only: [Event.InvalidExit] ) end @@ -463,7 +463,7 @@ defmodule OMG.Watcher.ExitProcessor.StandardExitTest do assert %{utxos_to_check: [_, Utxo.position(1, 2, 1), @utxo_pos_tx]} = exit_processor_request = - %ExitProcessor.Request{eth_height_now: 5, blknum_now: @late_blknum} + %ExitProcessor.Request{eth_timestamp_now: 5 + :os.system_time(:second), blknum_now: @late_blknum} |> Core.determine_utxo_existence_to_get(processor) block_updates = [{:put, :block, %{number: @blknum, hash: <<0::160>>, transactions: [signed_tx_bytes]}}] @@ -491,7 +491,7 @@ defmodule OMG.Watcher.ExitProcessor.StandardExitTest do # doesn't check the challenged SE utxo assert %{utxos_to_check: [_, Utxo.position(1, 2, 1)]} = exit_processor_request = - %ExitProcessor.Request{eth_height_now: 5, blknum_now: @late_blknum} + %ExitProcessor.Request{eth_timestamp_now: 5 + :os.system_time(:second), blknum_now: @late_blknum} |> Core.determine_utxo_existence_to_get(processor) # doesn't alert on the challenged SE, despite it being a double-spend wrt the IFE @@ -508,7 +508,7 @@ defmodule OMG.Watcher.ExitProcessor.StandardExitTest do assert %{utxos_to_check: [_, Utxo.position(1, 2, 1), @utxo_pos_tx]} = exit_processor_request = - %ExitProcessor.Request{eth_height_now: 5, blknum_now: @late_blknum} + %ExitProcessor.Request{eth_timestamp_now: 5 + :os.system_time(:second), blknum_now: @late_blknum} |> Core.determine_utxo_existence_to_get(processor) assert {:ok, []} = diff --git a/apps/omg_watcher/test/support/exit_processor/case.ex b/apps/omg_watcher/test/support/exit_processor/case.ex index f6605eac08..e0e0d3e141 100644 --- a/apps/omg_watcher/test/support/exit_processor/case.ex +++ b/apps/omg_watcher/test/support/exit_processor/case.ex @@ -85,7 +85,7 @@ defmodule OMG.Watcher.ExitProcessor.Case do defp invalid_piggyback_on_input(state, [tx | _], [ife_id | _], competing_tx) do request = %ExitProcessor.Request{ blknum_now: 4000, - eth_height_now: 5, + eth_timestamp_now: 5, ife_input_spending_blocks_result: [Block.hashed_txs_at([tx], 3000)] } @@ -118,7 +118,7 @@ defmodule OMG.Watcher.ExitProcessor.Case do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_height_now: 5, + eth_timestamp_now: 5, blocks_result: [block], ife_input_spending_blocks_result: [block, Block.hashed_txs_at([comp], comp_blknum)] } diff --git a/apps/omg_watcher/test/support/exit_processor/test_helper.ex b/apps/omg_watcher/test/support/exit_processor/test_helper.ex index 9e3d5ad496..69a7ae699d 100644 --- a/apps/omg_watcher/test/support/exit_processor/test_helper.ex +++ b/apps/omg_watcher/test/support/exit_processor/test_helper.ex @@ -79,7 +79,7 @@ defmodule OMG.Watcher.ExitProcessor.TestHelper do # See `OMG.Eth.RootChain.get_in_flight_exits_structs/2` for reference of where this comes from # `nil`s are unused portions of the returns data from the contract - def active_ife_status(), do: {nil, 1, nil, nil, nil, nil, nil} + def active_ife_status(), do: {nil, :os.system_time(:second), nil, nil, nil, nil, nil} def inactive_ife_status(), do: {nil, 0, nil, nil, nil, nil, nil} def piggyback_ife_from(%Core{} = processor, tx_hash, output_index, piggyback_type) do From 67d08db7e42e16afad889b9495670be8ba2e49fb Mon Sep 17 00:00:00 2001 From: souradeep-das Date: Thu, 28 May 2020 17:14:49 +0530 Subject: [PATCH 20/28] fix: update eth_timestamp_now in finalization and core tests --- .../test/omg_watcher/exit_processor/core_test.exs | 8 ++++---- .../omg_watcher/exit_processor/finalizations_test.exs | 6 +++--- apps/omg_watcher/test/support/exit_processor/case.ex | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/apps/omg_watcher/test/omg_watcher/exit_processor/core_test.exs b/apps/omg_watcher/test/omg_watcher/exit_processor/core_test.exs index d24384dcd9..2d3633de15 100644 --- a/apps/omg_watcher/test/omg_watcher/exit_processor/core_test.exs +++ b/apps/omg_watcher/test/omg_watcher/exit_processor/core_test.exs @@ -204,7 +204,7 @@ defmodule OMG.Watcher.ExitProcessor.CoreTest do describe "finding IFE txs in blocks" do test "handles well situation when syncing is in progress", %{processor_filled: state} do assert %ExitProcessor.Request{utxos_to_check: [], ife_input_utxos_to_check: []} = - %ExitProcessor.Request{eth_timestamp_now: 13, blknum_now: 0} + %ExitProcessor.Request{eth_timestamp_now: :os.system_time(:second) + 13, blknum_now: 0} |> Core.determine_ife_input_utxos_existence_to_get(state) |> Core.determine_utxo_existence_to_get(state) end @@ -212,7 +212,7 @@ defmodule OMG.Watcher.ExitProcessor.CoreTest do test "seeks all IFE txs' inputs spends in blocks", %{processor_filled: processor, transactions: txs} do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_timestamp_now: 5 + eth_timestamp_now: :os.system_time(:second) + 5 } # for one piggybacked output, we're asking for its inputs positions to check utxo existence @@ -237,7 +237,7 @@ defmodule OMG.Watcher.ExitProcessor.CoreTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_timestamp_now: 5 + eth_timestamp_now: :os.system_time(:second) + 5 } # for one piggybacked output, we're asking for its inputs positions to check utxo existence @@ -251,7 +251,7 @@ defmodule OMG.Watcher.ExitProcessor.CoreTest do %{processor_filled: processor, transactions: [tx1, tx2]} do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_timestamp_now: 5, + eth_timestamp_now: :os.system_time(:second) + 5, ife_input_spending_blocks_result: [Block.hashed_txs_at([tx1], 3000)] } diff --git a/apps/omg_watcher/test/omg_watcher/exit_processor/finalizations_test.exs b/apps/omg_watcher/test/omg_watcher/exit_processor/finalizations_test.exs index 06d6da4969..9226442f73 100644 --- a/apps/omg_watcher/test/omg_watcher/exit_processor/finalizations_test.exs +++ b/apps/omg_watcher/test/omg_watcher/exit_processor/finalizations_test.exs @@ -51,7 +51,7 @@ defmodule OMG.Watcher.ExitProcessor.FinalizationsTest do # both IFE txs are inlcuded in one of the blocks and picked up by the `ExitProcessor` request = %ExitProcessor.Request{ blknum_now: 5000, - eth_timestamp_now: 5, + eth_timestamp_now: :os.system_time(:second) + 5, ife_input_spending_blocks_result: [Block.hashed_txs_at([tx1], tx1_blknum)] } @@ -85,7 +85,7 @@ defmodule OMG.Watcher.ExitProcessor.FinalizationsTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_timestamp_now: 5, + eth_timestamp_now: :os.system_time(:second) + 5, ife_input_spending_blocks_result: [] } @@ -118,7 +118,7 @@ defmodule OMG.Watcher.ExitProcessor.FinalizationsTest do # both IFE txs are inlcuded in one of the blocks and picked up by the `ExitProcessor` request = %ExitProcessor.Request{ blknum_now: 5000, - eth_timestamp_now: 5, + eth_timestamp_now: :os.system_time(:second) + 5, ife_input_spending_blocks_result: [Block.hashed_txs_at([tx1, tx2], tx2_blknum)] } diff --git a/apps/omg_watcher/test/support/exit_processor/case.ex b/apps/omg_watcher/test/support/exit_processor/case.ex index e0e0d3e141..14adb0b527 100644 --- a/apps/omg_watcher/test/support/exit_processor/case.ex +++ b/apps/omg_watcher/test/support/exit_processor/case.ex @@ -85,7 +85,7 @@ defmodule OMG.Watcher.ExitProcessor.Case do defp invalid_piggyback_on_input(state, [tx | _], [ife_id | _], competing_tx) do request = %ExitProcessor.Request{ blknum_now: 4000, - eth_timestamp_now: 5, + eth_timestamp_now: :os.system_time(:second) + 5, ife_input_spending_blocks_result: [Block.hashed_txs_at([tx], 3000)] } @@ -118,7 +118,7 @@ defmodule OMG.Watcher.ExitProcessor.Case do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_timestamp_now: 5, + eth_timestamp_now: :os.system_time(:second) + 5, blocks_result: [block], ife_input_spending_blocks_result: [block, Block.hashed_txs_at([comp], comp_blknum)] } From 84b44722774f7d377ee52f845daea13a5927ebcc Mon Sep 17 00:00:00 2001 From: souradeep-das Date: Thu, 28 May 2020 18:58:55 +0530 Subject: [PATCH 21/28] fix: get_block_timestamp in exit_processor --- apps/omg_watcher/lib/omg_watcher/exit_processor.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/omg_watcher/lib/omg_watcher/exit_processor.ex b/apps/omg_watcher/lib/omg_watcher/exit_processor.ex index bfb46481a3..f363781470 100644 --- a/apps/omg_watcher/lib/omg_watcher/exit_processor.ex +++ b/apps/omg_watcher/lib/omg_watcher/exit_processor.ex @@ -633,7 +633,8 @@ defmodule OMG.Watcher.ExitProcessor do end defp run_status_gets(%ExitProcessor.Request{eth_timestamp_now: nil, blknum_now: nil} = request) do - {:ok, eth_timestamp_now} = Eth.get_block_timestamp_by_number(EthereumHeight.get()) + {:ok, eth_height_now} = EthereumHeight.get() + {:ok, eth_timestamp_now} = Eth.get_block_timestamp_by_number(eth_height_now) {blknum_now, _} = State.get_status() _ = Logger.debug("eth_timestamp_now: #{inspect(eth_timestamp_now)}, blknum_now: #{inspect(blknum_now)}") From 4a98cda25c02d2224cfb7bf3195364a006f6d174 Mon Sep 17 00:00:00 2001 From: souradeep-das Date: Fri, 29 May 2020 16:26:35 +0530 Subject: [PATCH 22/28] refactor: remove unix time usage --- .../exit_processor/standard_exit.ex | 3 +- .../exit_processor/canonicity_test.exs | 64 +++++++++---------- .../core/state_interaction_test.exs | 16 ++--- .../omg_watcher/exit_processor/core_test.exs | 8 +-- .../exit_processor/finalizations_test.exs | 6 +- .../exit_processor/piggyback_test.exs | 62 +++++++++--------- .../exit_processor/standard_exit_test.exs | 16 ++--- .../test/support/exit_processor/case.ex | 4 +- .../support/exit_processor/test_helper.ex | 4 +- 9 files changed, 92 insertions(+), 91 deletions(-) diff --git a/apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex b/apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex index 9377227f42..0e82ed6017 100644 --- a/apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex +++ b/apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex @@ -99,7 +99,8 @@ defmodule OMG.Watcher.ExitProcessor.StandardExit do _ethereum_block_time_seconds = OMG.Eth.Configuration.ethereum_block_time_seconds() # get exits which are still invalid and after the SLA margin late_invalid_exits = - Enum.filter(invalid_exits, fn {_, %ExitInfo{block_timestamp: block_timestamp}} -> + Enum.filter(invalid_exits, fn {_, %ExitInfo{block_timestamp: block_timestamp, eth_height: eth_height}} -> + IO.inspect(eth_height) block_timestamp + sla_seconds <= eth_timestamp_now end) diff --git a/apps/omg_watcher/test/omg_watcher/exit_processor/canonicity_test.exs b/apps/omg_watcher/test/omg_watcher/exit_processor/canonicity_test.exs index 95acba3abb..d5b1e19d32 100644 --- a/apps/omg_watcher/test/omg_watcher/exit_processor/canonicity_test.exs +++ b/apps/omg_watcher/test/omg_watcher/exit_processor/canonicity_test.exs @@ -48,7 +48,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do test "none if input never spent elsewhere", %{processor_filled: processor} do assert {:ok, []} = - %ExitProcessor.Request{blknum_now: 1000, eth_timestamp_now: :os.system_time(:second) + 5} + %ExitProcessor.Request{blknum_now: 1000, eth_timestamp_now: 5} |> check_validity_filtered(processor, exclude: [Event.PiggybackAvailable]) end @@ -58,11 +58,11 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do processor = processor |> start_ife_from(comp) assert {:ok, []} = - %ExitProcessor.Request{blknum_now: 1000, eth_timestamp_now: :os.system_time(:second) + 5} + %ExitProcessor.Request{blknum_now: 1000, eth_timestamp_now: 5} |> check_validity_filtered(processor, exclude: [Event.PiggybackAvailable]) assert {:error, :competitor_not_found} = - %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: :os.system_time(:second) + 5} + %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: 5} |> Core.get_competitor_for_ife(processor, txbytes) end @@ -72,7 +72,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do exit_processor_request = %ExitProcessor.Request{ blknum_now: 5000, - eth_timestamp_now: :os.system_time(:second) + 5, + eth_timestamp_now: 5, blocks_result: [Block.hashed_txs_at([comp], 3000)] } @@ -88,7 +88,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do exit_processor_request = %ExitProcessor.Request{ blknum_now: 5000, - eth_timestamp_now: :os.system_time(:second) + 5, + eth_timestamp_now: 5, blocks_result: [Block.hashed_txs_at([tx1], 3000)] } @@ -106,11 +106,11 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do processor = processor |> start_ife_from(tx) assert {:ok, []} = - %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: :os.system_time(:second) + 5} + %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: 5} |> check_validity_filtered(processor, exclude: [Event.PiggybackAvailable]) assert {:error, :competitor_not_found} = - %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: :os.system_time(:second) + 5} + %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: 5} |> Core.get_competitor_for_ife(processor, txbytes) end @@ -121,7 +121,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do processor = processor |> start_ife_from(comp) assert {:ok, events} = - %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: :os.system_time(:second) + 5} + %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: 5} |> check_validity_filtered(processor, only: [Event.NonCanonicalIFE]) assert_events(events, [%Event.NonCanonicalIFE{txbytes: txbytes}, %Event.NonCanonicalIFE{txbytes: comp_txbytes}]) @@ -136,7 +136,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do competing_tx_pos: Utxo.position(0, 0, 0), competing_proof: "" }} = - %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: :os.system_time(:second) + 5} + %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: 5} |> Core.get_competitor_for_ife(processor, txbytes) end @@ -150,7 +150,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do challenge_event = ife_challenge(tx2, comp) {processor, _} = Core.new_ife_challenges(processor, [challenge_event]) - exit_processor_request = %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: :os.system_time(:second) + 5} + exit_processor_request = %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: 5} assert {:ok, [%Event.NonCanonicalIFE{txbytes: ^txbytes}]} = exit_processor_request |> check_validity_filtered(processor, only: [Event.NonCanonicalIFE]) @@ -173,7 +173,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do exit_processor_request = %ExitProcessor.Request{ blknum_now: 5000, - eth_timestamp_now: :os.system_time(:second) + 5, + eth_timestamp_now: 5, blocks_result: [Block.hashed_txs_at([comp], other_blknum)] } @@ -205,7 +205,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_timestamp_now: :os.system_time(:second) + 5, + eth_timestamp_now: 5, blocks_result: [Block.hashed_txs_at([comp, comp], other_blknum)], ife_input_spending_blocks_result: [Block.hashed_txs_at([comp, comp], other_blknum)] } @@ -249,7 +249,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do comp1 = TestHelper.create_recovered([{1, 0, 0, alice}], [{alice, @eth, 1}]) comp2 = TestHelper.create_recovered([{1, 0, 0, alice}], [{alice, @eth, 2}]) txbytes = txbytes(tx1) - request = %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: :os.system_time(:second) + 5} + request = %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: 5} processor = processor |> start_ife_from(comp1) |> start_ife_from(comp2) # before any challenge @@ -272,7 +272,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_timestamp_now: :os.system_time(:second) + 5, + eth_timestamp_now: 5, ife_input_spending_blocks_result: [Block.hashed_txs_at([tx1], other_blknum)] } @@ -292,7 +292,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_timestamp_now: :os.system_time(:second) + 5, + eth_timestamp_now: 5, blocks_result: [Block.hashed_txs_at([tx1, comp], other_blknum)], ife_input_spending_blocks_result: [Block.hashed_txs_at([tx1, comp], other_blknum)] } @@ -310,7 +310,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_timestamp_now: :os.system_time(:second) + 5, + eth_timestamp_now: 5, blocks_result: [Block.hashed_txs_at([comp, tx1], other_blknum)], ife_input_spending_blocks_result: [Block.hashed_txs_at([comp, tx1], other_blknum)] } @@ -330,7 +330,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_timestamp_now: :os.system_time(:second) + 5 + processor.sla_seconds, + eth_timestamp_now: 5 + processor.sla_seconds, blocks_result: [Block.hashed_txs_at([comp, tx1], other_blknum)], ife_input_spending_blocks_result: [Block.hashed_txs_at([comp, tx1], other_blknum)] } @@ -349,7 +349,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_timestamp_now: :os.system_time(:second) + 5, + eth_timestamp_now: 5, blocks_result: [block1, block2], # note the flipped order here, all still works as the blocks should be processed starting from oldest ife_input_spending_blocks_result: [block2, block1] @@ -370,7 +370,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_timestamp_now: :os.system_time(:second) + 5, + eth_timestamp_now: 5, blocks_result: [Block.hashed_txs_at([comp], other_blknum)] } @@ -420,7 +420,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do exit_processor_request = %ExitProcessor.Request{ blknum_now: 5000, - eth_timestamp_now: :os.system_time(:second) + 5, + eth_timestamp_now: 5, blocks_result: [Block.hashed_txs_at([other_recovered], 3000)] } @@ -448,7 +448,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do exit_processor_request = %ExitProcessor.Request{ blknum_now: 5000, - eth_timestamp_now: :os.system_time(:second) + 5, + eth_timestamp_now: 5, blocks_result: [Block.hashed_txs_at([comp], 3000)] } @@ -471,7 +471,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do exit_processor_request = %ExitProcessor.Request{ blknum_now: 5000, - eth_timestamp_now: :os.system_time(:second) + 5, + eth_timestamp_now: 5, blocks_result: [Block.hashed_txs_at([recovered_oldest], 2000), Block.hashed_txs_at([recovered_recent], 3000)] } @@ -552,7 +552,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do txbytes = txbytes(tx) processor = processor |> start_ife_from(comp) - request = %ExitProcessor.Request{blknum_now: 1000, eth_timestamp_now: :os.system_time(:second) + 5} + request = %ExitProcessor.Request{blknum_now: 1000, eth_timestamp_now: 5} assert {:ok, %{input_tx: "input_tx", input_utxo_pos: Utxo.position(1, 0, 0)}} = Core.get_competitor_for_ife(request, processor, txbytes) @@ -568,7 +568,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do test "none if input not yet created during sync", %{processor_filled: processor} do assert %{utxos_to_check: to_check} = - %ExitProcessor.Request{blknum_now: 1000, eth_timestamp_now: :os.system_time(:second) + 13} + %ExitProcessor.Request{blknum_now: 1000, eth_timestamp_now: 13} |> Core.determine_utxo_existence_to_get(processor) assert Utxo.position(9000, 0, 1) not in to_check @@ -579,14 +579,14 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do txbytes = Transaction.raw_txbytes(tx) assert {:error, :ife_not_known_for_tx} = - %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: :os.system_time(:second) + 5} + %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: 5} |> Core.get_competitor_for_ife(processor, txbytes) end test "for malformed input txbytes doesn't crash", %{processor_empty: processor} do assert {:error, :malformed_transaction} = - %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: :os.system_time(:second) + 5} + %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: 5} |> Core.get_competitor_for_ife(processor, <<0>>) end end @@ -600,7 +600,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_timestamp_now: :os.system_time(:second) + 5, + eth_timestamp_now: 5, ife_input_spending_blocks_result: [Block.hashed_txs_at(txs, other_blknum)] } @@ -621,20 +621,20 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do test "proving canonical for nonexistent tx doesn't crash", %{processor_empty: processor, transactions: [tx | _]} do txbytes = Transaction.raw_txbytes(tx) - request = %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: :os.system_time(:second) + 5} + request = %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: 5} processor = processor |> Core.find_ifes_in_blocks(request) assert {:error, :ife_not_known_for_tx} = Core.prove_canonical_for_ife(processor, txbytes) end test "for malformed input txbytes doesn't crash", %{processor_empty: processor} do - request = %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: :os.system_time(:second) + 5} + request = %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: 5} processor = processor |> Core.find_ifes_in_blocks(request) assert {:error, :malformed_transaction} = Core.prove_canonical_for_ife(processor, <<0>>) end test "none if ifes are fresh and canonical by default", %{processor_filled: processor} do assert {:ok, []} = - %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: :os.system_time(:second) + 5} + %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: 5} |> check_validity_filtered(processor, exclude: [Event.PiggybackAvailable]) end @@ -650,7 +650,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_timestamp_now: :os.system_time(:second) + 5, + eth_timestamp_now: 5, ife_input_spending_blocks_result: [Block.hashed_txs_at(txs, other_blknum)] } @@ -667,7 +667,7 @@ defmodule OMG.Watcher.ExitProcessor.CanonicityTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_timestamp_now: :os.system_time(:second) + 5, + eth_timestamp_now: 5, # NOTE: `tx` is included twice ife_input_spending_blocks_result: [Block.hashed_txs_at([tx, tx], other_blknum)] } diff --git a/apps/omg_watcher/test/omg_watcher/exit_processor/core/state_interaction_test.exs b/apps/omg_watcher/test/omg_watcher/exit_processor/core/state_interaction_test.exs index 1f0b7ad69a..9b5d5ba63b 100644 --- a/apps/omg_watcher/test/omg_watcher/exit_processor/core/state_interaction_test.exs +++ b/apps/omg_watcher/test/omg_watcher/exit_processor/core/state_interaction_test.exs @@ -74,7 +74,7 @@ defmodule OMG.Watcher.ExitProcessor.Core.StateInteractionTest do processor = start_se_from(processor, standard_exit_tx, @utxo_pos1) assert {:ok, [%Event.InvalidExit{utxo_pos: ^exiting_position}]} = - %ExitProcessor.Request{eth_timestamp_now: 5 + :os.system_time(:second), blknum_now: @late_blknum} + %ExitProcessor.Request{eth_timestamp_now: 5, blknum_now: @late_blknum} |> Core.determine_utxo_existence_to_get(processor) |> mock_utxo_exists(state) |> Core.check_validity(processor) @@ -86,7 +86,7 @@ defmodule OMG.Watcher.ExitProcessor.Core.StateInteractionTest do processor = start_se_from(processor, standard_exit_tx, Utxo.position(@late_blknum, 0, 0)) assert {:ok, []} = - %ExitProcessor.Request{eth_timestamp_now: 13 + :os.system_time(:second), blknum_now: @early_blknum} + %ExitProcessor.Request{eth_timestamp_now: 13, blknum_now: @early_blknum} |> Core.determine_utxo_existence_to_get(processor) |> mock_utxo_exists(state) |> Core.check_validity(processor) @@ -112,7 +112,7 @@ defmodule OMG.Watcher.ExitProcessor.Core.StateInteractionTest do assert {processor, _} = Core.finalize_exits(processor, two_spend) assert {{:error, :unchallenged_exit}, [_event1, _event2, _event3]} = - %ExitProcessor.Request{eth_timestamp_now: 12 + :os.system_time(:second), blknum_now: @late_blknum} + %ExitProcessor.Request{eth_timestamp_now: 12, blknum_now: @late_blknum} |> Core.determine_utxo_existence_to_get(processor) |> mock_utxo_exists(state_after_spend) |> Core.check_validity(processor) @@ -126,14 +126,14 @@ defmodule OMG.Watcher.ExitProcessor.Core.StateInteractionTest do processor = start_se_from(processor, standard_exit_tx, @utxo_pos1) assert {:ok, []} = - %ExitProcessor.Request{eth_timestamp_now: 5 + :os.system_time(:second), blknum_now: @late_blknum} + %ExitProcessor.Request{eth_timestamp_now: 5, blknum_now: @late_blknum} |> Core.determine_utxo_existence_to_get(processor) |> mock_utxo_exists(state) |> Core.check_validity(processor) # go into the future - old exits work the same assert {:ok, []} = - %ExitProcessor.Request{eth_timestamp_now: 105 + :os.system_time(:second), blknum_now: @late_blknum} + %ExitProcessor.Request{eth_timestamp_now: 105, blknum_now: @late_blknum} |> Core.determine_utxo_existence_to_get(processor) |> mock_utxo_exists(state) |> Core.check_validity(processor) @@ -197,7 +197,7 @@ defmodule OMG.Watcher.ExitProcessor.Core.StateInteractionTest do {:ok, {block, _}, state} = State.Core.form_block(state) - request = %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: 5 + :os.system_time(:second), ife_input_spending_blocks_result: [block]} + request = %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: 5, ife_input_spending_blocks_result: [block]} processor = processor @@ -235,7 +235,7 @@ defmodule OMG.Watcher.ExitProcessor.Core.StateInteractionTest do ife_id = 1 # ife tx cannot be found in blocks, hence `ife_input_spending_blocks_result: []` - request = %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: 5 + :os.system_time(:second), ife_input_spending_blocks_result: []} + request = %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: 5, ife_input_spending_blocks_result: []} processor = processor @@ -268,7 +268,7 @@ defmodule OMG.Watcher.ExitProcessor.Core.StateInteractionTest do {:ok, {_, _, _}, state} = State.Core.exec(state, spending_tx, @fee) {:ok, {block, _}, state} = State.Core.form_block(state) - request = %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: 5 + :os.system_time(:second), ife_input_spending_blocks_result: [block]} + request = %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: 5, ife_input_spending_blocks_result: [block]} processor = processor diff --git a/apps/omg_watcher/test/omg_watcher/exit_processor/core_test.exs b/apps/omg_watcher/test/omg_watcher/exit_processor/core_test.exs index b4fcb2e917..f3429e2485 100644 --- a/apps/omg_watcher/test/omg_watcher/exit_processor/core_test.exs +++ b/apps/omg_watcher/test/omg_watcher/exit_processor/core_test.exs @@ -204,7 +204,7 @@ defmodule OMG.Watcher.ExitProcessor.CoreTest do describe "finding IFE txs in blocks" do test "handles well situation when syncing is in progress", %{processor_filled: state} do assert %ExitProcessor.Request{utxos_to_check: [], ife_input_utxos_to_check: []} = - %ExitProcessor.Request{eth_timestamp_now: :os.system_time(:second) + 13, blknum_now: 0} + %ExitProcessor.Request{eth_timestamp_now: 13, blknum_now: 0} |> Core.determine_ife_input_utxos_existence_to_get(state) |> Core.determine_utxo_existence_to_get(state) end @@ -212,7 +212,7 @@ defmodule OMG.Watcher.ExitProcessor.CoreTest do test "seeks all IFE txs' inputs spends in blocks", %{processor_filled: processor, transactions: txs} do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_timestamp_now: :os.system_time(:second) + 5 + eth_timestamp_now: 5 } # for one piggybacked output, we're asking for its inputs positions to check utxo existence @@ -237,7 +237,7 @@ defmodule OMG.Watcher.ExitProcessor.CoreTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_timestamp_now: :os.system_time(:second) + 5 + eth_timestamp_now: 5 } # for one piggybacked output, we're asking for its inputs positions to check utxo existence @@ -251,7 +251,7 @@ defmodule OMG.Watcher.ExitProcessor.CoreTest do %{processor_filled: processor, transactions: [tx1, tx2]} do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_timestamp_now: :os.system_time(:second) + 5, + eth_timestamp_now: 5, ife_input_spending_blocks_result: [Block.hashed_txs_at([tx1], 3000)] } diff --git a/apps/omg_watcher/test/omg_watcher/exit_processor/finalizations_test.exs b/apps/omg_watcher/test/omg_watcher/exit_processor/finalizations_test.exs index 3518ad1e41..fbb4ece208 100644 --- a/apps/omg_watcher/test/omg_watcher/exit_processor/finalizations_test.exs +++ b/apps/omg_watcher/test/omg_watcher/exit_processor/finalizations_test.exs @@ -51,7 +51,7 @@ defmodule OMG.Watcher.ExitProcessor.FinalizationsTest do # both IFE txs are inlcuded in one of the blocks and picked up by the `ExitProcessor` request = %ExitProcessor.Request{ blknum_now: 5000, - eth_timestamp_now: :os.system_time(:second) + 5, + eth_timestamp_now: 5, ife_input_spending_blocks_result: [Block.hashed_txs_at([tx1], tx1_blknum)] } @@ -88,7 +88,7 @@ defmodule OMG.Watcher.ExitProcessor.FinalizationsTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_timestamp_now: :os.system_time(:second) + 5, + eth_timestamp_now: 5, ife_input_spending_blocks_result: [] } @@ -121,7 +121,7 @@ defmodule OMG.Watcher.ExitProcessor.FinalizationsTest do # both IFE txs are inlcuded in one of the blocks and picked up by the `ExitProcessor` request = %ExitProcessor.Request{ blknum_now: 5000, - eth_timestamp_now: :os.system_time(:second) + 5, + eth_timestamp_now: 5, ife_input_spending_blocks_result: [Block.hashed_txs_at([tx1, tx2], tx2_blknum)] } diff --git a/apps/omg_watcher/test/omg_watcher/exit_processor/piggyback_test.exs b/apps/omg_watcher/test/omg_watcher/exit_processor/piggyback_test.exs index 765a969f8f..d0710c69e4 100644 --- a/apps/omg_watcher/test/omg_watcher/exit_processor/piggyback_test.exs +++ b/apps/omg_watcher/test/omg_watcher/exit_processor/piggyback_test.exs @@ -108,7 +108,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do txbytes_2 = Transaction.raw_txbytes(tx2) assert {:ok, events} = - %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: :os.system_time(:second) + 5} + %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: 5} |> Core.check_validity(processor) assert_events(events, [ @@ -133,7 +133,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do processor = processor |> start_ife_from(tx) assert {:ok, [%Event.PiggybackAvailable{txbytes: ^txbytes}]} = - %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: :os.system_time(:second) + 5} + %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: 5} |> Core.check_validity(processor) end @@ -148,7 +148,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do processor = processor |> start_ife_from(signed_tx, sigs: sigs) assert {:ok, [%Event.PiggybackAvailable{txbytes: ^txbytes}]} = - %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: :os.system_time(:second) + 5} + %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: 5} |> Core.check_validity(processor) end @@ -158,7 +158,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_timestamp_now: :os.system_time(:second) + 5, + eth_timestamp_now: 5, ife_input_spending_blocks_result: [Block.hashed_txs_at([tx1], 3000)] } @@ -183,7 +183,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do txbytes: ^txbytes } ]} = - check_validity_filtered(%ExitProcessor.Request{blknum_now: 1000, eth_timestamp_now: :os.system_time(:second) + 5}, processor, + check_validity_filtered(%ExitProcessor.Request{blknum_now: 1000, eth_timestamp_now: 5}, processor, only: [Event.PiggybackAvailable] ) end @@ -201,7 +201,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do available_outputs: [%{index: 0}] } ]} = - check_validity_filtered(%ExitProcessor.Request{blknum_now: 1000, eth_timestamp_now: :os.system_time(:second) + 5}, processor, + check_validity_filtered(%ExitProcessor.Request{blknum_now: 1000, eth_timestamp_now: 5}, processor, only: [Event.PiggybackAvailable] ) end @@ -219,7 +219,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do available_outputs: [] } ]} = - check_validity_filtered(%ExitProcessor.Request{blknum_now: 1000, eth_timestamp_now: :os.system_time(:second) + 5}, processor, + check_validity_filtered(%ExitProcessor.Request{blknum_now: 1000, eth_timestamp_now: 5}, processor, only: [Event.PiggybackAvailable] ) end @@ -242,7 +242,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do available_outputs: [] } ]} = - check_validity_filtered(%ExitProcessor.Request{blknum_now: 1000, eth_timestamp_now: :os.system_time(:second) + 5}, processor, + check_validity_filtered(%ExitProcessor.Request{blknum_now: 1000, eth_timestamp_now: 5}, processor, only: [Event.PiggybackAvailable] ) end @@ -256,7 +256,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do {:ok, processor, _} = Core.finalize_in_flight_exits(processor, [finalization], %{}) assert {:ok, []} = - check_validity_filtered(%ExitProcessor.Request{blknum_now: 1000, eth_timestamp_now: :os.system_time(:second) + 5}, processor, + check_validity_filtered(%ExitProcessor.Request{blknum_now: 1000, eth_timestamp_now: 5}, processor, only: [Event.PiggybackAvailable] ) end @@ -264,12 +264,12 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do test "challenged IFEs emit the same piggybacks as canonical ones", %{processor_filled: processor, transactions: [tx | _], competing_tx: comp} do assert {:ok, events_canonical} = - Core.check_validity(%ExitProcessor.Request{blknum_now: 1000, eth_timestamp_now: :os.system_time(:second) + 5}, processor) + Core.check_validity(%ExitProcessor.Request{blknum_now: 1000, eth_timestamp_now: 5}, processor) {challenged_processor, _} = Core.new_ife_challenges(processor, [ife_challenge(tx, comp)]) assert {:ok, events_challenged} = - Core.check_validity(%ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: :os.system_time(:second) + 5}, challenged_processor) + Core.check_validity(%ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: 5}, challenged_processor) assert_events(events_canonical, events_challenged) end @@ -281,7 +281,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do processor = processor |> start_ife_from(comp) assert {:ok, []} = - %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: :os.system_time(:second) + 5} + %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: 5} |> check_validity_filtered(processor, only: [Event.InvalidPiggyback]) end @@ -294,7 +294,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_timestamp_now: :os.system_time(:second) + 5, + eth_timestamp_now: 5, ife_input_spending_blocks_result: [Block.hashed_txs_at([tx], tx_blknum)] } @@ -302,7 +302,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do processor = processor |> start_ife_from(comp) |> Core.find_ifes_in_blocks(request) assert {:ok, []} = - %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: :os.system_time(:second) + 5} + %ExitProcessor.Request{blknum_now: 5000, eth_timestamp_now: 5} |> check_validity_filtered(processor, only: [Event.InvalidPiggyback]) end @@ -311,7 +311,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do txbytes = txbytes(tx) {comp_txbytes, other_sig} = {txbytes(comp), sig(comp, 1)} state = state |> start_ife_from(comp) |> piggyback_ife_from(ife_id, 0, :input) - request = %ExitProcessor.Request{blknum_now: 1000, eth_timestamp_now: :os.system_time(:second) + 5} + request = %ExitProcessor.Request{blknum_now: 1000, eth_timestamp_now: 5} assert {:ok, [%Event.InvalidPiggyback{txbytes: ^txbytes, inputs: [0], outputs: []}]} = check_validity_filtered(request, state, only: [Event.InvalidPiggyback]) @@ -341,7 +341,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do %{} ) - request = %ExitProcessor.Request{blknum_now: 1000, eth_timestamp_now: :os.system_time(:second) + 5} + request = %ExitProcessor.Request{blknum_now: 1000, eth_timestamp_now: 5} assert {:ok, [%Event.InvalidPiggyback{txbytes: ^txbytes, inputs: [0], outputs: []}]} = check_validity_filtered(request, state, only: [Event.InvalidPiggyback]) @@ -357,7 +357,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do |> piggyback_ife_from(tx_hash, 0, :input) |> Core.challenge_piggybacks([%{tx_hash: tx_hash, output_index: 0, omg_data: %{piggyback_type: :input}}]) - request = %ExitProcessor.Request{blknum_now: 1000, eth_timestamp_now: :os.system_time(:second) + 5} + request = %ExitProcessor.Request{blknum_now: 1000, eth_timestamp_now: 5} assert {:ok, []} = check_validity_filtered(request, state, only: [Event.InvalidPiggyback]) @@ -374,7 +374,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_timestamp_now: :os.system_time(:second) + 5, + eth_timestamp_now: 5, blocks_result: [Block.hashed_txs_at([comp], comp_blknum)] } @@ -405,7 +405,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_timestamp_now: :os.system_time(:second) + 5, + eth_timestamp_now: 5, ife_input_spending_blocks_result: [Block.hashed_txs_at([tx], tx_blknum)] } @@ -440,7 +440,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_timestamp_now: :os.system_time(:second) + 5 + state.sla_seconds, + eth_timestamp_now: 5 + state.sla_seconds, ife_input_spending_blocks_result: [Block.hashed_txs_at([tx], tx_blknum)] } @@ -465,7 +465,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_timestamp_now: :os.system_time(:second) + 5, + eth_timestamp_now: 5, ife_input_spending_blocks_result: [Block.hashed_txs_at([tx], tx_blknum)] } @@ -492,7 +492,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_timestamp_now: :os.system_time(:second) + 5, + eth_timestamp_now: 5, ife_input_spending_blocks_result: [Block.hashed_txs_at([tx], tx_blknum)] } @@ -524,7 +524,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_timestamp_now: :os.system_time(:second) + 5, + eth_timestamp_now: 5, ife_input_spending_blocks_result: [Block.hashed_txs_at([tx], tx_blknum)], blocks_result: [Block.hashed_txs_at([comp], comp_blknum)] } @@ -560,7 +560,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_timestamp_now: :os.system_time(:second) + 5, + eth_timestamp_now: 5, ife_input_spending_blocks_result: [Block.hashed_txs_at([tx], tx_blknum)], blocks_result: [Block.hashed_txs_at([comp], comp_blknum)] } @@ -595,7 +595,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_timestamp_now: :os.system_time(:second) + 5, + eth_timestamp_now: 5, ife_input_spending_blocks_result: [Block.hashed_txs_at([tx], tx_blknum)], blocks_result: [Block.hashed_txs_at([comp], comp_blknum)] } @@ -631,7 +631,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_timestamp_now: :os.system_time(:second) + 5, + eth_timestamp_now: 5, ife_input_spending_blocks_result: [Block.hashed_txs_at([other_tx, tx], tx_blknum)], blocks_result: [Block.hashed_txs_at([comp], comp_blknum)] } @@ -659,7 +659,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do # NOTE: the piggybacked index is the second one, compared to the invalid piggyback situation request = %ExitProcessor.Request{ blknum_now: 5000, - eth_timestamp_now: :os.system_time(:second) + 5, + eth_timestamp_now: 5, blocks_result: [Block.hashed_txs_at([comp], 4000)] } @@ -678,7 +678,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_timestamp_now: :os.system_time(:second) + 5, + eth_timestamp_now: 5, ife_input_spending_blocks_result: [Block.hashed_txs_at([tx], tx_blknum)], blocks_result: [Block.hashed_txs_at([comp], 4000)] } @@ -692,7 +692,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do %{processor_filled: state, transactions: [tx | _], ife_tx_hashes: [ife_id | _]} do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_timestamp_now: :os.system_time(:second) + 5, + eth_timestamp_now: 5, ife_input_spending_blocks_result: [Block.hashed_txs_at([tx], 3000)] } @@ -719,7 +719,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do request = %ExitProcessor.Request{ blknum_now: 4000, - eth_timestamp_now: :os.system_time(:second) + 5, + eth_timestamp_now: 5, ife_input_spending_blocks_result: [Block.hashed_txs_at([tx], tx_blknum)] } @@ -771,7 +771,7 @@ defmodule OMG.Watcher.ExitProcessor.PiggybackTest do txbytes = txbytes(tx) state = state |> start_ife_from(comp) |> piggyback_ife_from(ife_id, 0, :input) - request = %ExitProcessor.Request{blknum_now: 1000, eth_timestamp_now: :os.system_time(:second) + 5} + request = %ExitProcessor.Request{blknum_now: 1000, eth_timestamp_now: 5} assert {:ok, %{input_tx: "input_tx", input_utxo_pos: Utxo.position(1, 0, 0)}} = Core.get_input_challenge_data(request, state, txbytes, 0) diff --git a/apps/omg_watcher/test/omg_watcher/exit_processor/standard_exit_test.exs b/apps/omg_watcher/test/omg_watcher/exit_processor/standard_exit_test.exs index d80c0c70f8..a38a7e250e 100644 --- a/apps/omg_watcher/test/omg_watcher/exit_processor/standard_exit_test.exs +++ b/apps/omg_watcher/test/omg_watcher/exit_processor/standard_exit_test.exs @@ -366,7 +366,7 @@ defmodule OMG.Watcher.ExitProcessor.StandardExitTest do standard_exit_tx = TestHelper.create_recovered([{@blknum, 0, 0, alice}], @eth, [{alice, 10}]) request = %ExitProcessor.Request{ - eth_timestamp_now: 5 + :os.system_time(:second), + eth_timestamp_now: 5, blknum_now: @late_blknum, utxos_to_check: [exiting_pos], utxo_exists_result: [false] @@ -393,7 +393,7 @@ defmodule OMG.Watcher.ExitProcessor.StandardExitTest do standard_exit_tx = TestHelper.create_recovered([{@blknum, 0, 0, alice}], @eth, [{alice, 10}]) request = %ExitProcessor.Request{ - eth_timestamp_now: 50 + :os.system_time(:second), + eth_timestamp_now: 50, blknum_now: @late_blknum, utxos_to_check: [exiting_pos], utxo_exists_result: [false] @@ -418,7 +418,7 @@ defmodule OMG.Watcher.ExitProcessor.StandardExitTest do standard_exit_tx = TestHelper.create_recovered([{@deposit_blknum, 0, 0, alice}], @eth, [{alice, 10}]) request = %ExitProcessor.Request{ - eth_timestamp_now: 13 + :os.system_time(:second), + eth_timestamp_now: 13, blknum_now: @late_blknum, utxos_to_check: [exiting_pos], utxo_exists_result: [false] @@ -436,7 +436,7 @@ defmodule OMG.Watcher.ExitProcessor.StandardExitTest do processor = processor |> start_se_from(standard_exit_tx, exiting_pos) assert %ExitProcessor.Request{utxos_to_check: []} = - %ExitProcessor.Request{eth_timestamp_now: 13 + :os.system_time(:second), blknum_now: @early_blknum} + %ExitProcessor.Request{eth_timestamp_now: 13, blknum_now: @early_blknum} |> Core.determine_utxo_existence_to_get(processor) end @@ -449,7 +449,7 @@ defmodule OMG.Watcher.ExitProcessor.StandardExitTest do processor = processor |> start_se_from(standard_exit_tx, exiting_pos) |> start_ife_from(tx) assert {:ok, [%Event.InvalidExit{utxo_pos: ^exiting_pos_enc, spending_txhash: ^tx_hash}]} = - check_validity_filtered(%ExitProcessor.Request{eth_timestamp_now: 5 + :os.system_time(:second), blknum_now: @late_blknum}, processor, + check_validity_filtered(%ExitProcessor.Request{eth_timestamp_now: 5, blknum_now: @late_blknum}, processor, only: [Event.InvalidExit] ) end @@ -463,7 +463,7 @@ defmodule OMG.Watcher.ExitProcessor.StandardExitTest do assert %{utxos_to_check: [_, Utxo.position(1, 2, 1), @utxo_pos_tx]} = exit_processor_request = - %ExitProcessor.Request{eth_timestamp_now: 5 + :os.system_time(:second), blknum_now: @late_blknum} + %ExitProcessor.Request{eth_timestamp_now: 5, blknum_now: @late_blknum} |> Core.determine_utxo_existence_to_get(processor) block_updates = [{:put, :block, %{number: @blknum, hash: <<0::160>>, transactions: [signed_tx_bytes]}}] @@ -491,7 +491,7 @@ defmodule OMG.Watcher.ExitProcessor.StandardExitTest do # doesn't check the challenged SE utxo assert %{utxos_to_check: [_, Utxo.position(1, 2, 1)]} = exit_processor_request = - %ExitProcessor.Request{eth_timestamp_now: 5 + :os.system_time(:second), blknum_now: @late_blknum} + %ExitProcessor.Request{eth_timestamp_now: 5, blknum_now: @late_blknum} |> Core.determine_utxo_existence_to_get(processor) # doesn't alert on the challenged SE, despite it being a double-spend wrt the IFE @@ -508,7 +508,7 @@ defmodule OMG.Watcher.ExitProcessor.StandardExitTest do assert %{utxos_to_check: [_, Utxo.position(1, 2, 1), @utxo_pos_tx]} = exit_processor_request = - %ExitProcessor.Request{eth_timestamp_now: 5 + :os.system_time(:second), blknum_now: @late_blknum} + %ExitProcessor.Request{eth_timestamp_now: 5, blknum_now: @late_blknum} |> Core.determine_utxo_existence_to_get(processor) assert {:ok, []} = diff --git a/apps/omg_watcher/test/support/exit_processor/case.ex b/apps/omg_watcher/test/support/exit_processor/case.ex index 14adb0b527..e0e0d3e141 100644 --- a/apps/omg_watcher/test/support/exit_processor/case.ex +++ b/apps/omg_watcher/test/support/exit_processor/case.ex @@ -85,7 +85,7 @@ defmodule OMG.Watcher.ExitProcessor.Case do defp invalid_piggyback_on_input(state, [tx | _], [ife_id | _], competing_tx) do request = %ExitProcessor.Request{ blknum_now: 4000, - eth_timestamp_now: :os.system_time(:second) + 5, + eth_timestamp_now: 5, ife_input_spending_blocks_result: [Block.hashed_txs_at([tx], 3000)] } @@ -118,7 +118,7 @@ defmodule OMG.Watcher.ExitProcessor.Case do request = %ExitProcessor.Request{ blknum_now: 5000, - eth_timestamp_now: :os.system_time(:second) + 5, + eth_timestamp_now: 5, blocks_result: [block], ife_input_spending_blocks_result: [block, Block.hashed_txs_at([comp], comp_blknum)] } diff --git a/apps/omg_watcher/test/support/exit_processor/test_helper.ex b/apps/omg_watcher/test/support/exit_processor/test_helper.ex index 69a7ae699d..9a189b92fa 100644 --- a/apps/omg_watcher/test/support/exit_processor/test_helper.ex +++ b/apps/omg_watcher/test/support/exit_processor/test_helper.ex @@ -43,7 +43,7 @@ defmodule OMG.Watcher.ExitProcessor.TestHelper do exit_id = Keyword.get(opts, :exit_id, @exit_id) call_data = %{utxo_pos: enc_pos, output_tx: txbytes} root_chain_txhash = <<1::256>> - block_timestamp = :os.system_time(:second) + block_timestamp = 2 scheduled_finalization_time = block_timestamp + 100 event = %{ @@ -79,7 +79,7 @@ defmodule OMG.Watcher.ExitProcessor.TestHelper do # See `OMG.Eth.RootChain.get_in_flight_exits_structs/2` for reference of where this comes from # `nil`s are unused portions of the returns data from the contract - def active_ife_status(), do: {nil, :os.system_time(:second), nil, nil, nil, nil, nil} + def active_ife_status(), do: {nil, 1, nil, nil, nil, nil, nil} def inactive_ife_status(), do: {nil, 0, nil, nil, nil, nil, nil} def piggyback_ife_from(%Core{} = processor, tx_hash, output_index, piggyback_type) do From 2b663c2f74e39be7c3956084da36766a50d56b87 Mon Sep 17 00:00:00 2001 From: souradeep-das Date: Fri, 29 May 2020 19:11:32 +0530 Subject: [PATCH 23/28] fix: get block_timestamp from opts for tests --- .../lib/omg_watcher/exit_processor/standard_exit.ex | 3 +-- .../omg_watcher/exit_processor/core/state_interaction_test.exs | 2 +- apps/omg_watcher/test/support/exit_processor/test_helper.ex | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex b/apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex index 0e82ed6017..9377227f42 100644 --- a/apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex +++ b/apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex @@ -99,8 +99,7 @@ defmodule OMG.Watcher.ExitProcessor.StandardExit do _ethereum_block_time_seconds = OMG.Eth.Configuration.ethereum_block_time_seconds() # get exits which are still invalid and after the SLA margin late_invalid_exits = - Enum.filter(invalid_exits, fn {_, %ExitInfo{block_timestamp: block_timestamp, eth_height: eth_height}} -> - IO.inspect(eth_height) + Enum.filter(invalid_exits, fn {_, %ExitInfo{block_timestamp: block_timestamp}} -> block_timestamp + sla_seconds <= eth_timestamp_now end) diff --git a/apps/omg_watcher/test/omg_watcher/exit_processor/core/state_interaction_test.exs b/apps/omg_watcher/test/omg_watcher/exit_processor/core/state_interaction_test.exs index 9b5d5ba63b..845cc6e0c6 100644 --- a/apps/omg_watcher/test/omg_watcher/exit_processor/core/state_interaction_test.exs +++ b/apps/omg_watcher/test/omg_watcher/exit_processor/core/state_interaction_test.exs @@ -100,7 +100,7 @@ defmodule OMG.Watcher.ExitProcessor.Core.StateInteractionTest do processor = processor |> start_se_from(standard_exit_tx1, @utxo_pos1, exit_id: 1) - |> start_se_from(standard_exit_tx2, @utxo_pos2, eth_height: 4, exit_id: 2) + |> start_se_from(standard_exit_tx2, @utxo_pos2, block_timestamp: 4, exit_id: 2) # exits invalidly finalize and continue/start emitting events and complain {:ok, {_, two_spend}, state_after_spend} = diff --git a/apps/omg_watcher/test/support/exit_processor/test_helper.ex b/apps/omg_watcher/test/support/exit_processor/test_helper.ex index 9a189b92fa..9073b5fb33 100644 --- a/apps/omg_watcher/test/support/exit_processor/test_helper.ex +++ b/apps/omg_watcher/test/support/exit_processor/test_helper.ex @@ -43,7 +43,7 @@ defmodule OMG.Watcher.ExitProcessor.TestHelper do exit_id = Keyword.get(opts, :exit_id, @exit_id) call_data = %{utxo_pos: enc_pos, output_tx: txbytes} root_chain_txhash = <<1::256>> - block_timestamp = 2 + block_timestamp = Keyword.get(opts, :block_timestamp, 2) scheduled_finalization_time = block_timestamp + 100 event = %{ From 99cf0720811c482a9d94b025f492020e25cc7bc2 Mon Sep 17 00:00:00 2001 From: souradeep-das Date: Fri, 29 May 2020 19:24:44 +0530 Subject: [PATCH 24/28] style: lint fix --- apps/omg_watcher/lib/omg_watcher/exit_processor.ex | 3 ++- apps/omg_watcher/lib/omg_watcher/exit_processor/canonicity.ex | 1 - .../lib/omg_watcher/exit_processor/in_flight_exit_info.ex | 1 + apps/omg_watcher/lib/omg_watcher/exit_processor/piggyback.ex | 1 - .../lib/omg_watcher/exit_processor/standard_exit.ex | 3 +-- .../test/omg_watcher/exit_processor/standard_exit_test.exs | 4 +++- 6 files changed, 7 insertions(+), 6 deletions(-) diff --git a/apps/omg_watcher/lib/omg_watcher/exit_processor.ex b/apps/omg_watcher/lib/omg_watcher/exit_processor.ex index f363781470..ed5640aa7c 100644 --- a/apps/omg_watcher/lib/omg_watcher/exit_processor.ex +++ b/apps/omg_watcher/lib/omg_watcher/exit_processor.ex @@ -263,7 +263,7 @@ defmodule OMG.Watcher.ExitProcessor do exit_processor_sla_margin_forced: exit_processor_sla_margin_forced, metrics_collection_interval: metrics_collection_interval, min_exit_period_seconds: min_exit_period_seconds, - ethereum_block_time_seconds: ethereum_block_time_seconds, + ethereum_block_time_seconds: _ethereum_block_time_seconds, child_block_interval: child_block_interval ) do {:ok, db_exits} = PaymentExitInfo.all_exit_infos() @@ -710,6 +710,7 @@ defmodule OMG.Watcher.ExitProcessor do {:utxo_position, blknum, _, _} = Utxo.Position.decode!(utxo_pos_enc) {_block_hash, utxo_creation_block_timestamp} = RootChain.blocks(blknum) {:ok, exit_block_timestamp} = Eth.get_block_timestamp_by_number(eth_height) + {:ok, scheduled_finalization_time} = ExitInfo.calculate_sft( blknum, diff --git a/apps/omg_watcher/lib/omg_watcher/exit_processor/canonicity.ex b/apps/omg_watcher/lib/omg_watcher/exit_processor/canonicity.ex index 8468cc2aac..4ec33e45c0 100644 --- a/apps/omg_watcher/lib/omg_watcher/exit_processor/canonicity.ex +++ b/apps/omg_watcher/lib/omg_watcher/exit_processor/canonicity.ex @@ -34,7 +34,6 @@ defmodule OMG.Watcher.ExitProcessor.Canonicity do alias OMG.Crypto alias OMG.State.Transaction alias OMG.Utxo - alias OMG.Eth alias OMG.Watcher.Event alias OMG.Watcher.ExitProcessor alias OMG.Watcher.ExitProcessor.Core diff --git a/apps/omg_watcher/lib/omg_watcher/exit_processor/in_flight_exit_info.ex b/apps/omg_watcher/lib/omg_watcher/exit_processor/in_flight_exit_info.ex index 7e648e3512..886a23f150 100644 --- a/apps/omg_watcher/lib/omg_watcher/exit_processor/in_flight_exit_info.ex +++ b/apps/omg_watcher/lib/omg_watcher/exit_processor/in_flight_exit_info.ex @@ -121,6 +121,7 @@ defmodule OMG.Watcher.ExitProcessor.InFlightExitInfo do defp do_new(tx_bytes, tx_signatures, contract_status, fields) do {timestamp, is_active} = parse_contract_in_flight_exit_status(contract_status) + with {:ok, tx} <- prepare_tx(tx_bytes, tx_signatures) do # NOTE: in case of using output_id as the input pointer, getting the youngest will be entirely different Utxo.position(youngest_input_blknum, _, _) = diff --git a/apps/omg_watcher/lib/omg_watcher/exit_processor/piggyback.ex b/apps/omg_watcher/lib/omg_watcher/exit_processor/piggyback.ex index ee59e331a7..3b30112c2c 100644 --- a/apps/omg_watcher/lib/omg_watcher/exit_processor/piggyback.ex +++ b/apps/omg_watcher/lib/omg_watcher/exit_processor/piggyback.ex @@ -32,7 +32,6 @@ defmodule OMG.Watcher.ExitProcessor.Piggyback do alias OMG.State.Transaction alias OMG.Utxo - alias OMG.Eth alias OMG.Watcher.Event alias OMG.Watcher.ExitProcessor alias OMG.Watcher.ExitProcessor.Core diff --git a/apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex b/apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex index 9377227f42..f182757389 100644 --- a/apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex +++ b/apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex @@ -41,7 +41,6 @@ defmodule OMG.Watcher.ExitProcessor.StandardExit do alias OMG.Block alias OMG.State.Transaction alias OMG.Utxo - alias OMG.Eth alias OMG.Watcher.ExitProcessor alias OMG.Watcher.ExitProcessor.Core alias OMG.Watcher.ExitProcessor.DoubleSpend @@ -95,7 +94,7 @@ defmodule OMG.Watcher.ExitProcessor.StandardExit do end) invalid_exits = standard_invalid_exits |> Enum.concat(exits_invalid_by_ife) |> Enum.uniq() - + _ethereum_block_time_seconds = OMG.Eth.Configuration.ethereum_block_time_seconds() # get exits which are still invalid and after the SLA margin late_invalid_exits = diff --git a/apps/omg_watcher/test/omg_watcher/exit_processor/standard_exit_test.exs b/apps/omg_watcher/test/omg_watcher/exit_processor/standard_exit_test.exs index a38a7e250e..65c68db5c9 100644 --- a/apps/omg_watcher/test/omg_watcher/exit_processor/standard_exit_test.exs +++ b/apps/omg_watcher/test/omg_watcher/exit_processor/standard_exit_test.exs @@ -449,7 +449,9 @@ defmodule OMG.Watcher.ExitProcessor.StandardExitTest do processor = processor |> start_se_from(standard_exit_tx, exiting_pos) |> start_ife_from(tx) assert {:ok, [%Event.InvalidExit{utxo_pos: ^exiting_pos_enc, spending_txhash: ^tx_hash}]} = - check_validity_filtered(%ExitProcessor.Request{eth_timestamp_now: 5, blknum_now: @late_blknum}, processor, + check_validity_filtered( + %ExitProcessor.Request{eth_timestamp_now: 5, blknum_now: @late_blknum}, + processor, only: [Event.InvalidExit] ) end From 8c072f98b102d72e02fbb2f7f3e54066427ac6be Mon Sep 17 00:00:00 2001 From: souradeep-das Date: Mon, 1 Jun 2020 16:13:14 +0530 Subject: [PATCH 25/28] style: remove unused vars --- apps/omg_watcher/lib/omg_watcher/exit_processor.ex | 1 - apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex | 1 - apps/omg_watcher/lib/omg_watcher/sync_supervisor.ex | 1 - 3 files changed, 3 deletions(-) diff --git a/apps/omg_watcher/lib/omg_watcher/exit_processor.ex b/apps/omg_watcher/lib/omg_watcher/exit_processor.ex index ed5640aa7c..562b2f9493 100644 --- a/apps/omg_watcher/lib/omg_watcher/exit_processor.ex +++ b/apps/omg_watcher/lib/omg_watcher/exit_processor.ex @@ -263,7 +263,6 @@ defmodule OMG.Watcher.ExitProcessor do exit_processor_sla_margin_forced: exit_processor_sla_margin_forced, metrics_collection_interval: metrics_collection_interval, min_exit_period_seconds: min_exit_period_seconds, - ethereum_block_time_seconds: _ethereum_block_time_seconds, child_block_interval: child_block_interval ) do {:ok, db_exits} = PaymentExitInfo.all_exit_infos() diff --git a/apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex b/apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex index f182757389..40db4dfb0e 100644 --- a/apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex +++ b/apps/omg_watcher/lib/omg_watcher/exit_processor/standard_exit.ex @@ -95,7 +95,6 @@ defmodule OMG.Watcher.ExitProcessor.StandardExit do invalid_exits = standard_invalid_exits |> Enum.concat(exits_invalid_by_ife) |> Enum.uniq() - _ethereum_block_time_seconds = OMG.Eth.Configuration.ethereum_block_time_seconds() # get exits which are still invalid and after the SLA margin late_invalid_exits = Enum.filter(invalid_exits, fn {_, %ExitInfo{block_timestamp: block_timestamp}} -> diff --git a/apps/omg_watcher/lib/omg_watcher/sync_supervisor.ex b/apps/omg_watcher/lib/omg_watcher/sync_supervisor.ex index f6462af746..7a8ddc175c 100644 --- a/apps/omg_watcher/lib/omg_watcher/sync_supervisor.ex +++ b/apps/omg_watcher/lib/omg_watcher/sync_supervisor.ex @@ -73,7 +73,6 @@ defmodule OMG.Watcher.SyncSupervisor do exit_processor_sla_margin_forced: exit_processor_sla_margin_forced, metrics_collection_interval: metrics_collection_interval, min_exit_period_seconds: min_exit_period_seconds, - ethereum_block_time_seconds: ethereum_block_time_seconds, child_block_interval: child_block_interval ]}, %{ From 34cd0352df4ad75972f61b8075856edf4a918052 Mon Sep 17 00:00:00 2001 From: souradeep-das Date: Mon, 1 Jun 2020 17:03:18 +0530 Subject: [PATCH 26/28] style: fix lint --- apps/omg_watcher/lib/omg_watcher/sync_supervisor.ex | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/omg_watcher/lib/omg_watcher/sync_supervisor.ex b/apps/omg_watcher/lib/omg_watcher/sync_supervisor.ex index 0055de0dd5..80ccfaf4bd 100644 --- a/apps/omg_watcher/lib/omg_watcher/sync_supervisor.ex +++ b/apps/omg_watcher/lib/omg_watcher/sync_supervisor.ex @@ -65,7 +65,6 @@ defmodule OMG.Watcher.SyncSupervisor do ethereum_events_check_interval_ms = OMG.Configuration.ethereum_events_check_interval_ms() coordinator_eth_height_check_interval_ms = OMG.Configuration.coordinator_eth_height_check_interval_ms() min_exit_period_seconds = OMG.Eth.Configuration.min_exit_period_seconds() - ethereum_block_time_seconds = OMG.Eth.Configuration.ethereum_block_time_seconds() child_block_interval = OMG.Eth.Configuration.child_block_interval() contracts = OMG.Eth.Configuration.contracts() From b64b5eb081f9969bcac3696fa8627e4f8d87b151 Mon Sep 17 00:00:00 2001 From: souradeep-das Date: Fri, 12 Jun 2020 16:20:24 +0530 Subject: [PATCH 27/28] fix: typo --- .../test/omg_watcher/integration/invalid_exit_test.exs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/omg_watcher/test/omg_watcher/integration/invalid_exit_test.exs b/apps/omg_watcher/test/omg_watcher/integration/invalid_exit_test.exs index 91347543fc..d47335f3ed 100644 --- a/apps/omg_watcher/test/omg_watcher/integration/invalid_exit_test.exs +++ b/apps/omg_watcher/test/omg_watcher/integration/invalid_exit_test.exs @@ -21,6 +21,7 @@ defmodule OMG.Watcher.Integration.InvalidExitTest do alias OMG.Utxo alias OMG.Watcher.Event + alias OMG.Watcher.Configuration alias OMG.Watcher.Integration.TestHelper, as: IntegrationTest alias Support.DevHelper alias Support.RootChainHelper @@ -115,7 +116,7 @@ defmodule OMG.Watcher.Integration.InvalidExitTest do IntegrationTest.wait_for_byzantine_events([%Event.InvalidExit{}.name], @timeout) - exit_processor_sla_seconds = OMG.Watcher.Configuraion.exit_processor_sla_seconds() + exit_processor_sla_seconds = OMG.Watcher.Configuration.exit_processor_sla_seconds() exit_processor_sla_ms = exit_processor_sla_seconds * 1000 # after exit, the event fetch time + waiting for sla_seconds goes beyond the required time Process.sleep(exit_processor_sla_ms) From c1a07700ad94d4e3035ab97dab6cdfa2584a21b9 Mon Sep 17 00:00:00 2001 From: souradeep-das Date: Fri, 12 Jun 2020 16:30:28 +0530 Subject: [PATCH 28/28] style: lint fix --- .../test/omg_watcher/integration/invalid_exit_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/omg_watcher/test/omg_watcher/integration/invalid_exit_test.exs b/apps/omg_watcher/test/omg_watcher/integration/invalid_exit_test.exs index d47335f3ed..73bed0e066 100644 --- a/apps/omg_watcher/test/omg_watcher/integration/invalid_exit_test.exs +++ b/apps/omg_watcher/test/omg_watcher/integration/invalid_exit_test.exs @@ -20,8 +20,8 @@ defmodule OMG.Watcher.Integration.InvalidExitTest do use Plug.Test alias OMG.Utxo - alias OMG.Watcher.Event alias OMG.Watcher.Configuration + alias OMG.Watcher.Event alias OMG.Watcher.Integration.TestHelper, as: IntegrationTest alias Support.DevHelper alias Support.RootChainHelper