sectorbuilder: apply some review suggestions

This commit is contained in:
Łukasz Magiera 2019-11-09 00:20:42 +01:00
parent aaacfd15cd
commit ed64e52e3a
4 changed files with 12 additions and 9 deletions

View File

@ -78,7 +78,7 @@ var Units = []string{"B", "KiB", "MiB", "GiB", "TiB"}
func sizeStr(size uint64) string {
i := 0
unitSize := float64(size)
for unitSize >= 1024 && i < len(Units) - 1 {
for unitSize >= 1024 && i < len(Units)-1 {
unitSize = unitSize / 1024
i++
}

View File

@ -49,10 +49,10 @@ const CommLen = sectorbuilder.CommitmentBytesLen
type SectorBuilder struct {
handle unsafe.Pointer
ds dtypes.MetadataDS
idLk sync.Mutex
ds dtypes.MetadataDS
idLk sync.Mutex
ssize uint64
ssize uint64
Miner address.Address
@ -112,9 +112,9 @@ func New(cfg *Config, ds dtypes.MetadataDS) (*SectorBuilder, error) {
sb := &SectorBuilder{
handle: sbp,
ds: ds,
ds: ds,
ssize: cfg.SectorSize,
ssize: cfg.SectorSize,
stagedDir: cfg.StagedDir,
sealedDir: cfg.SealedDir,

View File

@ -149,7 +149,9 @@ func (p *post) preparePost(ctx context.Context) error {
}
p.sset = sset
r, err := p.m.api.ChainGetRandomness(ctx, p.ts, nil, int(int64(p.ts.Height())-int64(p.ppe)+int64(build.PoStChallangeTime)+int64(build.PoStRandomnessLookback))) // TODO: review: check math
// Compute how many blocks back we have to look from the given tipset for the PoSt challenge
challengeLookback := int((int64(p.ts.Height()) - int64(p.ppe)) + int64(build.PoStChallangeTime) + int64(build.PoStRandomnessLookback))
r, err := p.m.api.ChainGetRandomness(ctx, p.ts, nil, challengeLookback)
if err != nil {
return xerrors.Errorf("failed to get chain randomness for post (ts=%d; ppe=%d): %w", p.ts.Height(), p.ppe, err)
}

View File

@ -205,12 +205,14 @@ func (m *Miner) onSectorUpdated(ctx context.Context, update sectorUpdate) {
m.handle(ctx, sector, m.preCommitted, api.SectorNoUpdate)
case api.Committing:
m.handle(ctx, sector, m.committing, api.Proving)
case api.SectorNoUpdate: // noop
default:
log.Error("unexpected sector update state: %d", update.newState)
}
}
func (m *Miner) failSector(id uint64, err error) {
log.Errorf("sector %d error: %+v", id, err)
panic(err) // todo: better error handling strategy
}
func (m *Miner) SealPiece(ctx context.Context, ref string, size uint64, r io.Reader, dealID uint64) (uint64, error) {
@ -231,7 +233,6 @@ func (m *Miner) SealPiece(ctx context.Context, ref string, size uint64, r io.Rea
func (m *Miner) newSector(ctx context.Context, sid uint64, dealID uint64, ref string, ppi sectorbuilder.PublicPieceInfo) error {
si := &SectorInfo{
State: api.UndefinedSectorState,
SectorID: sid,
Pieces: []Piece{