Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

refactor: ExtCostsConfig as simple map of costs #8115

Merged
merged 5 commits into from
Dec 7, 2022

Conversation

jakmeier
Copy link
Contributor

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 by

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.

  1. 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.

  2. 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 (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`.
@jakmeier jakmeier requested a review from a team as a code owner November 24, 2022 15:01
@jakmeier
Copy link
Contributor Author

jakmeier commented Dec 6, 2022

ping @Longarithm
this is blocking progress on parameter weights, do you have time to review soon it or should I ask someone else?

EnumCount,
Display,
strum::EnumIter,
enum_map::Enum,
)]
#[allow(non_camel_case_types)]
pub enum ExtCosts {
Copy link
Member

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.

Copy link
Contributor Author

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.

@near-bulldozer near-bulldozer bot merged commit 8c83455 into near:master Dec 7, 2022
@jakmeier jakmeier deleted the refactor-gas-profiles-part3 branch December 7, 2022 08:47
nikurt pushed a commit to nikurt/nearcore that referenced this pull request Dec 14, 2022
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`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants