Skip to content
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
2 changes: 2 additions & 0 deletions api-augment/dist/parachain/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/parachain/interfaces/lookup.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions api-augment/dist/solochain-evm/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/solochain-evm/interfaces/lookup.js.map

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,10 @@ declare module '@polkadot/api-base/types/events' {
* Note: the storage request will be marked as "incomplete", and it is expected that fisherman
* nodes will pick it up and delete the file from the confirmed BSPs as well as the Bucket.
**/
StorageRequestRejected: AugmentedEvent<ApiType, [fileKey: H256, reason: PalletFileSystemRejectedStorageRequestReason], {
StorageRequestRejected: AugmentedEvent<ApiType, [fileKey: H256, mspId: H256, bucketId: H256, reason: PalletFileSystemRejectedStorageRequestReason], {
fileKey: H256;
mspId: H256;
bucketId: H256;
reason: PalletFileSystemRejectedStorageRequestReason;
}>;
/**
Expand Down
2 changes: 2 additions & 0 deletions api-augment/dist/types/parachain/interfaces/lookup.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1565,6 +1565,8 @@ declare const _default: {
};
StorageRequestRejected: {
fileKey: string;
mspId: string;
bucketId: string;
reason: string;
};
BspRequestedToStopStoring: {
Expand Down
2 changes: 2 additions & 0 deletions api-augment/dist/types/parachain/interfaces/types-lookup.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1659,6 +1659,8 @@ declare module '@polkadot/types/lookup' {
readonly isStorageRequestRejected: boolean;
readonly asStorageRequestRejected: {
readonly fileKey: H256;
readonly mspId: H256;
readonly bucketId: H256;
readonly reason: PalletFileSystemRejectedStorageRequestReason;
} & Struct;
readonly isBspRequestedToStopStoring: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,8 +557,10 @@ declare module '@polkadot/api-base/types/events' {
* Note: the storage request will be marked as "incomplete", and it is expected that fisherman
* nodes will pick it up and delete the file from the confirmed BSPs as well as the Bucket.
**/
StorageRequestRejected: AugmentedEvent<ApiType, [fileKey: H256, reason: PalletFileSystemRejectedStorageRequestReason], {
StorageRequestRejected: AugmentedEvent<ApiType, [fileKey: H256, mspId: H256, bucketId: H256, reason: PalletFileSystemRejectedStorageRequestReason], {
fileKey: H256;
mspId: H256;
bucketId: H256;
reason: PalletFileSystemRejectedStorageRequestReason;
}>;
/**
Expand Down
2 changes: 2 additions & 0 deletions api-augment/dist/types/solochain-evm/interfaces/lookup.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,8 @@ declare const _default: {
};
StorageRequestRejected: {
fileKey: string;
mspId: string;
bucketId: string;
reason: string;
};
BspRequestedToStopStoring: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,8 @@ declare module '@polkadot/types/lookup' {
readonly isStorageRequestRejected: boolean;
readonly asStorageRequestRejected: {
readonly fileKey: H256;
readonly mspId: H256;
readonly bucketId: H256;
readonly reason: PalletFileSystemRejectedStorageRequestReason;
} & Struct;
readonly isBspRequestedToStopStoring: boolean;
Expand Down
2 changes: 1 addition & 1 deletion api-augment/metadata-sh-parachain.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion api-augment/metadata-sh-solochain-evm.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion api-augment/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@storagehub/api-augment",
"version": "0.2.8",
"version": "0.2.9",
"description": "",
"scripts": {
"scrape": "pnpm tsx scripts/scrapeMetadata.ts",
Expand Down
14 changes: 12 additions & 2 deletions api-augment/src/parachain/interfaces/augment-api-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -780,8 +780,18 @@ declare module "@polkadot/api-base/types/events" {
**/
StorageRequestRejected: AugmentedEvent<
ApiType,
[fileKey: H256, reason: PalletFileSystemRejectedStorageRequestReason],
{ fileKey: H256; reason: PalletFileSystemRejectedStorageRequestReason }
[
fileKey: H256,
mspId: H256,
bucketId: H256,
reason: PalletFileSystemRejectedStorageRequestReason
],
{
fileKey: H256;
mspId: H256;
bucketId: H256;
reason: PalletFileSystemRejectedStorageRequestReason;
}
>;
/**
* Notifies that a storage request has been revoked by the user who initiated it.
Expand Down
2 changes: 2 additions & 0 deletions api-augment/src/parachain/interfaces/lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1596,6 +1596,8 @@ export default {
},
StorageRequestRejected: {
fileKey: "H256",
mspId: "H256",
bucketId: "H256",
reason: "PalletFileSystemRejectedStorageRequestReason"
},
BspRequestedToStopStoring: {
Expand Down
2 changes: 2 additions & 0 deletions api-augment/src/parachain/interfaces/types-lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2099,6 +2099,8 @@ declare module "@polkadot/types/lookup" {
readonly isStorageRequestRejected: boolean;
readonly asStorageRequestRejected: {
readonly fileKey: H256;
readonly mspId: H256;
readonly bucketId: H256;
readonly reason: PalletFileSystemRejectedStorageRequestReason;
} & Struct;
readonly isBspRequestedToStopStoring: boolean;
Expand Down
14 changes: 12 additions & 2 deletions api-augment/src/solochain-evm/interfaces/augment-api-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -719,8 +719,18 @@ declare module "@polkadot/api-base/types/events" {
**/
StorageRequestRejected: AugmentedEvent<
ApiType,
[fileKey: H256, reason: PalletFileSystemRejectedStorageRequestReason],
{ fileKey: H256; reason: PalletFileSystemRejectedStorageRequestReason }
[
fileKey: H256,
mspId: H256,
bucketId: H256,
reason: PalletFileSystemRejectedStorageRequestReason
],
{
fileKey: H256;
mspId: H256;
bucketId: H256;
reason: PalletFileSystemRejectedStorageRequestReason;
}
>;
/**
* Notifies that a storage request has been revoked by the user who initiated it.
Expand Down
2 changes: 2 additions & 0 deletions api-augment/src/solochain-evm/interfaces/lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,8 @@ export default {
},
StorageRequestRejected: {
fileKey: "H256",
mspId: "H256",
bucketId: "H256",
reason: "PalletFileSystemRejectedStorageRequestReason"
},
BspRequestedToStopStoring: {
Expand Down
2 changes: 2 additions & 0 deletions api-augment/src/solochain-evm/interfaces/types-lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,8 @@ declare module "@polkadot/types/lookup" {
readonly isStorageRequestRejected: boolean;
readonly asStorageRequestRejected: {
readonly fileKey: H256;
readonly mspId: H256;
readonly bucketId: H256;
readonly reason: PalletFileSystemRejectedStorageRequestReason;
} & Struct;
readonly isBspRequestedToStopStoring: boolean;
Expand Down
11 changes: 11 additions & 0 deletions client/blockchain-service/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,17 @@ pub struct SlashableProvider<Runtime: StorageEnableRuntime> {
pub next_challenge_deadline: BlockNumber<Runtime>,
}

// Storage Request Expired in a Finalised Block
//
// This event is emitted when a storage request expires in a finalised block.
#[derive(Debug, Clone, ActorEvent)]
#[actor(actor = "blockchain_service")]
pub struct FinalisedStorageRequestRejected<Runtime: StorageEnableRuntime> {
pub file_key: FileKey,
pub provider_id: ProofsDealerProviderId<Runtime>,
pub bucket_id: BucketId<Runtime>,
}

/// Mutations applied event in a finalised block, for a BSP.
///
/// This event is emitted when a finalised block is received by the Blockchain service,
Expand Down
31 changes: 29 additions & 2 deletions client/blockchain-service/src/handler_msp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ use crate::{
events::{
DistributeFileToBsp, FinalisedBucketMovedAway, FinalisedBucketMutationsApplied,
FinalisedMspStopStoringBucketInsolventUser, FinalisedMspStoppedStoringBucket,
ForestWriteLockTaskData, MoveBucketRequestedForMsp, NewStorageRequest,
ProcessMspRespondStoringRequest, ProcessMspRespondStoringRequestData,
FinalisedStorageRequestRejected, ForestWriteLockTaskData, MoveBucketRequestedForMsp,
NewStorageRequest, ProcessMspRespondStoringRequest, ProcessMspRespondStoringRequestData,
ProcessStopStoringForInsolventUserRequest, ProcessStopStoringForInsolventUserRequestData,
StartMovedBucketDownload, VerifyMspBucketForests,
},
Expand Down Expand Up @@ -235,6 +235,33 @@ where
}
}
}
StorageEnableEvents::FileSystem(
pallet_file_system::Event::StorageRequestRejected {
file_key,
msp_id,
bucket_id,
reason,
},
) => {
// Other reason than RequestExpired means that the MSP proactively rejected the request.
// We also check for InternalError just to be sure we dont have an inconsistent state due the error.
if !matches!(
reason,
pallet_file_system::types::RejectedStorageRequestReason::RequestExpired
| pallet_file_system::types::RejectedStorageRequestReason::InternalError
) {
return;
}
Comment on lines +248 to +254
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the storage request failed for any of these reasons, wouldn't we want to delete the file from storage anyways?

ReachedMaximumCapacity
ReceivedInvalidProof
FileKeyAlreadyStored


// Process either InternalError or RequestExpire if this provider is managing the bucket.
if managed_msp_id == &msp_id {
self.emit(FinalisedStorageRequestRejected {
file_key: file_key.into(),
provider_id: msp_id.into(),
bucket_id,
})
}
}
StorageEnableEvents::ProofsDealer(pallet_proofs_dealer::Event::MutationsApplied {
mutations,
old_root: _,
Expand Down
4 changes: 3 additions & 1 deletion client/indexer-service/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,9 @@ impl<Runtime: StorageEnableRuntime> IndexerService<Runtime> {
}
// If the file has associations, the `IncompleteStorageRequest` event will handle it
}
pallet_file_system::Event::StorageRequestRejected { file_key, reason } => {
pallet_file_system::Event::StorageRequestRejected {
file_key, reason, ..
} => {
// Check if the file has any BSP associations (it will not have MSP ones since the MSP did not accept it)
let has_bsp = File::has_bsp_associations(conn, file_key.as_ref()).await?;
if has_bsp {
Expand Down
8 changes: 5 additions & 3 deletions client/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ use shc_blockchain_service::{
AcceptedBspVolunteer, DistributeFileToBsp, FinalisedBspConfirmStoppedStoring,
FinalisedBucketMovedAway, FinalisedBucketMutationsApplied,
FinalisedMspStopStoringBucketInsolventUser, FinalisedMspStoppedStoringBucket,
FinalisedTrieRemoveMutationsAppliedForBsp, LastChargeableInfoUpdated, MoveBucketAccepted,
MoveBucketExpired, MoveBucketRejected, MoveBucketRequested, MoveBucketRequestedForMsp,
MultipleNewChallengeSeeds, NewStorageRequest, NotifyPeriod, ProcessConfirmStoringRequest,
FinalisedStorageRequestRejected, FinalisedTrieRemoveMutationsAppliedForBsp,
LastChargeableInfoUpdated, MoveBucketAccepted, MoveBucketExpired, MoveBucketRejected,
MoveBucketRequested, MoveBucketRequestedForMsp, MultipleNewChallengeSeeds,
NewStorageRequest, NotifyPeriod, ProcessConfirmStoringRequest,
ProcessMspRespondStoringRequest, ProcessStopStoringForInsolventUserRequest,
ProcessSubmitProofRequest, SlashableProvider, SpStopStoringInsolventUser,
StartMovedBucketDownload, UserWithoutFunds, VerifyMspBucketForests,
Expand Down Expand Up @@ -319,6 +320,7 @@ where
DistributeFileToBsp<Runtime> => MspDistributeFileTask,
// MspRemoveFinalisedFilesTask handles events for removing files from file storage after mutations are finalised.
FinalisedBucketMutationsApplied<Runtime> => MspDeleteFileTask,
FinalisedStorageRequestRejected<Runtime> => MspDeleteFileTask,
VerifyMspBucketForests => MspVerifyBucketForestsTask,
]
);
Expand Down
79 changes: 78 additions & 1 deletion client/src/tasks/msp_delete_file.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use anyhow::anyhow;
use sc_tracing::tracing::*;
use shc_actors_framework::event_bus::EventHandler;
use shc_blockchain_service::events::FinalisedBucketMutationsApplied;
use shc_blockchain_service::events::{
FinalisedBucketMutationsApplied, FinalisedStorageRequestRejected,
};
use shc_common::{
traits::StorageEnableRuntime,
types::{FileKey, TrieMutation, TrieRemoveMutation},
Expand Down Expand Up @@ -140,3 +142,78 @@ where
Ok(())
}
}

/// Handles the [`FinalisedStorageRequestRejected`] event.
impl<NT, Runtime> EventHandler<FinalisedStorageRequestRejected<Runtime>>
for MspDeleteFileTask<NT, Runtime>
where
NT: ShNodeType<Runtime> + 'static,
NT::FSH: MspForestStorageHandlerT<Runtime>,
Runtime: StorageEnableRuntime,
{
async fn handle_event(
&mut self,
event: FinalisedStorageRequestRejected<Runtime>,
) -> anyhow::Result<()> {
info!(
target: LOG_TARGET,
"Processing finalised storage request expired for file key {:?} in bucket {:?}",
event.file_key,
event.bucket_id
);

// Ensure the file key is not present in the bucket's Forest.
let bucket_forest_key = event.bucket_id.as_ref().to_vec();
let read_fs = self
.storage_hub_handler
.forest_storage_handler
.get(&bucket_forest_key.into())
.await
.ok_or_else(|| {
anyhow!(
"CRITICAL❗️❗️ Failed to get forest storage for bucket [{:?}].",
event.bucket_id
)
})?;
Comment on lines +166 to +177
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Buckets can be removed from MSPs in unfinalized blocks. I don't think this needs to be a critical error.


if read_fs
.read()
.await
.contains_file_key(&event.file_key.into())?
{
warn!(
target: LOG_TARGET,
"StorageRequestExpired and finalised for file key {:?} in bucket {:?}, but file key is still in Forest.",
event.file_key,
event.bucket_id
);
return Err(anyhow!("File key is still in Forest"));
Comment on lines +184 to +190
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we consider this case a warning and also return an error?

}

// Check that the file is present in the File Storage.
let is_in_file_storage = {
let read_file_storage = self.storage_hub_handler.file_storage.read().await;
read_file_storage
.get_metadata(&event.file_key.into())
.map_err(|e| {
error!(target: LOG_TARGET, "Failed to get file metadata from File Storage: {:?}", e);
anyhow!("Failed to get file metadata from File Storage: {:?}", e)
})?
.is_some()
};

if is_in_file_storage {
// If file is present in File Storage and not in Forest, remove it from File Storage.
self.remove_file_from_file_storage(&event.file_key.into())
.await?;
} else {
debug!(
target: LOG_TARGET,
"File key {:?} not present in File Storage; skipping removal.",
event.file_key
);
}

Ok(())
}
}
2 changes: 2 additions & 0 deletions pallets/file-system/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2180,6 +2180,8 @@ mod benchmarks {
let expected_event =
<T as pallet::Config>::RuntimeEvent::from(Event::StorageRequestRejected {
file_key,
msp_id,
bucket_id,
reason: RejectedStorageRequestReason::RequestExpired,
});
frame_system::Pallet::<T>::assert_last_event(expected_event.into());
Expand Down
2 changes: 2 additions & 0 deletions pallets/file-system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,8 @@ pub mod pallet {
/// nodes will pick it up and delete the file from the confirmed BSPs as well as the Bucket.
StorageRequestRejected {
file_key: MerkleHash<T>,
msp_id: ProviderIdFor<T>,
bucket_id: BucketIdFor<T>,
reason: RejectedStorageRequestReason,
},
BspRequestedToStopStoring {
Expand Down
Loading
Loading