Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 🚧 set up pallet providers skeleton #9

Merged
merged 25 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f04a3d2
feat: :construction: set up providers pallet
TDemeco Mar 12, 2024
5521508
docs: :memo: improved code comments of types and extrinsics
TDemeco Mar 12, 2024
a6a750d
refactor: :construction: minor benchmark refactor
TDemeco Mar 12, 2024
eab2fcd
feat: :construction: add data used tracking for SPs
TDemeco Mar 13, 2024
de1da36
feat: :construction: add events, errors and total SP tracking
TDemeco Mar 15, 2024
597680d
Merge branch 'main' into feat/pallet-providers
ffarall Mar 15, 2024
5078d8b
feat: :building_construction: Update project structure from main
ffarall Mar 15, 2024
c0f19a4
feat: :construction_worker: add interface and skeleton of trait impl
TDemeco Mar 15, 2024
e46b934
style: :rotating_light: fix rust formatter warning
TDemeco Mar 15, 2024
6ccd399
style: :building_construction: move interface to lib.rs (+ docs fixes)
TDemeco Mar 15, 2024
0311bd2
feat: :construction: add root handling
TDemeco Mar 18, 2024
9979780
docs: :bulb: refactor TODOs' format
TDemeco Mar 18, 2024
0a555de
fix: :recycle: refactor MSP/BSP logic
TDemeco Mar 18, 2024
292d9cf
feat: :construction: add way for MSPs to add value propositions
TDemeco Mar 18, 2024
0b8c96d
refactor: :recycle: complete refactor of storage and interfaces
TDemeco Mar 19, 2024
6fc9f95
fix: :rotating_light: fix linter warnings
TDemeco Mar 19, 2024
a10c7c1
Merge branch 'main' into feat/pallet-providers
TDemeco Mar 19, 2024
ff81641
refactor: :recycle: change user ID from a specific type to AccountId
TDemeco Mar 19, 2024
c6d2bce
feat: :truck: create support folder for repo and add common traits fo…
TDemeco Mar 19, 2024
6588e7c
refactor: :recycle: adapt proofs-dealer pallet to use new common traits
TDemeco Mar 19, 2024
aba4802
refactor: :recycle: refactor `pallet-providers` to use common traits …
TDemeco Mar 19, 2024
911d5b9
Merge branch 'main' into feat/pallet-providers
ffarall Mar 19, 2024
666786c
fix: :rotating_light: Disable default features when importing `storag…
ffarall Mar 19, 2024
db779ab
fix: :rotating_light: Disable default features when importing `storag…
ffarall Mar 19, 2024
a616822
fix: :rotating_light: Add `#![cfg_attr(not(feature = "std"), no_std)]…
ffarall Mar 19, 2024
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
33 changes: 33 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ homepage = "https://moonsonglabs.com/"
panic = "unwind"

[workspace]
members = ["runtime", "pallets/*", "node", "bsp", "msp", "storage-kit"]
members = ["runtime", "pallets/*", "node", "bsp", "msp", "storage-kit", "support/*"]
resolver = "2"

[workspace.lints.rust]
Expand Down
13 changes: 10 additions & 3 deletions pallets/proofs-dealer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,21 @@ workspace = true
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { package = "parity-scale-codec", version = "3.0.0", features = ["derive"], default-features = false }
scale-info = { version = "2.10.0", default-features = false, features = ["derive"] }
codec = { package = "parity-scale-codec", version = "3.0.0", features = [
"derive",
], default-features = false }
scale-info = { version = "2.10.0", default-features = false, features = [
"derive",
] }

# Local
storage-hub-traits = { path = "../../support/traits", version = "0.1.0", default-features = false }

# Substrate
frame-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.5.0", default-features = false, optional = true }
frame-support = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.5.0", default-features = false }
frame-system = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.5.0", default-features = false }
sp-trie = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.5.0", default-features = false }
sp-trie = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.5.0", default-features = false }

[dev-dependencies]
serde = { version = "1.0.193" }
Expand Down
55 changes: 3 additions & 52 deletions pallets/proofs-dealer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,7 @@ pub use pallet::*;
pub mod types;
pub mod utils;

use codec::FullCodec;
use frame_support::{
inherent::IsFatalError,
pallet_prelude::*,
sp_runtime::{
traits::{CheckEqual, MaybeDisplay, SimpleBitOps},
RuntimeString,
},
traits::fungible,
};
use frame_support::{inherent::IsFatalError, pallet_prelude::*, sp_runtime::RuntimeString};
use scale_info::prelude::fmt::Debug;
use sp_trie::CompactProof;

Expand All @@ -45,6 +36,7 @@ pub mod pallet {
use frame_system::pallet_prelude::*;
use scale_info::prelude::fmt::Debug;
use sp_trie::CompactProof;
use storage_hub_traits::ProvidersInterface;
use types::ProviderFor;

use crate::types::*;
Expand All @@ -57,7 +49,7 @@ pub mod pallet {

/// The Providers pallet.
/// To check if whoever submits a proof is a registered Provider.
type ProvidersPallet: crate::ProvidersInterface<AccountId = Self::AccountId>;
type ProvidersPallet: ProvidersInterface<AccountId = Self::AccountId>;

/// Type to access the Balances Pallet.
type NativeBalance: fungible::Inspect<Self::AccountId>
Expand Down Expand Up @@ -390,47 +382,6 @@ impl InherentError {
}
}

/// A trait to lookup registered Providers, their Merkle Patricia Trie roots and their stake.
///
/// It is abstracted over the `AccountId` type, `Provider` type, `Balance` type and `MerkleHash` type.
pub trait ProvidersInterface {
/// The type which can be used to identify accounts.
type AccountId: Parameter + Member + MaybeSerializeDeserialize + Debug + Ord + MaxEncodedLen;
/// The type which represents a registered Provider.
type Provider: Parameter + Member + MaybeSerializeDeserialize + Debug + Ord + MaxEncodedLen;
/// The type corresponding to the staking balance of a registered Provider.
type Balance: fungible::Inspect<Self::AccountId> + fungible::hold::Inspect<Self::AccountId>;
/// The type corresponding to the root of a registered Provider.
type MerkleHash: Parameter
+ Member
+ MaybeSerializeDeserialize
+ Debug
+ MaybeDisplay
+ SimpleBitOps
+ Ord
+ Default
+ Copy
+ CheckEqual
+ AsRef<[u8]>
+ AsMut<[u8]>
+ MaxEncodedLen
+ FullCodec;

/// Check if an account is a registered Provider.
fn is_provider(who: Self::Provider) -> bool;

// Get Provider from AccountId, if it is a registered Provider.
fn get_provider(who: Self::AccountId) -> Option<Self::Provider>;

/// Get the root for a registered Provider.
fn get_root(who: Self::Provider) -> Option<Self::MerkleHash>;

/// Get the stake for a registered Provider.
fn get_stake(
who: Self::Provider,
) -> Option<<Self::Balance as fungible::Inspect<Self::AccountId>>::Balance>;
}

// TODO: Move this to a primitives crate.
// TODO: Abstract better the types of arguments
/// A trait to verify Merkle Patricia Trie proofs.
Expand Down
4 changes: 2 additions & 2 deletions pallets/proofs-dealer/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use codec::{Decode, Encode};
use frame_support::traits::fungible;
use scale_info::TypeInfo;
use storage_hub_traits::ProvidersInterface;

#[derive(Debug, Clone, PartialEq, Decode, Encode, TypeInfo)]
pub enum ProofRejectionReason {
Expand Down Expand Up @@ -41,8 +42,7 @@ pub type ChallengesQueueLengthFor<T> = <T as crate::Config>::ChallengesQueueLeng
pub type ProvidersPalletFor<T> = <T as crate::Config>::ProvidersPallet;

/// Syntactic sugar for the Provider type used in the proofs pallet.
pub type ProviderFor<T> =
<<T as crate::Config>::ProvidersPallet as crate::ProvidersInterface>::Provider;
pub type ProviderFor<T> = <<T as crate::Config>::ProvidersPallet as ProvidersInterface>::Provider;

/// Syntactic sugar for the type of Balance used in the NativeBalances pallet.
pub type BalanceFor<T> = <<T as crate::Config>::NativeBalance as fungible::Inspect<
Expand Down
3 changes: 2 additions & 1 deletion pallets/proofs-dealer/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
use frame_support::{ensure, pallet_prelude::DispatchResult};
use frame_system::pallet_prelude::BlockNumberFor;
use sp_trie::CompactProof;
use storage_hub_traits::ProvidersInterface;

use crate::{
pallet,
types::{AccountIdFor, BalanceFor, FileKeyFor, ProviderFor, ProvidersPalletFor},
ChallengesQueue, Error, Pallet, ProvidersInterface,
ChallengesQueue, Error, Pallet,
};

impl<T> Pallet<T>
Expand Down
65 changes: 65 additions & 0 deletions pallets/providers/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
[package]
name = "pallet-storage-providers"
description = "FRAME pallet that works as a registry for storage providers (both main and backup ones)"
version = "0.1.0"
homepage = { workspace = true }
license = { workspace = true }
authors = { workspace = true }
repository = { workspace = true }
edition = { workspace = true }

[lints]
workspace = true

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { package = "parity-scale-codec", version = "3.0.0", features = [
"derive",
], default-features = false }
scale-info = { version = "2.10.0", default-features = false, features = [
"derive",
] }

# Local
storage-hub-traits = { path = "../../support/traits", version = "0.1.0", default-features = false}

# Substrate
frame-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.5.0", default-features = false, optional = true }
frame-support = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.5.0", default-features = false }
frame-system = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.5.0", default-features = false }

[dev-dependencies]
serde = { version = "1.0.193" }
pallet-balances = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.5.0" }


# Substrate
sp-core = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.5.0", default-features = false }
sp-io = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.5.0", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-v1.5.0", default-features = false }

[features]
default = ["std"]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
std = [
"codec/std",
"frame-benchmarking/std",
"frame-support/std",
"frame-system/std",
"scale-info/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"sp-runtime/try-runtime",
]
1 change: 1 addition & 0 deletions pallets/providers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
License: Unlicense
24 changes: 24 additions & 0 deletions pallets/providers/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//! Benchmarking setup for pallet-providers

/* use super::*;

#[allow(unused)]
use crate::Pallet as StorageProviders;
use frame_benchmarking::{benchmarks, impl_benchmark_test_suite, whitelisted_caller};
use frame_system::RawOrigin;

benchmarks! {
do_something {
let s in 0 .. 100;
let caller: T::AccountId = whitelisted_caller();
}: _(RawOrigin::Signed(caller), s)
verify {
assert_eq!(Something::<T>::get(), Some(s));
}
}

impl_benchmark_test_suite!(
StorageProviders,
crate::mock::new_test_ext(),
crate::mock::Test,
); */
Loading
Loading