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: 📈 benchmark on_idle hook of pallet-storage-providers #345

Merged
merged 9 commits into from
Feb 5, 2025
12 changes: 12 additions & 0 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.

35 changes: 34 additions & 1 deletion api-augment/dist/types/interfaces/augment-api-events.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2235,7 +2235,7 @@ declare module "@polkadot/api-base/types/events" {
providers: {
/**
* Event emitted when a provider has been slashed and they have reached a capacity deficit (i.e. the provider's capacity fell below their used capacity)
* signaling the end of the grace period since an automatic top up could not be performed due to insufficient free balance.
* signalling the end of the grace period since an automatic top up could not be performed due to insufficient free balance.
**/
AwaitingTopUp: AugmentedEvent<
ApiType,
Expand Down Expand Up @@ -2341,6 +2341,39 @@ declare module "@polkadot/api-base/types/events" {
nextBlockWhenChangeAllowed: u32;
}
>;
/**
* Event emitted when the account ID of a provider that has just been marked as insolvent can't be found in storage.
**/
FailedToGetOwnerAccountOfInsolventProvider: AugmentedEvent<
ApiType,
[providerId: H256],
{
providerId: H256;
}
>;
/**
* Event emitted when there's an error slashing the now insolvent provider.
**/
FailedToSlashInsolventProvider: AugmentedEvent<
ApiType,
[providerId: H256, amountToSlash: u128, error: SpRuntimeDispatchError],
{
providerId: H256;
amountToSlash: u128;
error: SpRuntimeDispatchError;
}
>;
/**
* Event emitted when there's an error stopping all cycles for an insolvent Backup Storage Provider.
**/
FailedToStopAllCyclesForInsolventBsp: AugmentedEvent<
ApiType,
[providerId: H256, error: SpRuntimeDispatchError],
{
providerId: H256;
error: SpRuntimeDispatchError;
}
>;
/**
* Event emitted when an MSP has been deleted.
**/
Expand Down
12 changes: 12 additions & 0 deletions api-augment/dist/types/interfaces/lookup.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1379,6 +1379,18 @@ declare const _default: {
providerId: string;
amount: string;
};
FailedToGetOwnerAccountOfInsolventProvider: {
providerId: string;
};
FailedToSlashInsolventProvider: {
providerId: string;
amountToSlash: string;
error: string;
};
FailedToStopAllCyclesForInsolventBsp: {
providerId: string;
error: string;
};
ProviderInsolvent: {
providerId: string;
};
Expand Down
18 changes: 18 additions & 0 deletions api-augment/dist/types/interfaces/types-lookup.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1785,6 +1785,21 @@ declare module "@polkadot/types/lookup" {
readonly providerId: H256;
readonly amount: u128;
} & Struct;
readonly isFailedToGetOwnerAccountOfInsolventProvider: boolean;
readonly asFailedToGetOwnerAccountOfInsolventProvider: {
readonly providerId: H256;
} & Struct;
readonly isFailedToSlashInsolventProvider: boolean;
readonly asFailedToSlashInsolventProvider: {
readonly providerId: H256;
readonly amountToSlash: u128;
readonly error: SpRuntimeDispatchError;
} & Struct;
readonly isFailedToStopAllCyclesForInsolventBsp: boolean;
readonly asFailedToStopAllCyclesForInsolventBsp: {
readonly providerId: H256;
readonly error: SpRuntimeDispatchError;
} & Struct;
readonly isProviderInsolvent: boolean;
readonly asProviderInsolvent: {
readonly providerId: H256;
Expand Down Expand Up @@ -1841,6 +1856,9 @@ declare module "@polkadot/types/lookup" {
| "Slashed"
| "AwaitingTopUp"
| "TopUpFulfilled"
| "FailedToGetOwnerAccountOfInsolventProvider"
| "FailedToSlashInsolventProvider"
| "FailedToStopAllCyclesForInsolventBsp"
| "ProviderInsolvent"
| "BucketsOfInsolventMsp"
| "BucketRootChanged"
Expand Down
26 changes: 25 additions & 1 deletion api-augment/src/interfaces/augment-api-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1737,7 +1737,7 @@ declare module "@polkadot/api-base/types/events" {
providers: {
/**
* Event emitted when a provider has been slashed and they have reached a capacity deficit (i.e. the provider's capacity fell below their used capacity)
* signaling the end of the grace period since an automatic top up could not be performed due to insufficient free balance.
* signalling the end of the grace period since an automatic top up could not be performed due to insufficient free balance.
**/
AwaitingTopUp: AugmentedEvent<
ApiType,
Expand Down Expand Up @@ -1814,6 +1814,30 @@ declare module "@polkadot/api-base/types/events" {
nextBlockWhenChangeAllowed: u32;
}
>;
/**
* Event emitted when the account ID of a provider that has just been marked as insolvent can't be found in storage.
**/
FailedToGetOwnerAccountOfInsolventProvider: AugmentedEvent<
ApiType,
[providerId: H256],
{ providerId: H256 }
>;
/**
* Event emitted when there's an error slashing the now insolvent provider.
**/
FailedToSlashInsolventProvider: AugmentedEvent<
ApiType,
[providerId: H256, amountToSlash: u128, error: SpRuntimeDispatchError],
{ providerId: H256; amountToSlash: u128; error: SpRuntimeDispatchError }
>;
/**
* Event emitted when there's an error stopping all cycles for an insolvent Backup Storage Provider.
**/
FailedToStopAllCyclesForInsolventBsp: AugmentedEvent<
ApiType,
[providerId: H256, error: SpRuntimeDispatchError],
{ providerId: H256; error: SpRuntimeDispatchError }
>;
/**
* Event emitted when an MSP has been deleted.
**/
Expand Down
12 changes: 12 additions & 0 deletions api-augment/src/interfaces/lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1395,6 +1395,18 @@ export default {
providerId: "H256",
amount: "u128"
},
FailedToGetOwnerAccountOfInsolventProvider: {
providerId: "H256"
},
FailedToSlashInsolventProvider: {
providerId: "H256",
amountToSlash: "u128",
error: "SpRuntimeDispatchError"
},
FailedToStopAllCyclesForInsolventBsp: {
providerId: "H256",
error: "SpRuntimeDispatchError"
},
ProviderInsolvent: {
providerId: "H256"
},
Expand Down
18 changes: 18 additions & 0 deletions api-augment/src/interfaces/types-lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1868,6 +1868,21 @@ declare module "@polkadot/types/lookup" {
readonly providerId: H256;
readonly amount: u128;
} & Struct;
readonly isFailedToGetOwnerAccountOfInsolventProvider: boolean;
readonly asFailedToGetOwnerAccountOfInsolventProvider: {
readonly providerId: H256;
} & Struct;
readonly isFailedToSlashInsolventProvider: boolean;
readonly asFailedToSlashInsolventProvider: {
readonly providerId: H256;
readonly amountToSlash: u128;
readonly error: SpRuntimeDispatchError;
} & Struct;
readonly isFailedToStopAllCyclesForInsolventBsp: boolean;
readonly asFailedToStopAllCyclesForInsolventBsp: {
readonly providerId: H256;
readonly error: SpRuntimeDispatchError;
} & Struct;
readonly isProviderInsolvent: boolean;
readonly asProviderInsolvent: {
readonly providerId: H256;
Expand Down Expand Up @@ -1924,6 +1939,9 @@ declare module "@polkadot/types/lookup" {
| "Slashed"
| "AwaitingTopUp"
| "TopUpFulfilled"
| "FailedToGetOwnerAccountOfInsolventProvider"
| "FailedToSlashInsolventProvider"
| "FailedToStopAllCyclesForInsolventBsp"
| "ProviderInsolvent"
| "BucketsOfInsolventMsp"
| "BucketRootChanged"
Expand Down
2 changes: 1 addition & 1 deletion api-augment/storagehub.json

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions client/indexer-service/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,17 @@ impl IndexerService {
pallet_storage_providers::Event::BspDeleted { provider_id } => {
Bsp::delete(conn, provider_id.to_string()).await?;
}
pallet_storage_providers::Event::FailedToGetOwnerAccountOfInsolventProvider {
..
} => {
// In the future we should monitor for this to detect eventual bugs in the pallets
}
pallet_storage_providers::Event::FailedToSlashInsolventProvider { .. } => {
// In the future we should monitor for this to detect eventual bugs in the pallets
}
pallet_storage_providers::Event::FailedToStopAllCyclesForInsolventBsp { .. } => {
// In the future we should monitor for this to detect eventual bugs in the pallets
}
pallet_storage_providers::Event::__Ignore(_, _) => {}
}
Ok(())
Expand Down
8 changes: 4 additions & 4 deletions pallets/file-system/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2576,8 +2576,8 @@ mod hooks {

// Expired storage requests clean up section:
// If there's enough weight to get from storage the maximum amount of BSPs required for a storage request
// and get the storage request expirations for the current tick, continue.
if meter.can_consume(db_weight.reads_writes(2, 1)) {
// and get the storage request expirations for the current tick, and reinsert them if needed, continue.
if meter.can_consume(db_weight.reads_writes(2, 2)) {
// Get the maximum amount of BSPs required for a storage request.
// As of right now, the upper bound limit to the number of BSPs required to fulfill a storage request is set by `MaxReplicationTarget`.
// We could increase this potential weight to account for potentially more volunteers.
Expand Down Expand Up @@ -2624,8 +2624,8 @@ mod hooks {
}

// Expired move bucket requests clean up section:
// If there's enough weight to get from storage the expired move bucket requests, continue.
if meter.can_consume(db_weight.reads_writes(1, 1)) {
// If there's enough weight to get from storage the expired move bucket requests and reinsert them if needed, continue.
if meter.can_consume(db_weight.reads_writes(1, 2)) {
// Get the expired move bucket requests for the current tick.
let mut expired_move_bucket_requests =
MoveBucketRequestExpirations::<T>::take(&tick);
Expand Down
Loading
Loading