-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change EXIT_PROCESSOR_SLA_MARGIN to EXIT_PROCESSOR_SLA_SECONDS #1491
base: master
Are you sure you want to change the base?
Conversation
# 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a good way or should the timestamp of each exit be stored in the DB and retrieved here to check if sla_seconds is elapsed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is fine for this PR since it's still the existing behaviour, but could you maybe raise this discussion separately in the engineering channel?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will change the logic to exit_timestamp + sla_seconds <= time_now
when #1495 is merged
@@ -44,7 +44,7 @@ defmodule OMG.Watcher.ExitProcessor.Core do | |||
|
|||
use OMG.Utils.LoggerExt | |||
|
|||
@default_sla_margin 10 | |||
@default_sla_seconds 10 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure should the value reflect the original value, which I think should be 10 block * 15s per block = 150?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this only takes place on tests. @souradeep-das can we confirm this - raise a value and whether tests fails?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true, I think these are for tests. Fails when sla_seconds is >10
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this is for tests then let's remove it. we should also remove the default setting below:
sla_seconds \\ @default_sla_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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is fine for this PR since it's still the existing behaviour, but could you maybe raise this discussion separately in the engineering channel?
# 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}} -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're moving away from single pipes. Could you update invalid_exits |> Enum.filter(fn...
to Enum.filter(invalid_exits, fn...
? Thanks!
@@ -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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that before merging this PR, we'll need to update our infra to have this environment variable so we don't break the CI/CD environment.
Also, could you add this change to https://github.com/omisego/elixir-omg/blob/master/CHANGELOG.md under the Unreleased header? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work!
@@ -44,7 +44,7 @@ defmodule OMG.Watcher.ExitProcessor.Core do | |||
|
|||
use OMG.Utils.LoggerExt | |||
|
|||
@default_sla_margin 10 | |||
@default_sla_seconds 10 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this only takes place on tests. @souradeep-das can we confirm this - raise a value and whether tests fails?
@@ -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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only here we introduce this antipattern ;)
Please restore it as init param - which will be set where others are - and pass it to the Core's init (Core module serves usually as GenServer state). So you could retrieve its value as you do with sla_seconds
@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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too verbose I think :)
@app_env_name_margin :exit_processor_sla_seconds | |
@app_env_name :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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Restore this and pass through as I suggested in exit_processor/standard_exit.ex
config/test.exs
Outdated
@@ -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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But this is test - prev we had 1 secs blocks - is it OK?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes yes 1 sec blocks. Updating!
…_margin to @app_env_name
# 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#1495 is now merged
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks O! Updating.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this fine? 🙇
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine to me, we're really waiting for the seconds to come
Also @pnowosie asking for a re-review to confirm the latest changes. Thanks 🙇 |
Adding |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine to me, we're really waiting for the seconds to come
config/test.exs
Outdated
# NOTE `exit_processor_sla_margin` can't be made shorter. At 8 it sometimes | ||
# causes unchallenged exits events because `geth --dev` is too fast | ||
exit_processor_sla_margin: 10, | ||
# NOTE `exit_processor_sla_margin` can't be made shorter. At 3 it sometimes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice that you also checked and updated this 👍 🙏
@unnawut do we need to update any env vars? |
Yeah the ones you have in the infra PR should suffice |
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this guard is irrelevant and should be removed!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed 96d9e31
defp sla_seconds_safe?(exit_processor_sla_seconds, min_exit_period_seconds), | ||
do: exit_processor_sla_seconds < min_exit_period_seconds |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defp sla_seconds_safe?(exit_processor_sla_seconds, min_exit_period_seconds), | |
do: exit_processor_sla_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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the function spreads over multiple lines, let's allow it to do so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
def get_invalid( | ||
%Core{sla_seconds: sla_seconds} = state, | ||
utxo_exists?, | ||
eth_timestamp_now | ||
) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def get_invalid( | |
%Core{sla_seconds: sla_seconds} = state, | |
utxo_exists?, | |
eth_timestamp_now | |
) do | |
def get_invalid(state, utxo_exists?, eth_timestamp_now) do | |
state.sla_seconds |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done 96d9e31
@@ -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: 5} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm... how does this make sense? what is eth_timestamp_now 5
?
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exit_processor_sla_seconds = Application.fetch_env!(:omg_watcher, :exit_processor_sla_seconds) | |
exit_processor_sla_seconds = OMG.Watcher.Configuraion.exit_processor_sla_seconds() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done 96d9e31
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few things:
- this PR changes a API endpoint (cc @T-Dnzt @unnawut ). A property is removed and replaced with a different one, the new one has a different meaning.
- I've seen
eth_timestamp_now
. I don't exactly understand what it means and how it's used. The tests use values like 5,13,... What is this? Seems like a very odd timestamp.
Hey @InoMurko! Thanks for the review 🙇 Previously we had - late_invalid_exits = Enum.filter(invalid_exits, fn {_, %ExitInfo{eth_height: eth_height}} -> eth_height + sla_margin <= eth_height_now Since, we added the exit timestamp already, using it for the check and checking with late_invalid_exits = Enum.filter(invalid_exits, fn {_, %ExitInfo{block_timestamp: block_timestamp}} -> block_timestamp + sla_seconds <= eth_timestamp_now assigning the actual timestamp of the block here, For the tests, Should |
@T-Dnzt @achiurizo I think we should get a thumbs up from either of you for any API breaking change. It's the watcher & watcher_info So I guess either:
I recommend 2 for consistency with the contracts outweighs dropping this key from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
#1399
Overview
This unifies
sla_margin
to hold values in seconds instead of the number of blocks and renamesEXIT_PROCESSOR_SLA_MARGIN
toEXIT_PROCESSOR_SLA_SECONDS
. The internal logic to detect invalid exits has also been changed to use timestamps instead of number of blocksEXIT_PROCESSOR_SLA_MARGIN_FORCED
hasn't been renamedChanges
EXIT_PROCESSOR_SLA_MARGIN
toEXIT_PROCESSOR_SLA_SECONDS
eth_height_now
toeth_timestamp_now
EXIT_PROCESSOR_SLA_MARGIN_FORCED
is unchanged till now