-
Notifications
You must be signed in to change notification settings - Fork 31
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): refactor native stack config #3003
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
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 3 files at r1, all commit messages.
Reviewable status: 1 of 3 files reviewed, 3 unresolved discussions (waiting on @AvivYossef-starkware)
crates/blockifier/src/versioned_constants.rs
line 503 at r1 (raw file):
pub fn get_target_stack_size(&self, red_zone: usize) -> usize { std::cmp::min(red_zone + self.buffer_size, self.max_stack_size) }
Take the min
in get_stack_size_red_zone
as well, not here.
Add the self.max_stack_size
to the red zone without capping to get the target size.
crates/blockifier/src/execution/native/entry_point_execution.rs
line 65 at r1 (raw file):
max_stack_size: 170 * 1024 * 1024, min_stack_red_zone: 2 * 1024 * 1024, buffer_size: 1024 * 1024,
To be on the safe side
Suggestion:
gas_to_stack_ratio: Ratio::new(1, 20),
max_stack_size: 200 * 1024 * 1024,
min_stack_red_zone: 2 * 1024 * 1024,
buffer_size: 5 * 1024 * 1024,
crates/blockifier/src/execution/native/entry_point_execution.rs
line 69 at r1 (raw file):
let stack_size_red_zone = stack_config.get_stack_size_red_zone( usize::try_from(syscall_handler.base.call.initial_gas) .expect("initial gas to usize should always succeed"),
Not sure about it. usize can be 32 bit.
The stack size should be usize, try to convert at the end.
Code quote:
.expect("initial gas to usize should always succeed"),
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: 1 of 3 files reviewed, 3 unresolved discussions (waiting on @AvivYossef-starkware)
crates/blockifier/src/versioned_constants.rs
line 503 at r1 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
Take the
min
inget_stack_size_red_zone
as well, not here.
Add theself.max_stack_size
to the red zone without capping to get the target size.
(I want the target size to always be greater then the red zone)
9d9e407
to
fa0e3b8
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: 1 of 3 files reviewed, 3 unresolved discussions (waiting on @Yoni-Starkware)
crates/blockifier/src/versioned_constants.rs
line 503 at r1 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
(I want the target size to always be greater then the red zone)
So, don't we want to limit the stack size?
In that case, do we need both buffer_size
and max_stack_size
?
crates/blockifier/src/execution/native/entry_point_execution.rs
line 65 at r1 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
To be on the safe side
Done.
crates/blockifier/src/execution/native/entry_point_execution.rs
line 69 at r1 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
Not sure about it. usize can be 32 bit.
The stack size should be usize, try to convert at the end.
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.
Reviewable status: 1 of 3 files reviewed, 3 unresolved discussions (waiting on @AvivYossef-starkware)
crates/blockifier/src/execution/native/entry_point_execution.rs
line 71 at r2 (raw file):
let target_stack_size = usize::try_from(stack_config.get_target_stack_size(stack_size_red_zone)) .map_err(|e| EntryPointExecutionError::InternalError(e.to_string()))?;
You should panic here - it is our problem, not the user's (returning an error will fail the transaction)
Code quote:
.map_err(|e| EntryPointExecutionError::InternalError(e.to_string()))?;
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: 1 of 3 files reviewed, 3 unresolved discussions (waiting on @AvivYossef-starkware)
crates/blockifier/src/versioned_constants.rs
line 503 at r1 (raw file):
Previously, AvivYossef-starkware wrote…
So, don't we want to limit the stack size?
In that case, do we need bothbuffer_size
andmax_stack_size
?
We want:
- to limit the stack size
- to have the target size always
red_zone + buffer
.
So the "real" max is the config + buffer, which is fine.
fa0e3b8
to
5d2bcf8
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: 1 of 3 files reviewed, 3 unresolved discussions (waiting on @Yoni-Starkware)
crates/blockifier/src/versioned_constants.rs
line 503 at r1 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
We want:
- to limit the stack size
- to have the target size always
red_zone + buffer
.So the "real" max is the config + buffer, which is fine.
Ok so I'll limit the min < red zone < max
and always add the buffer size
crates/blockifier/src/execution/native/entry_point_execution.rs
line 71 at r2 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
You should panic here - it is our problem, not the user's (returning an error will fail the transaction)
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 all commit messages.
Reviewable status: 1 of 3 files reviewed, 4 unresolved discussions (waiting on @AvivYossef-starkware)
crates/blockifier/src/versioned_constants.rs
line 498 at r3 (raw file):
std::cmp::max( self.max_stack_size, std::cmp::min(
Oops.
Use clamp
instead (google it)
Suggestion:
std::cmp::min(
self.max_stack_size,
std::cmp::max(
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: 1 of 3 files reviewed, 5 unresolved discussions (waiting on @AvivYossef-starkware)
crates/blockifier/src/versioned_constants.rs
line 494 at r3 (raw file):
impl CairoNativeStackConfig { /// Returns the size of the stack red zone, relative to the remaining gas.
Suggestion:
/// Returnד the stack size sufficient for running Cairo Native with the given gas.
5d2bcf8
to
df74543
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: 1 of 3 files reviewed, 4 unresolved discussions (waiting on @Yoni-Starkware)
crates/blockifier/src/versioned_constants.rs
line 498 at r3 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
Oops.
Useclamp
instead (google it)
Done.
crates/blockifier/src/versioned_constants.rs
line 494 at r3 (raw file):
impl CairoNativeStackConfig { /// Returns the size of the stack red zone, relative to the remaining gas.
Done.
df74543
to
d14f9d4
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 r4, all commit messages.
Reviewable status: 2 of 3 files reviewed, 1 unresolved discussion (waiting on @AvivYossef-starkware)
crates/blockifier/src/execution/native/entry_point_execution.rs
line 76 at r4 (raw file):
let execution_result = stacker::maybe_grow( usize::try_from(stack_size_red_zone) .unwrap_or_else(|e| panic!("Failed to convert stack size red zone to usize: {}", e)),
Move the convesion up, to be consistent with target_stack_size
Code quote:
usize::try_from(stack_size_red_zone)
.unwrap_or_else(|e| panic!("Failed to convert stack size red zone to usize: {}", e)),
c12d04c
to
6c60441
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: 0 of 3 files reviewed, 1 unresolved discussion (waiting on @Yoni-Starkware)
crates/blockifier/src/execution/native/entry_point_execution.rs
line 76 at r4 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
Move the convesion up, to be consistent with
target_stack_size
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 3 of 3 files at r5, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @AvivYossef-starkware)
crates/blockifier/src/versioned_constants.rs
line 512 at r5 (raw file):
pub fn get_target_stack_size(&self, red_zone: u64) -> u64 { red_zone + self.buffer_size
This is the size that matters. Round also here to be on the safe side.
Code quote:
red_zone + self.buffer_size
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: all files reviewed, 2 unresolved discussions (waiting on @AvivYossef-starkware)
crates/blockifier/src/versioned_constants.rs
line 511 at r5 (raw file):
} pub fn get_target_stack_size(&self, red_zone: u64) -> u64 {
Also, document that the stack size must be in page_size
multiplications since there is a bug in stacker::grow
Code quote:
pub fn get_target_stack_size(&self, red_zone: u64) -> u64 {
6c60441
to
121acb4
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: 2 of 3 files reviewed, 2 unresolved discussions (waiting on @Yoni-Starkware)
crates/blockifier/src/versioned_constants.rs
line 511 at r5 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
Also, document that the stack size must be in
page_size
multiplications since there is a bug instacker::grow
Ok, I wasn't sure if we want to make it public
crates/blockifier/src/versioned_constants.rs
line 512 at r5 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
This is the size that matters. Round also here to be on the safe side.
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 1 files at r6, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @AvivYossef-starkware)
crates/blockifier/src/versioned_constants.rs
line 511 at r5 (raw file):
Previously, AvivYossef-starkware wrote…
Ok, I wasn't sure if we want to make it public
Hmm okay, so let's rephrase
// Stack size should be a multiple of page size, since `stacker::grow` works with this unit.
crates/blockifier/src/versioned_constants.rs
line 497 at r6 (raw file):
pub fn round_up_to_mb(size: u64) -> u64 { const MB: u64 = 1024 * 1024; if size % MB == 0 { size } else { ((size / MB) + 1) * MB }
Consider
Suggestion:
((size + MB - 1) / MB) * MB
crates/blockifier/src/versioned_constants.rs
line 513 at r6 (raw file):
pub fn get_target_stack_size(&self, red_zone: u64) -> u64 { // Stack size must be a multiple of page size. // Since there is a bug in `stacker::grow`.
121acb4
to
14547da
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: 2 of 3 files reviewed, 1 unresolved discussion (waiting on @Yoni-Starkware)
crates/blockifier/src/versioned_constants.rs
line 497 at r6 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
Consider
The compiler asked me to use div_ceil
( its the same )
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: all files reviewed, 1 unresolved discussion (waiting on @AvivYossef-starkware)
crates/blockifier/src/versioned_constants.rs
line 497 at r6 (raw file):
Previously, AvivYossef-starkware wrote…
The compiler asked me to use
div_ceil
( its the same )
Don't you need to multiply by MB?
14547da
to
0a2cd80
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 r8, all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @AvivYossef-starkware)
No description provided.