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

Change read behavior on the InMemoryTransaction to use offset and allow not equal buf size #2673

Merged
merged 4 commits into from
Feb 5, 2025

Conversation

AurelienFT
Copy link
Contributor

@AurelienFT AurelienFT commented Feb 5, 2025

Linked Issues/PRs

closes #2672

Description

Change code of read of InMemoryTransaction to match the other read functions

Tests had been added and the error in read function has been improved to be more clear.

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

@AurelienFT AurelienFT marked this pull request as ready for review February 5, 2025 16:45
rymnc
rymnc previously approved these changes Feb 5, 2025
Copy link
Member

@rymnc rymnc left a comment

Choose a reason for hiding this comment

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

can confirm this fixes my bug

@@ -13,6 +13,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- [2667](https://github.com/FuelLabs/fuel-core/pull/2667): Populate `Blobs` table in global merkle root storage.
- [2652](https://github.com/FuelLabs/fuel-core/pull/2652): Global Merkle Root storage crate: Add Raw contract bytecode to global merkle root storage when processing Create transactions.

### Fixed
- [2673](https://github.com/FuelLabs/fuel-core/pull/2673): Change read behavior on the InMemoryTransaction to use offset and allow not equal buf size (fix CCP and LDC broken from https://github.com/FuelLabs/fuel-vm/pull/847)
Copy link
Contributor

Choose a reason for hiding this comment

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

technically the bug was introduced in #2438, the change in fuel-vm seems to be working as expected from what I can tell

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For me it's FuelLabs/fuel-vm#847 that broke CCP and LDC opcode if this PR hasn't land on master, the read function would have been wrong since #2438 but the opcode would have been fine.

Copy link
Contributor

Choose a reason for hiding this comment

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

yep, but the error is triggered in the if branch of an if else statement that does not invoke any of the code in fuel-vm.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes I talked about the error just before in the sentence I just added this parenthesis with the opcode in case we want to find later to have beteer search results

@AurelienFT AurelienFT enabled auto-merge (squash) February 5, 2025 17:45
let storage = InMemoryStorage::<Column>::default();
let mut view = storage.read_transaction();
let key = vec![0xA, 0xB, 0xC];
let expected = Value::from([1, 2, 3]);
Copy link
Member

Choose a reason for hiding this comment

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

nit: we probably shouldn't use expected here (or on the other tests). Copy pasta.
Perhaps source_data makes more sense.

Copy link
Member

Choose a reason for hiding this comment

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

should we address in a follow up?

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

Comment on lines 683 to 697
#[test]
fn read_returns_from_view_buf_smaller() {
// setup
let storage = InMemoryStorage::<Column>::default();
let mut view = storage.read_transaction();
let key = vec![0xA, 0xB, 0xC];
let expected = Value::from([1, 2, 3]);
view.put(&key, Column::Metadata, expected.clone()).unwrap();
// test
let mut buf = [0; 2];
let ret = view.read(&key, Column::Metadata, 0, &mut buf).unwrap();
// verify
assert_eq!(ret, Some(2));
assert_eq!(buf, [1, 2]);
}
Copy link
Member

Choose a reason for hiding this comment

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

Maybe add another test with offset and passing. Could just be the same as this but
assert_eq!(buf, [2, 3]);

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

@netrome netrome linked an issue Feb 5, 2025 that may be closed by this pull request
Copy link
Member

@rymnc rymnc left a comment

Choose a reason for hiding this comment

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

g1

Copy link
Member

@MitchTurner MitchTurner left a comment

Choose a reason for hiding this comment

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

LGTM. I'd recommend getting @xgreenx 's eyes on it just in case.

@AurelienFT AurelienFT merged commit 3725f21 into master Feb 5, 2025
32 checks passed
@AurelienFT AurelienFT deleted the fix_read_behaviour branch February 5, 2025 19:21
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.

CCP and LDC errors if given a buffer size less than the contract size.
4 participants