-
Notifications
You must be signed in to change notification settings - Fork 59
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
feat: configurable fee specs path from env var #1385
Conversation
# Conflicts: # apps/omg_child_chain/test/omg_child_chain/integration/fee_server_test.exs
# Conflicts: # apps/omg_child_chain/config/config.exs # apps/omg_child_chain/lib/omg_child_chain/fees/file_adapter.ex # apps/omg_child_chain/test/omg_child_chain/fees/file_adapter_test.exs # apps/omg_child_chain/test/omg_child_chain/integration/fee_server_test.exs # apps/omg_child_chain/test/omg_child_chain/integration/fixtures.exs # apps/omg_watcher/test/fixtures.exs # docs/deployment_configuration.md # docs/details.md
apps/omg/test/support/test_helper.ex
Outdated
@spec write_fee_file(%{Crypto.address_t() => map()} | binary(), binary() | nil) :: {:ok, binary, binary} | ||
def write_fee_file(fee_map, file_name \\ nil) | ||
@spec write_fee_file(%{Crypto.address_t() => map()} | binary()) :: {:ok, binary, binary} | ||
def write_fee_file(fee_map, file_path \\ nil) |
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.
what purpose does this serve though?
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 fee specs file is supposed to be updatable but it's residing deep in _build/.../<app-version>/.../omg_child_chain/priv
folder making it hard and error prone to update.
So going for a path instead so infra could keep the file somewhere else outside the repo directory and we can refer to it via env var.
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.
do we stil need the default arument? file_path \\ nil
?
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 like we still do because https://github.com/omisego/elixir-omg/blob/master/apps/omg_child_chain/test/omg_child_chain/integration/fee_server_test.exs specifically tests the behaviour when the same file gets updated.
apps/omg_watcher/test/fixtures.exs
Outdated
@@ -90,7 +90,7 @@ defmodule OMG.Watcher.Fixtures do | |||
config :omg_db, path: "#{db_path}" | |||
# this causes the inner test child chain server process to log info. To see these logs adjust test's log level | |||
config :logger, level: :info | |||
config :omg_child_chain, fee_adapter_opts: [specs_file_name: "#{fee_file}"] | |||
config :omg_child_chain, fee_adapter_opts: [specs_file_path: "#{fee_file}"] |
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.
in the last week, this configuration has been changed 4 times :D
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.
Yeah the other big change to fees was from #1373 which turned the file-only into an adapter for file & feed. I had to rebase and fix conflicts a few times 🤦♂
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'm curious was there an issue created for this? It isn't linked.
I want to understand more because what I thought is that having fees in file is hard/impossible to change in the production deployment.
I also thought that fee file become obsolete by the feed service.
Thanks for explaination!
@@ -13,65 +13,86 @@ | |||
# limitations under the License. | |||
|
|||
defmodule OMG.ChildChain.ReleaseTasks.SetFeeFeedAdapterOpts do | |||
@moduledoc false | |||
@moduledoc """ |
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 👍
apps/omg_child_chain/lib/omg_child_chain/release_tasks/set_fee_file_adapter_opts.ex
Outdated
Show resolved
Hide resolved
# Conflicts: # apps/omg_child_chain/config/config.exs # apps/omg_child_chain/config/test.exs # apps/omg_child_chain/lib/omg_child_chain/release_tasks/set_fee_feed_adapter_opts.ex # apps/omg_watcher/test/fixtures.exs # docs/deployment_configuration.md # rel/config.exs
# Conflicts: # docker-compose.yml
apps/omg/test/support/test_helper.ex
Outdated
@spec write_fee_file(%{Crypto.address_t() => map()} | binary(), binary() | nil) :: {:ok, binary, binary} | ||
def write_fee_file(fee_map, file_name \\ nil) | ||
@spec write_fee_file(%{Crypto.address_t() => map()} | binary()) :: {:ok, binary, binary} | ||
def write_fee_file(fee_map, file_path \\ nil) |
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.
do we stil need the default arument? file_path \\ nil
?
|
||
def write_fee_file(map, file_name) when is_map(map) do | ||
def write_fee_file(map, file_path) when is_map(map) 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.
why does this first parameter keep on changing it's name?
fee_map
, map
, content
?
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.
🤦 renamed fee_map
to a more accurate map_or_content
apps/omg/test/support/test_helper.ex
Outdated
full_path = "#{priv_dir}/#{file}" | ||
def write_fee_file(content, file_path) do | ||
file_path = | ||
file_path || "#{:code.priv_dir(:omg_child_chain)}/test_fees_file-#{DateTime.to_unix(DateTime.utc_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.
maybe this ought to be expanded?
is this a case?
path = case file_path do
nil->"#{:code.priv_dir(:omg_child_chain)}/test_fees_file-#{DateTime.to_unix(DateTime.utc_now())}"
_ -> file_path
|> parse_adapter_value() | ||
|> case do | ||
"FEED" -> configure_feed_adapter(existing_config, config) | ||
_ -> config |
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.
seems like in this case we're not margining into Config.Reader.merge/2
?
is this not tested?
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.
In this case no config is changed so I'm passing the original config
back. Refactored in d2b16ca to make this clearer though.
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.
And the test for this is this one https://github.com/omisego/elixir-omg/pull/1385/files#diff-123f6adf27c8ab33907e154dfc96b071R103-R110
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.
ahhh shit. my bad!
|> parse_adapter_value() | ||
|> case do | ||
"FILE" -> configure_file_adapter(config) | ||
_ -> config |
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.
same as above, do we not need to Config.Reader.merge/2
?
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.
In this case no config is changed so I'm passing the original config
back. Refactored in d2b16ca to make this clearer though.
:ok = System.put_env(@env_fee_adapter, "feed") | ||
|
||
:ok = System.put_env(@env_fee_change_tolerance_percent, "1.5") | ||
assert_raise ArgumentError, fn -> SetFeeFeedAdapterOpts.load([], []) 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.
is this raising with a message
key? do you want to check if's returning your message?
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.
It was a plain ArgumentError
from String.to_integer/1
. I've updated it to include a message + assertions though! f2157dc
Closes #1353
Overview
This PR allows the fee specs path to be configured via the environment variable
FEE_SPECS_FILE_PATH
.Changes
OMG.ChildChain.Fees.FileAdapter
andOMG.ChildChain.ReleaseTasks.SetFeeFileAdapterOpts
to support passingFEE_SPECS_FILE_PATH
environment variableFees.FileAdapter
andFees.FeedAdapter
to supportFEE_ADAPTER=file
andFEE_ADAPTER=feed
respectively so it can be changed without a new compile & version release.SetFeeFeedAdapterOpts
and fixed the code resulting from test failuresUsage
On the childchain, set
FEE_ADAPTER
andFEE_SPECS_FILE_PATH
:Testing
Unit tests pass:
mix test test/omg_child_chain/release_tasks/set_fee_file_adapter_opts_test.exs test/omg_child_chain/release_tasks/set_fee_feed_adapter_opts_test.exs
Specs test pass:
cd priv/cabbage && mix test
Fees are reflected from the fee specs file e.g. the specs file:
Gives