Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make legacy deals optional #1524

Merged
merged 12 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,11 @@ workflows:
suite: itest-markets_v1_offline_deal
target: "./itests/markets_v1_offline_deal_test.go"

- test:
name: test-itest-disabled_markets_v1_deal
suite: itest-disabled_markets_v1_deal
target: "./itests/disabled_markets_v1_deal_test.go"

- test:
name: test-all
suite: all
Expand Down
53 changes: 53 additions & 0 deletions itests/disabled_markets_v1_deal_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package itests

import (
"context"
"testing"

"github.com/filecoin-project/boost/itests/framework"
"github.com/filecoin-project/boost/testutil"
lapi "github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/itests/kit"
"github.com/stretchr/testify/require"
)

func TestDisabledMarketsV1Deal(t *testing.T) {
ctx := context.Background()
log := framework.Log

kit.QuietMiningLogs()
framework.SetLogLevel()
var opts []framework.FrameworkOpts
opts = append(opts, framework.EnableLegacyDeals(false))
f := framework.NewTestFramework(ctx, t, opts...)
err := f.Start()
require.NoError(t, err)
defer f.Stop()

// Create a CAR file
log.Debugw("using tempdir", "dir", f.HomeDir)
rseed := 0
size := 7 << 20 // 7MiB file

inPath, err := testutil.CreateRandomFile(f.HomeDir, rseed, size)
require.NoError(t, err)
res, err := f.FullNode.ClientImport(ctx, lapi.FileRef{Path: inPath})
require.NoError(t, err)

// Create a new markets v1 deal
dp := f.DefaultMarketsV1DealParams()
dp.Data.Root = res.Root

log.Debugw("starting deal", "root", res.Root)
dealProposalCid, err := f.FullNode.ClientStartDeal(ctx, &dp)
require.NoError(t, err)

log.Debugw("got deal proposal cid", "cid", dealProposalCid)
di, err := f.FullNode.ClientGetDealInfo(ctx, *dealProposalCid)
require.NoError(t, err)

log.Debugw(di.Message)

err = f.WaitDealSealed(ctx, dealProposalCid)
require.ErrorContains(t, err, "protocol are deprecated")
}
4 changes: 3 additions & 1 deletion itests/dummydeal_offline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ func TestDummydealOffline(t *testing.T) {

kit.QuietMiningLogs()
framework.SetLogLevel()
f := framework.NewTestFramework(ctx, t)
var opts []framework.FrameworkOpts
opts = append(opts, framework.EnableLegacyDeals(true))
f := framework.NewTestFramework(ctx, t, opts...)
err := f.Start()
require.NoError(t, err)
defer f.Stop()
Expand Down
4 changes: 3 additions & 1 deletion itests/dummydeal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ func TestDummydealOnline(t *testing.T) {

kit.QuietMiningLogs()
framework.SetLogLevel()
f := framework.NewTestFramework(ctx, t)
var opts []framework.FrameworkOpts
opts = append(opts, framework.EnableLegacyDeals(true))
f := framework.NewTestFramework(ctx, t, opts...)
err := f.Start()
require.NoError(t, err)
defer f.Stop()
Expand Down
27 changes: 24 additions & 3 deletions itests/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,14 @@ import (

var Log = logging.Logger("boosttest")

type TestFrameworkConfig struct {
EnableLegacy bool
}

type TestFramework struct {
ctx context.Context
Stop func()
ctx context.Context
Stop func()
config *TestFrameworkConfig

HomeDir string
Client *boostclient.StorageClient
Expand All @@ -84,11 +89,24 @@ type TestFramework struct {
DefaultWallet address.Address
}

func NewTestFramework(ctx context.Context, t *testing.T) *TestFramework {
type FrameworkOpts func(pc *TestFrameworkConfig)

func EnableLegacyDeals(enable bool) FrameworkOpts {
return func(tmc *TestFrameworkConfig) {
tmc.EnableLegacy = enable
}
}

func NewTestFramework(ctx context.Context, t *testing.T, opts ...FrameworkOpts) *TestFramework {
fullNode, miner := FullNodeAndMiner(t)
fmc := &TestFrameworkConfig{}
for _, opt := range opts {
opt(fmc)
}

return &TestFramework{
ctx: ctx,
config: fmc,
HomeDir: t.TempDir(),
FullNode: fullNode,
LotusMiner: miner,
Expand Down Expand Up @@ -294,6 +312,9 @@ func (f *TestFramework) Start() error {
// No transfers will start until the first stall check period has elapsed
cfg.Dealmaking.HttpTransferStallCheckPeriod = config.Duration(100 * time.Millisecond)
cfg.Storage.ParallelFetchLimit = 10
if f.config.EnableLegacy {
cfg.Dealmaking.EnableLegacyStorageDeals = true
}

err = lr.SetConfig(func(raw interface{}) {
rcfg := raw.(*config.Boost)
Expand Down
1 change: 1 addition & 0 deletions itests/framework/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ func SetLogLevel() {
_ = logging.SetLogLevel("storagemanager", "DEBUG")
_ = logging.SetLogLevel("storageadapter", "DEBUG")
_ = logging.SetLogLevel("messagepool", "WARN")
_ = logging.SetLogLevel("consensus-common", "WARN")
}
4 changes: 3 additions & 1 deletion itests/markets_v1_deal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ func TestMarketsV1Deal(t *testing.T) {

kit.QuietMiningLogs()
framework.SetLogLevel()
f := framework.NewTestFramework(ctx, t)
var opts []framework.FrameworkOpts
opts = append(opts, framework.EnableLegacyDeals(true))
f := framework.NewTestFramework(ctx, t, opts...)
err := f.Start()
require.NoError(t, err)
defer f.Stop()
Expand Down
4 changes: 3 additions & 1 deletion itests/markets_v1_offline_deal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ func TestMarketsV1OfflineDeal(t *testing.T) {

kit.QuietMiningLogs()
framework.SetLogLevel()
f := framework.NewTestFramework(ctx, t)
var opts []framework.FrameworkOpts
opts = append(opts, framework.EnableLegacyDeals(true))
f := framework.NewTestFramework(ctx, t, opts...)
err := f.Start()
require.NoError(t, err)
defer f.Stop()
Expand Down
2 changes: 1 addition & 1 deletion node/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ func ConfigBoost(cfg *config.Boost) Option {
Override(new(gfm_storagemarket.StorageProviderNode), storageadapter.NewProviderNodeAdapter(&legacyFees, &cfg.LotusDealmaking)),
Override(new(gfm_storagemarket.StorageProvider), modules.NewLegacyStorageProvider(cfg)),
Override(HandleDealsKey, modules.HandleLegacyDeals),
Override(HandleBoostDealsKey, modules.HandleBoostLibp2pDeals),
Override(HandleBoostDealsKey, modules.HandleBoostLibp2pDeals(cfg)),
Override(HandleContractDealsKey, modules.HandleContractDeals(&cfg.ContractDeals)),
Override(HandleProposalLogCleanerKey, modules.HandleProposalLogCleaner(time.Duration(cfg.Dealmaking.DealProposalLogDuration))),
Override(HandleSetLinkSystem, modules.SetLinkSystem),
Expand Down
1 change: 1 addition & 0 deletions node/config/def.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ func DefaultBoost() *Boost {
DealLogDurationDays: 30,
SealingPipelineCacheTimeout: Duration(30 * time.Second),
FundsTaggingEnabled: true,
EnableLegacyStorageDeals: false,
},

LotusDealmaking: lotus_config.DealmakingConfig{
Expand Down
7 changes: 7 additions & 0 deletions node/config/doc_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions node/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ type DealmakingConfig struct {
// accepted boost will tag funds for that deal so that they cannot be used
// for any other deal.
FundsTaggingEnabled bool

// Whether to enable legacy deals on the Boost node or not. We recommend keeping
// them disabled. These will be completely deprecated soon.
EnableLegacyStorageDeals bool
}

type ContractDealsConfig struct {
Expand Down
14 changes: 12 additions & 2 deletions node/modules/legacy_markets.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
smnet "github.com/filecoin-project/boost-gfm/storagemarket/network"
"github.com/filecoin-project/boost-gfm/stores"
"github.com/filecoin-project/boost/markets/idxprov"
"github.com/filecoin-project/boost/node/config"
"github.com/filecoin-project/boost/node/modules/dtypes"
"github.com/filecoin-project/go-address"
datatransferv2 "github.com/filecoin-project/go-data-transfer/v2"
Expand All @@ -25,6 +26,7 @@ import (
"github.com/ipfs/go-datastore/namespace"
provider "github.com/ipni/index-provider"
"github.com/libp2p/go-libp2p/core/host"
"github.com/libp2p/go-libp2p/core/protocol"
)

func StorageProvider(minerAddress lotus_dtypes.MinerAddress,
Expand All @@ -37,9 +39,17 @@ func StorageProvider(minerAddress lotus_dtypes.MinerAddress,
spn storagemarket.StorageProviderNode,
df storageimpl.DealDeciderFunc,
dsw stores.DAGStoreWrapper,
meshCreator idxprov.MeshCreator,
meshCreator idxprov.MeshCreator, cfg config.DealmakingConfig,
) (storagemarket.StorageProvider, error) {
net := smnet.NewFromLibp2pHost(h)
var opts []smnet.Option

// Provide an empty deal protocol list to the libp2p host if legacy deals are disabled
// These protocols are handled by Boost provider and all legacy deals are rejected
if !cfg.EnableLegacyStorageDeals {
opts = append(opts, smnet.SupportedDealProtocols([]protocol.ID{}))
}

net := smnet.NewFromLibp2pHost(h, opts...)

dir := filepath.Join(r.Path(), lotus_modules.StagingAreaDirName)
err := os.MkdirAll(dir, os.ModePerm)
Expand Down
89 changes: 46 additions & 43 deletions node/modules/storageminer.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,50 +390,53 @@ func HandleLegacyDeals(mctx helpers.MetricsCtx, lc fx.Lifecycle, lsp gfm_storage
return nil
}

func HandleBoostLibp2pDeals(lc fx.Lifecycle, h host.Host, prov *storagemarket.Provider, a v1api.FullNode, legacySP gfm_storagemarket.StorageProvider, idxProv *indexprovider.Wrapper, plDB *db.ProposalLogsDB, spApi sealingpipeline.API) {
lp2pnet := lp2pimpl.NewDealProvider(h, prov, a, plDB, spApi)
func HandleBoostLibp2pDeals(cfg *config.Boost) func(lc fx.Lifecycle, h host.Host, prov *storagemarket.Provider, a v1api.FullNode, legacySP gfm_storagemarket.StorageProvider, idxProv *indexprovider.Wrapper, plDB *db.ProposalLogsDB, spApi sealingpipeline.API) {
return func(lc fx.Lifecycle, h host.Host, prov *storagemarket.Provider, a v1api.FullNode, legacySP gfm_storagemarket.StorageProvider, idxProv *indexprovider.Wrapper, plDB *db.ProposalLogsDB, spApi sealingpipeline.API) {

lc.Append(fx.Hook{
OnStart: func(ctx context.Context) error {
// Wait for the legacy SP to fire the "ready" event before starting
// the boost SP.
// Boost overrides some listeners so it must start after the legacy SP.
errch := make(chan error, 1)
log.Info("waiting for legacy storage provider 'ready' event")
legacySP.OnReady(func(err error) {
errch <- err
})
err := <-errch
if err != nil {
log.Errorf("failed to start legacy storage provider: %w", err)
return err
}
log.Info("legacy storage provider started successfully")
lp2pnet := lp2pimpl.NewDealProvider(h, prov, a, plDB, spApi, cfg.Dealmaking.EnableLegacyStorageDeals)

// Start the Boost SP
log.Info("starting boost storage provider")
err = prov.Start()
if err != nil {
return fmt.Errorf("starting storage provider: %w", err)
}
lp2pnet.Start(ctx)
log.Info("boost storage provider started successfully")

// Start the Boost Index Provider.
// It overrides the multihash lister registered by the legacy
// index provider so it must start after the legacy SP.
log.Info("starting boost index provider wrapper")
idxProv.Start(ctx)
log.Info("boost index provider wrapper started successfully")
return nil
},
OnStop: func(ctx context.Context) error {
lp2pnet.Stop()
prov.Stop()
idxProv.Stop()
return nil
},
})
lc.Append(fx.Hook{
OnStart: func(ctx context.Context) error {
// Wait for the legacy SP to fire the "ready" event before starting
// the boost SP.
// Boost overrides some listeners so it must start after the legacy SP.
errch := make(chan error, 1)
log.Info("waiting for legacy storage provider 'ready' event")
legacySP.OnReady(func(err error) {
errch <- err
})
err := <-errch
if err != nil {
log.Errorf("failed to start legacy storage provider: %w", err)
return err
}
log.Info("legacy storage provider started successfully")

// Start the Boost SP
log.Info("starting boost storage provider")
err = prov.Start()
if err != nil {
return fmt.Errorf("starting storage provider: %w", err)
}
lp2pnet.Start(ctx)
log.Info("boost storage provider started successfully")

// Start the Boost Index Provider.
// It overrides the multihash lister registered by the legacy
// index provider so it must start after the legacy SP.
log.Info("starting boost index provider wrapper")
idxProv.Start(ctx)
log.Info("boost index provider wrapper started successfully")
return nil
},
OnStop: func(ctx context.Context) error {
lp2pnet.Stop()
prov.Stop()
idxProv.Stop()
return nil
},
})
}
}

func HandleContractDeals(c *config.ContractDealsConfig) func(mctx helpers.MetricsCtx, lc fx.Lifecycle, prov *storagemarket.Provider, a v1api.FullNode, subCh *gateway.EthSubHandler, maddr lotus_dtypes.MinerAddress) {
Expand Down Expand Up @@ -574,7 +577,7 @@ func NewLegacyStorageProvider(cfg *config.Boost) func(minerAddress lotus_dtypes.
dsw stores.DAGStoreWrapper,
meshCreator idxprov.MeshCreator,
) (gfm_storagemarket.StorageProvider, error) {
prov, err := StorageProvider(minerAddress, storedAsk, h, ds, r, pieceStore, indexer, dataTransfer, spn, df, dsw, meshCreator)
prov, err := StorageProvider(minerAddress, storedAsk, h, ds, r, pieceStore, indexer, dataTransfer, spn, df, dsw, meshCreator, cfg.Dealmaking)
if err != nil {
return prov, err
}
Expand Down
Loading