Skip to content

Commit

Permalink
itests ensemble: import presealed sector metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k committed Jul 15, 2022
1 parent beeab64 commit a1ece56
Showing 1 changed file with 47 additions and 8 deletions.
55 changes: 47 additions & 8 deletions itests/kit/ensemble.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import (
"bytes"
"context"
"crypto/rand"
"encoding/binary"
"fmt"
cborutil "github.com/filecoin-project/go-cbor-util"
pipeline "github.com/filecoin-project/lotus/storage/pipeline"
"io/ioutil"
"net"
"net/http"
Expand All @@ -26,7 +29,6 @@ import (
"github.com/filecoin-project/go-state-types/exitcode"
"github.com/filecoin-project/go-state-types/network"
"github.com/filecoin-project/go-statestore"
"github.com/filecoin-project/go-storedcounter"
miner2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/miner"
power3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/power"

Expand Down Expand Up @@ -535,13 +537,7 @@ func (n *Ensemble) Start() *Ensemble {
err = ds.Put(ctx, datastore.NewKey("miner-address"), m.ActorAddr.Bytes())
require.NoError(n.t, err)

nic := storedcounter.New(ds, datastore.NewKey(modules.StorageCounterDSPrefix))
for i := 0; i < m.options.sectors; i++ {
_, err := nic.Next()
require.NoError(n.t, err)
}
_, err = nic.Next()
require.NoError(n.t, err)
require.NoError(n.t, importPreSealMeta(ctx, n.genesis.miners[i], ds))

// using real proofs, therefore need real sectors.
if !n.bootstrapped && !n.options.mockProofs {
Expand Down Expand Up @@ -912,3 +908,46 @@ func (n *Ensemble) generateGenesis() *genesis.Template {

return templ
}

func importPreSealMeta(ctx context.Context, meta genesis.Miner, mds dtypes.MetadataDS) error {
maxSectorID := abi.SectorNumber(0)
for _, sector := range meta.Sectors {
sectorKey := datastore.NewKey(pipeline.SectorStorePrefix).ChildString(fmt.Sprint(sector.SectorID))

commD := sector.CommD
commR := sector.CommR

info := &pipeline.SectorInfo{
State: pipeline.Proving,
SectorNumber: sector.SectorID,
Pieces: []pipeline.Piece{
{
Piece: abi.PieceInfo{
Size: abi.PaddedPieceSize(meta.SectorSize),
PieceCID: commD,
},
DealInfo: nil, // todo: likely possible to get, but not really that useful
},
},
CommD: &commD,
CommR: &commR,
}

b, err := cborutil.Dump(info)
if err != nil {
return err
}

if err := mds.Put(ctx, sectorKey, b); err != nil {
return err
}

if sector.SectorID > maxSectorID {
maxSectorID = sector.SectorID
}
}

buf := make([]byte, binary.MaxVarintLen64)
size := binary.PutUvarint(buf, uint64(maxSectorID))
return mds.Put(ctx, datastore.NewKey(modules.StorageCounterDSPrefix), buf[:size])
}

0 comments on commit a1ece56

Please sign in to comment.