-
Notifications
You must be signed in to change notification settings - Fork 21
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
feat(blockifier, starknet_api): add explcit typing and arithmetic to gas amount/price, and fee #1173
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1173 +/- ##
==========================================
- Coverage 74.18% 67.87% -6.32%
==========================================
Files 359 254 -105
Lines 36240 28462 -7778
Branches 36240 28462 -7778
==========================================
- Hits 26886 19319 -7567
- Misses 7220 7530 +310
+ Partials 2134 1613 -521
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
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.
Reviewable status: 0 of 42 files reviewed, all discussions resolved
crates/blockifier/src/utils.rs
line 71 at r1 (raw file):
} result }
was only used for nonzero- gas price; implementation moved
Code quote:
/// Returns the ceiling of the division of two u128 numbers.
pub fn u128_div_ceil(a: u128, b: NonZeroU128) -> u128 {
let mut result = a / b;
if result * b.get() < a {
result += 1;
}
result
}
crates/blockifier/src/utils_test.rs
line 77 at r1 (raw file):
assert_eq!(9, u128_div_ceil(27, NonZeroU128::new(3).unwrap())); assert_eq!(10, u128_div_ceil(28, NonZeroU128::new(3).unwrap())); }
this test was moved (see above)
Code quote:
#[test]
fn test_u128_div_ceil() {
assert_eq!(1, u128_div_ceil(1, NonZeroU128::new(1).unwrap()));
assert_eq!(0, u128_div_ceil(0, NonZeroU128::new(1).unwrap()));
assert_eq!(1, u128_div_ceil(1, NonZeroU128::new(2).unwrap()));
assert_eq!(9, u128_div_ceil(27, NonZeroU128::new(3).unwrap()));
assert_eq!(10, u128_div_ceil(28, NonZeroU128::new(3).unwrap()));
}
crates/starknet_api/src/transaction.rs
line 752 at r1 (raw file):
} result }
logic was moved (see above)
Code quote:
pub fn div_ceil(self, rhs: NonzeroGasPrice) -> GasAmount {
let mut result: GasAmount = self / rhs;
if result.0 * rhs.get().0 < self.0 {
result = GasAmount(result.0 + 1);
}
result
}
crates/starknet_api/src/transaction_test.rs
line 12 at r1 (raw file):
assert_eq!(GasAmount(9), Fee(27).div_ceil(NonzeroGasPrice::new(GasPrice(3)).unwrap())); assert_eq!(GasAmount(10), Fee(28).div_ceil(NonzeroGasPrice::new(GasPrice(3)).unwrap())); }
this test was moved (see above)
Code quote:
#[test]
fn test_fee_div_ceil() {
assert_eq!(GasAmount(1), Fee(1).div_ceil(NonzeroGasPrice::new(GasPrice(1)).unwrap()));
assert_eq!(GasAmount(0), Fee(0).div_ceil(NonzeroGasPrice::new(GasPrice(1)).unwrap()));
assert_eq!(GasAmount(1), Fee(1).div_ceil(NonzeroGasPrice::new(GasPrice(2)).unwrap()));
assert_eq!(GasAmount(9), Fee(27).div_ceil(NonzeroGasPrice::new(GasPrice(3)).unwrap()));
assert_eq!(GasAmount(10), Fee(28).div_ceil(NonzeroGasPrice::new(GasPrice(3)).unwrap()));
}
160c32b
to
eccb0e4
Compare
1289853
to
2ad639a
Compare
Benchmark movements: |
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.
Reviewed 2 of 42 files at r1.
Reviewable status: 2 of 42 files reviewed, all discussions resolved
eccb0e4
to
594c451
Compare
2ad639a
to
fd9d729
Compare
Benchmark movements: |
fd9d729
to
74c50d6
Compare
594c451
to
f10a3f2
Compare
74c50d6
to
76ec0e3
Compare
f10a3f2
to
8ac2e90
Compare
76ec0e3
to
f67b6be
Compare
8ac2e90
to
b7cfbe3
Compare
f67b6be
to
6f1a5fb
Compare
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.
Reviewed 6 of 42 files at r1, 2 of 11 files at r3, all commit messages.
Reviewable status: 10 of 42 files reviewed, 1 unresolved discussion (waiting on @dorimedini-starkware)
crates/blockifier/src/execution/entry_point.rs
line 205 at r3 (raw file):
} TransactionInfo::Current(context) => { GasAmount(u128::from(context.l1_resource_bounds().max_amount))
Throughout this PR as well
Suggestion:
context.l1_resource_bounds().max_amount.into()
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.
Reviewed 4 of 42 files at r1.
Reviewable status: 14 of 42 files reviewed, 1 unresolved discussion (waiting on @dorimedini-starkware)
6f1a5fb
to
a877b2b
Compare
b7cfbe3
to
87dfe7e
Compare
a877b2b
to
455529c
Compare
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.
Reviewed 3 of 42 files at r1, 1 of 13 files at r2, 3 of 11 files at r3.
Reviewable status: 21 of 42 files reviewed, 2 unresolved discussions (waiting on @dorimedini-starkware)
crates/blockifier/src/transaction/errors.rs
line 60 at r3 (raw file):
#[error( "Max {resource} price ({max_gas_price:?}) is lower than the actual gas price: \ {actual_gas_price:?}."
Remove :?
Code quote:
"Max {resource} price ({max_gas_price:?}) is lower than the actual gas price: \
{actual_gas_price:?}."
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.
Reviewed 1 of 11 files at r3.
Reviewable status: 22 of 42 files reviewed, 3 unresolved discussions (waiting on @dorimedini-starkware)
crates/starknet_api/src/block.rs
line 242 at r3 (raw file):
#[derive(Copy, Clone, Debug)] pub struct NonzeroGasPrice(GasPrice);
Please document why this struct is needed (since we also have GasPrice in this file)
Also, I guess that the nonzero variant is not part of the block header, so maybe it's not the right file for it (this part is not blocking)
Code quote:
pub struct NonzeroGasPrice(GasPrice);
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.
Reviewed 2 of 42 files at r1.
Reviewable status: 24 of 42 files reviewed, 4 unresolved discussions (waiting on @dorimedini-starkware)
crates/starknet_api/src/transaction.rs
line 812 at r3 (raw file):
pub fn checked_mul(self, rhs: GasPrice) -> Option<Fee> { rhs.checked_mul(self) }
Why here? I think the convention is having a single impl block next to the struct definition.
Also, consider gathering all gas/price/fee structs in a separate file (non blocking)
Code quote:
impl Div<NonzeroGasPrice> for Fee {
type Output = GasAmount;
fn div(self, rhs: NonzeroGasPrice) -> Self::Output {
GasAmount(self.0 / GasPrice::from(rhs).0)
}
}
impl GasPrice {
pub const fn saturating_mul(self, rhs: GasAmount) -> Fee {
Fee(self.0.saturating_mul(rhs.0))
}
pub fn checked_mul(self, rhs: GasAmount) -> Option<Fee> {
self.0.checked_mul(rhs.0).map(Fee)
}
}
impl NonzeroGasPrice {
pub const fn saturating_mul(self, rhs: GasAmount) -> Fee {
self.get().saturating_mul(rhs)
}
pub fn checked_mul(self, rhs: GasAmount) -> Option<Fee> {
self.get().checked_mul(rhs)
}
}
impl GasAmount {
pub const fn saturating_mul(self, rhs: GasPrice) -> Fee {
rhs.saturating_mul(self)
}
pub const fn nonzero_saturating_mul(self, rhs: NonzeroGasPrice) -> Fee {
rhs.saturating_mul(self)
}
pub fn checked_mul(self, rhs: GasPrice) -> Option<Fee> {
rhs.checked_mul(self)
}
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.
Reviewed 1 of 11 files at r3.
Reviewable status: 25 of 42 files reviewed, 4 unresolved discussions (waiting on @dorimedini-starkware)
455529c
to
f28fdce
Compare
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.
Reviewable status: 17 of 50 files reviewed, 4 unresolved discussions (waiting on @Yoni-Starkware)
crates/blockifier/src/execution/entry_point.rs
line 205 at r3 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
Throughout this PR as well
Done.
crates/blockifier/src/transaction/errors.rs
line 60 at r3 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
Remove
:?
Done.
crates/starknet_api/src/block.rs
line 242 at r3 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
Please document why this struct is needed (since we also have GasPrice in this file)
Also, I guess that the nonzero variant is not part of the block header, so maybe it's not the right file for it (this part is not blocking)
- It should be in starknet-api so we can have
impl Fee { fn div_ceil(self, rhs: NonzeroGasPrice) -> GasAmount; }
- I put it in this module so it's next to
GasPrice
documented
crates/starknet_api/src/transaction.rs
line 812 at r3 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
Why here? I think the convention is having a single impl block next to the struct definition.
Also, consider gathering all gas/price/fee structs in a separate file (non blocking)
Done.
Benchmark movements: |
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.
Reviewed 1 of 42 files at r1, 1 of 13 files at r2, 1 of 11 files at r3, 7 of 23 files at r4, all commit messages.
Reviewable status: 27 of 50 files reviewed, 3 unresolved discussions (waiting on @dorimedini-starkware)
crates/blockifier/src/execution/entry_point.rs
line 205 at r3 (raw file):
Previously, dorimedini-starkware wrote…
Done.
Not done :(
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.
Reviewed 1 of 13 files at r2, 3 of 23 files at r4.
Reviewable status: 31 of 50 files reviewed, 4 unresolved discussions (waiting on @dorimedini-starkware)
crates/blockifier/src/transaction/test_utils.rs
line 361 at r4 (raw file):
) -> ValidResourceBounds { ValidResourceBounds::AllResources(AllResourceBounds { l1_gas: ResourceBounds {
Are you going to change its types in a future PR?
Code quote:
ResourceBounds {
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.
Reviewed 3 of 42 files at r1, 6 of 23 files at r4.
Reviewable status: 40 of 50 files reviewed, 5 unresolved discussions (waiting on @dorimedini-starkware)
crates/gateway/src/rpc_objects.rs
line 102 at r4 (raw file):
fn parse_gas_price(gas_price: GasPrice) -> Result<NonzeroGasPrice, RPCStateReaderError> { NonzeroGasPrice::new(gas_price) .map_err(|_| RPCStateReaderError::GasPriceParsingFailure(gas_price))
What's the difference?
Code quote:
.map_err(|_|
f28fdce
to
fe58aee
Compare
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.
Reviewable status: 31 of 51 files reviewed, 3 unresolved discussions (waiting on @Yoni-Starkware)
crates/blockifier/src/execution/entry_point.rs
line 205 at r3 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
Not done :(
oops... now done, I hope
crates/blockifier/src/transaction/test_utils.rs
line 361 at r4 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
Are you going to change its types in a future PR?
crates/gateway/src/rpc_objects.rs
line 102 at r4 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
What's the difference?
NonZeroU128::new
returns Option
, while NonzeroGasPrice::new
returns Result
9b4d1d0
to
26aa095
Compare
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.
Reviewed 1 of 42 files at r1, 2 of 13 files at r2, 5 of 23 files at r4, 12 of 12 files at r5, 5 of 5 files at r6, all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @dorimedini-starkware)
…gas amount/price, and fee
26aa095
to
3c2d2d7
Compare
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.
Reviewed 1 of 1 files at r7, all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @dorimedini-starkware)
This change is