Merge remote-tracking branch 'origin/master' into feat/post-worker
This commit is contained in:
+6
-2
@@ -231,8 +231,12 @@ func IsType(t repo.RepoType) func(s *Settings) bool {
|
||||
}
|
||||
|
||||
func isFullOrLiteNode(s *Settings) bool { return s.nodeType == repo.FullNode }
|
||||
func isFullNode(s *Settings) bool { return s.nodeType == repo.FullNode && !s.Lite }
|
||||
func isLiteNode(s *Settings) bool { return s.nodeType == repo.FullNode && s.Lite }
|
||||
func isFullNode(s *Settings) bool {
|
||||
return s.nodeType == repo.FullNode && !s.Lite
|
||||
}
|
||||
func isLiteNode(s *Settings) bool {
|
||||
return s.nodeType == repo.FullNode && s.Lite
|
||||
}
|
||||
|
||||
func Base() Option {
|
||||
return Options(
|
||||
|
||||
@@ -154,8 +154,8 @@ func ConfigStorageMiner(c interface{}) Option {
|
||||
Override(new(dtypes.RetrievalPricingFunc), modules.RetrievalPricingFunc(cfg.Dealmaking)),
|
||||
|
||||
// DAG Store
|
||||
Override(new(dagstore.MinerAPI), modules.NewMinerAPI),
|
||||
Override(DAGStoreKey, modules.DAGStore),
|
||||
Override(new(dagstore.MinerAPI), modules.NewMinerAPI(cfg.DAGStore)),
|
||||
Override(DAGStoreKey, modules.DAGStore(cfg.DAGStore)),
|
||||
|
||||
// Markets (retrieval)
|
||||
Override(new(dagstore.SectorAccessor), sectoraccessor.NewSectorAccessor),
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package config
|
||||
|
||||
type DealmakingConfiger interface {
|
||||
GetDealmakingConfig() DealmakingConfig
|
||||
SetDealmakingConfig(DealmakingConfig)
|
||||
}
|
||||
|
||||
func (c *StorageMiner) GetDealmakingConfig() DealmakingConfig {
|
||||
return c.Dealmaking
|
||||
}
|
||||
|
||||
func (c *StorageMiner) SetDealmakingConfig(other DealmakingConfig) {
|
||||
c.Dealmaking = other
|
||||
}
|
||||
|
||||
type SealingConfiger interface {
|
||||
GetSealingConfig() SealingConfig
|
||||
SetSealingConfig(SealingConfig)
|
||||
}
|
||||
|
||||
func (c *StorageMiner) GetSealingConfig() SealingConfig {
|
||||
return c.Sealing
|
||||
}
|
||||
|
||||
func (c *StorageMiner) SetSealingConfig(other SealingConfig) {
|
||||
c.Sealing = other
|
||||
}
|
||||
@@ -42,7 +42,6 @@ import (
|
||||
"github.com/libp2p/go-libp2p-core/host"
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
"github.com/multiformats/go-multibase"
|
||||
mh "github.com/multiformats/go-multihash"
|
||||
"go.uber.org/fx"
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
@@ -56,6 +55,7 @@ import (
|
||||
"github.com/filecoin-project/go-fil-markets/storagemarket/network"
|
||||
"github.com/filecoin-project/go-fil-markets/stores"
|
||||
|
||||
"github.com/filecoin-project/lotus/lib/unixfs"
|
||||
"github.com/filecoin-project/lotus/markets/retrievaladapter"
|
||||
"github.com/filecoin-project/lotus/markets/storageadapter"
|
||||
|
||||
@@ -79,7 +79,7 @@ import (
|
||||
|
||||
var log = logging.Logger("client")
|
||||
|
||||
var DefaultHashFunction = uint64(mh.BLAKE2B_MIN + 31)
|
||||
var DefaultHashFunction = unixfs.DefaultHashFunction
|
||||
|
||||
// 8 days ~= SealDuration + PreCommit + MaxProveCommitDuration + 8 hour buffer
|
||||
const dealStartBufferHours uint64 = 8 * 24
|
||||
@@ -548,7 +548,7 @@ func (a *API) ClientImport(ctx context.Context, ref api.FileRef) (res *api.Impor
|
||||
}()
|
||||
|
||||
// perform the unixfs chunking.
|
||||
root, err = a.createUnixFSFilestore(ctx, ref.Path, carPath)
|
||||
root, err = unixfs.CreateFilestore(ctx, ref.Path, carPath)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("failed to import file using unixfs: %w", err)
|
||||
}
|
||||
@@ -618,7 +618,7 @@ func (a *API) ClientImportLocal(ctx context.Context, r io.Reader) (cid.Cid, erro
|
||||
// once the DAG is formed and the root is calculated, we overwrite the
|
||||
// inner carv1 header with the final root.
|
||||
|
||||
b, err := unixFSCidBuilder()
|
||||
b, err := unixfs.CidBuilder()
|
||||
if err != nil {
|
||||
return cid.Undef, err
|
||||
}
|
||||
@@ -635,7 +635,7 @@ func (a *API) ClientImportLocal(ctx context.Context, r io.Reader) (cid.Cid, erro
|
||||
return cid.Undef, xerrors.Errorf("failed to create carv2 read/write blockstore: %w", err)
|
||||
}
|
||||
|
||||
root, err := buildUnixFS(ctx, file, bs, false)
|
||||
root, err := unixfs.Build(ctx, file, bs, false)
|
||||
if err != nil {
|
||||
return cid.Undef, xerrors.Errorf("failed to build unixfs dag: %w", err)
|
||||
}
|
||||
@@ -1364,7 +1364,7 @@ func (a *API) ClientGenCar(ctx context.Context, ref api.FileRef, outputPath stri
|
||||
defer os.Remove(tmp) //nolint:errcheck
|
||||
|
||||
// generate and import the UnixFS DAG into a filestore (positional reference) CAR.
|
||||
root, err := a.createUnixFSFilestore(ctx, ref.Path, tmp)
|
||||
root, err := unixfs.CreateFilestore(ctx, ref.Path, tmp)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("failed to import file using unixfs: %w", err)
|
||||
}
|
||||
|
||||
@@ -1,156 +0,0 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"github.com/filecoin-project/go-fil-markets/stores"
|
||||
"github.com/ipfs/go-blockservice"
|
||||
"github.com/ipfs/go-cid"
|
||||
"github.com/ipfs/go-cidutil"
|
||||
bstore "github.com/ipfs/go-ipfs-blockstore"
|
||||
chunker "github.com/ipfs/go-ipfs-chunker"
|
||||
offline "github.com/ipfs/go-ipfs-exchange-offline"
|
||||
files "github.com/ipfs/go-ipfs-files"
|
||||
ipld "github.com/ipfs/go-ipld-format"
|
||||
"github.com/ipfs/go-merkledag"
|
||||
"github.com/ipfs/go-unixfs/importer/balanced"
|
||||
ihelper "github.com/ipfs/go-unixfs/importer/helpers"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/filecoin-project/lotus/build"
|
||||
)
|
||||
|
||||
func unixFSCidBuilder() (cid.Builder, error) {
|
||||
prefix, err := merkledag.PrefixForCidVersion(1)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to initialize UnixFS CID Builder: %w", err)
|
||||
}
|
||||
prefix.MhType = DefaultHashFunction
|
||||
b := cidutil.InlineBuilder{
|
||||
Builder: prefix,
|
||||
Limit: 126,
|
||||
}
|
||||
return b, nil
|
||||
}
|
||||
|
||||
// createUnixFSFilestore takes a standard file whose path is src, forms a UnixFS DAG, and
|
||||
// writes a CARv2 file with positional mapping (backed by the go-filestore library).
|
||||
func (a *API) createUnixFSFilestore(ctx context.Context, srcPath string, dstPath string) (cid.Cid, error) {
|
||||
// This method uses a two-phase approach with a staging CAR blockstore and
|
||||
// a final CAR blockstore.
|
||||
//
|
||||
// This is necessary because of https://github.com/ipld/go-car/issues/196
|
||||
//
|
||||
// TODO: do we need to chunk twice? Isn't the first output already in the
|
||||
// right order? Can't we just copy the CAR file and replace the header?
|
||||
|
||||
src, err := os.Open(srcPath)
|
||||
if err != nil {
|
||||
return cid.Undef, xerrors.Errorf("failed to open input file: %w", err)
|
||||
}
|
||||
defer src.Close() //nolint:errcheck
|
||||
|
||||
stat, err := src.Stat()
|
||||
if err != nil {
|
||||
return cid.Undef, xerrors.Errorf("failed to stat file :%w", err)
|
||||
}
|
||||
|
||||
file, err := files.NewReaderPathFile(srcPath, src, stat)
|
||||
if err != nil {
|
||||
return cid.Undef, xerrors.Errorf("failed to create reader path file: %w", err)
|
||||
}
|
||||
|
||||
f, err := ioutil.TempFile("", "")
|
||||
if err != nil {
|
||||
return cid.Undef, xerrors.Errorf("failed to create temp file: %w", err)
|
||||
}
|
||||
_ = f.Close() // close; we only want the path.
|
||||
|
||||
tmp := f.Name()
|
||||
defer os.Remove(tmp) //nolint:errcheck
|
||||
|
||||
// Step 1. Compute the UnixFS DAG and write it to a CARv2 file to get
|
||||
// the root CID of the DAG.
|
||||
fstore, err := stores.ReadWriteFilestore(tmp)
|
||||
if err != nil {
|
||||
return cid.Undef, xerrors.Errorf("failed to create temporary filestore: %w", err)
|
||||
}
|
||||
|
||||
finalRoot1, err := buildUnixFS(ctx, file, fstore, true)
|
||||
if err != nil {
|
||||
_ = fstore.Close()
|
||||
return cid.Undef, xerrors.Errorf("failed to import file to store to compute root: %w", err)
|
||||
}
|
||||
|
||||
if err := fstore.Close(); err != nil {
|
||||
return cid.Undef, xerrors.Errorf("failed to finalize car filestore: %w", err)
|
||||
}
|
||||
|
||||
// Step 2. We now have the root of the UnixFS DAG, and we can write the
|
||||
// final CAR for real under `dst`.
|
||||
bs, err := stores.ReadWriteFilestore(dstPath, finalRoot1)
|
||||
if err != nil {
|
||||
return cid.Undef, xerrors.Errorf("failed to create a carv2 read/write filestore: %w", err)
|
||||
}
|
||||
|
||||
// rewind file to the beginning.
|
||||
if _, err := src.Seek(0, 0); err != nil {
|
||||
return cid.Undef, xerrors.Errorf("failed to rewind file: %w", err)
|
||||
}
|
||||
|
||||
finalRoot2, err := buildUnixFS(ctx, file, bs, true)
|
||||
if err != nil {
|
||||
_ = bs.Close()
|
||||
return cid.Undef, xerrors.Errorf("failed to create UnixFS DAG with carv2 blockstore: %w", err)
|
||||
}
|
||||
|
||||
if err := bs.Close(); err != nil {
|
||||
return cid.Undef, xerrors.Errorf("failed to finalize car blockstore: %w", err)
|
||||
}
|
||||
|
||||
if finalRoot1 != finalRoot2 {
|
||||
return cid.Undef, xerrors.New("roots do not match")
|
||||
}
|
||||
|
||||
return finalRoot1, nil
|
||||
}
|
||||
|
||||
// buildUnixFS builds a UnixFS DAG out of the supplied reader,
|
||||
// and imports the DAG into the supplied service.
|
||||
func buildUnixFS(ctx context.Context, reader io.Reader, into bstore.Blockstore, filestore bool) (cid.Cid, error) {
|
||||
b, err := unixFSCidBuilder()
|
||||
if err != nil {
|
||||
return cid.Undef, err
|
||||
}
|
||||
|
||||
bsvc := blockservice.New(into, offline.Exchange(into))
|
||||
dags := merkledag.NewDAGService(bsvc)
|
||||
bufdag := ipld.NewBufferedDAG(ctx, dags)
|
||||
|
||||
params := ihelper.DagBuilderParams{
|
||||
Maxlinks: build.UnixfsLinksPerLevel,
|
||||
RawLeaves: true,
|
||||
CidBuilder: b,
|
||||
Dagserv: bufdag,
|
||||
NoCopy: filestore,
|
||||
}
|
||||
|
||||
db, err := params.New(chunker.NewSizeSplitter(reader, int64(build.UnixfsChunkSize)))
|
||||
if err != nil {
|
||||
return cid.Undef, err
|
||||
}
|
||||
nd, err := balanced.Layout(db)
|
||||
if err != nil {
|
||||
return cid.Undef, err
|
||||
}
|
||||
|
||||
if err := bufdag.Commit(); err != nil {
|
||||
return cid.Undef, err
|
||||
}
|
||||
|
||||
return nd.Cid(), nil
|
||||
}
|
||||
@@ -1,136 +0,0 @@
|
||||
//stm: #unit
|
||||
package client
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/ipfs/go-blockservice"
|
||||
"github.com/ipfs/go-cid"
|
||||
offline "github.com/ipfs/go-ipfs-exchange-offline"
|
||||
files "github.com/ipfs/go-ipfs-files"
|
||||
"github.com/ipfs/go-merkledag"
|
||||
unixfile "github.com/ipfs/go-unixfs/file"
|
||||
carv2 "github.com/ipld/go-car/v2"
|
||||
"github.com/ipld/go-car/v2/blockstore"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/filecoin-project/go-fil-markets/stores"
|
||||
|
||||
"github.com/filecoin-project/lotus/node/repo/imports"
|
||||
)
|
||||
|
||||
// This test uses a full "dense" CARv2, and not a filestore (positional mapping).
|
||||
func TestRoundtripUnixFS_Dense(t *testing.T) {
|
||||
//stm: @CLIENT_DATA_IMPORT_002
|
||||
ctx := context.Background()
|
||||
|
||||
inputPath, inputContents := genInputFile(t)
|
||||
defer os.Remove(inputPath) //nolint:errcheck
|
||||
|
||||
carv2File := newTmpFile(t)
|
||||
defer os.Remove(carv2File) //nolint:errcheck
|
||||
|
||||
// import a file to a Unixfs DAG using a CARv2 read/write blockstore.
|
||||
bs, err := blockstore.OpenReadWrite(carv2File, nil,
|
||||
carv2.ZeroLengthSectionAsEOF(true),
|
||||
blockstore.UseWholeCIDs(true))
|
||||
require.NoError(t, err)
|
||||
|
||||
root, err := buildUnixFS(ctx, bytes.NewBuffer(inputContents), bs, false)
|
||||
require.NoError(t, err)
|
||||
require.NotEqual(t, cid.Undef, root)
|
||||
require.NoError(t, bs.Finalize())
|
||||
|
||||
// reconstruct the file.
|
||||
readOnly, err := blockstore.OpenReadOnly(carv2File,
|
||||
carv2.ZeroLengthSectionAsEOF(true),
|
||||
blockstore.UseWholeCIDs(true))
|
||||
require.NoError(t, err)
|
||||
defer readOnly.Close() //nolint:errcheck
|
||||
|
||||
dags := merkledag.NewDAGService(blockservice.New(readOnly, offline.Exchange(readOnly)))
|
||||
|
||||
nd, err := dags.Get(ctx, root)
|
||||
require.NoError(t, err)
|
||||
|
||||
file, err := unixfile.NewUnixfsFile(ctx, dags, nd)
|
||||
require.NoError(t, err)
|
||||
|
||||
tmpOutput := newTmpFile(t)
|
||||
defer os.Remove(tmpOutput) //nolint:errcheck
|
||||
require.NoError(t, files.WriteTo(file, tmpOutput))
|
||||
|
||||
// ensure contents of the initial input file and the output file are identical.
|
||||
fo, err := os.Open(tmpOutput)
|
||||
require.NoError(t, err)
|
||||
bz2, err := ioutil.ReadAll(fo)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, fo.Close())
|
||||
require.Equal(t, inputContents, bz2)
|
||||
}
|
||||
|
||||
func TestRoundtripUnixFS_Filestore(t *testing.T) {
|
||||
//stm: @CLIENT_DATA_IMPORT_001
|
||||
ctx := context.Background()
|
||||
a := &API{
|
||||
Imports: &imports.Manager{},
|
||||
}
|
||||
|
||||
inputPath, inputContents := genInputFile(t)
|
||||
defer os.Remove(inputPath) //nolint:errcheck
|
||||
|
||||
dst := newTmpFile(t)
|
||||
defer os.Remove(dst) //nolint:errcheck
|
||||
|
||||
root, err := a.createUnixFSFilestore(ctx, inputPath, dst)
|
||||
require.NoError(t, err)
|
||||
require.NotEqual(t, cid.Undef, root)
|
||||
|
||||
// convert the CARv2 to a normal file again and ensure the contents match
|
||||
fs, err := stores.ReadOnlyFilestore(dst)
|
||||
require.NoError(t, err)
|
||||
defer fs.Close() //nolint:errcheck
|
||||
|
||||
dags := merkledag.NewDAGService(blockservice.New(fs, offline.Exchange(fs)))
|
||||
|
||||
nd, err := dags.Get(ctx, root)
|
||||
require.NoError(t, err)
|
||||
|
||||
file, err := unixfile.NewUnixfsFile(ctx, dags, nd)
|
||||
require.NoError(t, err)
|
||||
|
||||
tmpOutput := newTmpFile(t)
|
||||
defer os.Remove(tmpOutput) //nolint:errcheck
|
||||
require.NoError(t, files.WriteTo(file, tmpOutput))
|
||||
|
||||
// ensure contents of the initial input file and the output file are identical.
|
||||
fo, err := os.Open(tmpOutput)
|
||||
require.NoError(t, err)
|
||||
bz2, err := ioutil.ReadAll(fo)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, fo.Close())
|
||||
require.Equal(t, inputContents, bz2)
|
||||
}
|
||||
|
||||
func newTmpFile(t *testing.T) string {
|
||||
f, err := os.CreateTemp("", "")
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.Close())
|
||||
return f.Name()
|
||||
}
|
||||
|
||||
func genInputFile(t *testing.T) (filepath string, contents []byte) {
|
||||
s := strings.Repeat("abcde", 100)
|
||||
tmp, err := os.CreateTemp("", "")
|
||||
require.NoError(t, err)
|
||||
_, err = io.Copy(tmp, strings.NewReader(s))
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, tmp.Close())
|
||||
return tmp.Name(), []byte(s)
|
||||
}
|
||||
+141
-74
@@ -764,8 +764,9 @@ func StorageAuthWithURL(apiInfo string) func(ctx helpers.MetricsCtx, ca v0api.Co
|
||||
|
||||
func NewConsiderOnlineStorageDealsConfigFunc(r repo.LockedRepo) (dtypes.ConsiderOnlineStorageDealsConfigFunc, error) {
|
||||
return func() (out bool, err error) {
|
||||
err = readCfg(r, func(cfg *config.StorageMiner) {
|
||||
out = cfg.Dealmaking.ConsiderOnlineStorageDeals
|
||||
err = readDealmakingCfg(r, func(c config.DealmakingConfiger) {
|
||||
cfg := c.GetDealmakingConfig()
|
||||
out = cfg.ConsiderOnlineStorageDeals
|
||||
})
|
||||
return
|
||||
}, nil
|
||||
@@ -773,8 +774,10 @@ func NewConsiderOnlineStorageDealsConfigFunc(r repo.LockedRepo) (dtypes.Consider
|
||||
|
||||
func NewSetConsideringOnlineStorageDealsFunc(r repo.LockedRepo) (dtypes.SetConsiderOnlineStorageDealsConfigFunc, error) {
|
||||
return func(b bool) (err error) {
|
||||
err = mutateCfg(r, func(cfg *config.StorageMiner) {
|
||||
cfg.Dealmaking.ConsiderOnlineStorageDeals = b
|
||||
err = mutateDealmakingCfg(r, func(c config.DealmakingConfiger) {
|
||||
cfg := c.GetDealmakingConfig()
|
||||
cfg.ConsiderOnlineStorageDeals = b
|
||||
c.SetDealmakingConfig(cfg)
|
||||
})
|
||||
return
|
||||
}, nil
|
||||
@@ -782,8 +785,9 @@ func NewSetConsideringOnlineStorageDealsFunc(r repo.LockedRepo) (dtypes.SetConsi
|
||||
|
||||
func NewConsiderOnlineRetrievalDealsConfigFunc(r repo.LockedRepo) (dtypes.ConsiderOnlineRetrievalDealsConfigFunc, error) {
|
||||
return func() (out bool, err error) {
|
||||
err = readCfg(r, func(cfg *config.StorageMiner) {
|
||||
out = cfg.Dealmaking.ConsiderOnlineRetrievalDeals
|
||||
err = readDealmakingCfg(r, func(c config.DealmakingConfiger) {
|
||||
cfg := c.GetDealmakingConfig()
|
||||
out = cfg.ConsiderOnlineRetrievalDeals
|
||||
})
|
||||
return
|
||||
}, nil
|
||||
@@ -791,8 +795,10 @@ func NewConsiderOnlineRetrievalDealsConfigFunc(r repo.LockedRepo) (dtypes.Consid
|
||||
|
||||
func NewSetConsiderOnlineRetrievalDealsConfigFunc(r repo.LockedRepo) (dtypes.SetConsiderOnlineRetrievalDealsConfigFunc, error) {
|
||||
return func(b bool) (err error) {
|
||||
err = mutateCfg(r, func(cfg *config.StorageMiner) {
|
||||
cfg.Dealmaking.ConsiderOnlineRetrievalDeals = b
|
||||
err = mutateDealmakingCfg(r, func(c config.DealmakingConfiger) {
|
||||
cfg := c.GetDealmakingConfig()
|
||||
cfg.ConsiderOnlineRetrievalDeals = b
|
||||
c.SetDealmakingConfig(cfg)
|
||||
})
|
||||
return
|
||||
}, nil
|
||||
@@ -800,8 +806,9 @@ func NewSetConsiderOnlineRetrievalDealsConfigFunc(r repo.LockedRepo) (dtypes.Set
|
||||
|
||||
func NewStorageDealPieceCidBlocklistConfigFunc(r repo.LockedRepo) (dtypes.StorageDealPieceCidBlocklistConfigFunc, error) {
|
||||
return func() (out []cid.Cid, err error) {
|
||||
err = readCfg(r, func(cfg *config.StorageMiner) {
|
||||
out = cfg.Dealmaking.PieceCidBlocklist
|
||||
err = readDealmakingCfg(r, func(c config.DealmakingConfiger) {
|
||||
cfg := c.GetDealmakingConfig()
|
||||
out = cfg.PieceCidBlocklist
|
||||
})
|
||||
return
|
||||
}, nil
|
||||
@@ -809,8 +816,10 @@ func NewStorageDealPieceCidBlocklistConfigFunc(r repo.LockedRepo) (dtypes.Storag
|
||||
|
||||
func NewSetStorageDealPieceCidBlocklistConfigFunc(r repo.LockedRepo) (dtypes.SetStorageDealPieceCidBlocklistConfigFunc, error) {
|
||||
return func(blocklist []cid.Cid) (err error) {
|
||||
err = mutateCfg(r, func(cfg *config.StorageMiner) {
|
||||
cfg.Dealmaking.PieceCidBlocklist = blocklist
|
||||
err = mutateDealmakingCfg(r, func(c config.DealmakingConfiger) {
|
||||
cfg := c.GetDealmakingConfig()
|
||||
cfg.PieceCidBlocklist = blocklist
|
||||
c.SetDealmakingConfig(cfg)
|
||||
})
|
||||
return
|
||||
}, nil
|
||||
@@ -818,8 +827,9 @@ func NewSetStorageDealPieceCidBlocklistConfigFunc(r repo.LockedRepo) (dtypes.Set
|
||||
|
||||
func NewConsiderOfflineStorageDealsConfigFunc(r repo.LockedRepo) (dtypes.ConsiderOfflineStorageDealsConfigFunc, error) {
|
||||
return func() (out bool, err error) {
|
||||
err = readCfg(r, func(cfg *config.StorageMiner) {
|
||||
out = cfg.Dealmaking.ConsiderOfflineStorageDeals
|
||||
err = readDealmakingCfg(r, func(c config.DealmakingConfiger) {
|
||||
cfg := c.GetDealmakingConfig()
|
||||
out = cfg.ConsiderOfflineStorageDeals
|
||||
})
|
||||
return
|
||||
}, nil
|
||||
@@ -827,8 +837,10 @@ func NewConsiderOfflineStorageDealsConfigFunc(r repo.LockedRepo) (dtypes.Conside
|
||||
|
||||
func NewSetConsideringOfflineStorageDealsFunc(r repo.LockedRepo) (dtypes.SetConsiderOfflineStorageDealsConfigFunc, error) {
|
||||
return func(b bool) (err error) {
|
||||
err = mutateCfg(r, func(cfg *config.StorageMiner) {
|
||||
cfg.Dealmaking.ConsiderOfflineStorageDeals = b
|
||||
err = mutateDealmakingCfg(r, func(c config.DealmakingConfiger) {
|
||||
cfg := c.GetDealmakingConfig()
|
||||
cfg.ConsiderOfflineStorageDeals = b
|
||||
c.SetDealmakingConfig(cfg)
|
||||
})
|
||||
return
|
||||
}, nil
|
||||
@@ -836,8 +848,9 @@ func NewSetConsideringOfflineStorageDealsFunc(r repo.LockedRepo) (dtypes.SetCons
|
||||
|
||||
func NewConsiderOfflineRetrievalDealsConfigFunc(r repo.LockedRepo) (dtypes.ConsiderOfflineRetrievalDealsConfigFunc, error) {
|
||||
return func() (out bool, err error) {
|
||||
err = readCfg(r, func(cfg *config.StorageMiner) {
|
||||
out = cfg.Dealmaking.ConsiderOfflineRetrievalDeals
|
||||
err = readDealmakingCfg(r, func(c config.DealmakingConfiger) {
|
||||
cfg := c.GetDealmakingConfig()
|
||||
out = cfg.ConsiderOfflineRetrievalDeals
|
||||
})
|
||||
return
|
||||
}, nil
|
||||
@@ -845,8 +858,10 @@ func NewConsiderOfflineRetrievalDealsConfigFunc(r repo.LockedRepo) (dtypes.Consi
|
||||
|
||||
func NewSetConsiderOfflineRetrievalDealsConfigFunc(r repo.LockedRepo) (dtypes.SetConsiderOfflineRetrievalDealsConfigFunc, error) {
|
||||
return func(b bool) (err error) {
|
||||
err = mutateCfg(r, func(cfg *config.StorageMiner) {
|
||||
cfg.Dealmaking.ConsiderOfflineRetrievalDeals = b
|
||||
err = mutateDealmakingCfg(r, func(c config.DealmakingConfiger) {
|
||||
cfg := c.GetDealmakingConfig()
|
||||
cfg.ConsiderOfflineRetrievalDeals = b
|
||||
c.SetDealmakingConfig(cfg)
|
||||
})
|
||||
return
|
||||
}, nil
|
||||
@@ -854,8 +869,9 @@ func NewSetConsiderOfflineRetrievalDealsConfigFunc(r repo.LockedRepo) (dtypes.Se
|
||||
|
||||
func NewConsiderVerifiedStorageDealsConfigFunc(r repo.LockedRepo) (dtypes.ConsiderVerifiedStorageDealsConfigFunc, error) {
|
||||
return func() (out bool, err error) {
|
||||
err = readCfg(r, func(cfg *config.StorageMiner) {
|
||||
out = cfg.Dealmaking.ConsiderVerifiedStorageDeals
|
||||
err = readDealmakingCfg(r, func(c config.DealmakingConfiger) {
|
||||
cfg := c.GetDealmakingConfig()
|
||||
out = cfg.ConsiderVerifiedStorageDeals
|
||||
})
|
||||
return
|
||||
}, nil
|
||||
@@ -863,8 +879,10 @@ func NewConsiderVerifiedStorageDealsConfigFunc(r repo.LockedRepo) (dtypes.Consid
|
||||
|
||||
func NewSetConsideringVerifiedStorageDealsFunc(r repo.LockedRepo) (dtypes.SetConsiderVerifiedStorageDealsConfigFunc, error) {
|
||||
return func(b bool) (err error) {
|
||||
err = mutateCfg(r, func(cfg *config.StorageMiner) {
|
||||
cfg.Dealmaking.ConsiderVerifiedStorageDeals = b
|
||||
err = mutateDealmakingCfg(r, func(c config.DealmakingConfiger) {
|
||||
cfg := c.GetDealmakingConfig()
|
||||
cfg.ConsiderVerifiedStorageDeals = b
|
||||
c.SetDealmakingConfig(cfg)
|
||||
})
|
||||
return
|
||||
}, nil
|
||||
@@ -872,8 +890,9 @@ func NewSetConsideringVerifiedStorageDealsFunc(r repo.LockedRepo) (dtypes.SetCon
|
||||
|
||||
func NewConsiderUnverifiedStorageDealsConfigFunc(r repo.LockedRepo) (dtypes.ConsiderUnverifiedStorageDealsConfigFunc, error) {
|
||||
return func() (out bool, err error) {
|
||||
err = readCfg(r, func(cfg *config.StorageMiner) {
|
||||
out = cfg.Dealmaking.ConsiderUnverifiedStorageDeals
|
||||
err = readDealmakingCfg(r, func(c config.DealmakingConfiger) {
|
||||
cfg := c.GetDealmakingConfig()
|
||||
out = cfg.ConsiderUnverifiedStorageDeals
|
||||
})
|
||||
return
|
||||
}, nil
|
||||
@@ -881,8 +900,10 @@ func NewConsiderUnverifiedStorageDealsConfigFunc(r repo.LockedRepo) (dtypes.Cons
|
||||
|
||||
func NewSetConsideringUnverifiedStorageDealsFunc(r repo.LockedRepo) (dtypes.SetConsiderUnverifiedStorageDealsConfigFunc, error) {
|
||||
return func(b bool) (err error) {
|
||||
err = mutateCfg(r, func(cfg *config.StorageMiner) {
|
||||
cfg.Dealmaking.ConsiderUnverifiedStorageDeals = b
|
||||
err = mutateDealmakingCfg(r, func(c config.DealmakingConfiger) {
|
||||
cfg := c.GetDealmakingConfig()
|
||||
cfg.ConsiderUnverifiedStorageDeals = b
|
||||
c.SetDealmakingConfig(cfg)
|
||||
})
|
||||
return
|
||||
}, nil
|
||||
@@ -890,8 +911,8 @@ func NewSetConsideringUnverifiedStorageDealsFunc(r repo.LockedRepo) (dtypes.SetC
|
||||
|
||||
func NewSetSealConfigFunc(r repo.LockedRepo) (dtypes.SetSealingConfigFunc, error) {
|
||||
return func(cfg sealiface.Config) (err error) {
|
||||
err = mutateCfg(r, func(c *config.StorageMiner) {
|
||||
c.Sealing = config.SealingConfig{
|
||||
err = mutateSealingCfg(r, func(c config.SealingConfiger) {
|
||||
newCfg := config.SealingConfig{
|
||||
MaxWaitDealsSectors: cfg.MaxWaitDealsSectors,
|
||||
MaxSealingSectors: cfg.MaxSealingSectors,
|
||||
MaxSealingSectorsForDeals: cfg.MaxSealingSectorsForDeals,
|
||||
@@ -922,51 +943,54 @@ func NewSetSealConfigFunc(r repo.LockedRepo) (dtypes.SetSealingConfigFunc, error
|
||||
TerminateBatchMin: cfg.TerminateBatchMin,
|
||||
TerminateBatchWait: config.Duration(cfg.TerminateBatchWait),
|
||||
}
|
||||
c.SetSealingConfig(newCfg)
|
||||
})
|
||||
return
|
||||
}, nil
|
||||
}
|
||||
|
||||
func ToSealingConfig(cfg *config.StorageMiner) sealiface.Config {
|
||||
func ToSealingConfig(dealmakingCfg config.DealmakingConfig, sealingCfg config.SealingConfig) sealiface.Config {
|
||||
return sealiface.Config{
|
||||
MaxWaitDealsSectors: cfg.Sealing.MaxWaitDealsSectors,
|
||||
MaxSealingSectors: cfg.Sealing.MaxSealingSectors,
|
||||
MaxSealingSectorsForDeals: cfg.Sealing.MaxSealingSectorsForDeals,
|
||||
StartEpochSealingBuffer: abi.ChainEpoch(cfg.Dealmaking.StartEpochSealingBuffer),
|
||||
MakeNewSectorForDeals: cfg.Dealmaking.MakeNewSectorForDeals,
|
||||
CommittedCapacitySectorLifetime: time.Duration(cfg.Sealing.CommittedCapacitySectorLifetime),
|
||||
WaitDealsDelay: time.Duration(cfg.Sealing.WaitDealsDelay),
|
||||
MakeCCSectorsAvailable: cfg.Sealing.MakeCCSectorsAvailable,
|
||||
AlwaysKeepUnsealedCopy: cfg.Sealing.AlwaysKeepUnsealedCopy,
|
||||
FinalizeEarly: cfg.Sealing.FinalizeEarly,
|
||||
MaxWaitDealsSectors: sealingCfg.MaxWaitDealsSectors,
|
||||
MaxSealingSectors: sealingCfg.MaxSealingSectors,
|
||||
MaxSealingSectorsForDeals: sealingCfg.MaxSealingSectorsForDeals,
|
||||
StartEpochSealingBuffer: abi.ChainEpoch(dealmakingCfg.StartEpochSealingBuffer),
|
||||
MakeNewSectorForDeals: dealmakingCfg.MakeNewSectorForDeals,
|
||||
CommittedCapacitySectorLifetime: time.Duration(sealingCfg.CommittedCapacitySectorLifetime),
|
||||
WaitDealsDelay: time.Duration(sealingCfg.WaitDealsDelay),
|
||||
MakeCCSectorsAvailable: sealingCfg.MakeCCSectorsAvailable,
|
||||
AlwaysKeepUnsealedCopy: sealingCfg.AlwaysKeepUnsealedCopy,
|
||||
FinalizeEarly: sealingCfg.FinalizeEarly,
|
||||
|
||||
CollateralFromMinerBalance: cfg.Sealing.CollateralFromMinerBalance,
|
||||
AvailableBalanceBuffer: types.BigInt(cfg.Sealing.AvailableBalanceBuffer),
|
||||
DisableCollateralFallback: cfg.Sealing.DisableCollateralFallback,
|
||||
CollateralFromMinerBalance: sealingCfg.CollateralFromMinerBalance,
|
||||
AvailableBalanceBuffer: types.BigInt(sealingCfg.AvailableBalanceBuffer),
|
||||
DisableCollateralFallback: sealingCfg.DisableCollateralFallback,
|
||||
|
||||
BatchPreCommits: cfg.Sealing.BatchPreCommits,
|
||||
MaxPreCommitBatch: cfg.Sealing.MaxPreCommitBatch,
|
||||
PreCommitBatchWait: time.Duration(cfg.Sealing.PreCommitBatchWait),
|
||||
PreCommitBatchSlack: time.Duration(cfg.Sealing.PreCommitBatchSlack),
|
||||
BatchPreCommits: sealingCfg.BatchPreCommits,
|
||||
MaxPreCommitBatch: sealingCfg.MaxPreCommitBatch,
|
||||
PreCommitBatchWait: time.Duration(sealingCfg.PreCommitBatchWait),
|
||||
PreCommitBatchSlack: time.Duration(sealingCfg.PreCommitBatchSlack),
|
||||
|
||||
AggregateCommits: cfg.Sealing.AggregateCommits,
|
||||
MinCommitBatch: cfg.Sealing.MinCommitBatch,
|
||||
MaxCommitBatch: cfg.Sealing.MaxCommitBatch,
|
||||
CommitBatchWait: time.Duration(cfg.Sealing.CommitBatchWait),
|
||||
CommitBatchSlack: time.Duration(cfg.Sealing.CommitBatchSlack),
|
||||
AggregateAboveBaseFee: types.BigInt(cfg.Sealing.AggregateAboveBaseFee),
|
||||
BatchPreCommitAboveBaseFee: types.BigInt(cfg.Sealing.BatchPreCommitAboveBaseFee),
|
||||
AggregateCommits: sealingCfg.AggregateCommits,
|
||||
MinCommitBatch: sealingCfg.MinCommitBatch,
|
||||
MaxCommitBatch: sealingCfg.MaxCommitBatch,
|
||||
CommitBatchWait: time.Duration(sealingCfg.CommitBatchWait),
|
||||
CommitBatchSlack: time.Duration(sealingCfg.CommitBatchSlack),
|
||||
AggregateAboveBaseFee: types.BigInt(sealingCfg.AggregateAboveBaseFee),
|
||||
BatchPreCommitAboveBaseFee: types.BigInt(sealingCfg.BatchPreCommitAboveBaseFee),
|
||||
|
||||
TerminateBatchMax: cfg.Sealing.TerminateBatchMax,
|
||||
TerminateBatchMin: cfg.Sealing.TerminateBatchMin,
|
||||
TerminateBatchWait: time.Duration(cfg.Sealing.TerminateBatchWait),
|
||||
TerminateBatchMax: sealingCfg.TerminateBatchMax,
|
||||
TerminateBatchMin: sealingCfg.TerminateBatchMin,
|
||||
TerminateBatchWait: time.Duration(sealingCfg.TerminateBatchWait),
|
||||
}
|
||||
}
|
||||
|
||||
func NewGetSealConfigFunc(r repo.LockedRepo) (dtypes.GetSealingConfigFunc, error) {
|
||||
return func() (out sealiface.Config, err error) {
|
||||
err = readCfg(r, func(cfg *config.StorageMiner) {
|
||||
out = ToSealingConfig(cfg)
|
||||
err = readSealingCfg(r, func(dc config.DealmakingConfiger, sc config.SealingConfiger) {
|
||||
scfg := sc.GetSealingConfig()
|
||||
dcfg := dc.GetDealmakingConfig()
|
||||
out = ToSealingConfig(dcfg, scfg)
|
||||
})
|
||||
return
|
||||
}, nil
|
||||
@@ -974,8 +998,10 @@ func NewGetSealConfigFunc(r repo.LockedRepo) (dtypes.GetSealingConfigFunc, error
|
||||
|
||||
func NewSetExpectedSealDurationFunc(r repo.LockedRepo) (dtypes.SetExpectedSealDurationFunc, error) {
|
||||
return func(delay time.Duration) (err error) {
|
||||
err = mutateCfg(r, func(cfg *config.StorageMiner) {
|
||||
cfg.Dealmaking.ExpectedSealDuration = config.Duration(delay)
|
||||
err = mutateDealmakingCfg(r, func(c config.DealmakingConfiger) {
|
||||
cfg := c.GetDealmakingConfig()
|
||||
cfg.ExpectedSealDuration = config.Duration(delay)
|
||||
c.SetDealmakingConfig(cfg)
|
||||
})
|
||||
return
|
||||
}, nil
|
||||
@@ -983,8 +1009,9 @@ func NewSetExpectedSealDurationFunc(r repo.LockedRepo) (dtypes.SetExpectedSealDu
|
||||
|
||||
func NewGetExpectedSealDurationFunc(r repo.LockedRepo) (dtypes.GetExpectedSealDurationFunc, error) {
|
||||
return func() (out time.Duration, err error) {
|
||||
err = readCfg(r, func(cfg *config.StorageMiner) {
|
||||
out = time.Duration(cfg.Dealmaking.ExpectedSealDuration)
|
||||
err = readDealmakingCfg(r, func(c config.DealmakingConfiger) {
|
||||
cfg := c.GetDealmakingConfig()
|
||||
out = time.Duration(cfg.ExpectedSealDuration)
|
||||
})
|
||||
return
|
||||
}, nil
|
||||
@@ -992,8 +1019,10 @@ func NewGetExpectedSealDurationFunc(r repo.LockedRepo) (dtypes.GetExpectedSealDu
|
||||
|
||||
func NewSetMaxDealStartDelayFunc(r repo.LockedRepo) (dtypes.SetMaxDealStartDelayFunc, error) {
|
||||
return func(delay time.Duration) (err error) {
|
||||
err = mutateCfg(r, func(cfg *config.StorageMiner) {
|
||||
cfg.Dealmaking.MaxDealStartDelay = config.Duration(delay)
|
||||
err = mutateDealmakingCfg(r, func(c config.DealmakingConfiger) {
|
||||
cfg := c.GetDealmakingConfig()
|
||||
cfg.MaxDealStartDelay = config.Duration(delay)
|
||||
c.SetDealmakingConfig(cfg)
|
||||
})
|
||||
return
|
||||
}, nil
|
||||
@@ -1001,22 +1030,60 @@ func NewSetMaxDealStartDelayFunc(r repo.LockedRepo) (dtypes.SetMaxDealStartDelay
|
||||
|
||||
func NewGetMaxDealStartDelayFunc(r repo.LockedRepo) (dtypes.GetMaxDealStartDelayFunc, error) {
|
||||
return func() (out time.Duration, err error) {
|
||||
err = readCfg(r, func(cfg *config.StorageMiner) {
|
||||
out = time.Duration(cfg.Dealmaking.MaxDealStartDelay)
|
||||
err = readDealmakingCfg(r, func(c config.DealmakingConfiger) {
|
||||
cfg := c.GetDealmakingConfig()
|
||||
out = time.Duration(cfg.MaxDealStartDelay)
|
||||
})
|
||||
return
|
||||
}, nil
|
||||
}
|
||||
|
||||
func readCfg(r repo.LockedRepo, accessor func(*config.StorageMiner)) error {
|
||||
func readSealingCfg(r repo.LockedRepo, accessor func(config.DealmakingConfiger, config.SealingConfiger)) error {
|
||||
raw, err := r.Config()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cfg, ok := raw.(*config.StorageMiner)
|
||||
scfg, ok := raw.(config.SealingConfiger)
|
||||
if !ok {
|
||||
return xerrors.New("expected address of config.StorageMiner")
|
||||
return xerrors.New("expected config with sealing config trait")
|
||||
}
|
||||
|
||||
dcfg, ok := raw.(config.DealmakingConfiger)
|
||||
if !ok {
|
||||
return xerrors.New("expected config with dealmaking config trait")
|
||||
}
|
||||
|
||||
accessor(dcfg, scfg)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func mutateSealingCfg(r repo.LockedRepo, mutator func(config.SealingConfiger)) error {
|
||||
var typeErr error
|
||||
|
||||
setConfigErr := r.SetConfig(func(raw interface{}) {
|
||||
cfg, ok := raw.(config.SealingConfiger)
|
||||
if !ok {
|
||||
typeErr = errors.New("expected config with sealing config trait")
|
||||
return
|
||||
}
|
||||
|
||||
mutator(cfg)
|
||||
})
|
||||
|
||||
return multierr.Combine(typeErr, setConfigErr)
|
||||
}
|
||||
|
||||
func readDealmakingCfg(r repo.LockedRepo, accessor func(config.DealmakingConfiger)) error {
|
||||
raw, err := r.Config()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cfg, ok := raw.(config.DealmakingConfiger)
|
||||
if !ok {
|
||||
return xerrors.New("expected config with dealmaking config trait")
|
||||
}
|
||||
|
||||
accessor(cfg)
|
||||
@@ -1024,13 +1091,13 @@ func readCfg(r repo.LockedRepo, accessor func(*config.StorageMiner)) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func mutateCfg(r repo.LockedRepo, mutator func(*config.StorageMiner)) error {
|
||||
func mutateDealmakingCfg(r repo.LockedRepo, mutator func(config.DealmakingConfiger)) error {
|
||||
var typeErr error
|
||||
|
||||
setConfigErr := r.SetConfig(func(raw interface{}) {
|
||||
cfg, ok := raw.(*config.StorageMiner)
|
||||
cfg, ok := raw.(config.DealmakingConfiger)
|
||||
if !ok {
|
||||
typeErr = errors.New("expected miner config")
|
||||
typeErr = errors.New("expected config with dealmaking config trait")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -25,88 +25,70 @@ const (
|
||||
)
|
||||
|
||||
// NewMinerAPI creates a new MinerAPI adaptor for the dagstore mounts.
|
||||
func NewMinerAPI(lc fx.Lifecycle, r repo.LockedRepo, pieceStore dtypes.ProviderPieceStore, sa mdagstore.SectorAccessor) (mdagstore.MinerAPI, error) {
|
||||
cfg, err := extractDAGStoreConfig(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// caps the amount of concurrent calls to the storage, so that we don't
|
||||
// spam it during heavy processes like bulk migration.
|
||||
if v, ok := os.LookupEnv("LOTUS_DAGSTORE_MOUNT_CONCURRENCY"); ok {
|
||||
concurrency, err := strconv.Atoi(v)
|
||||
if err == nil {
|
||||
cfg.MaxConcurrencyStorageCalls = concurrency
|
||||
}
|
||||
}
|
||||
|
||||
mountApi := mdagstore.NewMinerAPI(pieceStore, sa, cfg.MaxConcurrencyStorageCalls, cfg.MaxConcurrentUnseals)
|
||||
ready := make(chan error, 1)
|
||||
pieceStore.OnReady(func(err error) {
|
||||
ready <- err
|
||||
})
|
||||
lc.Append(fx.Hook{
|
||||
OnStart: func(ctx context.Context) error {
|
||||
if err := <-ready; err != nil {
|
||||
return fmt.Errorf("aborting dagstore start; piecestore failed to start: %s", err)
|
||||
func NewMinerAPI(cfg config.DAGStoreConfig) func(fx.Lifecycle, repo.LockedRepo, dtypes.ProviderPieceStore, mdagstore.SectorAccessor) (mdagstore.MinerAPI, error) {
|
||||
return func(lc fx.Lifecycle, r repo.LockedRepo, pieceStore dtypes.ProviderPieceStore, sa mdagstore.SectorAccessor) (mdagstore.MinerAPI, error) {
|
||||
// caps the amount of concurrent calls to the storage, so that we don't
|
||||
// spam it during heavy processes like bulk migration.
|
||||
if v, ok := os.LookupEnv("LOTUS_DAGSTORE_MOUNT_CONCURRENCY"); ok {
|
||||
concurrency, err := strconv.Atoi(v)
|
||||
if err == nil {
|
||||
cfg.MaxConcurrencyStorageCalls = concurrency
|
||||
}
|
||||
return mountApi.Start(ctx)
|
||||
},
|
||||
OnStop: func(context.Context) error {
|
||||
return nil
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
return mountApi, nil
|
||||
mountApi := mdagstore.NewMinerAPI(pieceStore, sa, cfg.MaxConcurrencyStorageCalls, cfg.MaxConcurrentUnseals)
|
||||
ready := make(chan error, 1)
|
||||
pieceStore.OnReady(func(err error) {
|
||||
ready <- err
|
||||
})
|
||||
lc.Append(fx.Hook{
|
||||
OnStart: func(ctx context.Context) error {
|
||||
if err := <-ready; err != nil {
|
||||
return fmt.Errorf("aborting dagstore start; piecestore failed to start: %s", err)
|
||||
}
|
||||
return mountApi.Start(ctx)
|
||||
},
|
||||
OnStop: func(context.Context) error {
|
||||
return nil
|
||||
},
|
||||
})
|
||||
|
||||
return mountApi, nil
|
||||
}
|
||||
}
|
||||
|
||||
// DAGStore constructs a DAG store using the supplied minerAPI, and the
|
||||
// user configuration. It returns both the DAGStore and the Wrapper suitable for
|
||||
// passing to markets.
|
||||
func DAGStore(lc fx.Lifecycle, r repo.LockedRepo, minerAPI mdagstore.MinerAPI, h host.Host) (*dagstore.DAGStore, *mdagstore.Wrapper, error) {
|
||||
cfg, err := extractDAGStoreConfig(r)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
// fall back to default root directory if not explicitly set in the config.
|
||||
if cfg.RootDir == "" {
|
||||
cfg.RootDir = filepath.Join(r.Path(), DefaultDAGStoreDir)
|
||||
}
|
||||
|
||||
v, ok := os.LookupEnv(EnvDAGStoreCopyConcurrency)
|
||||
if ok {
|
||||
concurrency, err := strconv.Atoi(v)
|
||||
if err == nil {
|
||||
cfg.MaxConcurrentReadyFetches = concurrency
|
||||
func DAGStore(cfg config.DAGStoreConfig) func(lc fx.Lifecycle, r repo.LockedRepo, minerAPI mdagstore.MinerAPI, h host.Host) (*dagstore.DAGStore, *mdagstore.Wrapper, error) {
|
||||
return func(lc fx.Lifecycle, r repo.LockedRepo, minerAPI mdagstore.MinerAPI, h host.Host) (*dagstore.DAGStore, *mdagstore.Wrapper, error) {
|
||||
// fall back to default root directory if not explicitly set in the config.
|
||||
if cfg.RootDir == "" {
|
||||
cfg.RootDir = filepath.Join(r.Path(), DefaultDAGStoreDir)
|
||||
}
|
||||
|
||||
v, ok := os.LookupEnv(EnvDAGStoreCopyConcurrency)
|
||||
if ok {
|
||||
concurrency, err := strconv.Atoi(v)
|
||||
if err == nil {
|
||||
cfg.MaxConcurrentReadyFetches = concurrency
|
||||
}
|
||||
}
|
||||
|
||||
dagst, w, err := mdagstore.NewDAGStore(cfg, minerAPI, h)
|
||||
if err != nil {
|
||||
return nil, nil, xerrors.Errorf("failed to create DAG store: %w", err)
|
||||
}
|
||||
|
||||
lc.Append(fx.Hook{
|
||||
OnStart: func(ctx context.Context) error {
|
||||
return w.Start(ctx)
|
||||
},
|
||||
OnStop: func(context.Context) error {
|
||||
return w.Close()
|
||||
},
|
||||
})
|
||||
|
||||
return dagst, w, nil
|
||||
}
|
||||
|
||||
dagst, w, err := mdagstore.NewDAGStore(cfg, minerAPI, h)
|
||||
if err != nil {
|
||||
return nil, nil, xerrors.Errorf("failed to create DAG store: %w", err)
|
||||
}
|
||||
|
||||
lc.Append(fx.Hook{
|
||||
OnStart: func(ctx context.Context) error {
|
||||
return w.Start(ctx)
|
||||
},
|
||||
OnStop: func(context.Context) error {
|
||||
return w.Close()
|
||||
},
|
||||
})
|
||||
|
||||
return dagst, w, nil
|
||||
}
|
||||
|
||||
func extractDAGStoreConfig(r repo.LockedRepo) (config.DAGStoreConfig, error) {
|
||||
cfg, err := r.Config()
|
||||
if err != nil {
|
||||
return config.DAGStoreConfig{}, xerrors.Errorf("could not load config: %w", err)
|
||||
}
|
||||
mcfg, ok := cfg.(*config.StorageMiner)
|
||||
if !ok {
|
||||
return config.DAGStoreConfig{}, xerrors.Errorf("config not expected type; expected config.StorageMiner, got: %T", cfg)
|
||||
}
|
||||
return mcfg.DAGStore, nil
|
||||
}
|
||||
|
||||
+167
-40
@@ -41,47 +41,174 @@ const (
|
||||
fsKeystore = "keystore"
|
||||
)
|
||||
|
||||
type RepoType int
|
||||
|
||||
const (
|
||||
_ = iota // Default is invalid
|
||||
FullNode RepoType = iota
|
||||
StorageMiner
|
||||
Worker
|
||||
Wallet
|
||||
Markets
|
||||
)
|
||||
|
||||
func (t RepoType) String() string {
|
||||
s := [...]string{
|
||||
"__invalid__",
|
||||
"FullNode",
|
||||
"StorageMiner",
|
||||
"Worker",
|
||||
"Wallet",
|
||||
"Markets",
|
||||
func NewRepoTypeFromString(t string) RepoType {
|
||||
switch t {
|
||||
case "FullNode":
|
||||
return FullNode
|
||||
case "StorageMiner":
|
||||
return StorageMiner
|
||||
case "Worker":
|
||||
return Worker
|
||||
case "Wallet":
|
||||
return Wallet
|
||||
default:
|
||||
panic("unknown RepoType")
|
||||
}
|
||||
if t < 0 || int(t) > len(s) {
|
||||
return "__invalid__"
|
||||
}
|
||||
return s[t]
|
||||
}
|
||||
|
||||
func defConfForType(t RepoType) interface{} {
|
||||
switch t {
|
||||
case FullNode:
|
||||
return config.DefaultFullNode()
|
||||
case StorageMiner, Markets:
|
||||
// markets is a specialised miner service
|
||||
// this taxonomy needs to be cleaned up
|
||||
return config.DefaultStorageMiner()
|
||||
case Worker:
|
||||
return &struct{}{}
|
||||
case Wallet:
|
||||
return &struct{}{}
|
||||
default:
|
||||
panic(fmt.Sprintf("unknown RepoType(%d)", int(t)))
|
||||
}
|
||||
type RepoType interface {
|
||||
Type() string
|
||||
Config() interface{}
|
||||
|
||||
// APIFlags returns flags passed on the command line with the listen address
|
||||
// of the API server (only used by the tests), in the order of precedence they
|
||||
// should be applied for the requested kind of node.
|
||||
APIFlags() []string
|
||||
|
||||
RepoFlags() []string
|
||||
|
||||
// APIInfoEnvVars returns the environment variables to use in order of precedence
|
||||
// to determine the API endpoint of the specified node type.
|
||||
//
|
||||
// It returns the current variables and deprecated ones separately, so that
|
||||
// the user can log a warning when deprecated ones are found to be in use.
|
||||
APIInfoEnvVars() (string, []string, []string)
|
||||
}
|
||||
|
||||
// SupportsStagingDeals is a trait for services that support staging deals
|
||||
type SupportsStagingDeals interface {
|
||||
SupportsStagingDeals()
|
||||
}
|
||||
|
||||
var FullNode fullNode
|
||||
|
||||
type fullNode struct {
|
||||
}
|
||||
|
||||
func (fullNode) Type() string {
|
||||
return "FullNode"
|
||||
}
|
||||
|
||||
func (fullNode) Config() interface{} {
|
||||
return config.DefaultFullNode()
|
||||
}
|
||||
|
||||
func (fullNode) APIFlags() []string {
|
||||
return []string{"api-url"}
|
||||
}
|
||||
|
||||
func (fullNode) RepoFlags() []string {
|
||||
return []string{"repo"}
|
||||
}
|
||||
|
||||
func (fullNode) APIInfoEnvVars() (primary string, fallbacks []string, deprecated []string) {
|
||||
return "FULLNODE_API_INFO", nil, nil
|
||||
}
|
||||
|
||||
var StorageMiner storageMiner
|
||||
|
||||
type storageMiner struct{}
|
||||
|
||||
func (storageMiner) SupportsStagingDeals() {}
|
||||
|
||||
func (storageMiner) Type() string {
|
||||
return "StorageMiner"
|
||||
}
|
||||
|
||||
func (storageMiner) Config() interface{} {
|
||||
return config.DefaultStorageMiner()
|
||||
}
|
||||
|
||||
func (storageMiner) APIFlags() []string {
|
||||
return []string{"miner-api-url"}
|
||||
}
|
||||
|
||||
func (storageMiner) RepoFlags() []string {
|
||||
return []string{"miner-repo"}
|
||||
}
|
||||
|
||||
func (storageMiner) APIInfoEnvVars() (primary string, fallbacks []string, deprecated []string) {
|
||||
// TODO remove deprecated deprecation period
|
||||
return "MINER_API_INFO", nil, []string{"STORAGE_API_INFO"}
|
||||
}
|
||||
|
||||
var Markets markets
|
||||
|
||||
type markets struct{}
|
||||
|
||||
func (markets) SupportsStagingDeals() {}
|
||||
|
||||
func (markets) Type() string {
|
||||
return "Markets"
|
||||
}
|
||||
|
||||
func (markets) Config() interface{} {
|
||||
return config.DefaultStorageMiner()
|
||||
}
|
||||
|
||||
func (markets) APIFlags() []string {
|
||||
// support split markets-miner and monolith deployments.
|
||||
return []string{"markets-api-url", "miner-api-url"}
|
||||
}
|
||||
|
||||
func (markets) RepoFlags() []string {
|
||||
// support split markets-miner and monolith deployments.
|
||||
return []string{"markets-repo", "miner-repo"}
|
||||
}
|
||||
|
||||
func (markets) APIInfoEnvVars() (primary string, fallbacks []string, deprecated []string) {
|
||||
// support split markets-miner and monolith deployments.
|
||||
return "MARKETS_API_INFO", []string{"MINER_API_INFO"}, nil
|
||||
}
|
||||
|
||||
type worker struct {
|
||||
}
|
||||
|
||||
var Worker worker
|
||||
|
||||
func (worker) Type() string {
|
||||
return "Worker"
|
||||
}
|
||||
|
||||
func (worker) Config() interface{} {
|
||||
return &struct{}{}
|
||||
}
|
||||
|
||||
func (worker) APIFlags() []string {
|
||||
return []string{"worker-api-url"}
|
||||
}
|
||||
|
||||
func (worker) RepoFlags() []string {
|
||||
return []string{"worker-repo"}
|
||||
}
|
||||
|
||||
func (worker) APIInfoEnvVars() (primary string, fallbacks []string, deprecated []string) {
|
||||
return "WORKER_API_INFO", nil, nil
|
||||
}
|
||||
|
||||
var Wallet wallet
|
||||
|
||||
type wallet struct {
|
||||
}
|
||||
|
||||
func (wallet) Type() string {
|
||||
return "Wallet"
|
||||
}
|
||||
|
||||
func (wallet) Config() interface{} {
|
||||
return &struct{}{}
|
||||
}
|
||||
|
||||
func (wallet) APIFlags() []string {
|
||||
panic("not supported")
|
||||
}
|
||||
|
||||
func (wallet) RepoFlags() []string {
|
||||
panic("not supported")
|
||||
}
|
||||
|
||||
func (wallet) APIInfoEnvVars() (primary string, fallbacks []string, deprecated []string) {
|
||||
panic("not supported")
|
||||
}
|
||||
|
||||
var log = logging.Logger("repo")
|
||||
@@ -165,7 +292,7 @@ func (fsr *FsRepo) initConfig(t RepoType) error {
|
||||
return err
|
||||
}
|
||||
|
||||
comm, err := config.ConfigComment(defConfForType(t))
|
||||
comm, err := config.ConfigComment(t.Config())
|
||||
if err != nil {
|
||||
return xerrors.Errorf("comment: %w", err)
|
||||
}
|
||||
@@ -406,7 +533,7 @@ func (fsr *fsLockedRepo) Config() (interface{}, error) {
|
||||
}
|
||||
|
||||
func (fsr *fsLockedRepo) loadConfigFromDisk() (interface{}, error) {
|
||||
return config.FromFile(fsr.configPath, defConfForType(fsr.repoType))
|
||||
return config.FromFile(fsr.configPath, fsr.repoType.Config())
|
||||
}
|
||||
|
||||
func (fsr *fsLockedRepo) SetConfig(c func(interface{})) error {
|
||||
|
||||
+3
-11
@@ -40,9 +40,6 @@ type MemRepo struct {
|
||||
sc *stores.StorageConfig
|
||||
tempDir string
|
||||
|
||||
// given a repo type, produce the default config
|
||||
configF func(t RepoType) interface{}
|
||||
|
||||
// holds the current config value
|
||||
config struct {
|
||||
sync.Mutex
|
||||
@@ -108,7 +105,7 @@ func (lmem *lockedMemRepo) Path() string {
|
||||
panic(err) // only used in tests, probably fine
|
||||
}
|
||||
|
||||
if lmem.t == StorageMiner {
|
||||
if _, ok := lmem.t.(SupportsStagingDeals); ok {
|
||||
// this is required due to the method makeDealStaging from cmd/lotus-storage-miner/init.go
|
||||
// deal-staging is the directory deal files are staged in before being sealed into sectors
|
||||
// for offline deal flow.
|
||||
@@ -152,7 +149,6 @@ var _ Repo = &MemRepo{}
|
||||
// MemRepoOptions contains options for memory repo
|
||||
type MemRepoOptions struct {
|
||||
Ds datastore.Datastore
|
||||
ConfigF func(RepoType) interface{}
|
||||
KeyStore map[string]types.KeyInfo
|
||||
}
|
||||
|
||||
@@ -163,9 +159,6 @@ func NewMemory(opts *MemRepoOptions) *MemRepo {
|
||||
if opts == nil {
|
||||
opts = &MemRepoOptions{}
|
||||
}
|
||||
if opts.ConfigF == nil {
|
||||
opts.ConfigF = defConfForType
|
||||
}
|
||||
if opts.Ds == nil {
|
||||
opts.Ds = dssync.MutexWrap(datastore.NewMapDatastore())
|
||||
}
|
||||
@@ -177,7 +170,6 @@ func NewMemory(opts *MemRepoOptions) *MemRepo {
|
||||
repoLock: make(chan struct{}, 1),
|
||||
blockstore: blockstore.WrapIDStore(blockstore.NewMemorySync()),
|
||||
datastore: opts.Ds,
|
||||
configF: opts.ConfigF,
|
||||
keystore: opts.KeyStore,
|
||||
}
|
||||
}
|
||||
@@ -296,7 +288,7 @@ func (lmem *lockedMemRepo) Config() (interface{}, error) {
|
||||
defer lmem.mem.config.Unlock()
|
||||
|
||||
if lmem.mem.config.val == nil {
|
||||
lmem.mem.config.val = lmem.mem.configF(lmem.t)
|
||||
lmem.mem.config.val = lmem.t.Config()
|
||||
}
|
||||
|
||||
return lmem.mem.config.val, nil
|
||||
@@ -311,7 +303,7 @@ func (lmem *lockedMemRepo) SetConfig(c func(interface{})) error {
|
||||
defer lmem.mem.config.Unlock()
|
||||
|
||||
if lmem.mem.config.val == nil {
|
||||
lmem.mem.config.val = lmem.mem.configF(lmem.t)
|
||||
lmem.mem.config.val = lmem.t.Config()
|
||||
}
|
||||
|
||||
c(lmem.mem.config.val)
|
||||
|
||||
Reference in New Issue
Block a user