From 9246788bff07b5901a067800233d2b294204ba4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 10 Dec 2019 00:19:46 +0100 Subject: [PATCH 1/3] Don't allow retrieval of unsealed data --- storage/sectorblocks/blockstore.go | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/storage/sectorblocks/blockstore.go b/storage/sectorblocks/blockstore.go index de6039ff5..b0807ef3a 100644 --- a/storage/sectorblocks/blockstore.go +++ b/storage/sectorblocks/blockstore.go @@ -2,6 +2,8 @@ package sectorblocks import ( "context" + "github.com/filecoin-project/lotus/api" + "github.com/filecoin-project/lotus/storage" "io/ioutil" blocks "github.com/ipfs/go-block-format" @@ -72,11 +74,22 @@ func (s *SectorBlockStore) Get(c cid.Cid) (blocks.Block, error) { return nil, blockstore.ErrNotFound } - best := refs[0] // TODO: better strategy (e.g. look for already unsealed) - - si, err := s.sectorBlocks.Miner.GetSectorInfo(best.SectorID) - if err != nil { - return nil, xerrors.Errorf("getting sector info: %w", err) + // TODO: better strategy (e.g. look for already unsealed) + var best api.SealedRef + var bestSi storage.SectorInfo + for _, r := range refs { + si, err := s.sectorBlocks.Miner.GetSectorInfo(r.SectorID) + if err != nil { + return nil, xerrors.Errorf("getting sector info: %w", err) + } + if si.State == api.Proving { + best = r + bestSi = si + break + } + } + if bestSi.State == api.UndefinedSectorState { + return nil, xerrors.New("no sealed sector found") } log.Infof("reading block %s from sector %d(+%d;%d)", c, best.SectorID, best.Offset, best.Size) @@ -85,8 +98,8 @@ func (s *SectorBlockStore) Get(c cid.Cid) (blocks.Block, error) { best.SectorID, best.Offset, best.Size, - si.Ticket.TicketBytes, - si.CommD, + bestSi.Ticket.TicketBytes, + bestSi.CommD, ) if err != nil { return nil, xerrors.Errorf("unsealing block: %w", err) From 707f7878e3ee06a2af3c8077114754a52e5ac7b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 10 Dec 2019 13:09:56 +0100 Subject: [PATCH 2/3] paramfetch: respect FIL_PROOFS_PARAMETER_CACHE --- build/paramfetch.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/build/paramfetch.go b/build/paramfetch.go index b647f675b..14bb80f29 100644 --- a/build/paramfetch.go +++ b/build/paramfetch.go @@ -25,6 +25,7 @@ var log = logging.Logger("build") //const gateway = "http://198.211.99.118/ipfs/" const gateway = "https://ipfs.io/ipfs/" const paramdir = "/var/tmp/filecoin-proof-parameters" +const dirEnv = "FIL_PROOFS_PARAMETER_CACHE" type paramFile struct { Cid string `json:"cid"` @@ -39,8 +40,15 @@ type fetch struct { errs []error } +func getParamDir() string { + if os.Getenv(dirEnv) == "" { + return paramdir + } + return os.Getenv(dirEnv) +} + func GetParams(storageSize uint64) error { - if err := os.Mkdir(paramdir, 0755); err != nil && !os.IsExist(err) { + if err := os.Mkdir(getParamDir(), 0755); err != nil && !os.IsExist(err) { return err } @@ -70,7 +78,7 @@ func (ft *fetch) maybeFetchAsync(name string, info paramFile) { go func() { defer ft.wg.Done() - path := filepath.Join(paramdir, name) + path := filepath.Join(getParamDir(), name) err := ft.checkFile(path, info) if !os.IsNotExist(err) && err != nil { From 5e7402cbfaa85cff1f6ab36269c1fe8656fe9f66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 10 Dec 2019 13:10:15 +0100 Subject: [PATCH 3/3] gofmt --- api/api_storage.go | 4 ++-- node/impl/storminer.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/api/api_storage.go b/api/api_storage.go index 816ad74bf..f34bb3367 100644 --- a/api/api_storage.go +++ b/api/api_storage.go @@ -87,9 +87,9 @@ type SectorInfo struct { Deals []uint64 Ticket sectorbuilder.SealTicket Seed sectorbuilder.SealSeed - Retries uint64 + Retries uint64 - LastErr string + LastErr string } type SealedRef struct { diff --git a/node/impl/storminer.go b/node/impl/storminer.go index 2b3a0352e..a31bd07a9 100644 --- a/node/impl/storminer.go +++ b/node/impl/storminer.go @@ -167,7 +167,7 @@ func (sm *StorageMinerAPI) SectorsStatus(ctx context.Context, sid uint64) (api.S Deals: deals, Ticket: info.Ticket.SB(), Seed: info.Seed.SB(), - Retries: info.Nonce, + Retries: info.Nonce, LastErr: info.LastErr, }, nil