Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Signed-off-by: Oliver Tale-Yazdi <[email protected]>
  • Loading branch information
ggwpez committed Dec 22, 2022
1 parent fe5caf9 commit c34b538
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
6 changes: 6 additions & 0 deletions frame/support/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,12 @@ pub trait StorageDecodeLength: private::Sealed + codec::DecodeLength {
}
}

#[derive(codec::Encode, codec::Decode, crate::RuntimeDebug, Eq, PartialEq, Clone)]
pub enum ProofSizeMode {
MaxEncodedLen,
Measured,
}

/// Provides `Sealed` trait to prevent implementing trait `StorageAppend` & `StorageDecodeLength`
/// & `EncodeLikeTuple` outside of this crate.
mod private {
Expand Down
27 changes: 19 additions & 8 deletions frame/support/src/storage/types/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,28 @@ use codec::{Decode, Encode, EncodeLike, FullCodec, MaxEncodedLen};
use sp_arithmetic::traits::SaturatedConversion;
use sp_std::prelude::*;

use crate::storage::ProofSizeMode;

/// A type that allow to store a value.
///
/// Each value is stored at:
/// ```nocompile
/// Twox128(Prefix::pallet_prefix()) ++ Twox128(Prefix::STORAGE_PREFIX)
/// ```
pub struct StorageValue<Prefix, Value, QueryKind = OptionQuery, OnEmpty = GetDefault>(
core::marker::PhantomData<(Prefix, Value, QueryKind, OnEmpty)>,
pub struct StorageValue<Prefix, Value, QueryKind = OptionQuery, OnEmpty = GetDefault, ProofSize = MeasureProofSize>(
core::marker::PhantomData<(Prefix, Value, QueryKind, OnEmpty, ProofSize)>,
);

impl<Prefix, Value, QueryKind, OnEmpty> crate::storage::generator::StorageValue<Value>
for StorageValue<Prefix, Value, QueryKind, OnEmpty>
pub struct MeasureProofSize;

impl crate::pallet_prelude::Get<Option<ProofSizeMode>> for MeasureProofSize {
fn get() -> Option<ProofSizeMode> {
None
}
}

impl<Prefix, Value, QueryKind, OnEmpty, ProofSize> crate::storage::generator::StorageValue<Value>
for StorageValue<Prefix, Value, QueryKind, OnEmpty, ProofSize>
where
Prefix: StorageInstance,
Value: FullCodec,
Expand All @@ -63,7 +73,7 @@ where
}
}

impl<Prefix, Value, QueryKind, OnEmpty> StorageValue<Prefix, Value, QueryKind, OnEmpty>
impl<Prefix, Value, QueryKind, OnEmpty, ProofSize> StorageValue<Prefix, Value, QueryKind, OnEmpty, ProofSize>
where
Prefix: StorageInstance,
Value: FullCodec,
Expand Down Expand Up @@ -224,13 +234,14 @@ where
}
}

impl<Prefix, Value, QueryKind, OnEmpty> crate::traits::StorageInfoTrait
for StorageValue<Prefix, Value, QueryKind, OnEmpty>
impl<Prefix, Value, QueryKind, OnEmpty, ProofSize> crate::traits::StorageInfoTrait
for StorageValue<Prefix, Value, QueryKind, OnEmpty, ProofSize>
where
Prefix: StorageInstance,
Value: FullCodec + MaxEncodedLen,
QueryKind: QueryKindTrait<Value, OnEmpty>,
OnEmpty: crate::traits::Get<QueryKind::Query> + 'static,
ProofSize: crate::traits::Get<Option<crate::storage::ProofSizeMode>>,
{
fn storage_info() -> Vec<StorageInfo> {
vec![StorageInfo {
Expand All @@ -239,7 +250,7 @@ where
prefix: Self::hashed_key().to_vec(),
max_values: Some(1),
max_size: Some(Value::max_encoded_len().saturated_into()),
proof_size: None,
proof_size: ProofSize::get(),
}]
}
}
Expand Down
8 changes: 1 addition & 7 deletions frame/support/src/traits/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,7 @@ pub struct StorageInfo {
pub max_values: Option<u32>,
/// The maximum size of key/values in the storage, or none if no maximum specified.
pub max_size: Option<u32>,
pub proof_size: Option<ProofSizeMode>,
}

#[derive(codec::Encode, codec::Decode, crate::RuntimeDebug, Eq, PartialEq, Clone)]
pub enum ProofSizeMode {
MaxEncodedLen,
Measured,
pub proof_size: Option<crate::storage::ProofSizeMode>,
}

/// A trait to give information about storage.
Expand Down

0 comments on commit c34b538

Please sign in to comment.