From ed64e52e3a5919cc6b3ed6bf982292eff8402ecb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Sat, 9 Nov 2019 00:20:42 +0100 Subject: [PATCH] sectorbuilder: apply some review suggestions --- cmd/lotus-storage-miner/info.go | 2 +- lib/sectorbuilder/sectorbuilder.go | 10 +++++----- storage/post.go | 4 +++- storage/sealing.go | 5 +++-- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/cmd/lotus-storage-miner/info.go b/cmd/lotus-storage-miner/info.go index 54184a63c..074540faf 100644 --- a/cmd/lotus-storage-miner/info.go +++ b/cmd/lotus-storage-miner/info.go @@ -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++ } diff --git a/lib/sectorbuilder/sectorbuilder.go b/lib/sectorbuilder/sectorbuilder.go index 9c2b24af2..35f37ac2d 100644 --- a/lib/sectorbuilder/sectorbuilder.go +++ b/lib/sectorbuilder/sectorbuilder.go @@ -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, diff --git a/storage/post.go b/storage/post.go index ad1050dfb..3d6ac56b3 100644 --- a/storage/post.go +++ b/storage/post.go @@ -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) } diff --git a/storage/sealing.go b/storage/sealing.go index 232ddf5c4..bffb878b8 100644 --- a/storage/sealing.go +++ b/storage/sealing.go @@ -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{