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: introduce ViewConfig for storing max_gas_burnt_view #4716

Merged
merged 16 commits into from
Aug 20, 2021

Conversation

Longarithm
Copy link
Member

@Longarithm Longarithm commented Aug 19, 2021

One step towards #4649.

max_gas_burnt_view should not be a part of RuntimeConfig, see #3080 for more details. While it is the case, we have to modify RuntimeConfig inside runtime in a hacky way.

Here we introduce ViewConfig to store view parameters and remove usages of max_gas_burnt_view from RuntimeConfig. In the following protocol upgrade, this field will be removed.

Test plan

python3 tests/sanity/rpc_max_gas_burnt.py
Nayduck run: http://nayduck.eastus.cloudapp.azure.com:3000/#/run/2013

@Longarithm Longarithm marked this pull request as ready for review August 20, 2021 00:23
@Longarithm Longarithm self-assigned this Aug 20, 2021
@Longarithm Longarithm added the A-transaction-runtime Area: transaction runtime (transaction and receipts processing, state transition, etc) label Aug 20, 2021
Copy link
Contributor

@matklad matklad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

`

let max_gas_burnt = if context.view_config.is_view {
match context.view_config.max_gas_burnt_view {
Some(max_gas_burnt_view) => max_gas_burnt_view,
None => config.limit_config.max_gas_burnt,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, am I correct that this is essentially dead code? Every time we view_config.is_view is true, view_cconfig.max_gas_burnt is Some?

If that's the case, I suggest making this code staticall unreachable, as follows:

impl VmContext {
  view_config: Option<ViewConfig>
}

struct ViewConfig {
  max_gas_burnt: gas
}

than, we'll be passing Option<VIewConfig> everywhere, with the semantics that we are in a view if the config is Some.

Comment on lines 30 to 31
/// TODO: remove this field because it does not affect the protocol
pub max_gas_burnt_view: Gas,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How hard is it to fix this? I'd like to prioritize this follow up, if possible, as this is a significant chunk of debt.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, I didn't read the PR description properly, you are tackling this in the next change, thanks!

deposit: 0,
};
let view_config =
ViewConfig { is_view: true, max_gas_burnt_view: Some(self.max_gas_burnt_view) };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks so much nicer now, thanks!

core/primitives-core/src/config.rs Outdated Show resolved Hide resolved
runtime/near-vm-logic/src/context.rs Outdated Show resolved Hide resolved
runtime/near-vm-logic/src/logic.rs Outdated Show resolved Hide resolved
core/primitives-core/src/config.rs Outdated Show resolved Hide resolved
runtime/near-vm-logic/src/context.rs Outdated Show resolved Hide resolved
pub is_view: bool,
/// If non-None, means that execution is made in a view mode and defines its configuration.
/// View mode means that only read-only operations are allowed.
/// See https://nomicon.io/Proposals/0018-view-change-method.html for more details.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Longarithm and others added 2 commits August 20, 2021 20:40
Co-authored-by: Bowen Wang <bowenwang1996@users.noreply.github.com>
@Longarithm Longarithm merged commit a20c12e into master Aug 20, 2021
@Longarithm Longarithm deleted the separate-gas-view branch August 20, 2021 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-transaction-runtime Area: transaction runtime (transaction and receipts processing, state transition, etc)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants