Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
80d302e
Fix links in release notes (#1277)
cmichi May 25, 2022
0a96173
Revert "Optimise deny_payment. Use eerywhere semantic of deny. (#1267)"
agryaznov Jun 5, 2022
cd26767
Revert backward-incompatible piece of #1224: dependency on `[seal1] s…
agryaznov Jun 6, 2022
061c94e
Revert backward-incompatible piece of #1233: removal of eth_compatibi…
agryaznov Jun 6, 2022
b17e8af
bump crate versions + update RELEASES.md
agryaznov Jun 6, 2022
5ae4bc1
Mapping::insert_return_size is back, having now both `seal1` and `sea…
agryaznov Jun 6, 2022
5633392
set_storage_silent -> set_storage_compat renaming
agryaznov Jun 6, 2022
4be7403
spell fix
agryaznov Jun 10, 2022
ee532c8
Apply suggestions from code review
agryaznov Jun 15, 2022
b0daa41
Apply suggestions from code review
agryaznov Jun 15, 2022
fa6d2c8
Update crates/env/src/backend.rs
agryaznov Jun 15, 2022
e0f2259
doc comments enhanced
agryaznov Jun 15, 2022
3fb9c76
`Mapping::insert()` to use backwards compatible seal fn
agryaznov Jun 15, 2022
06bedc4
unreleased changes planned for 4.x removed from 3.x
agryaznov Jun 15, 2022
f5f6bc9
Add more details to the release notes
HCastano Jun 15, 2022
609236a
fix catched issue with changed api function signature
agryaznov Jun 16, 2022
5a03407
fix storage trait dependent func
agryaznov Jun 16, 2022
dbee0ab
Apply new versions naming policy: step1. Old versions to keep their n…
agryaznov Jun 16, 2022
7e14d0b
Apply new versions naming policy: step2. Add `deprecated` attr and `#…
agryaznov Jun 16, 2022
b1a7393
Apply suggestions from code review
agryaznov Jun 17, 2022
9171c38
fixes after next review round
agryaznov Jun 17, 2022
89b94fc
Merge branch 'v3.x.x' into ag-3.3.0-hotfixes
agryaznov Jun 17, 2022
05f7e82
more fixes after the review round
agryaznov Jun 20, 2022
2466027
fmt
agryaznov Jun 20, 2022
180af6c
Merge branch 'v3.x.x' into ag-3.3.0-hotfixes
agryaznov Jun 20, 2022
ddebf6c
spellcheck config fix
agryaznov Jun 20, 2022
28ee702
Small wording fixes
HCastano Jun 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Mapping::insert_return_size is back, having now both seal1 and `sea…
…l0` seal_set_storage versions used
  • Loading branch information
agryaznov committed Jun 6, 2022
commit 5ae4bc1fa9432c11836f6de5c1144e371bc6ff20
19 changes: 17 additions & 2 deletions crates/engine/src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ impl Engine {
});
}

/// Writes the encoded value into the storage at the given key.
pub fn set_storage(&mut self, key: &[u8; 32], encoded_value: &[u8]) {
/// Silently writes the encoded value into the storage at the given key.
pub fn set_storage_silent(&mut self, key: &[u8; 32], encoded_value: &[u8]) {
let callee = self.get_callee();
let account_id = AccountId::from_bytes(&callee[..]);

Expand All @@ -244,6 +244,21 @@ impl Engine {
);
}

/// Writes the encoded value into the storage at the given key.
/// Returns the size of the previously stored value at the key if any.
pub fn set_storage(&mut self, key: &[u8; 32], encoded_value: &[u8]) -> Option<u32> {
let callee = self.get_callee();
let account_id = AccountId::from_bytes(&callee[..]);

self.debug_info.inc_writes(account_id.clone());
self.debug_info
.record_cell_for_account(account_id, key.to_vec());

self.database
.insert_into_contract_storage(&callee, key, encoded_value.to_vec())
.map(|v| <u32>::try_from(v.len()).expect("usize to u32 conversion failed"))
}

/// Returns the decoded contract storage at the key if any.
pub fn get_storage(&mut self, key: &[u8; 32], output: &mut &mut [u8]) -> Result {
let callee = self.get_callee();
Expand Down
17 changes: 16 additions & 1 deletion crates/env/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,27 @@ where
})
}

/// The elder version of the function which is equivalent to the new one
/// but returns nothing.
///
/// # Panics
///
/// - If the encode length of value exceeds the configured maximum value length of a storage entry.
pub fn set_contract_storage_silent<V>(key: &Key, value: &V)
where
V: scale::Encode,
{
<EnvInstance as OnInstance>::on_instance(|instance| {
EnvBackend::set_contract_storage_silent::<V>(instance, key, value)
});
}

/// Writes the value to the contract storage under the given key.
///
/// # Panics
///
/// - If the encode length of value exceeds the configured maximum value length of a storage entry.
pub fn set_contract_storage<V>(key: &Key, value: &V)
pub fn set_contract_storage<V>(key: &Key, value: &V) -> Option<u32>
where
V: scale::Encode,
{
Expand Down
7 changes: 6 additions & 1 deletion crates/env/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,13 @@ impl CallFlags {

/// Environmental contract functionality that does not require `Environment`.
pub trait EnvBackend {
/// Eqivalent to the newer version but returns nothing.
fn set_contract_storage_silent<V>(&mut self, key: &Key, value: &V)
where
V: scale::Encode;

/// Writes the value to the contract storage under the given key.
fn set_contract_storage<V>(&mut self, key: &Key, value: &V)
fn set_contract_storage<V>(&mut self, key: &Key, value: &V) -> Option<u32>
where
V: scale::Encode;

Expand Down
12 changes: 10 additions & 2 deletions crates/env/src/engine/off_chain/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,20 @@ impl EnvInstance {
}

impl EnvBackend for EnvInstance {
fn set_contract_storage<V>(&mut self, key: &Key, value: &V)
fn set_contract_storage_silent<V>(&mut self, key: &Key, value: &V)
where
V: scale::Encode,
{
let v = scale::Encode::encode(value);
self.engine.set_storage(key.as_ref(), &v[..]);
self.engine.set_storage_silent(key.as_ref(), &v[..]);
}

fn set_contract_storage<V>(&mut self, key: &Key, value: &V) -> Option<u32>
where
V: scale::Encode,
{
let v = scale::Encode::encode(value);
self.engine.set_storage(key.as_ref(), &v[..])
}

fn get_contract_storage<R>(&mut self, key: &Key) -> Result<Option<R>>
Expand Down
24 changes: 21 additions & 3 deletions crates/env/src/engine/on_chain/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ mod sys {
data_len: u32,
);

pub fn seal_set_storage(
#[link_name = "seal_set_storage"]
pub fn seal_set_storage_silent(
key_ptr: Ptr32<[u8]>,
value_ptr: Ptr32<[u8]>,
value_len: u32,
Expand Down Expand Up @@ -380,6 +381,12 @@ mod sys {
output_ptr: Ptr32Mut<[u8]>,
output_len_ptr: Ptr32Mut<u32>,
) -> ReturnCode;

pub fn seal_set_storage(
key_ptr: Ptr32<[u8]>,
value_ptr: Ptr32<[u8]>,
value_len: u32,
) -> ReturnCode;
}
}

Expand Down Expand Up @@ -495,16 +502,27 @@ pub fn deposit_event(topics: &[u8], data: &[u8]) {
}
}

pub fn set_storage(key: &[u8], encoded_value: &[u8]) {
pub fn set_storage_silent(key: &[u8], encoded_value: &[u8]) {
unsafe {
sys::seal_set_storage(
sys::seal_set_storage_silent(
Ptr32::from_slice(key),
Ptr32::from_slice(encoded_value),
encoded_value.len() as u32,
)
}
}

pub fn set_storage(key: &[u8], encoded_value: &[u8]) -> Option<u32> {
let ret_code = unsafe {
sys::seal_set_storage(
Ptr32::from_slice(key),
Ptr32::from_slice(encoded_value),
encoded_value.len() as u32,
)
};
ret_code.into()
}

pub fn clear_storage(key: &[u8]) {
unsafe { sys::seal_clear_storage(Ptr32::from_slice(key)) }
}
Expand Down
16 changes: 14 additions & 2 deletions crates/env/src/engine/on_chain/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,20 @@ impl EnvInstance {
}

impl EnvBackend for EnvInstance {
fn set_contract_storage<V>(&mut self, key: &Key, value: &V)
fn set_contract_storage_silent<V>(&mut self, key: &Key, value: &V)
where
V: scale::Encode,
{
let buffer = self.scoped_buffer().take_encoded(value);
ext::set_storage(key.as_ref(), buffer);
ext::set_storage_silent(key.as_ref(), buffer);
}

fn set_contract_storage<V>(&mut self, key: &Key, value: &V) -> Option<u32>
where
V: scale::Encode,
{
let buffer = self.scoped_buffer().take_encoded(value);
ext::set_storage(key.as_ref(), buffer)
}

fn get_contract_storage<R>(&mut self, key: &Key) -> Result<Option<R>>
Expand All @@ -241,6 +249,10 @@ impl EnvBackend for EnvInstance {
Ok(Some(decoded))
}

fn contract_storage_contains(&mut self, key: &Key) -> Option<u32> {
ext::storage_contains(key.as_ref())
}

fn clear_contract_storage(&mut self, key: &Key) {
ext::clear_storage(key.as_ref())
}
Expand Down
12 changes: 12 additions & 0 deletions crates/storage/src/lazy/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,18 @@ where
push_packed_root(value, &self.storage_key(&key));
}

/// Insert the given `value` to the contract storage.
///
/// Returns the size of the pre-existing value at the specified key if any.
#[inline]
pub fn insert_return_size<Q, R>(&mut self, key: Q, value: &R) -> Option<u32>
where
Q: scale::EncodeLike<K>,
R: scale::EncodeLike<V> + PackedLayout,
{
push_packed_root(value, &self.storage_key(&key))
}

/// Get the `value` at `key` from the contract storage.
///
/// Returns `None` if no `value` exists at the given `key`.
Expand Down
4 changes: 2 additions & 2 deletions crates/storage/src/traits/impls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ use super::{
allocate_packed_root,
clear_packed_root,
pull_packed_root,
push_packed_root,
push_packed_root_silent,
PackedAllocate,
PackedLayout,
};
Expand Down Expand Up @@ -162,7 +162,7 @@ pub fn forward_push_packed<T>(entity: &T, ptr: &mut KeyPtr)
where
T: PackedLayout,
{
push_packed_root::<T>(entity, ptr.next_for::<T>())
push_packed_root_silent::<T>(entity, ptr.next_for::<T>());
}

/// Clears an instance of type `T` in packed fashion from the contract storage.
Expand Down
16 changes: 14 additions & 2 deletions crates/storage/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,18 @@ where

/// Pushes the entity to the contract storage using packed layout.
///
/// This is the silent equivalent to the newer version.
pub fn push_packed_root_silent<T>(entity: &T, root_key: &Key)
where
T: PackedLayout,
{
<T as PackedLayout>::push_packed(entity, root_key);
ink_env::set_contract_storage_silent(root_key, entity);
}

/// Pushes the entity to the contract storage using packed layout and
/// returns the size of the pre-existing value if any.
///
/// The root key denotes the offset into the contract storage where the
/// instance of type `T` is being pushed to.
///
Expand All @@ -196,12 +208,12 @@ where
/// packed layout.
/// - Users should prefer using this function directly instead of using the
/// trait methods on [`PackedLayout`].
pub fn push_packed_root<T>(entity: &T, root_key: &Key)
pub fn push_packed_root<T>(entity: &T, root_key: &Key) -> Option<u32>
where
T: PackedLayout,
{
<T as PackedLayout>::push_packed(entity, root_key);
ink_env::set_contract_storage(root_key, entity);
ink_env::set_contract_storage(root_key, entity)
}

/// Clears the entity from the contract storage using packed layout.
Expand Down