-
Notifications
You must be signed in to change notification settings - Fork 454
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
Add Gas and Ink types in rust #2736
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.
LGTM.
I have a precious few minor comments/ideas, but this looks great.
arbitrator/arbutil/src/pricing.rs
Outdated
|
||
/// For hostios that include pointers. | ||
pub const PTR_INK: u64 = 13440 - HOSTIO_INK; | ||
pub const PTR_INK: Ink = Ink(13440 - HOSTIO_INK.0); |
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.
Should we prefer:
pub const PTR_INK: Ink = Ink(13440) - HOSTIO_INK
I find it a little nicer to read instead of thinking, "Oh right, .0 means the wrapped u64."
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.
I'm afraid
calls in constants are limited to constant functions, tuple structs and tuple variants
I could make a constant subtraction method or use saturating_sub, but the normal subtraction is via a trait which can't be made const yet (they're still figuring out the syntax for that and how it'll work).
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.
Actually, after seeing your comment on the Gas(EVM_API_INK.0)
line, I decided to introduce a const sub method to prevent accidentally mixing Gas and Ink types in a situation like this, and use it here.
@@ -147,7 +147,7 @@ pub trait UserHost<DR: DataReader>: GasMeteredMachine { | |||
|
|||
// require for cache-miss case, preserve wrong behavior for old arbos | |||
let evm_api_gas_to_use = if arbos_version < ARBOS_VERSION_STYLUS_CHARGING_FIXES { | |||
EVM_API_INK | |||
Gas(EVM_API_INK.0) |
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 actionable:
But, I love how quickly my mind went, "Wait, this can't be right! He's using an ink value to initialize a Gas." before I realized that this is in the block that says, "preserve wrong behavior" in the comment.
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.
LGTM
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.
LGTM
This should help prevent future incidents like the one in storage_load where an ink cost was mistakenly used as an amount of gas.
Fixes NIT-2850