Skip to content

Commit

Permalink
Dont throw error in case of not zero capacity used instead emit event
Browse files Browse the repository at this point in the history
  • Loading branch information
undercover-cactus committed Jan 6, 2025
1 parent 02b6e33 commit e22a94a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
3 changes: 3 additions & 0 deletions client/indexer-service/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@ impl IndexerService {
Bucket::delete(conn, bucket_id.as_ref().to_vec()).await?;
}
pallet_file_system::Event::FailedToDecreaseBucketSize { .. } => {}
pallet_file_system::Event::UsedCapacityShouldBeZero { .. } => {
// In the future we should monitor for this to detect eventual bugs in the pallets
}
pallet_file_system::Event::__Ignore(_, _) => {}
}
Ok(())
Expand Down
4 changes: 4 additions & 0 deletions pallets/file-system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,10 @@ pub mod pallet {
file_size: StorageData<T>,
error: DispatchError,
},
/// Event to notify of incoherencies in used capacity.
UsedCapacityShouldBeZero {
actual_used_capacity: StorageData<T>,
},
}

// Errors inform users that something went wrong.
Expand Down
38 changes: 23 additions & 15 deletions pallets/file-system/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1791,6 +1791,15 @@ where
<PendingStopStoringRequests<T>>::remove(&bsp_id, &file_key);

if new_root == <T::Providers as shp_traits::ReadProvidersInterface>::get_default_root() {
let used_capacity =
<T::Providers as ReadStorageProvidersInterface>::get_used_capacity(&bsp_id);
if used_capacity == Zero::zero() {
// Emit event if we have inconsistency. We can later monitor for those.
Self::deposit_event(Event::UsedCapacityShouldBeZero {
actual_used_capacity: used_capacity,
});
}

// We should remove the BSP from the dealer proof
<T::ProofDealer as shp_traits::ProofsDealerInterface>::stop_challenge_cycle(&bsp_id)?;
};
Expand Down Expand Up @@ -1949,24 +1958,23 @@ where
// Decrease data used by the SP.
<T::Providers as MutateStorageProvidersInterface>::decrease_capacity_used(&sp_id, size)?;

if <T::Providers as ReadStorageProvidersInterface>::is_bsp(&sp_id) {
if <T::Providers as ReadStorageProvidersInterface>::is_bsp(&sp_id)
&& new_root == <T::Providers as shp_traits::ReadProvidersInterface>::get_default_root()
{
// If it doesn't store any files we stop the challenge cycle and stop its randomness cycle.
if new_root == <T::Providers as shp_traits::ReadProvidersInterface>::get_default_root()
{
ensure!(
<T::Providers as ReadStorageProvidersInterface>::get_used_capacity(&sp_id)
== Zero::zero(),
Error::<T>::UsedCapacityShouldBeZero,
);

<T::ProofDealer as shp_traits::ProofsDealerInterface>::stop_challenge_cycle(
&sp_id,
)?;
let used_capacity =
<T::Providers as ReadStorageProvidersInterface>::get_used_capacity(&sp_id);
if used_capacity == Zero::zero() {
// Emit event if we have inconsistency. We can later monitor for those.
Self::deposit_event(Event::UsedCapacityShouldBeZero {
actual_used_capacity: used_capacity,
});
}

<T::CrRandomness as CommitRevealRandomnessInterface>::stop_randomness_cycle(
&sp_id,
)?;
};
<T::ProofDealer as shp_traits::ProofsDealerInterface>::stop_challenge_cycle(&sp_id)?;

<T::CrRandomness as CommitRevealRandomnessInterface>::stop_randomness_cycle(&sp_id)?;
};

Ok((sp_id, new_root))
Expand Down

0 comments on commit e22a94a

Please sign in to comment.