Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

[contracts] Implement transparent hashing for contract storage #11501

Merged
merged 78 commits into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from 69 commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
9a0da02
save
agryaznov May 19, 2022
da608cb
builds and old tests pass
agryaznov May 21, 2022
e15f881
type names enhanced
agryaznov May 22, 2022
78fa5d5
Merge branch 'master' into ag-transparent-hashing
agryaznov May 22, 2022
ceb1588
VarSizedKey bounded to new Config param
agryaznov May 22, 2022
ea8c5be
improved wasm runtime updated funcs
agryaznov May 22, 2022
7d5a613
unstable-interface tests fixed
agryaznov May 22, 2022
0d8206c
benchmarks fixed
agryaznov May 22, 2022
e1a735f
Apply suggestions from code review
agryaznov May 24, 2022
e195d5c
fixes on feedback
agryaznov May 24, 2022
1534c24
Merge branch 'ag-transparent-hashing' of github.com:paritytech/substr…
agryaznov May 24, 2022
b6c2915
Merge branch 'master' into ag-transparent-hashing
agryaznov May 24, 2022
cb01583
fixes on feedback applied + make it build
agryaznov May 25, 2022
75fadc8
benchmarks build but fail (old)
agryaznov May 25, 2022
7a8ea0f
"Original code too large"
agryaznov May 25, 2022
4d548c8
seal_clear_storage bench fixed (code size workaround hack removal tbd)
agryaznov May 25, 2022
ed3539c
bench_seal_clear_storage pass
agryaznov May 27, 2022
86b9275
bench_seal_take_storage ... ok
agryaznov May 27, 2022
a0ffe4b
added new seal_set_storage + updated benchmarks
agryaznov May 27, 2022
01db020
added new seal_get_storage + updated benchmarks
agryaznov May 27, 2022
67ee754
added new seal_contains_storage + updated benchmarks
agryaznov May 27, 2022
25f4e85
added tests for _transparent exec functions
agryaznov May 27, 2022
036c4a0
Merge branch 'master' into ag-transparent-hashing
agryaznov May 27, 2022
970f8b7
wasm test for clear_storage
agryaznov May 30, 2022
d9206b4
Merge branch 'master' into ag-transparent-hashing
agryaznov May 30, 2022
840488a
wasm test for take_storage
agryaznov May 30, 2022
d1068d8
wasm test for new set_storage
agryaznov May 30, 2022
c7663fc
wasm test for new get_storage
agryaznov May 31, 2022
a38bda6
wasm test for new contains_storage
agryaznov May 31, 2022
1e47811
Merge branch 'master' into ag-transparent-hashing
agryaznov May 31, 2022
a2f5143
CI fix
agryaznov May 31, 2022
76fbbb0
ci fix
agryaznov May 31, 2022
7b76ea9
ci fix
agryaznov May 31, 2022
d5d4bae
ci fix
agryaznov May 31, 2022
f79d9d7
Merge branch 'master' of https://github.com/paritytech/substrate into…
Jun 7, 2022
f35dccd
cargo run --quiet --profile=production --features=runtime-benchmarks…
Jun 7, 2022
954c185
fixes according to the review feedback
agryaznov Jun 9, 2022
513c256
Merge branch 'master' into ag-transparent-hashing
agryaznov Jun 9, 2022
c429e99
tests & benchmarks fixed
agryaznov Jun 9, 2022
abc1a22
Merge branch 'ag-transparent-hashing' of github.com:paritytech/substr…
agryaznov Jun 9, 2022
bfb1550
Merge branch 'master' of https://github.com/paritytech/substrate into…
Jun 10, 2022
f6336eb
cargo run --quiet --profile=production --features=runtime-benchmarks…
Jun 10, 2022
7b3ddf8
refactoring
agryaznov Jun 11, 2022
7b99cb4
Merge branch 'master' into ag-transparent-hashing
agryaznov Jun 11, 2022
62735c2
fix to runtime api
agryaznov Jun 11, 2022
d5f240c
ci fix
agryaznov Jun 11, 2022
929ec62
ctx.get_storage() factored out
agryaznov Jun 14, 2022
e81d2c2
ctx.contains_storage() factored out
agryaznov Jun 14, 2022
52a6982
number of batches reduced for transparent hashing storage benchmarks
agryaznov Jun 14, 2022
8a5ce46
Merge branch 'master' into ag-transparent-hashing
agryaznov Jun 14, 2022
456f4c9
contracts RPC & pallet::get_storage to use transparent hashing
agryaznov Jun 14, 2022
e99e7a9
Merge branch 'master' into ag-transparent-hashing
agryaznov Jun 21, 2022
2b764ff
node and rpc updated to use get_storage with VarSizedKey
agryaznov Jun 21, 2022
4652e6f
refactored (more concize)
agryaznov Jun 21, 2022
4ff9bf3
refactored contains_storage (DRYed)
agryaznov Jun 21, 2022
5f28ab8
refactored contains_storage (DRYed)
agryaznov Jun 21, 2022
744bf2e
Merge branch 'master' into ag-transparent-hashing
agryaznov Jun 21, 2022
2e59a8e
fix rpc
agryaznov Jun 21, 2022
c582cff
fmt fix
agryaznov Jun 21, 2022
a5c2659
more fixes in rpc
agryaznov Jun 21, 2022
205d428
rollback `Pallet:get_storage` to Vec<u8> and rpc and node parts relat…
agryaznov Jun 21, 2022
cb6945b
added `KeyDecodingFailed` error
agryaznov Jun 21, 2022
72682de
Revert weird "fmt fix"
agryaznov Jun 21, 2022
23d2209
node-executor basic test update
agryaznov Jun 21, 2022
a7c58b4
fix node-executor basic test
agryaznov Jun 21, 2022
0497517
benchmarks fix
agryaznov Jun 22, 2022
13777b3
more benchmarks fix
agryaznov Jun 22, 2022
12c246e
FixedSizedKey is hidden from pub, VarSizedKey is exported as StorageKey
agryaznov Jun 22, 2022
b91af13
ci fix
agryaznov Jun 22, 2022
591b4b7
set_storage benchmark fix
agryaznov Jun 22, 2022
5802637
ci fix
agryaznov Jun 22, 2022
d95fe82
ci fix
agryaznov Jun 22, 2022
d659578
comments improved
agryaznov Jun 22, 2022
ada2139
new error code to rpc: KEY_DECODING_FAILED
agryaznov Jun 22, 2022
3f578bd
Put `rusty-cachier` before PR merge into `master` for `cargo-check-be…
rcny Jun 22, 2022
363ac54
Merge branch 'vi-fix-cargo-check-benches-ordering' into ag-transparen…
agryaznov Jun 22, 2022
b19f503
cargo run --quiet --profile=production --features=runtime-benchmarks…
Jun 22, 2022
f34676c
minor optimization
agryaznov Jun 23, 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
8 changes: 6 additions & 2 deletions bin/node/executor/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -764,13 +764,17 @@ fn deploying_wasm_contract_should_work() {
t.execute_with(|| {
// Verify that the contract does exist by querying some of its storage items
// It does not matter that the storage item itself does not exist.
assert!(&pallet_contracts::Pallet::<Runtime>::get_storage(addr, Default::default()).is_ok());
assert!(&pallet_contracts::Pallet::<Runtime>::get_storage(
addr,
pallet_contracts::StorageKey<Runtime>::default().to_vec()
KiChjang marked this conversation as resolved.
Show resolved Hide resolved
)
.is_ok());
});
}

#[test]
fn wasm_big_block_import_fails() {
let mut t = new_test_ext(compact_code_unwrap());
let mut t = new_test_ext(compact_code_unwrap()1);
KiChjang marked this conversation as resolved.
Show resolved Hide resolved

set_heap_pages(&mut t.ext(), 4);

Expand Down
3 changes: 2 additions & 1 deletion bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,7 @@ impl pallet_contracts::Config for Runtime {
type ContractAccessWeight = pallet_contracts::DefaultContractAccessWeight<RuntimeBlockWeights>;
type MaxCodeLen = ConstU32<{ 128 * 1024 }>;
type RelaxedMaxCodeLen = ConstU32<{ 256 * 1024 }>;
type MaxStorageKeyLen = ConstU32<128>;
}

impl pallet_sudo::Config for Runtime {
Expand Down Expand Up @@ -1942,7 +1943,7 @@ impl_runtime_apis! {

fn get_storage(
address: AccountId,
key: [u8; 32],
key: Vec<u8>,
) -> pallet_contracts_primitives::GetStorageResult {
athei marked this conversation as resolved.
Show resolved Hide resolved
Contracts::get_storage(address, key)
}
Expand Down
2 changes: 2 additions & 0 deletions frame/contracts/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ pub type GetStorageResult = Result<Option<Vec<u8>>, ContractAccessError>;
pub enum ContractAccessError {
/// The given address doesn't point to a contract.
DoesntExist,
/// Storage key cannot be decoded from the provided input data.
KeyDecodingFailed,
}

bitflags! {
Expand Down
2 changes: 1 addition & 1 deletion frame/contracts/rpc/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ sp_api::decl_runtime_apis! {
/// doesn't exist, or doesn't have a contract then `Err` is returned.
fn get_storage(
address: AccountId,
key: [u8; 32],
key: Vec<u8>,
) -> GetStorageResult;
}
}
14 changes: 10 additions & 4 deletions frame/contracts/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use pallet_contracts_primitives::{
use serde::{Deserialize, Serialize};
use sp_api::ProvideRuntimeApi;
use sp_blockchain::HeaderBackend;
use sp_core::{Bytes, H256};
use sp_core::Bytes;
use sp_rpc::number::NumberOrHex;
use sp_runtime::{
generic::BlockId,
Expand Down Expand Up @@ -74,6 +74,12 @@ impl From<ContractAccessError> for JsonRpseeError {
None::<()>,
))
.into(),
KeyDecodingFailed => CallError::Custom(ErrorObject::owned(
CONTRACT_DOESNT_EXIST,
athei marked this conversation as resolved.
Show resolved Hide resolved
"Failed to decode the specified storage key.",
None::<()>,
))
.into(),
}
}
}
Expand Down Expand Up @@ -167,7 +173,7 @@ where
fn get_storage(
&self,
address: AccountId,
key: H256,
key: Bytes,
at: Option<BlockHash>,
) -> RpcResult<Option<Bytes>>;
}
Expand Down Expand Up @@ -292,13 +298,13 @@ where
fn get_storage(
&self,
address: AccountId,
key: H256,
key: Bytes,
at: Option<<Block as BlockT>::Hash>,
) -> RpcResult<Option<Bytes>> {
let api = self.client.runtime_api();
let at = BlockId::hash(at.unwrap_or_else(|| self.client.info().best_hash));
let result = api
.get_storage(&at, address, key.into())
.get_storage(&at, address, key.to_vec())
.map_err(runtime_error_into_rpc_err)?
.map_err(ContractAccessError)?
.map(Bytes);
Expand Down
Loading