Skip to content

Commit c34b538

Browse files
committed
WIP
Signed-off-by: Oliver Tale-Yazdi <[email protected]>
1 parent fe5caf9 commit c34b538

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

frame/support/src/storage/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,12 @@ pub trait StorageDecodeLength: private::Sealed + codec::DecodeLength {
12901290
}
12911291
}
12921292

1293+
#[derive(codec::Encode, codec::Decode, crate::RuntimeDebug, Eq, PartialEq, Clone)]
1294+
pub enum ProofSizeMode {
1295+
MaxEncodedLen,
1296+
Measured,
1297+
}
1298+
12931299
/// Provides `Sealed` trait to prevent implementing trait `StorageAppend` & `StorageDecodeLength`
12941300
/// & `EncodeLikeTuple` outside of this crate.
12951301
mod private {

frame/support/src/storage/types/value.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,28 @@ use codec::{Decode, Encode, EncodeLike, FullCodec, MaxEncodedLen};
3030
use sp_arithmetic::traits::SaturatedConversion;
3131
use sp_std::prelude::*;
3232

33+
use crate::storage::ProofSizeMode;
34+
3335
/// A type that allow to store a value.
3436
///
3537
/// Each value is stored at:
3638
/// ```nocompile
3739
/// Twox128(Prefix::pallet_prefix()) ++ Twox128(Prefix::STORAGE_PREFIX)
3840
/// ```
39-
pub struct StorageValue<Prefix, Value, QueryKind = OptionQuery, OnEmpty = GetDefault>(
40-
core::marker::PhantomData<(Prefix, Value, QueryKind, OnEmpty)>,
41+
pub struct StorageValue<Prefix, Value, QueryKind = OptionQuery, OnEmpty = GetDefault, ProofSize = MeasureProofSize>(
42+
core::marker::PhantomData<(Prefix, Value, QueryKind, OnEmpty, ProofSize)>,
4143
);
4244

43-
impl<Prefix, Value, QueryKind, OnEmpty> crate::storage::generator::StorageValue<Value>
44-
for StorageValue<Prefix, Value, QueryKind, OnEmpty>
45+
pub struct MeasureProofSize;
46+
47+
impl crate::pallet_prelude::Get<Option<ProofSizeMode>> for MeasureProofSize {
48+
fn get() -> Option<ProofSizeMode> {
49+
None
50+
}
51+
}
52+
53+
impl<Prefix, Value, QueryKind, OnEmpty, ProofSize> crate::storage::generator::StorageValue<Value>
54+
for StorageValue<Prefix, Value, QueryKind, OnEmpty, ProofSize>
4555
where
4656
Prefix: StorageInstance,
4757
Value: FullCodec,
@@ -63,7 +73,7 @@ where
6373
}
6474
}
6575

66-
impl<Prefix, Value, QueryKind, OnEmpty> StorageValue<Prefix, Value, QueryKind, OnEmpty>
76+
impl<Prefix, Value, QueryKind, OnEmpty, ProofSize> StorageValue<Prefix, Value, QueryKind, OnEmpty, ProofSize>
6777
where
6878
Prefix: StorageInstance,
6979
Value: FullCodec,
@@ -224,13 +234,14 @@ where
224234
}
225235
}
226236

227-
impl<Prefix, Value, QueryKind, OnEmpty> crate::traits::StorageInfoTrait
228-
for StorageValue<Prefix, Value, QueryKind, OnEmpty>
237+
impl<Prefix, Value, QueryKind, OnEmpty, ProofSize> crate::traits::StorageInfoTrait
238+
for StorageValue<Prefix, Value, QueryKind, OnEmpty, ProofSize>
229239
where
230240
Prefix: StorageInstance,
231241
Value: FullCodec + MaxEncodedLen,
232242
QueryKind: QueryKindTrait<Value, OnEmpty>,
233243
OnEmpty: crate::traits::Get<QueryKind::Query> + 'static,
244+
ProofSize: crate::traits::Get<Option<crate::storage::ProofSizeMode>>,
234245
{
235246
fn storage_info() -> Vec<StorageInfo> {
236247
vec![StorageInfo {
@@ -239,7 +250,7 @@ where
239250
prefix: Self::hashed_key().to_vec(),
240251
max_values: Some(1),
241252
max_size: Some(Value::max_encoded_len().saturated_into()),
242-
proof_size: None,
253+
proof_size: ProofSize::get(),
243254
}]
244255
}
245256
}

frame/support/src/traits/storage.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,7 @@ pub struct StorageInfo {
6565
pub max_values: Option<u32>,
6666
/// The maximum size of key/values in the storage, or none if no maximum specified.
6767
pub max_size: Option<u32>,
68-
pub proof_size: Option<ProofSizeMode>,
69-
}
70-
71-
#[derive(codec::Encode, codec::Decode, crate::RuntimeDebug, Eq, PartialEq, Clone)]
72-
pub enum ProofSizeMode {
73-
MaxEncodedLen,
74-
Measured,
68+
pub proof_size: Option<crate::storage::ProofSizeMode>,
7569
}
7670

7771
/// A trait to give information about storage.

0 commit comments

Comments
 (0)