Skip to content

Commit

Permalink
feat: ✨ add RPC methods to use in maintenance mode (#382)
Browse files Browse the repository at this point in the history
* feat: ✨ add maintenance RPC methods for adding and removing files

* chore: 🏷️ update the types-bundle and run typegen

* fix: 🩹 amend review

* chore: 🏷️ run typegen

* chore: 🏷️ run typegen
  • Loading branch information
TDemeco authored Feb 28, 2025
1 parent fe6db96 commit 270dad7
Show file tree
Hide file tree
Showing 16 changed files with 429 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ trie-db = { version = "0.29.1", default-features = false }
sp-core = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "stable2409", default-features = false }
sp-io = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "stable2409", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "stable2409", default-features = false }
sp-runtime-interface = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "stable2409", default-features = false }
sp-std = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "stable2409", default-features = false }
# TODO: Change sp-trie to the next stable version when it's released with the applied fix of this [PR](https://github.com/paritytech/polkadot-sdk/pull/6486)
sp-trie = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "master", default-features = false }
Expand Down
45 changes: 45 additions & 0 deletions api-augment/dist/types/interfaces/augment-api-rpc.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,12 @@ import type {
} from "@polkadot/types/interfaces/system";
import type { IExtrinsic, Observable } from "@polkadot/types/types";
import type {
AddFilesToForestStorageResult,
CheckpointChallenge,
FileMetadata,
GetFileFromFileStorageResult,
LoadFileInStorageResult,
RemoveFilesFromForestStorageResult,
SaveFileToDisk
} from "@storagehub/api-augment/interfaces/storagehubclient";
export type __AugmentedRpc = AugmentedRpc<() => unknown>;
Expand Down Expand Up @@ -1070,6 +1072,28 @@ declare module "@polkadot/rpc-core/types/jsonrpc" {
>;
};
storagehubclient: {
/**
* Add files to the forest storage. Useful when doing manual maintenance.
**/
addFilesToForestStorage: AugmentedRpc<
(
forest_key: Option<H256> | null | Uint8Array | H256 | string,
metadata_of_files_to_add:
| Vec<FileMetadata>
| (
| FileMetadata
| {
owner?: any;
bucket_id?: any;
location?: any;
file_size?: any;
fingerprint?: any;
}
| string
| Uint8Array
)[]
) => Observable<AddFilesToForestStorageResult>
>;
/**
* Add key to exclude list. Exclude type can be `file`, `user`, `bucket` and `fingerprint`.
**/
Expand Down Expand Up @@ -1177,6 +1201,27 @@ declare module "@polkadot/rpc-core/types/jsonrpc" {
* Remove keys of BCSV type for the Blockchain Service.
**/
removeBcsvKeys: AugmentedRpc<(keystore_path: Text | string) => Observable<ITuple<[]>>>;
/**
* Remove a list of files from the file storage. Useful when doing manual maintenance.
**/
removeFilesFromFileStorage: AugmentedRpc<
(file_keys: Vec<H256> | (H256 | string | Uint8Array)[]) => Observable<ITuple<[]>>
>;
/**
* Remove files from the forest storage. Useful when doing manual maintenance.
**/
removeFilesFromForestStorage: AugmentedRpc<
(
forest_key: Option<H256> | null | Uint8Array | H256 | string,
file_keys: Vec<H256> | (H256 | string | Uint8Array)[]
) => Observable<RemoveFilesFromForestStorageResult>
>;
/**
* Remove all files under a prefix from the file storage. Useful when doing manual maintenance.
**/
removeFilesWithPrefixFromFileStorage: AugmentedRpc<
(prefix: H256 | string | Uint8Array) => Observable<ITuple<[]>>
>;
/**
* Remove key from exclude list
**/
Expand Down
4 changes: 4 additions & 0 deletions api-augment/dist/types/interfaces/augment-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1318,6 +1318,7 @@ import type {
import type { XcmPaymentApiError } from "@polkadot/types/interfaces/xcmPaymentApi";
import type { Error } from "@polkadot/types/interfaces/xcmRuntimeApi";
import type {
AddFilesToForestStorageResult,
BackupStorageProvider,
BackupStorageProviderId,
BucketId,
Expand Down Expand Up @@ -1353,6 +1354,7 @@ import type {
QueryProviderMultiaddressesError,
QueryStorageProviderCapacityError,
RandomnessOutput,
RemoveFilesFromForestStorageResult,
ReputationWeightType,
SaveFileToDisk,
ShouldRemoveFile,
Expand Down Expand Up @@ -1391,6 +1393,7 @@ declare module "@polkadot/types/types/registry" {
ActiveGiltsTotal: ActiveGiltsTotal;
ActiveIndex: ActiveIndex;
ActiveRecovery: ActiveRecovery;
AddFilesToForestStorageResult: AddFilesToForestStorageResult;
Address: Address;
AliveContractInfo: AliveContractInfo;
AllowedSlots: AllowedSlots;
Expand Down Expand Up @@ -2276,6 +2279,7 @@ declare module "@polkadot/types/types/registry" {
RelayHash: RelayHash;
Releases: Releases;
Remark: Remark;
RemoveFilesFromForestStorageResult: RemoveFilesFromForestStorageResult;
Renouncing: Renouncing;
RentProjection: RentProjection;
ReplacementTimes: ReplacementTimes;
Expand Down
12 changes: 12 additions & 0 deletions api-augment/dist/types/interfaces/storagehubclient/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ import type {
u64
} from "@polkadot/types-codec";
import type { AccountId, BlockNumber, H256 } from "@polkadot/types/interfaces/runtime";
/** @name AddFilesToForestStorageResult */
export interface AddFilesToForestStorageResult extends Enum {
readonly isSuccess: boolean;
readonly isForestNotFound: boolean;
readonly type: "Success" | "ForestNotFound";
}
/** @name BackupStorageProvider */
export interface BackupStorageProvider extends Struct {
readonly capacity: StorageDataUnit;
Expand Down Expand Up @@ -238,6 +244,12 @@ export interface QueryStorageProviderCapacityError extends Enum {
}
/** @name RandomnessOutput */
export interface RandomnessOutput extends H256 {}
/** @name RemoveFilesFromForestStorageResult */
export interface RemoveFilesFromForestStorageResult extends Enum {
readonly isSuccess: boolean;
readonly isForestNotFound: boolean;
readonly type: "Success" | "ForestNotFound";
}
/** @name ReputationWeightType */
export interface ReputationWeightType extends u32 {}
/** @name SaveFileToDisk */
Expand Down
45 changes: 45 additions & 0 deletions api-augment/src/interfaces/augment-api-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,12 @@ import type {
} from "@polkadot/types/interfaces/system";
import type { IExtrinsic, Observable } from "@polkadot/types/types";
import type {
AddFilesToForestStorageResult,
CheckpointChallenge,
FileMetadata,
GetFileFromFileStorageResult,
LoadFileInStorageResult,
RemoveFilesFromForestStorageResult,
SaveFileToDisk
} from "@storagehub/api-augment/interfaces/storagehubclient";

Expand Down Expand Up @@ -1028,6 +1030,28 @@ declare module "@polkadot/rpc-core/types/jsonrpc" {
>;
};
storagehubclient: {
/**
* Add files to the forest storage. Useful when doing manual maintenance.
**/
addFilesToForestStorage: AugmentedRpc<
(
forest_key: Option<H256> | null | Uint8Array | H256 | string,
metadata_of_files_to_add:
| Vec<FileMetadata>
| (
| FileMetadata
| {
owner?: any;
bucket_id?: any;
location?: any;
file_size?: any;
fingerprint?: any;
}
| string
| Uint8Array
)[]
) => Observable<AddFilesToForestStorageResult>
>;
/**
* Add key to exclude list. Exclude type can be `file`, `user`, `bucket` and `fingerprint`.
**/
Expand Down Expand Up @@ -1132,6 +1156,27 @@ declare module "@polkadot/rpc-core/types/jsonrpc" {
* Remove keys of BCSV type for the Blockchain Service.
**/
removeBcsvKeys: AugmentedRpc<(keystore_path: Text | string) => Observable<ITuple<[]>>>;
/**
* Remove a list of files from the file storage. Useful when doing manual maintenance.
**/
removeFilesFromFileStorage: AugmentedRpc<
(file_keys: Vec<H256> | (H256 | string | Uint8Array)[]) => Observable<ITuple<[]>>
>;
/**
* Remove files from the forest storage. Useful when doing manual maintenance.
**/
removeFilesFromForestStorage: AugmentedRpc<
(
forest_key: Option<H256> | null | Uint8Array | H256 | string,
file_keys: Vec<H256> | (H256 | string | Uint8Array)[]
) => Observable<RemoveFilesFromForestStorageResult>
>;
/**
* Remove all files under a prefix from the file storage. Useful when doing manual maintenance.
**/
removeFilesWithPrefixFromFileStorage: AugmentedRpc<
(prefix: H256 | string | Uint8Array) => Observable<ITuple<[]>>
>;
/**
* Remove key from exclude list
**/
Expand Down
4 changes: 4 additions & 0 deletions api-augment/src/interfaces/augment-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1324,6 +1324,7 @@ import type {
import type { XcmPaymentApiError } from "@polkadot/types/interfaces/xcmPaymentApi";
import type { Error } from "@polkadot/types/interfaces/xcmRuntimeApi";
import type {
AddFilesToForestStorageResult,
BackupStorageProvider,
BackupStorageProviderId,
BucketId,
Expand Down Expand Up @@ -1359,6 +1360,7 @@ import type {
QueryProviderMultiaddressesError,
QueryStorageProviderCapacityError,
RandomnessOutput,
RemoveFilesFromForestStorageResult,
ReputationWeightType,
SaveFileToDisk,
ShouldRemoveFile,
Expand Down Expand Up @@ -1398,6 +1400,7 @@ declare module "@polkadot/types/types/registry" {
ActiveGiltsTotal: ActiveGiltsTotal;
ActiveIndex: ActiveIndex;
ActiveRecovery: ActiveRecovery;
AddFilesToForestStorageResult: AddFilesToForestStorageResult;
Address: Address;
AliveContractInfo: AliveContractInfo;
AllowedSlots: AllowedSlots;
Expand Down Expand Up @@ -2283,6 +2286,7 @@ declare module "@polkadot/types/types/registry" {
RelayHash: RelayHash;
Releases: Releases;
Remark: Remark;
RemoveFilesFromForestStorageResult: RemoveFilesFromForestStorageResult;
Renouncing: Renouncing;
RentProjection: RentProjection;
ReplacementTimes: ReplacementTimes;
Expand Down
14 changes: 14 additions & 0 deletions api-augment/src/interfaces/storagehubclient/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ import type {
} from "@polkadot/types-codec";
import type { AccountId, BlockNumber, H256 } from "@polkadot/types/interfaces/runtime";

/** @name AddFilesToForestStorageResult */
export interface AddFilesToForestStorageResult extends Enum {
readonly isSuccess: boolean;
readonly isForestNotFound: boolean;
readonly type: "Success" | "ForestNotFound";
}

/** @name BackupStorageProvider */
export interface BackupStorageProvider extends Struct {
readonly capacity: StorageDataUnit;
Expand Down Expand Up @@ -278,6 +285,13 @@ export interface QueryStorageProviderCapacityError extends Enum {
/** @name RandomnessOutput */
export interface RandomnessOutput extends H256 {}

/** @name RemoveFilesFromForestStorageResult */
export interface RemoveFilesFromForestStorageResult extends Enum {
readonly isSuccess: boolean;
readonly isForestNotFound: boolean;
readonly type: "Success" | "ForestNotFound";
}

/** @name ReputationWeightType */
export interface ReputationWeightType extends u32 {}

Expand Down
1 change: 1 addition & 0 deletions client/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ sp-api = { workspace = true }
sp-blockchain = { workspace = true }
sp-core = { workspace = true }
sp-runtime = { workspace = true }
sp-runtime-interface = { workspace = true }
sp-trie = { workspace = true }
sp-keystore = { workspace = true }
sc-rpc-api = { workspace = true }
Expand Down
Loading

0 comments on commit 270dad7

Please sign in to comment.