Skip to content

Commit 90c8ed2

Browse files
bitzoicironcev
andauthored
Reduce storage API byte allocation (#7430)
## Description Legacy functionality from the storage API now allocates more memory than required for the read and write functions. This allocation has been reduced to the correct amounts. Reduces unnecessary byte allocation by 8x. ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [x] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [x] If my change requires substantial documentation changes, I have [requested support from the DevRel team](https://github.com/FuelLabs/devrel-requests/issues/new/choose) - [x] I have added tests that prove my fix is effective or that my feature works. - [x] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers. --------- Co-authored-by: Igor Rončević <[email protected]>
1 parent bfbe490 commit 90c8ed2

File tree

6 files changed

+11
-11
lines changed
  • forc-plugins/forc-client/tests
  • sway-lib-std/src/storage
  • test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment

6 files changed

+11
-11
lines changed

forc-plugins/forc-client/tests/deploy.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ async fn test_simple_deploy() {
377377
node.kill().unwrap();
378378
let expected = vec![DeployedPackage::Contract(DeployedContract {
379379
id: ContractId::from_str(
380-
"677a9eefe864cde328b1f6e58a0d9829fc3b683fca48e36e9bcb4863179ae174",
380+
"307a59fbb6888da41942653ca21d9c71e06d72edb58b8d775eea87c7e755ebdb",
381381
)
382382
.unwrap(),
383383
proxy: None,
@@ -421,7 +421,7 @@ async fn test_deploy_submit_only() {
421421
node.kill().unwrap();
422422
let expected = vec![DeployedPackage::Contract(DeployedContract {
423423
id: ContractId::from_str(
424-
"677a9eefe864cde328b1f6e58a0d9829fc3b683fca48e36e9bcb4863179ae174",
424+
"307a59fbb6888da41942653ca21d9c71e06d72edb58b8d775eea87c7e755ebdb",
425425
)
426426
.unwrap(),
427427
proxy: None,
@@ -468,12 +468,12 @@ async fn test_deploy_fresh_proxy() {
468468
node.kill().unwrap();
469469
let impl_contract = DeployedPackage::Contract(DeployedContract {
470470
id: ContractId::from_str(
471-
"677a9eefe864cde328b1f6e58a0d9829fc3b683fca48e36e9bcb4863179ae174",
471+
"307a59fbb6888da41942653ca21d9c71e06d72edb58b8d775eea87c7e755ebdb",
472472
)
473473
.unwrap(),
474474
proxy: Some(
475475
ContractId::from_str(
476-
"fedbb732b17cf256aa378584438a154d11d413d5cfbdeca63a00128530aa0ebb",
476+
"70a447780b00c9725859bbef1cd327a9455cc62fbe607a0524b2c82a5846f5a9",
477477
)
478478
.unwrap(),
479479
),

sway-lib-std/src/storage/storage_api.sw

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
library;
22

3-
use ::alloc::alloc;
3+
use ::alloc::alloc_bytes;
44
use ::option::Option::{self, *};
55
use ::ops::*;
66
use ::primitive_conversions::{b256::*, u256::*, u64::*};
@@ -52,7 +52,7 @@ pub fn write<T>(slot: b256, offset: u64, value: T) {
5252

5353
// Allocate enough memory on the heap for `value` as well as any potential padding required due
5454
// to `offset`.
55-
let padded_value = alloc::<u64>(number_of_slots * 32);
55+
let padded_value = alloc_bytes(number_of_slots * 32);
5656

5757
// Read the values that currently exist in the affected storage slots.
5858
let _ = __state_load_quad(offset_slot, padded_value, number_of_slots);
@@ -105,7 +105,7 @@ pub fn read<T>(slot: b256, offset: u64) -> Option<T> {
105105

106106
// Allocate a buffer for the result. Its size needs to be a multiple of 32 bytes so we can
107107
// make the 'quad' storage instruction read without overflowing.
108-
let result_ptr = alloc::<u64>(number_of_slots * 32);
108+
let result_ptr = alloc_bytes(number_of_slots * 32);
109109

110110
// Read `number_of_slots * 32` bytes starting at storage slot `slot` and return an `Option`
111111
// wrapping the value stored at `result_ptr + offset` if all the slots are valid. Otherwise,

test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_basic_storage/src/main.sw

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use basic_storage_abi::{BasicStorage, Quad};
44
#[cfg(experimental_new_encoding = false)]
55
const CONTRACT_ID = 0x94db39f409a31b9f2ebcadeea44378e419208c20de90f5d8e1e33dc1523754cb;
66
#[cfg(experimental_new_encoding = true)]
7-
const CONTRACT_ID = 0x49d9bdf1aaba3772e9dd2f87c970bcab4d3e5b8a15d03267e5697312e4bfbf01; // AUTO-CONTRACT-ID ../../test_contracts/basic_storage --release
7+
const CONTRACT_ID = 0x5b200b16a332ccf2be472f4e027c587bdbe9504618d88c97b5f151c9b84a6763; // AUTO-CONTRACT-ID ../../test_contracts/basic_storage --release
88

99
fn main() -> u64 {
1010
let addr = abi(BasicStorage, CONTRACT_ID);

test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_increment_contract/src/main.sw

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use dynamic_contract_call::*;
66
#[cfg(experimental_new_encoding = false)]
77
const CONTRACT_ID = 0xd1b4047af7ef111c023ab71069e01dc2abfde487c0a0ce1268e4f447e6c6e4c2;
88
#[cfg(experimental_new_encoding = true)]
9-
const CONTRACT_ID = 0xbf495d4b4a2ee955073433b736a44e445b280cb0a7113408d1441515510b52aa; // AUTO-CONTRACT-ID ../../test_contracts/increment_contract --release
9+
const CONTRACT_ID = 0x2831f6a4598517a3e1de7ee8430b3e232d3b480c26cd2f36bea7e2838732c313; // AUTO-CONTRACT-ID ../../test_contracts/increment_contract --release
1010

1111
fn main() -> bool {
1212
let the_abi = abi(Incrementor, CONTRACT_ID);

test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_storage_enum/src/main.sw

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use storage_enum_abi::*;
55
#[cfg(experimental_new_encoding = false)]
66
const CONTRACT_ID = 0xc601d11767195485a6654d566c67774134668863d8c797a8c69e8778fb1f89e9;
77
#[cfg(experimental_new_encoding = true)]
8-
const CONTRACT_ID = 0x49753ced6c53395e8506fd429a397e644adb08db5d436def77231256630e94b6; // AUTO-CONTRACT-ID ../../test_contracts/storage_enum_contract --release
8+
const CONTRACT_ID = 0x0b8fc40c515e04d925fde7200b42f1e86108b4227de412bf245be24bbe3e2d5f; // AUTO-CONTRACT-ID ../../test_contracts/storage_enum_contract --release
99

1010
fn main() -> u64 {
1111
let caller = abi(StorageEnum, CONTRACT_ID);

test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/storage_access_caller/src/main.sw

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::hash::*;
66
#[cfg(experimental_new_encoding = false)]
77
const CONTRACT_ID = 0x3bc28acd66d327b8c1b9624c1fabfc07e9ffa1b5d71c2832c3bfaaf8f4b805e9;
88
#[cfg(experimental_new_encoding = true)]
9-
const CONTRACT_ID = 0x09055b9ec4efa2651fc5b753caf18a251af41f97ff25c60f8cc39ececa4a3364; // AUTO-CONTRACT-ID ../../test_contracts/storage_access_contract --release
9+
const CONTRACT_ID = 0x5f28104f4eb74dff6b73fd0a66bcfdd89d608005abc4196c1ffb5bc54092afca; // AUTO-CONTRACT-ID ../../test_contracts/storage_access_contract --release
1010

1111
fn main() -> bool {
1212
let caller = abi(StorageAccess, CONTRACT_ID);

0 commit comments

Comments
 (0)