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

SP pallet (hooks): pre-commit hook #103

Closed
aidan46 opened this issue Jun 28, 2024 · 5 comments · Fixed by #169
Closed

SP pallet (hooks): pre-commit hook #103

aidan46 opened this issue Jun 28, 2024 · 5 comments · Fixed by #169
Assignees
Labels
enhancement New feature or request pallet-storage-provider Relates to the Storage Provider Pallet
Milestone

Comments

@aidan46
Copy link
Contributor

aidan46 commented Jun 28, 2024

Pre-commit hook

This hook checks pre-committed sectors for all SPs and checks if the sector is expired (no proof submitted for X amount of time). If the sector is expired, it should remove that sector and burn the SPs initial deposit.

Reference:

@aidan46 aidan46 self-assigned this Jun 28, 2024
@aidan46 aidan46 added the enhancement New feature or request label Jul 9, 2024
@jmg-duarte jmg-duarte added this to the Phase 1 milestone Jul 16, 2024
@jmg-duarte jmg-duarte changed the title SP pallet: implement hooks SP pallet (hooks): pre-commit hook Jul 26, 2024
@jmg-duarte jmg-duarte added the pallet-storage-provider Relates to the Storage Provider Pallet label Jul 26, 2024
@th7nder th7nder assigned th7nder and aidan46 and unassigned aidan46 Jul 30, 2024
@jmg-duarte jmg-duarte changed the title SP pallet (hooks): pre-commit hook SP pallet (hooks): pre-commit hook (process_early_terminations) Jul 30, 2024
@jmg-duarte jmg-duarte changed the title SP pallet (hooks): pre-commit hook (process_early_terminations) SP pallet (hooks): pre-commit hook Jul 30, 2024
@th7nder
Copy link
Contributor

th7nder commented Jul 30, 2024

It's handled in handle_proving_deadline, which is executed in on_deferred_cron_event .

Pre-commits are stored in state.pre_committed_sectors_cleanup, and are modified by two functions:

They are added to add_precommit on pre_commit in storage provider.

I'm yet to figure out when CRON_EVENT_PROVING_DEADLINE is scheduled and executed.

@th7nder
Copy link
Contributor

th7nder commented Jul 30, 2024

Cron Events are scheduled for a Miner Actor on a deadline for a pre-commit.

https://github.com/filecoin-project/builtin-actors/blob/17ede2b256bc819dc309edf38e031e246a516486/actors/miner/src/lib.rs#L1737

@th7nder
Copy link
Contributor

th7nder commented Jul 30, 2024

As we don't have neither Miner Actor, nor 'scheduled crons', only have hooks, we need to 'schedule' it differently.
We need a data structure, that'll hold Pre-commits, indexed by BlockNumber, that were supposed to be activated by a given time.
The hook, which will be executed on every block, will check whether we got something to slash. If we have it, then we will.
Prove Commit will delete it from this data structure.

@th7nder
Copy link
Contributor

th7nder commented Jul 30, 2024

The first (#125) proposed implementation works like this:

  • On every block (in on_finalize), go through every Storage Provider and every Pre-Commit Sector (no matter the order) and see whether they were expired or not. It's O(StorageProviders * Sectors * Blocks) algorithm and at some point it maybe to heavy to be executed in on_finalize. Because it's supposed to be very short and it's not, it can affect block production.

I propose to make a O(Sectors * Blocks) algorithm (as in FileCoin), so -> indexing pre-commits by their expiration (BlockNumber). Then the work done in on_finalize is optimal, as each blocks only accesses data relevant to the block, without further scans.

@jmg-duarte
Copy link
Contributor

Go with bad complexity impl and document the good approach for refactoring

@th7nder th7nder linked a pull request Jul 31, 2024 that will close this issue
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pallet-storage-provider Relates to the Storage Provider Pallet
Projects
None yet
3 participants