Skip to content

Commit

Permalink
feat: ✨ Add BSP lockup period (#226)
Browse files Browse the repository at this point in the history
* feat: ✨ Add `BspSignUpLockPeriod` to Providers config

* chore: 🏷️ Update `api-augment`

* feat: ✨ Prevent BSPs from signing off before lockup period

* test: ✅ Add tests for BSP lockup period

* test: 🤡 Reduce lockup period in XCM mock runtime

* chore: 🏷️ Update `api-augment`

* test: ✅ Fix hardcoded error codes in test assertions

* fix: 🩹 Amend PR review
  • Loading branch information
ffarall authored Oct 14, 2024
1 parent ec17be4 commit 85e28c8
Show file tree
Hide file tree
Showing 28 changed files with 195 additions and 25 deletions.
7 changes: 5 additions & 2 deletions 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-consts.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,14 @@ declare module "@polkadot/api-base/types/consts" {
[key: string]: Codec;
};
providers: {
/**
* The amount of blocks that a BSP must wait before being able to sign off, after being signed up.
*
* This is to prevent BSPs from signing up and off too quickly, thus making it harder for an attacker
* to suddenly have a large portion of the total number of BSPs. The reason for this, is that the
* attacker would have to lock up a large amount of funds for this period of time.
**/
bspSignUpLockPeriod: u32 & AugmentedConst<ApiType>;
/**
* The amount that an account has to deposit to create a bucket.
**/
Expand Down
4 changes: 4 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 @@ -1054,6 +1054,10 @@ declare module "@polkadot/api-base/types/errors" {
* Error thrown when a user tries to confirm a sign up but the randomness is too fresh to be used yet.
**/
RandomnessNotValidYet: AugmentedError<ApiType>;
/**
* Error thrown when a user tries to sign off as a BSP but the sign off period has not passed yet.
**/
SignOffPeriodNotPassed: AugmentedError<ApiType>;
/**
* Error thrown when a user tries to confirm a sign up that was not requested previously.
**/
Expand Down
2 changes: 2 additions & 0 deletions api-augment/dist/types/interfaces/lookup.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3931,6 +3931,7 @@ declare const _default: {
ownerAccount: string;
paymentAccount: string;
reputationWeight: string;
signUpBlock: string;
};
/**
* Lookup429: pallet_storage_providers::types::MainStorageProvider<T>
Expand All @@ -3944,6 +3945,7 @@ declare const _default: {
lastCapacityChange: string;
ownerAccount: string;
paymentAccount: string;
signUpBlock: string;
};
/**
* Lookup431: pallet_storage_providers::types::Bucket<T>
Expand Down
4 changes: 4 additions & 0 deletions api-augment/dist/types/interfaces/types-lookup.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4821,6 +4821,7 @@ declare module "@polkadot/types/lookup" {
readonly ownerAccount: AccountId32;
readonly paymentAccount: AccountId32;
readonly reputationWeight: u32;
readonly signUpBlock: u32;
}
/** @name PalletStorageProvidersMainStorageProvider (429) */
interface PalletStorageProvidersMainStorageProvider extends Struct {
Expand All @@ -4832,6 +4833,7 @@ declare module "@polkadot/types/lookup" {
readonly lastCapacityChange: u32;
readonly ownerAccount: AccountId32;
readonly paymentAccount: AccountId32;
readonly signUpBlock: u32;
}
/** @name PalletStorageProvidersBucket (431) */
interface PalletStorageProvidersBucket extends Struct {
Expand All @@ -4853,6 +4855,7 @@ declare module "@polkadot/types/lookup" {
readonly isNotEnoughBalance: boolean;
readonly isCannotHoldDeposit: boolean;
readonly isStorageStillInUse: boolean;
readonly isSignOffPeriodNotPassed: boolean;
readonly isRandomnessNotValidYet: boolean;
readonly isSignUpRequestExpired: boolean;
readonly isNewCapacityLessThanUsedStorage: boolean;
Expand Down Expand Up @@ -4881,6 +4884,7 @@ declare module "@polkadot/types/lookup" {
| "NotEnoughBalance"
| "CannotHoldDeposit"
| "StorageStillInUse"
| "SignOffPeriodNotPassed"
| "RandomnessNotValidYet"
| "SignUpRequestExpired"
| "NewCapacityLessThanUsedStorage"
Expand Down
8 changes: 8 additions & 0 deletions api-augment/src/interfaces/augment-api-consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,14 @@ declare module "@polkadot/api-base/types/consts" {
[key: string]: Codec;
};
providers: {
/**
* The amount of blocks that a BSP must wait before being able to sign off, after being signed up.
*
* This is to prevent BSPs from signing up and off too quickly, thus making it harder for an attacker
* to suddenly have a large portion of the total number of BSPs. The reason for this, is that the
* attacker would have to lock up a large amount of funds for this period of time.
**/
bspSignUpLockPeriod: u32 & AugmentedConst<ApiType>;
/**
* The amount that an account has to deposit to create a bucket.
**/
Expand Down
4 changes: 4 additions & 0 deletions api-augment/src/interfaces/augment-api-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,10 @@ declare module "@polkadot/api-base/types/errors" {
* Error thrown when a user tries to confirm a sign up but the randomness is too fresh to be used yet.
**/
RandomnessNotValidYet: AugmentedError<ApiType>;
/**
* Error thrown when a user tries to sign off as a BSP but the sign off period has not passed yet.
**/
SignOffPeriodNotPassed: AugmentedError<ApiType>;
/**
* Error thrown when a user tries to confirm a sign up that was not requested previously.
**/
Expand Down
7 changes: 5 additions & 2 deletions api-augment/src/interfaces/lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4072,7 +4072,8 @@ export default {
lastCapacityChange: "u32",
ownerAccount: "AccountId32",
paymentAccount: "AccountId32",
reputationWeight: "u32"
reputationWeight: "u32",
signUpBlock: "u32"
},
/**
* Lookup429: pallet_storage_providers::types::MainStorageProvider<T>
Expand All @@ -4085,7 +4086,8 @@ export default {
valueProp: "PalletStorageProvidersValueProposition",
lastCapacityChange: "u32",
ownerAccount: "AccountId32",
paymentAccount: "AccountId32"
paymentAccount: "AccountId32",
signUpBlock: "u32"
},
/**
* Lookup431: pallet_storage_providers::types::Bucket<T>
Expand Down Expand Up @@ -4115,6 +4117,7 @@ export default {
"NotEnoughBalance",
"CannotHoldDeposit",
"StorageStillInUse",
"SignOffPeriodNotPassed",
"RandomnessNotValidYet",
"SignUpRequestExpired",
"NewCapacityLessThanUsedStorage",
Expand Down
4 changes: 4 additions & 0 deletions api-augment/src/interfaces/types-lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5058,6 +5058,7 @@ declare module "@polkadot/types/lookup" {
readonly ownerAccount: AccountId32;
readonly paymentAccount: AccountId32;
readonly reputationWeight: u32;
readonly signUpBlock: u32;
}

/** @name PalletStorageProvidersMainStorageProvider (429) */
Expand All @@ -5070,6 +5071,7 @@ declare module "@polkadot/types/lookup" {
readonly lastCapacityChange: u32;
readonly ownerAccount: AccountId32;
readonly paymentAccount: AccountId32;
readonly signUpBlock: u32;
}

/** @name PalletStorageProvidersBucket (431) */
Expand All @@ -5093,6 +5095,7 @@ declare module "@polkadot/types/lookup" {
readonly isNotEnoughBalance: boolean;
readonly isCannotHoldDeposit: boolean;
readonly isStorageStillInUse: boolean;
readonly isSignOffPeriodNotPassed: boolean;
readonly isRandomnessNotValidYet: boolean;
readonly isSignUpRequestExpired: boolean;
readonly isNewCapacityLessThanUsedStorage: boolean;
Expand Down Expand Up @@ -5121,6 +5124,7 @@ declare module "@polkadot/types/lookup" {
| "NotEnoughBalance"
| "CannotHoldDeposit"
| "StorageStillInUse"
| "SignOffPeriodNotPassed"
| "RandomnessNotValidYet"
| "SignUpRequestExpired"
| "NewCapacityLessThanUsedStorage"
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 @@ -365,6 +365,7 @@ impl pallet_storage_providers::Config for Test {
type DefaultMerkleRoot = DefaultMerkleRoot<LayoutV1<BlakeTwo256>>;
type SlashAmountPerMaxFileSize = ConstU128<10>;
type StartingReputationWeight = ConstU32<1>;
type BspSignUpLockPeriod = ConstU64<10>;
}

// Mocked list of Providers that submitted proofs that can be used to test the pallet. It just returns the block number passed to it as the only submitter.
Expand Down
1 change: 1 addition & 0 deletions pallets/bucket-nfts/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ fn add_msp_to_provider_storage(msp: &sp_runtime::AccountId32) -> ProviderIdFor<T
last_capacity_change: frame_system::Pallet::<Test>::block_number(),
owner_account: msp.clone(),
payment_account: msp.clone(),
sign_up_block: frame_system::Pallet::<Test>::block_number(),
};

pallet_storage_providers::MainStorageProviders::<Test>::insert(msp_hash, msp_info);
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 @@ -302,6 +302,7 @@ impl pallet_storage_providers::Config for Test {
type DefaultMerkleRoot = DefaultMerkleRoot<LayoutV1<BlakeTwo256>>;
type SlashAmountPerMaxFileSize = ConstU128<10>;
type StartingReputationWeight = ConstU32<1>;
type BspSignUpLockPeriod = ConstU64<10>;
}

// Mocked list of Providers that submitted proofs that can be used to test the pallet. It just returns the block number passed to it as the only submitter.
Expand Down
1 change: 1 addition & 0 deletions pallets/file-system/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8171,6 +8171,7 @@ fn add_msp_to_provider_storage(msp: &sp_runtime::AccountId32) -> ProviderIdFor<T
last_capacity_change: frame_system::Pallet::<Test>::block_number(),
owner_account: msp.clone(),
payment_account: msp.clone(),
sign_up_block: frame_system::Pallet::<Test>::block_number(),
};

pallet_storage_providers::MainStorageProviders::<Test>::insert(msp_hash, msp_info);
Expand Down
1 change: 1 addition & 0 deletions pallets/payment-streams/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ impl pallet_storage_providers::Config for Test {
type DefaultMerkleRoot = DefaultMerkleRoot<LayoutV1<BlakeTwo256>>;
type SlashAmountPerMaxFileSize = ConstU128<10>;
type StartingReputationWeight = ConstU32<1>;
type BspSignUpLockPeriod = ConstU64<10>;
}

parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions pallets/proofs-dealer/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ impl pallet_storage_providers::Config for Test {
type DefaultMerkleRoot = DefaultMerkleRoot<LayoutV1<BlakeTwo256>>;
type SlashAmountPerMaxFileSize = ConstU128<10>;
type StartingReputationWeight = ConstU32<1>;
type BspSignUpLockPeriod = ConstU64<10>;
}

// Mocked list of Providers that submitted proofs that can be used to test the pallet. It just returns the block number passed to it as the only submitter.
Expand Down
Loading

0 comments on commit 85e28c8

Please sign in to comment.