Skip to content

Commit

Permalink
add check after applying mutation; improve finishing cycles code;
Browse files Browse the repository at this point in the history
  • Loading branch information
undercover-cactus committed Dec 31, 2024
1 parent 565f096 commit f867acd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
2 changes: 2 additions & 0 deletions pallets/file-system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,8 @@ pub mod pallet {
NoPrivacyChange,
/// Operations not allowed for insolvent provider
OperationNotAllowedForInsolventProvider,
/// Used Capacity value should be 0.
UsedCapacityShouldBeZero,
}

/// This enum holds the HoldReasons for this pallet, allowing the runtime to identify each held balance with different reasons separately
Expand Down
15 changes: 8 additions & 7 deletions pallets/file-system/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1919,22 +1919,23 @@ where
<T::Providers as MutateStorageProvidersInterface>::decrease_capacity_used(&sp_id, size)?;

if <T::Providers as ReadStorageProvidersInterface>::is_bsp(&sp_id) {
// If it doesn't store any files we stop the challenge cycle.
// 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,
)?;
};

// If the new capacity used is 0 and the Provider is a BSP, stop its randomness cycle.
if <T::Providers as ReadStorageProvidersInterface>::get_used_capacity(&sp_id)
== Zero::zero()
{
<T::CrRandomness as CommitRevealRandomnessInterface>::stop_randomness_cycle(
&sp_id,
)?;
}
};
};

Ok((sp_id, new_root))
Expand Down
15 changes: 10 additions & 5 deletions pallets/proofs-dealer/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,17 +296,22 @@ where
}
}

// Update root of Provider after all mutations have been applied to the Forest.
<T::ProvidersPallet as MutateChallengeableProvidersInterface>::update_root(
*submitter, new_root,
)?;

if new_root == ProvidersPalletFor::<T>::get_default_root() {
// We should remove the BSP from the dealer proof
Self::stop_challenge_cycle(submitter)?;
};

// Emit event of mutation applied.
Self::deposit_event(Event::<T>::MutationsApplied {
provider: *submitter,
mutations,
new_root,
});

// Update root of Provider after all mutations have been applied to the Forest.
<T::ProvidersPallet as MutateChallengeableProvidersInterface>::update_root(
*submitter, new_root,
)?;
}
};

Expand Down

0 comments on commit f867acd

Please sign in to comment.