sectorstore: Address review feetback

This commit is contained in:
Łukasz Magiera 2019-08-15 00:17:27 +02:00
parent e6493afd46
commit baf4fbe309
3 changed files with 20 additions and 20 deletions

View File

@ -1,14 +1,14 @@
package sectorbuilder
package sectorbuilder_test
import (
"context"
"fmt"
"io"
"io/ioutil"
"math/rand"
"testing"
"github.com/filecoin-project/go-lotus/chain/address"
"github.com/filecoin-project/go-lotus/lib/sectorbuilder"
"github.com/filecoin-project/go-lotus/storage/sector"
)
func TestSealAndVerify(t *testing.T) {
@ -23,7 +23,7 @@ func TestSealAndVerify(t *testing.T) {
t.Fatal(err)
}
sb, err := New(&SectorBuilderConfig{
sb, err := sectorbuilder.New(&sectorbuilder.SectorBuilderConfig{
SectorSize: 1024,
SealedDir: dir,
StagedDir: dir,
@ -34,11 +34,6 @@ func TestSealAndVerify(t *testing.T) {
t.Fatal(err)
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
sb.Run(ctx)
fi, err := ioutil.TempFile("", "sbtestfi")
if err != nil {
t.Fatal(err)
@ -51,10 +46,11 @@ func TestSealAndVerify(t *testing.T) {
t.Fatal(err)
}
ssinfo := <-sb.SealedSectorChan()
fmt.Println("sector sealed...")
store := sector.NewStore(sb)
store.Service()
ssinfo := <-store.Incoming()
ok, err := VerifySeal(1024, ssinfo.CommR[:], ssinfo.CommD[:], ssinfo.CommRStar[:], addr, ssinfo.SectorID, ssinfo.Proof)
ok, err := sectorbuilder.VerifySeal(1024, ssinfo.CommR[:], ssinfo.CommD[:], ssinfo.CommRStar[:], addr, ssinfo.SectorID, ssinfo.Proof)
if err != nil {
t.Fatal(err)
}

View File

@ -3,14 +3,14 @@ package impl
import (
"context"
"fmt"
"github.com/filecoin-project/go-lotus/chain/address"
"github.com/filecoin-project/go-lotus/storage/sector"
"io"
"math/rand"
"github.com/filecoin-project/go-lotus/api"
"github.com/filecoin-project/go-lotus/chain/address"
"github.com/filecoin-project/go-lotus/lib/sectorbuilder"
"github.com/filecoin-project/go-lotus/storage"
"github.com/filecoin-project/go-lotus/storage/sector"
)
type StorageMinerAPI struct {

View File

@ -24,14 +24,14 @@ type Store struct {
incoming []chan sectorbuilder.SectorSealingStatus
// TODO: outdated chan
close chan struct{}
closeCh chan struct{}
}
func NewStore(sb *sectorbuilder.SectorBuilder) *Store {
return &Store{
sb: sb,
waiting: map[uint64]chan struct{}{},
close: make(chan struct{}),
closeCh: make(chan struct{}),
}
}
@ -88,7 +88,7 @@ func (s *Store) service() {
select {
case <-poll:
s.poll()
case <-s.close:
case <-s.closeCh:
s.lk.Lock()
for _, c := range s.incoming {
close(c)
@ -131,7 +131,9 @@ func (s *Store) CloseIncoming(c <-chan sectorbuilder.SectorSealingStatus) {
return
}
if len(s.incoming) > 1 {
s.incoming[at] = s.incoming[len(s.incoming)-1]
last := len(s.incoming) - 1
s.incoming[at] = s.incoming[last]
s.incoming[last] = nil
}
s.incoming = s.incoming[:len(s.incoming)-1]
s.lk.Unlock()
@ -161,7 +163,7 @@ func (s *Store) WaitSeal(ctx context.Context, sector uint64) (sectorbuilder.Sect
}
func (s *Store) Stop() {
close(s.close)
close(s.closeCh)
}
func withTemp(r io.Reader, cb func(string) error) error {
@ -178,7 +180,9 @@ func withTemp(r io.Reader, cb func(string) error) error {
err = cb(f.Name())
if err != nil {
os.Remove(f.Name())
if err := os.Remove(f.Name()); err != nil {
log.Errorf("couldn't remove temp file '%s'", f.Name())
}
return err
}