Skip to content

Commit

Permalink
fix: Pre commit hook test
Browse files Browse the repository at this point in the history
  • Loading branch information
aidan46 committed Jan 23, 2025
1 parent 7f6835b commit 3784c05
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
15 changes: 14 additions & 1 deletion pallets/storage-provider/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ pub mod pallet {
TooManyProofs,
/// AuthorVRF lookup failed.
MissingAuthorVRF,
/// After proving failed to return pre commit deposit.
FailedToReturnPreCommitDeposit,
/// Inner pallet errors
GeneralPalletError(crate::error::GeneralPalletError),
}
Expand Down Expand Up @@ -670,9 +672,20 @@ pub mod pallet {
.try_into()
.expect("Programmer error: ProveCommitResult's should fit in bound of MAX_SECTORS");

StorageProviders::<T>::set(owner.clone(), Some(sp));
// Reduce pre commit deposit amount in state
if let Some(pre_commit_deposits) = sp
.pre_commit_deposits
.checked_sub(&pre_commit_deposit_to_unlock)
{
log::info!("Unlocking {pre_commit_deposit_to_unlock:?} from pre-commit deposit");
sp.pre_commit_deposits = pre_commit_deposits
} else {
log::error!(target: LOG_TARGET, "catastrophe, failed to subtract from pre_commit_deposits {:?} - {:?} < 0", sp.pre_commit_deposits, pre_commit_deposit_to_unlock);
return Err(Error::<T>::FailedToReturnPreCommitDeposit.into());
};
// Unlock pre commit deposit funds.
T::Market::unlock_pre_commit_funds(&owner, pre_commit_deposit_to_unlock)?;
StorageProviders::<T>::set(owner.clone(), Some(sp));
Self::deposit_event(Event::SectorsProven {
owner,
sectors: sectors_proven,
Expand Down
7 changes: 4 additions & 3 deletions pallets/storage-provider/src/tests/pre_commit_sector_hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,14 @@ fn pre_commit_hook_slashed_deal() {
assert!(sp.sectors.contains_key(&second_sector.sector_number));
// First sector removed from here because it was slashed, second one because it was proven.
assert!(sp.pre_committed_sectors.is_empty());
// Pre-commit from the second deal is still there, as pre-commit deposits are until sector expired.
assert_eq!(sp.pre_commit_deposits, DEAL_PRECOMMIT_DEPOSIT);
// No pre-commit deposit as the second deal has been proven and the first one is expired and thus slashed.
assert_eq!(sp.pre_commit_deposits, 0);
// 1 deal got slashed so the respective locked funds *vanished*
assert_eq!(
Market::locked(&account(storage_provider)),
// The cast is kind of an hack but we know it is safe
Some(((2 * DEAL_COLLATERAL + DEAL_PRECOMMIT_DEPOSIT) as u32).into())
// Not add the DEAL_PRECOMMIT_DEPOSIT because this has been unlocked after proving.
Some(((2 * DEAL_COLLATERAL) as u32).into())
);
let mut expected_faulty_sectors = BoundedBTreeSet::new();
expected_faulty_sectors
Expand Down

0 comments on commit 3784c05

Please sign in to comment.