-
Notifications
You must be signed in to change notification settings - Fork 622
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
Conversation
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.
`
runtime/near-vm-logic/src/logic.rs
Outdated
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, |
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, 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.
core/primitives-core/src/config.rs
Outdated
/// TODO: remove this field because it does not affect the protocol | ||
pub max_gas_burnt_view: Gas, |
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.
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.
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.
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) }; |
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 looks so much nicer now, thanks!
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. |
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.
👍
Co-authored-by: Bowen Wang <bowenwang1996@users.noreply.github.com>
One step towards #4649.
max_gas_burnt_view
should not be a part ofRuntimeConfig
, see #3080 for more details. While it is the case, we have to modifyRuntimeConfig
inside runtime in a hacky way.Here we introduce
ViewConfig
to store view parameters and remove usages ofmax_gas_burnt_view
fromRuntimeConfig
. 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