-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Implement storage access via storage keyword #646
Conversation
This example should be updated after FuelLabs#646 lands.
… mdbook preprocessor. (#766) * Extract `hello_world` example from the book into a standalone project Related to #544. Follows the example set in #731. Tested with `mdbook serve`. Also adds the `hello_world` and `subcurrency` examples to the Sway workspace so that we can test both projects under CI. * Fix hello_world example project name in forc manifest * Move fizzbuzz and wallet_smart_contract examples to standalone projects * Add `build-all-examples` script and associated CI passes This script walks the examples directory and, for every directory containing a `forc.toml` file, runs `forc build` for that directory. Examples that encounter a failure of some kind have their `stdout` and `stderr` piped through so we can easily identify cause of failure in CI. This also removes the examples from the workspace. Currently unsure whether or not the added CI pass to install `forc` will result in `forc` actually being available on the PATH in the CI worker, but will find out soon. Still need to work out how to run `forc test` for each project without having cargo complain about building within the parent sway workspace. * Add a clear build summary at the end of `build-all-examples` Currently, it's tricky to get an idea of how many successes/failures there were without combing through the stdout/stderr. This adds a little summary to the end that looks something like this: ``` Build all examples summary: [✓]: /home/mindtree/programming/rust/fuel/sway/examples/fizzbuzz succeeded! [✓]: /home/mindtree/programming/rust/fuel/sway/examples/hello_world succeeded! [x]: /home/mindtree/programming/rust/fuel/sway/examples/wallet_smart_contract failed! [✓]: /home/mindtree/programming/rust/fuel/sway/examples/subcurrency succeeded! 3 successes, 1 failure ``` * Set build-all-examples script version to 0.0.0 * Exclude examples from workspace, Fix hello_world test harness path * Temporarily comment out storage related code in wallet example This example should be updated after #646 lands. * Install forc with `--debug` to share build artifacts Currently it takes CI another 7 mins to build and install forc from scratch. This should allow `cargo` to re-use the artifacts it has already built during the sway building and testing steps earlier in the CI job. * Change author field in examples from mindtree -> Fuel Labs
f2629ba
to
c7e93d6
Compare
I will do all the purity/impurity checks and warnings in a separate PR. Also, had to force push because consolidating my branch and this one would've been a nightmare. |
..._tests/test_programs/should_pass/require_contract_deployment/storage_access_caller/Forc.toml
Outdated
Show resolved
Hide resolved
|
||
// Test 1 | ||
caller.set_x { | ||
gas: 10000 |
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.
Is there a reason to specify gas here instead of default? My concern is that if we set the gas cost to a storage write to e.g. 20k like on Ethereum, then all these tests will fail. Why not just forward all gas?
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.
All of our contract tests seem to be overriding gas
.
When I remove this, I get an OutOfGas
panic.
I get the same behavior with this test: https://github.com/FuelLabs/sway/blob/master/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_basic_storage/src/main.sw and the assembly for it looks correct. Here's the relevant snippet
...
lw $r4 $cgas i0 ; loading $cgas (gas) into abi function
lw $r3 data_3 ; loading the default coins value for call
lw $r2 data_4 ; loading the default asset_id value for call
lw $r1 data_5 ; literal instantiation
move $r7 $sp
cfei i48
mcpi $r7 $r1 i32 ; copy contract address for call
sw $r7 $r0 i4 ; write fn selector to rA + 32 for call
sw $r7 $r5 i5 ; move user param for call
call $r7 $r3 $r2 $r4 ; call external contract
...
isn't $cgas
meant to start with a tx.gasLimit
?
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.
$cgas
starts at tx.gasLimit
, yes. But with each contract call, it's initially the gas forwarded. Note that if you try to forward more than $cgas
, then only $cgas
is forwarded. It should not be a panic in the VM.
Can't seem to add @sezna as a reviewer (maybe because he's the PR author?) |
taking a look! |
...ests/test_programs/should_pass/require_contract_deployment/storage_access_caller/src/main.sw
Show resolved
Hide resolved
Co-authored-by: Alex Hansen <alex@alex-hansen.com>
I would approve but I'm the author, so I can't. Cc @otrho perhaps since he has some context? |
@emilyaherbert merging with |
LGTM |
I'm merging this even though the test stopped working now due some changes that Toby had to (rightfully) make to the contract call stuff in IR to make the verifier work as it needs. Toby and I will be dealing with that asap. The AST generated for storage has not changed and so, this change continues to do the right thing as it was tested before Toby made the verifier changes. |
This closes #645. This is a WIP currently.
Remaining:
mapping
)This enables storage declarations, accesses, and reassignment via the
storage
keyword.Syntax
Storage Declaration
Storage Accesses
Storage Reassignment
Notes
x
andy
will get their own storage slots.