Skip to content
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

[FastX adapter/verifier] Followup to the module initializers PR (#337) #436

Merged
merged 7 commits into from
Feb 14, 2022

Conversation

awelc
Copy link
Contributor

@awelc awelc commented Feb 11, 2022

This is a followup to the #337 PR providing support for module initializers (Issue #90) with some additional checks and fixes, based on @lxfind's feedback.

@awelc awelc requested review from lxfind and sblackshear February 11, 2022 22:05
@awelc awelc self-assigned this Feb 11, 2022
Copy link
Contributor

@lxfind lxfind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!
Approve with a few nits

@@ -198,6 +198,8 @@ impl Storage for AuthorityTemporaryStore {
}

fn read_object(&self, id: &ObjectID) -> Option<Object> {
// there should be no read after delete
assert!(self.deleted.get(id) == None);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use debug_assert for consistency.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it! As I (think I) understand it now, assert! is only for tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert! is turned on in release build, while debug_assert! is only turned on in debug build.

// (before the call) must be larger than gas_used (after
// the call) in order for the call to succeed in the first
// place.
assert!(current_gas_budget > gas_used);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert!(current_gas_budget > gas_used);
assert!(current_gas_budget >= gas_used);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! Also changed to debug_assert!.

Comment on lines 159 to 161
total_gas_budget: u64, // gas budget for all operations in this transaction
current_gas_budget: u64, // gas budget for the current call operation
gas_previously_used: u64,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems really complicated. Not sure if I fully understand why we need all these three, but execute_internal shouldn't need to worry about the total budget or previously used gas. All it needs to know is the current remaining budget, and if fail, return the amount used (which will always be <= current budget). And the caller handle the final numbers

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that the logic is sound, and the additional parameters are used to create the correct error values in execute_internal. I agree that this is not easy to follow, though, and I will try to refactor it further to post-process failure results coming from execute_internal to reflect total gas values in its caller, rather than handling these directly in execute_internal and mostly propagating the errors up the call chain. This should hopefully simplify execute_internal and make the whole gas handling more intuitive.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An attempt to clean this up is in. Hopefully it's easier to read (and makes some sense) - it's surprisingly subtle (particularly to uninitiated not used to thinking in these terms).

Copy link
Contributor

@lxfind lxfind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left comments inline

@@ -44,12 +45,18 @@ use std::{

pub use move_vm_runtime::move_vm::MoveVM;

macro_rules! exec_failure {
macro_rules! exec_error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be a macro. The intention of macro is to express something that could not be expressed through function calls (e.g. embedded a return like exec_failure). exec_error seems something that can be done with a simple function. I recommend adding a function to ExecutionStatus for this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed! I really appreciate all the Rust-related suggestions as I am still learning what the best practices are - please keep them coming for as long as you have patience(in this case I simply thought it would be cleaner to use a macro within a macro rather than defining a new function)!

Copy link
Contributor

@lxfind lxfind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for cleaning this up!

@awelc awelc merged commit 82003cd into main Feb 14, 2022
@awelc awelc deleted the aw/module-initializers-followup branch February 14, 2022 23:48
@awelc awelc linked an issue Feb 17, 2022 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[fastx adapter/verifier] implement Move module initializers
2 participants