-
Notifications
You must be signed in to change notification settings - Fork 683
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
fix: don't misinterprent alt_bn128_g1 costs as action costs #4182
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.
This hack LGTM, but I would love to use strum::EnumCount
(it is an extra dependency for primitives-core, so it might be problematic; it is clearly not a problem for nearcore since we use strum elsewhere, but it might be problematic for non-std environments, e.g. for near-sdk-rs)
I personally try to avoid such "convenience" proc macros: for me, they actually hinder readability and understandability of the code, not to mention compile time implications. In rust-analyzer, we use only nearcore however seems to embrace convenience dependencies much more enthusiastically than I am, and I am not yet ready to fight the battle for that (I am not even sure it is an objective problem, and not my personal taste). So, for the time being, I agree that I should make use of strum, derive more and such. However, in this particular case, |
core/primitives-core/src/config.rs
Outdated
@@ -536,6 +536,9 @@ pub enum ExtCosts { | |||
alt_bn128_g1_sum_base, | |||
#[cfg(feature = "protocol_feature_alt_bn128")] | |||
alt_bn128_g1_sum_byte, | |||
|
|||
// NB: this should be the last element of the enum. |
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 is NB?
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.
Note Bene. I guess it's better to change this to Note.
a3884c4
to
5d883cc
Compare
TL;DR: let's merge this fix.
I prefer dedicated tools with clear naming that address a specific problem we have with a descriptive name and enforces proper use. This implementation requires non-zero attention to detail.
I read code to understand it, and I only use IDEs where I cannot follow the logic and need to jump around. A dedicated derive implementation is 1 line that I need to read whereas such IDE workarounds only bring more code to read to me.
This concern is valid, though I would say it falls into the optimization space where you need to measure first, and keep measuring the important metrics with all the future changes to the code, otherwise it is only a matter of taste, and I am not going to argue the taste decisions unless they are intrusive. |
Before this PR, we store costs for
alt_bn128_g1
and costs of certain actions in the same array index, becaues, when adding alt_bn128_g1, we forgot to update the number of costs. The fix is to make this mistake impossible, by including an explicit sentinel node at the end.Test plan
Add sanity check to existing ext tests that they don't increase action costs.