Skip to content
This repository has been archived by the owner on Jun 6, 2023. It is now read-only.

Miner: Simplify sector number allocation during precommit #905

Closed
wadealexc opened this issue Aug 5, 2020 · 2 comments
Closed

Miner: Simplify sector number allocation during precommit #905

wadealexc opened this issue Aug 5, 2020 · 2 comments
Labels
cleanup Technical debt recovery and other cleanup work P3 Not urgent or important

Comments

@wadealexc
Copy link

wadealexc commented Aug 5, 2020

Miner.PreCommitSector requires that params.SectorNumber has not been previously allocated, as sector numbers should not be reused:

err := st.AllocateSectorNumber(store, params.SectorNumber)
builtin.RequireNoErr(rt, err, exitcode.ErrIllegalState, "failed to allocate sector id %d", params.SectorNumber)
// The following two checks shouldn't be necessary, but it can't
// hurt to double-check (unless it's really just too
// expensive?).
_, preCommitFound, err := st.GetPrecommittedSector(store, params.SectorNumber)
builtin.RequireNoErr(rt, err, exitcode.ErrIllegalState, "failed to check pre-commit %v", params.SectorNumber)
if preCommitFound {
rt.Abortf(exitcode.ErrIllegalState, "sector %v already pre-committed", params.SectorNumber)
}
sectorFound, err := st.HasSectorNo(store, params.SectorNumber)
builtin.RequireNoErr(rt, err, exitcode.ErrIllegalState, "failed to check sector %v", params.SectorNumber)
if sectorFound {
rt.Abortf(exitcode.ErrIllegalState, "sector %v already committed", params.SectorNumber)
}

As the comment states, the checks following the call to AllocateSectorNumber are not entirely necessary, but they may be helpful sanity checks.

Assuming they're being kept, I propose moving the existence checks to the AllocateSectorNumber method - they're functionally similar, and this would make PreCommitSector easier to parse.

@anorth anorth added cleanup Technical debt recovery and other cleanup work P2 Medium priority, beneficial for network functionality and growth P3 Not urgent or important and removed P2 Medium priority, beneficial for network functionality and growth labels Aug 6, 2020
@ZenGround0 ZenGround0 added this to the 🧡 v3 milestone Oct 28, 2020
@anorth anorth modified the milestones: 🧡 v3 , v4 Jan 21, 2021
@ZenGround0 ZenGround0 mentioned this issue Apr 8, 2021
28 tasks
@ZenGround0 ZenGround0 modified the milestones: v6, QoL Improvements Aug 12, 2021
@ZenGround0
Copy link
Contributor

These duplicate checks have been removed

@ZenGround0
Copy link
Contributor

  • In v3 we modified HAMT to have PutIfAbsent which delegates a more efficient check to PutPrecommittedSectors
  • At some point (I think also v3) we stopped the HasSectorNo check

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cleanup Technical debt recovery and other cleanup work P3 Not urgent or important
Projects
None yet
Development

No branches or pull requests

3 participants