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

Refactor fuel-core to use version of StorageRead::read with offset #2438

Open
wants to merge 26 commits into
base: master
Choose a base branch
from

Conversation

acerone85
Copy link
Contributor

Linked Issues/PRs

Related to FuelLabs/fuel-vm#681

Description

In order to load contracts from a given offset efficiently, we have changed the interface of StorageRead::read to accept a n offset in input (see FuelLabs/fuel-vm#863). This PR refactors the fuel-core repo to make use of the new StorageRead trait.

Do not merge

we should first wait for the changes to StorageRead to be released in fuel-vm, after which we can update the dependencies in this PR

Checklist

  • Breaking changes are clearly marked as such in the PR description and changelog
  • New behavior is reflected in tests
  • The specification matches the implemented behavior (link update PR if changes are needed)

Before requesting review

  • I have reviewed the code myself
  • I have created follow-up issues caused by this PR and linked them here

After merging, notify other teams

[Add or remove entries as needed]

@acerone85
Copy link
Contributor Author

I find it suspicious that I never had to hardcode the offset value to 0 in this PR. Is StorageRead::read used at all in fuel-core?

@acerone85 acerone85 changed the title (Do not merge): Refactor fuel-core to use version of StorageRead::read with offset Refactor fuel-core to use version of StorageRead::read with offset Dec 4, 2024
@@ -546,7 +546,8 @@ impl TryFrom<VmBench> for VmBenchPrepared {
}
let storage_diff = vm.storage_diff();
let mut vm = vm.remove_recording();
let mut diff = start_vm.diff(&vm);
// TODO: Check if this is the intended use of rollback_to.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@xgreenx please check that this is how we intend to use the new rollback_to funciton, in which case we can remove the TODO

@@ -4084,6 +4084,7 @@ dependencies = [
"sha3",
"static_assertions",
"strum 0.24.1",
"substrate-bn",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Check, do we want this?

Copy link
Member

Choose a reason for hiding this comment

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

i think it is a side-effect of bumping fuel-vm. the ecc operations under the hood use substrate-bn

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes I confirm

Comment on lines +5408 to +5410
dependencies = [
"spin 0.9.8",
]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

same: do we need this?

Copy link
Contributor

Choose a reason for hiding this comment

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

it comes from lazy static from the substra-bn

.map_err(|e| DatabaseError::Other(anyhow::anyhow!(e)))?;
StorageResult::Ok(read)
if let Some(read) = value.len().checked_sub(offset) {
std::io::Write::write_all(&mut buf, value[offset..].as_ref())
Copy link
Contributor

@AurelienFT AurelienFT Dec 4, 2024

Choose a reason for hiding this comment

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

this can panic if offset is out of bounds maybe we should use .get ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If offset is out of bounds, then value.len().checked_sub(offset) should return None and this code won't be executed.
But I agree that it is not immediate from the code, so maybe there's a better way to write this? 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah i missed it a comment is fine

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.

3 participants