-
Notifications
You must be signed in to change notification settings - Fork 618
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
refactor: ExtCostsConfig as simple map of costs #8115
refactor: ExtCostsConfig as simple map of costs #8115
Conversation
This is the next step in the refactoring steps for changing gas profiles to track gas by parameter (near#8033). Here we make `ExtCostsConfig` opaque and look up parameters by ```rust pub fn cost(&self, param: ExtCosts) -> Gas ``` instead of using a specific field inside. There are side-effects for this in 1. parameter definition 2. JSON RPC 3. parameter estimator 1) We no longer load the parameters through "parameter table -> JSON -> serde_deser" steps because `ExtCostsConfig` no longer has serde derives. Instead each `ExtCosts` maps to a `Parameter` that allows looking up the value directly from `ParameterTable`. This explicit mapping also replaces the `Parameter::ext_costs()` iterator previously used to find all parameters that are ext costs. We used to define `wasm_read_cached_trie_node` in `53.txt` and fill old values with serde default. Serde was removed here, so I changed it to define the parameter the base files. This is equivalent to the old behavior, only it is less clear when we added the parameter. 2) JSON RPC must keep the old format. Thus, I added `ExtCostsConfigView` and `VMConfigView` there. It is a direct copy-paste of the old structs in the old format but without serde magic to fill in missing values. 3) The estimator generates a `ExtCostsConfig` from estimations. This is now done through a mapping from estimated costs to `ExtCosts`. # Testing The exact JSON output is checked in existing tests `test_json_unchanged`.
ping @Longarithm |
EnumCount, | ||
Display, | ||
strum::EnumIter, | ||
enum_map::Enum, | ||
)] | ||
#[allow(non_camel_case_types)] | ||
pub enum ExtCosts { |
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 related to the PR, but I think ExtCost
is a better name, because a single entity corresponds to a single cost, not many of them.
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 it has been bothering me ever since I joined haha. Same for ActionCosts. I'm just not a huge fan of renaming things, as it messes with git history badly.
This is the next step in the refactoring steps for changing gas profiles to track gas by parameter (near#8033). Here we make `ExtCostsConfig` opaque and look up parameters by ```rust pub fn cost(&self, param: ExtCosts) -> Gas ``` instead of using a specific field inside. There are side-effects for this in 1. parameter definition 2. JSON RPC 3. parameter estimator 1) We no longer load the parameters through "parameter table -> JSON -> serde_deser" steps because `ExtCostsConfig` no longer has serde derives. Instead each `ExtCosts` maps to a `Parameter` that allows looking up the value directly from `ParameterTable`. This explicit mapping also replaces the `Parameter::ext_costs()` iterator previously used to find all parameters that are ext costs. We used to define `wasm_read_cached_trie_node` in `53.txt` and fill old values with serde default. Serde was removed here, so I changed it to define the parameter in the base files. This is equivalent to the old behavior, only it is less clear when we added the parameter. 2) JSON RPC must keep the old format. Thus, I added `ExtCostsConfigView` and `VMConfigView` there. It is a direct copy-paste of the old structs in the old format but without serde magic to fill in missing values. 3) The estimator generates a `ExtCostsConfig` from estimations. This is now done through a mapping from estimated costs to `ExtCosts`. # Testing The exact JSON output is checked in existing tests `test_json_unchanged`.
This is the next step in the refactoring steps for changing gas profiles
to track gas by parameter (#8033).
Here we make
ExtCostsConfig
opaque and look up parameters byinstead of using a specific field inside.
There are side-effects for this in
"parameter table -> JSON -> serde_deser" steps because
ExtCostsConfig
no longer has serde derives. Instead each
ExtCosts
maps to aParameter
that allows looking up the value directly fromParameterTable
.This explicit mapping also replaces the
Parameter::ext_costs()
iterator previously used to find all parameters that are ext costs.
We used to define
wasm_read_cached_trie_node
in53.txt
and fillold values with serde default. Serde was removed here, so I changed it
to define the parameter in the base files. This is equivalent to the
old behavior, only it is less clear when we added the parameter.
JSON RPC must keep the old format. Thus, I added
ExtCostsConfigView
and
VMConfigView
there. It is a direct copy-paste of the old structsin the old format but without serde magic to fill in missing values.
The estimator generates a
ExtCostsConfig
from estimations. This isnow done through a mapping from estimated costs to
ExtCosts
.Testing
The exact JSON output is checked in existing tests
test_json_unchanged
.