storageminer: Fix preseal meta import for genesis miners

This commit is contained in:
Łukasz Magiera 2020-03-20 01:20:01 +01:00
parent 978a718159
commit e0c15b24fc
4 changed files with 35 additions and 13 deletions

View File

@ -174,7 +174,7 @@ var initCmd = &cli.Command{
var localPaths []config.LocalPath
if pssb := cctx.StringSlice("pre-sealed-sectors"); len(pssb) != 0 {
log.Infof("Setting up storage config with presealed sector: %v", pssb)
log.Infof("Setting up storage config with presealed sectors: %v", pssb)
for _, psp := range pssb {
psp, err := homedir.Expand(psp)
@ -249,11 +249,16 @@ func migratePreSealMeta(ctx context.Context, api lapi.FullNode, metadata string,
return xerrors.Errorf("reading preseal metadata: %w", err)
}
meta := genesis.Miner{}
if err := json.Unmarshal(b, &meta); err != nil {
psm := map[string]genesis.Miner{}
if err := json.Unmarshal(b, &psm); err != nil {
return xerrors.Errorf("unmarshaling preseal metadata: %w", err)
}
meta, ok := psm[maddr.String()]
if !ok {
return xerrors.Errorf("preseal file didn't contain metadata for miner %s", maddr)
}
maxSectorID := abi.SectorNumber(0)
for _, sector := range meta.Sectors {
sectorKey := datastore.NewKey(sealing.SectorStorePrefix).ChildString(fmt.Sprint(sector.SectorID))
@ -327,6 +332,8 @@ func migratePreSealMeta(ctx context.Context, api lapi.FullNode, metadata string,
}*/
}
log.Infof("Setting next sector ID to %d", maxSectorID+1)
buf := make([]byte, binary.MaxVarintLen64)
size := binary.PutUvarint(buf, uint64(maxSectorID+1))
return mds.Put(datastore.NewKey("/storage/nextid"), buf[:size])
@ -412,17 +419,30 @@ func storageMinerInit(ctx context.Context, cctx *cli.Context, api lapi.FullNode,
return xerrors.Errorf("failed to start up genesis miner: %w", err)
}
defer func() {
if err := m.Unregister(ctx, a); err != nil {
log.Error("failed to shut down storage miner: ", err)
}
}()
cerr := configureStorageMiner(ctx, api, a, peerid)
if err := configureStorageMiner(ctx, api, a, peerid); err != nil {
if err := m.Unregister(ctx, a); err != nil {
log.Error("failed to shut down storage miner: ", err)
}
if cerr != nil {
return xerrors.Errorf("failed to configure storage miner: %w", err)
}
}
if pssb := cctx.String("pre-sealed-metadata"); pssb != "" {
pssb, err := homedir.Expand(pssb)
if err != nil {
return err
}
log.Infof("Importing pre-sealed sector metadata for %s", a)
if err := migratePreSealMeta(ctx, api, pssb, a, mds); err != nil {
return xerrors.Errorf("migrating presealed sector metadata: %w", err)
}
}
return nil
}

View File

@ -3,7 +3,6 @@ package main
import (
"encoding/json"
"fmt"
"github.com/filecoin-project/specs-actors/actors/abi"
"io/ioutil"
"os"
"path/filepath"
@ -16,6 +15,7 @@ import (
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-sectorbuilder"
"github.com/filecoin-project/specs-actors/actors/abi"
lcli "github.com/filecoin-project/lotus/cli"
"github.com/filecoin-project/lotus/storage/sealmgr/stores"
@ -264,7 +264,9 @@ var storageFindCmd = &cli.Command{
fmt.Printf("In %s (Unsealed: %t; Sealed: %t; Cache: %t)\n", id, info.unsealed, info.sealed, info.cache)
fmt.Printf("\tSealing: %t; Storage: %t\n", info.store.CanSeal, info.store.CanSeal)
if localPath, ok := local[id]; ok {
fmt.Printf("\tLocal: %s\n", localPath)
fmt.Printf("\tLocal (%s)\n", localPath)
} else {
fmt.Printf("\tRemote\n")
}
for _, l := range info.store.URLs {
fmt.Printf("\tURL: %s\n", l)

View File

@ -85,7 +85,7 @@ func (m *Sealing) plan(events []statemachine.Event, state *SectorInfo) (func(sta
for _, event := range events {
l := Log{
Timestamp: uint64(time.Now().Unix()),
Message: fmt.Sprintf("%+v", event),
Message: fmt.Sprintf("%s", event),
Kind: fmt.Sprintf("event;%T", event.User),
}

View File

@ -148,7 +148,7 @@ func (i *Index) StorageFindSector(ctx context.Context, s abi.SectorID, ft sector
continue
}
for _, id := range i.sectors[Decl{s, ft}] {
for _, id := range i.sectors[Decl{s, pathType}] {
storageIDs[id]++
}
}