Skip to content

Commit

Permalink
Revert "fix: Unlock pre commit desposit after proving (#697)"
Browse files Browse the repository at this point in the history
This reverts commit fd17d46.
  • Loading branch information
th7nder committed Jan 23, 2025
1 parent 0d25411 commit df70548
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 33 deletions.
5 changes: 0 additions & 5 deletions pallets/market/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1180,11 +1180,6 @@ pub mod pallet {
lock_funds::<T>(who, amount)
}

fn unlock_pre_commit_funds(who: &T::AccountId, amount: BalanceOf<T>) -> DispatchResult {
// NOTE(@aidan,23/1/25): unsure if this should emit an event
unlock_funds::<T>(who, amount)
}

fn slash_pre_commit_funds(who: &T::AccountId, amount: BalanceOf<T>) -> DispatchResult {
// NOTE(@jmg-duarte,21/1/25): unsure if this should emit an event
slash_and_burn::<T>(who, amount)
Expand Down
17 changes: 0 additions & 17 deletions pallets/storage-provider/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,6 @@ 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 @@ -574,7 +572,6 @@ pub mod pallet {
let mut new_sectors = BoundedVec::new();
let mut sector_numbers: BoundedVec<SectorNumber, ConstU32<MAX_SECTORS_PER_CALL>> =
BoundedVec::new();
let mut pre_commit_deposit_to_unlock = BalanceOf::<T>::zero();

for sector in sectors {
// Get pre-committed sector. This is the sector we are currently
Expand Down Expand Up @@ -607,8 +604,6 @@ pub mod pallet {
new_sectors
.try_push(new_sector)
.expect("Programmer error: New sectors should fit in bound of MAX_SECTORS");

pre_commit_deposit_to_unlock += calculate_pre_commit_deposit::<T>();
}

// Activate the deals for the sectors that will be proven. This
Expand Down Expand Up @@ -672,18 +667,6 @@ pub mod pallet {
.try_into()
.expect("Programmer error: ProveCommitResult's should fit in bound of MAX_SECTORS");

// Reduce pre commit deposit amount in state
if let Some(pre_commit_deposits) = sp
.pre_commit_deposits
.checked_sub(&pre_commit_deposit_to_unlock)
{
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,
Expand Down
7 changes: 3 additions & 4 deletions pallets/storage-provider/src/tests/pre_commit_sector_hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,13 @@ 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());
// 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);
// 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);
// 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
// Not add the DEAL_PRECOMMIT_DEPOSIT because this has been unlocked after proving.
Some(((2 * DEAL_COLLATERAL) as u32).into())
Some(((2 * DEAL_COLLATERAL + DEAL_PRECOMMIT_DEPOSIT) as u32).into())
);
let mut expected_faulty_sectors = BoundedBTreeSet::new();
expected_faulty_sectors
Expand Down
12 changes: 8 additions & 4 deletions pallets/storage-provider/src/tests/prove_commit_sectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ fn successfully_prove_sector() {
]
);

// check that the funds are unlocked
// check that the funds are still locked
assert_eq!(
Market::free(&account(storage_provider)),
// Provider reserved 70 tokens in the market pallet and 1 token is used for the pre-commit
Some(20)
Some(20 - 1)
);
let sp_state = StorageProviders::<Test>::get(account(storage_provider))
.expect("Should be able to get providers info");
Expand Down Expand Up @@ -190,8 +190,12 @@ fn successfully_prove_multiple_sectors() {
]
);

// check that the funds are unlocked
assert_eq!(Market::free(&account(storage_provider)), Some(20));
// check that the funds are still locked
assert_eq!(
Market::free(&account(storage_provider)),
// 70 - 25 * 2 = 20
Some(20 - SECTORS_TO_COMMIT as u64)
);
let sp_state = StorageProviders::<Test>::get(account(storage_provider))
.expect("Should be able to get providers info");

Expand Down
3 changes: 0 additions & 3 deletions primitives/src/pallets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ pub trait Market<AccountId, BlockNumber, Balance> {
/// Locks funds for pre-commit purposes.
fn lock_pre_commit_funds(who: &AccountId, amount: Balance) -> DispatchResult;

/// Unlocks funds for pre-commit purposes.
fn unlock_pre_commit_funds(who: &AccountId, amount: Balance) -> DispatchResult;

/// Slashes funds locked for pre-commit purposes.
fn slash_pre_commit_funds(who: &AccountId, amount: Balance) -> DispatchResult;

Expand Down

0 comments on commit df70548

Please sign in to comment.