Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Unlock pre commit desposit after proving #697

Merged
merged 3 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions pallets/market/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,11 @@ 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
5 changes: 5 additions & 0 deletions pallets/storage-provider/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ 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 @@ -604,6 +605,8 @@ 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 @@ -668,6 +671,8 @@ pub mod pallet {
.expect("Programmer error: ProveCommitResult's should fit in bound of MAX_SECTORS");

StorageProviders::<T>::set(owner.clone(), Some(sp));
// Unlock pre commit deposit funds.
T::Market::unlock_pre_commit_funds(&owner, pre_commit_deposit_to_unlock)?;
Self::deposit_event(Event::SectorsProven {
owner,
sectors: sectors_proven,
Expand Down
12 changes: 4 additions & 8 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 still locked
// check that the funds are unlocked
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 - 1)
Some(20)
);
let sp_state = StorageProviders::<Test>::get(account(storage_provider))
.expect("Should be able to get providers info");
Expand Down Expand Up @@ -190,12 +190,8 @@ fn successfully_prove_multiple_sectors() {
]
);

// 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)
);
// check that the funds are unlocked
assert_eq!(Market::free(&account(storage_provider)), Some(20));
let sp_state = StorageProviders::<Test>::get(account(storage_provider))
.expect("Should be able to get providers info");

Expand Down
3 changes: 3 additions & 0 deletions primitives/src/pallets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ 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
Loading