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: Implement BSP stop cycles extrinsic #321

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion api-augment/dist/interfaces/lookup.js

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

2 changes: 1 addition & 1 deletion api-augment/dist/interfaces/lookup.js.map

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions api-augment/dist/types/interfaces/augment-api-errors.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,10 @@ declare module "@polkadot/api-base/types/errors" {
* Error thrown when a bucket ID could not be added to the list of buckets of a MSP.
**/
AppendBucketToMspFailed: AugmentedError<ApiType>;
/**
* An operation dedicated to BSPs only
**/
BspOnlyOperation: AugmentedError<ApiType>;
/**
* Error thrown when a bucket ID already exists in storage.
**/
Expand Down Expand Up @@ -1079,6 +1083,10 @@ declare module "@polkadot/api-base/types/errors" {
* Error thrown when the runtime cannot hold the required deposit from the account to register it as a SP or change its capacity.
**/
CannotHoldDeposit: AugmentedError<ApiType>;
/**
* Cannot stop BSP cycles without a default root
**/
CannotStopCycleWithNonDefaultRoot: AugmentedError<ApiType>;
/**
* Failed to delete a provider due to conditions not being met.
*
Expand Down
11 changes: 11 additions & 0 deletions api-augment/dist/types/interfaces/augment-api-tx.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3718,6 +3718,17 @@ declare module "@polkadot/api-base/types/submittable" {
(providerId: H256 | string | Uint8Array) => SubmittableExtrinsic<ApiType>,
[H256]
>;
/**
* BSP operation to stop all of your automatic cycles.
*
* This includes:
*
* - Commit reveal randomness cycle
* - Proof challenge cycle
*
* If you are an BSP, the only requirement that must be met is that your root is the default one (an empty root).
**/
stopAllCycles: AugmentedSubmittable<() => SubmittableExtrinsic<ApiType>, []>;
/**
* Dispatchable extrinsic to top-up the deposit of a Storage Provider.
*
Expand Down
1 change: 1 addition & 0 deletions api-augment/dist/types/interfaces/lookup.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3385,6 +3385,7 @@ declare const _default: {
delete_provider: {
providerId: string;
};
stop_all_cycles: string;
};
};
/**
Expand Down
8 changes: 7 additions & 1 deletion api-augment/dist/types/interfaces/types-lookup.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4142,6 +4142,7 @@ declare module "@polkadot/types/lookup" {
readonly asDeleteProvider: {
readonly providerId: H256;
} & Struct;
readonly isStopAllCycles: boolean;
readonly type:
| "RequestMspSignUp"
| "RequestBspSignUp"
Expand All @@ -4158,7 +4159,8 @@ declare module "@polkadot/types/lookup" {
| "ForceBspSignUp"
| "Slash"
| "TopUpDeposit"
| "DeleteProvider";
| "DeleteProvider"
| "StopAllCycles";
}
/** @name PalletFileSystemCall (339) */
interface PalletFileSystemCall extends Enum {
Expand Down Expand Up @@ -5303,6 +5305,8 @@ declare module "@polkadot/types/lookup" {
readonly isMaxBlockNumberReached: boolean;
readonly isOperationNotAllowedForInsolventProvider: boolean;
readonly isDeleteProviderConditionsNotMet: boolean;
readonly isCannotStopCycleWithNonDefaultRoot: boolean;
readonly isBspOnlyOperation: boolean;
readonly isInvalidEncodedFileMetadata: boolean;
readonly isInvalidEncodedAccountId: boolean;
readonly isPaymentStreamNotFound: boolean;
Expand Down Expand Up @@ -5350,6 +5354,8 @@ declare module "@polkadot/types/lookup" {
| "MaxBlockNumberReached"
| "OperationNotAllowedForInsolventProvider"
| "DeleteProviderConditionsNotMet"
| "CannotStopCycleWithNonDefaultRoot"
| "BspOnlyOperation"
| "InvalidEncodedFileMetadata"
| "InvalidEncodedAccountId"
| "PaymentStreamNotFound";
Expand Down
8 changes: 8 additions & 0 deletions api-augment/src/interfaces/augment-api-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,10 @@ declare module "@polkadot/api-base/types/errors" {
* Error thrown when a bucket ID could not be added to the list of buckets of a MSP.
**/
AppendBucketToMspFailed: AugmentedError<ApiType>;
/**
* An operation dedicated to BSPs only
**/
BspOnlyOperation: AugmentedError<ApiType>;
/**
* Error thrown when a bucket ID already exists in storage.
**/
Expand Down Expand Up @@ -1087,6 +1091,10 @@ declare module "@polkadot/api-base/types/errors" {
* Error thrown when the runtime cannot hold the required deposit from the account to register it as a SP or change its capacity.
**/
CannotHoldDeposit: AugmentedError<ApiType>;
/**
* Cannot stop BSP cycles without a default root
**/
CannotStopCycleWithNonDefaultRoot: AugmentedError<ApiType>;
/**
* Failed to delete a provider due to conditions not being met.
*
Expand Down
11 changes: 11 additions & 0 deletions api-augment/src/interfaces/augment-api-tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3160,6 +3160,17 @@ declare module "@polkadot/api-base/types/submittable" {
(providerId: H256 | string | Uint8Array) => SubmittableExtrinsic<ApiType>,
[H256]
>;
/**
* BSP operation to stop all of your automatic cycles.
*
* This includes:
*
* - Commit reveal randomness cycle
* - Proof challenge cycle
*
* If you are an BSP, the only requirement that must be met is that your root is the default one (an empty root).
**/
stopAllCycles: AugmentedSubmittable<() => SubmittableExtrinsic<ApiType>, []>;
/**
* Dispatchable extrinsic to top-up the deposit of a Storage Provider.
*
Expand Down
5 changes: 4 additions & 1 deletion api-augment/src/interfaces/lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3464,7 +3464,8 @@ export default {
top_up_deposit: "Null",
delete_provider: {
providerId: "H256"
}
},
stop_all_cycles: "Null"
}
},
/**
Expand Down Expand Up @@ -4419,6 +4420,8 @@ export default {
"MaxBlockNumberReached",
"OperationNotAllowedForInsolventProvider",
"DeleteProviderConditionsNotMet",
"CannotStopCycleWithNonDefaultRoot",
"BspOnlyOperation",
"InvalidEncodedFileMetadata",
"InvalidEncodedAccountId",
"PaymentStreamNotFound"
Expand Down
8 changes: 7 additions & 1 deletion api-augment/src/interfaces/types-lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4352,6 +4352,7 @@ declare module "@polkadot/types/lookup" {
readonly asDeleteProvider: {
readonly providerId: H256;
} & Struct;
readonly isStopAllCycles: boolean;
readonly type:
| "RequestMspSignUp"
| "RequestBspSignUp"
Expand All @@ -4368,7 +4369,8 @@ declare module "@polkadot/types/lookup" {
| "ForceBspSignUp"
| "Slash"
| "TopUpDeposit"
| "DeleteProvider";
| "DeleteProvider"
| "StopAllCycles";
}

/** @name PalletFileSystemCall (339) */
Expand Down Expand Up @@ -5565,6 +5567,8 @@ declare module "@polkadot/types/lookup" {
readonly isMaxBlockNumberReached: boolean;
readonly isOperationNotAllowedForInsolventProvider: boolean;
readonly isDeleteProviderConditionsNotMet: boolean;
readonly isCannotStopCycleWithNonDefaultRoot: boolean;
readonly isBspOnlyOperation: boolean;
readonly isInvalidEncodedFileMetadata: boolean;
readonly isInvalidEncodedAccountId: boolean;
readonly isPaymentStreamNotFound: boolean;
Expand Down Expand Up @@ -5612,6 +5616,8 @@ declare module "@polkadot/types/lookup" {
| "MaxBlockNumberReached"
| "OperationNotAllowedForInsolventProvider"
| "DeleteProviderConditionsNotMet"
| "CannotStopCycleWithNonDefaultRoot"
| "BspOnlyOperation"
| "InvalidEncodedFileMetadata"
| "InvalidEncodedAccountId"
| "PaymentStreamNotFound";
Expand Down
2 changes: 1 addition & 1 deletion api-augment/storagehub.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pallets/bucket-nfts/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ impl pallet_storage_providers::Config for Test {
{ shp_constants::FILE_SIZE_TO_CHALLENGES },
>;
type NativeBalance = Balances;
type CrRandomness = MockCommitRevealRandomness;
type RuntimeHoldReason = RuntimeHoldReason;
type StorageDataUnit = StorageDataUnit;
type SpCount = u32;
Expand Down
1 change: 1 addition & 0 deletions pallets/file-system/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ impl pallet_storage_providers::Config for Test {
{ shp_constants::FILE_SIZE_TO_CHALLENGES },
>;
type NativeBalance = Balances;
type CrRandomness = CrRandomness;
type RuntimeHoldReason = RuntimeHoldReason;
type StorageDataUnit = StorageDataUnit;
type SpCount = u32;
Expand Down
20 changes: 18 additions & 2 deletions pallets/payment-streams/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use frame_system::pallet_prelude::BlockNumberFor;
use pallet_nfts::PalletFeatures;
use shp_constants::GIGAUNIT;
use shp_traits::{
CommitmentVerifier, MaybeDebug, ProofSubmittersInterface, ReadProvidersInterface, TrieMutation,
TrieProofDeltaApplier,
CommitRevealRandomnessInterface, CommitmentVerifier, MaybeDebug, ProofSubmittersInterface,
ReadProvidersInterface, TrieMutation, TrieProofDeltaApplier,
};
use shp_treasury_funding::NoCutTreasuryCutCalculator;
use sp_core::{hashing::blake2_256, ConstU128, ConstU32, ConstU64, Hasher, H256};
Expand Down Expand Up @@ -217,12 +217,28 @@ parameter_types! {
pub const ProviderTopUpTtl: u64 = 10;
}

pub struct MockCommitRevealRandomness;
impl CommitRevealRandomnessInterface for MockCommitRevealRandomness {
type ProviderId = <Test as pallet_storage_providers::Config>::ProviderId;

fn initialise_randomness_cycle(
_who: &Self::ProviderId,
) -> frame_support::dispatch::DispatchResult {
Ok(())
}

fn stop_randomness_cycle(_who: &Self::ProviderId) -> frame_support::dispatch::DispatchResult {
Ok(())
}
}

impl pallet_storage_providers::Config for Test {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
type ProvidersRandomness = MockRandomness;
type FileMetadataManager = MockFileMetadataManager;
type NativeBalance = Balances;
type CrRandomness = MockCommitRevealRandomness;
type RuntimeHoldReason = RuntimeHoldReason;
type StorageDataUnit = StorageDataUnit;
type PaymentStreams = PaymentStreams;
Expand Down
19 changes: 18 additions & 1 deletion pallets/proofs-dealer/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ use frame_support::{
use frame_system::pallet_prelude::BlockNumberFor;
use shp_file_metadata::{FileMetadata, Fingerprint};
use shp_traits::{
CommitmentVerifier, MaybeDebug, ProofSubmittersInterface, TrieMutation, TrieProofDeltaApplier,
CommitRevealRandomnessInterface, CommitmentVerifier, MaybeDebug, ProofSubmittersInterface,
TrieMutation, TrieProofDeltaApplier,
};
use shp_treasury_funding::NoCutTreasuryCutCalculator;
use sp_core::{hashing::blake2_256, ConstU128, ConstU32, ConstU64, Hasher, H256};
Expand Down Expand Up @@ -204,6 +205,21 @@ parameter_types! {
pub const ProviderTopUpTtl: u64 = 5;
}

pub struct MockCommitRevealRandomness;
impl CommitRevealRandomnessInterface for MockCommitRevealRandomness {
type ProviderId = <Test as pallet_storage_providers::Config>::ProviderId;

fn initialise_randomness_cycle(
_who: &Self::ProviderId,
) -> frame_support::dispatch::DispatchResult {
Ok(())
}

fn stop_randomness_cycle(_who: &Self::ProviderId) -> frame_support::dispatch::DispatchResult {
Ok(())
}
}

// Storage Providers pallet:
impl pallet_storage_providers::Config for Test {
type RuntimeEvent = RuntimeEvent;
Expand All @@ -213,6 +229,7 @@ impl pallet_storage_providers::Config for Test {
type ProofDealer = ProofsDealer;
type FileMetadataManager = MockFileMetadataManager;
type NativeBalance = Balances;
type CrRandomness = MockCommitRevealRandomness;
type RuntimeHoldReason = RuntimeHoldReason;
type StorageDataUnit = StorageDataUnit;
type SpCount = u32;
Expand Down
1 change: 1 addition & 0 deletions pallets/provider-randomness/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ impl pallet_storage_providers::Config for Test {
type ProofDealer = ProofsDealer;
type FileMetadataManager = MockFileMetadataManager;
type NativeBalance = Balances;
type CrRandomness = CrRandomness;
type RuntimeHoldReason = RuntimeHoldReason;
type StorageDataUnit = StorageDataUnit;
type SpCount = u32;
Expand Down
28 changes: 28 additions & 0 deletions pallets/providers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@
+ freeze::Inspect<Self::AccountId>
+ freeze::Mutate<Self::AccountId>;

/// The trait to initialise a Provider's randomness commit-reveal cycle.
type CrRandomness: shp_traits::CommitRevealRandomnessInterface<
ProviderId = ProviderIdFor<Self>,
>;

/// The overarching hold reason
type RuntimeHoldReason: From<HoldReason>;

Expand Down Expand Up @@ -752,6 +757,10 @@
///
/// Call `can_delete_provider` runtime API to check if the provider can be deleted.
DeleteProviderConditionsNotMet,
/// Cannot stop BSP cycles without a default root
CannotStopCycleWithNonDefaultRoot,
/// An operation dedicated to BSPs only
BspOnlyOperation,

// `MutateChallengeableProvidersInterface` errors:
/// Error thrown when failing to decode the metadata from a received trie value that was removed.
Expand Down Expand Up @@ -1450,9 +1459,28 @@

Ok(Pays::No.into())
}

/// BSP operation to stop all of your automatic cycles.
///
/// This includes:
///
/// - Commit reveal randomness cycle
/// - Proof challenge cycle
///
/// If you are an BSP, the only requirement that must be met is that your root is the default one (an empty root).
#[pallet::call_index(16)]
#[pallet::weight(Weight::from_parts(10_000, 0) + T::DbWeight::get().writes(1))]
pub fn stop_all_cycles(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
// Check that the extrinsic was signed.
let who = ensure_signed(origin)?;

Self::do_stop_all_cycles(&who)?;

Ok(Pays::No.into())
}
}

#[pallet::hooks]

Check warning on line 1483 in pallets/providers/src/lib.rs

View workflow job for this annotation

GitHub Actions / Check lint with clippy

using `map_err` over `inspect_err`
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T>
where
u32: TryFrom<BlockNumberFor<T>>,
Expand Down
21 changes: 19 additions & 2 deletions pallets/providers/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ use pallet_proofs_dealer::SlashableProviders;
use pallet_randomness::GetBabeData;
use shp_file_metadata::FileMetadata;
use shp_traits::{
CommitmentVerifier, FileMetadataInterface, MaybeDebug, ProofSubmittersInterface,
ReadChallengeableProvidersInterface, TrieMutation, TrieProofDeltaApplier,
CommitRevealRandomnessInterface, CommitmentVerifier, FileMetadataInterface, MaybeDebug,
ProofSubmittersInterface, ReadChallengeableProvidersInterface, TrieMutation,
TrieProofDeltaApplier,
};
use shp_treasury_funding::NoCutTreasuryCutCalculator;
use sp_core::{hashing::blake2_256, ConstU128, ConstU32, ConstU64, Get, Hasher, H256};
Expand Down Expand Up @@ -336,12 +337,28 @@ impl shp_traits::StorageHubTickGetter for MockStorageHubTickGetter {
}
}

pub struct MockCommitRevealRandomness;
impl CommitRevealRandomnessInterface for MockCommitRevealRandomness {
type ProviderId = <Test as pallet_storage_providers::Config>::ProviderId;

fn initialise_randomness_cycle(
_who: &Self::ProviderId,
) -> frame_support::dispatch::DispatchResult {
Ok(())
}

fn stop_randomness_cycle(_who: &Self::ProviderId) -> frame_support::dispatch::DispatchResult {
Ok(())
}
}

// Storage providers pallet:
impl crate::Config for Test {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
type ProvidersRandomness = MockRandomness;
type NativeBalance = Balances;
type CrRandomness = MockCommitRevealRandomness;
type RuntimeHoldReason = RuntimeHoldReason;
type FileMetadataManager = MockFileMetadataManager;
type StorageDataUnit = StorageDataUnit;
Expand Down
Loading
Loading