Skip to content

Commit 3690801

Browse files
committed
initial draft of market 2.0
1 parent 5f0429f commit 3690801

File tree

27 files changed

+3284
-135
lines changed

27 files changed

+3284
-135
lines changed

cmd/curio/tasks/tasks.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,16 +244,19 @@ func StartTasks(ctx context.Context, dependencies *deps.Deps, shutdownChan chan
244244
}
245245

246246
{
247+
var sdeps cuhttp.ServiceDeps
247248
// Market tasks
248249
var dm *storage_market.CurioStorageDealMarket
249250
if cfg.Subsystems.EnableDealMarket {
250251
// Main market poller should run on all nodes
251-
dm = storage_market.NewCurioStorageDealMarket(miners, db, cfg, si, full, as)
252+
dm = storage_market.NewCurioStorageDealMarket(miners, db, cfg, must.One(dependencies.EthClient.Val()), si, full, as)
252253
err := dm.StartMarket(ctx)
253254
if err != nil {
254255
return nil, err
255256
}
256257

258+
sdeps.DealMarket = dm
259+
257260
if cfg.Subsystems.EnableCommP {
258261
commpTask := storage_market.NewCommpTask(dm, db, must.One(slrLazy.Val()), full, cfg.Subsystems.CommPMaxTasks)
259262
activeTasks = append(activeTasks, commpTask)
@@ -275,7 +278,6 @@ func StartTasks(ctx context.Context, dependencies *deps.Deps, shutdownChan chan
275278
if err != nil {
276279
return nil, err
277280
}
278-
var sdeps cuhttp.ServiceDeps
279281

280282
if cfg.Subsystems.EnablePDP {
281283
es := getSenderEth()
@@ -298,7 +300,7 @@ func StartTasks(ctx context.Context, dependencies *deps.Deps, shutdownChan chan
298300
activeTasks = append(activeTasks, ipniTask, indexingTask)
299301

300302
if cfg.HTTP.Enable {
301-
err = cuhttp.StartHTTPServer(ctx, dependencies, &sdeps, dm)
303+
err = cuhttp.StartHTTPServer(ctx, dependencies, &sdeps)
302304
if err != nil {
303305
return nil, xerrors.Errorf("failed to start the HTTP server: %w", err)
304306
}

cuhttp/server.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,11 @@ func isWebSocketUpgrade(r *http.Request) bool {
120120
}
121121

122122
type ServiceDeps struct {
123-
EthSender *message.SenderETH
123+
EthSender *message.SenderETH
124+
DealMarket *storage_market.CurioStorageDealMarket
124125
}
125126

126-
func StartHTTPServer(ctx context.Context, d *deps.Deps, sd *ServiceDeps, dm *storage_market.CurioStorageDealMarket) error {
127+
func StartHTTPServer(ctx context.Context, d *deps.Deps, sd *ServiceDeps) error {
127128
cfg := d.Cfg.HTTP
128129

129130
// Setup the Chi router for more complex routing (if needed in the future)
@@ -165,7 +166,9 @@ func StartHTTPServer(ctx context.Context, d *deps.Deps, sd *ServiceDeps, dm *sto
165166
fmt.Fprintf(w, "Service is up and running")
166167
})
167168

168-
chiRouter, err = attachRouters(ctx, chiRouter, d, sd, dm)
169+
// TODO: Attach a info page here with details about all the service and endpoints
170+
171+
chiRouter, err = attachRouters(ctx, chiRouter, d, sd)
169172
if err != nil {
170173
return xerrors.Errorf("failed to attach routers: %w", err)
171174
}
@@ -259,7 +262,7 @@ func (c cache) Delete(ctx context.Context, key string) error {
259262

260263
var _ autocert.Cache = cache{}
261264

262-
func attachRouters(ctx context.Context, r *chi.Mux, d *deps.Deps, sd *ServiceDeps, dm *storage_market.CurioStorageDealMarket) (*chi.Mux, error) {
265+
func attachRouters(ctx context.Context, r *chi.Mux, d *deps.Deps, sd *ServiceDeps) (*chi.Mux, error) {
263266
// Attach retrievals
264267
rp := retrieval.NewRetrievalProvider(ctx, d.DB, d.IndexStore, d.CachedPieceReader)
265268
retrieval.Router(r, rp)
@@ -283,7 +286,7 @@ func attachRouters(ctx context.Context, r *chi.Mux, d *deps.Deps, sd *ServiceDep
283286
}
284287

285288
// Attach the market handler
286-
dh, err := mhttp.NewMarketHandler(d.DB, d.Cfg, dm)
289+
dh, err := mhttp.NewMarketHandler(d.DB, d.Cfg, sd.DealMarket)
287290
if err != nil {
288291
return nil, xerrors.Errorf("failed to create new market handler: %w", err)
289292
}

deps/config/doc_gen.go

Lines changed: 53 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deps/config/types.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ func DefaultCurioConfig() *CurioConfig {
110110
ExpectedSnapSealDuration: 2 * time.Hour,
111111
CIDGravityTokens: []string{},
112112
},
113+
MK20: MK20Config{
114+
ExpectedPoRepSealDuration: 8 * time.Hour,
115+
ExpectedSnapSealDuration: 2 * time.Hour,
116+
},
113117
IPNI: IPNIConfig{
114118
ServiceURL: []string{"https://cid.contact"},
115119
DirectAnnounceURLs: []string{"https://cid.contact/ingest/announce"},
@@ -692,6 +696,9 @@ type StorageMarketConfig struct {
692696
// MK12 encompasses all configuration related to deal protocol mk1.2.0 and mk1.2.1 (i.e. Boost deals)
693697
MK12 MK12Config
694698

699+
// MK20 encompasses all configuration related to deal protocol mk2.0 i.e. market 2.0
700+
MK20 MK20Config
701+
695702
// IPNI configuration for ipni-provider
696703
IPNI IPNIConfig
697704

@@ -851,3 +858,32 @@ type MK12CollateralConfig struct {
851858
// Accepts a decimal string (e.g., "123.45" or "123 fil") with optional "fil" or "attofil" suffix. (Default: "20 FIL")
852859
CollateralHighThreshold types.FIL
853860
}
861+
862+
type MK20Config struct {
863+
// ExpectedPoRepSealDuration is the expected time it would take to seal the deal sector
864+
// This will be used to fail the deals which cannot be sealed on time.
865+
// Time duration string (e.g., "1h2m3s") in TOML format. (Default: "8h0m0s")
866+
ExpectedPoRepSealDuration time.Duration
867+
868+
// ExpectedSnapSealDuration is the expected time it would take to snap the deal sector
869+
// This will be used to fail the deals which cannot be sealed on time.
870+
// Time duration string (e.g., "1h2m3s") in TOML format. (Default: "2h0m0s")
871+
ExpectedSnapSealDuration time.Duration
872+
873+
// SkipCommP can be used to skip doing a commP check before PublishDealMessage is sent on chain
874+
// Warning: If this check is skipped and there is a commP mismatch, all deals in the
875+
// sector will need to be sent again (Default: false)
876+
SkipCommP bool
877+
878+
// DisabledMiners is a list of miner addresses that should be excluded from online deal making protocols
879+
DisabledMiners []string
880+
881+
// MaxConcurrentDealSizeGiB is a sum of all size of all deals which are waiting to be added to a sector
882+
// When the cumulative size of all deals in process reaches this number, new deals will be rejected.
883+
// (Default: 0 = unlimited)
884+
MaxConcurrentDealSizeGiB int64
885+
886+
// DenyUnknownClients determines the default behaviour for the deal of clients which are not in allow/deny list
887+
// If True then all deals coming from unknown clients will be rejected. (Default: false)
888+
DenyUnknownClients bool
889+
}

documentation/en/configuration/default-curio-configuration.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,45 @@ description: The default curio configuration
637637
# type: bool
638638
#DefaultCIDGravityAccept = false
639639

640+
# MK20 encompasses all configuration related to deal protocol mk2.0 i.e. market 2.0
641+
#
642+
# type: MK20Config
643+
[Market.StorageMarketConfig.MK20]
644+
645+
# ExpectedPoRepSealDuration is the expected time it would take to seal the deal sector
646+
# This will be used to fail the deals which cannot be sealed on time.
647+
# Time duration string (e.g., "1h2m3s") in TOML format. (Default: "8h0m0s")
648+
#
649+
# type: time.Duration
650+
#ExpectedPoRepSealDuration = "8h0m0s"
651+
652+
# ExpectedSnapSealDuration is the expected time it would take to snap the deal sector
653+
# This will be used to fail the deals which cannot be sealed on time.
654+
# Time duration string (e.g., "1h2m3s") in TOML format. (Default: "2h0m0s")
655+
#
656+
# type: time.Duration
657+
#ExpectedSnapSealDuration = "2h0m0s"
658+
659+
# SkipCommP can be used to skip doing a commP check before PublishDealMessage is sent on chain
660+
# Warning: If this check is skipped and there is a commP mismatch, all deals in the
661+
# sector will need to be sent again (Default: false)
662+
#
663+
# type: bool
664+
#SkipCommP = false
665+
666+
# MaxConcurrentDealSizeGiB is a sum of all size of all deals which are waiting to be added to a sector
667+
# When the cumulative size of all deals in process reaches this number, new deals will be rejected.
668+
# (Default: 0 = unlimited)
669+
#
670+
# type: int64
671+
#MaxConcurrentDealSizeGiB = 0
672+
673+
# DenyUnknownClients determines the default behaviour for the deal of clients which are not in allow/deny list
674+
# If True then all deals coming from unknown clients will be rejected. (Default: false)
675+
#
676+
# type: bool
677+
#DenyUnknownClients = false
678+
640679
# IPNI configuration for ipni-provider
641680
#
642681
# type: IPNIConfig

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ require (
2525
github.com/filecoin-project/go-commp-utils v0.1.4
2626
github.com/filecoin-project/go-commp-utils/nonffi v0.0.0-20240802040721-2a04ffc8ffe8
2727
github.com/filecoin-project/go-commp-utils/v2 v2.1.0
28+
github.com/filecoin-project/go-data-segment v0.0.1
2829
github.com/filecoin-project/go-f3 v0.8.3
2930
github.com/filecoin-project/go-fil-commcid v0.2.0
3031
github.com/filecoin-project/go-fil-commp-hashhash v0.2.0
@@ -84,6 +85,7 @@ require (
8485
github.com/multiformats/go-multicodec v0.9.0
8586
github.com/multiformats/go-multihash v0.2.3
8687
github.com/multiformats/go-varint v0.0.7
88+
github.com/oklog/ulid v1.3.1
8789
github.com/open-rpc/meta-schema v0.0.0-20201029221707-1b72ef2ea333
8890
github.com/pkg/errors v0.9.1
8991
github.com/prometheus/client_golang v1.20.5

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,8 @@ github.com/filecoin-project/go-commp-utils/v2 v2.1.0/go.mod h1:NbxJYlhxtWaNhlVCj
329329
github.com/filecoin-project/go-crypto v0.0.0-20191218222705-effae4ea9f03/go.mod h1:+viYnvGtUTgJRdy6oaeF4MTFKAfatX071MPDPBL11EQ=
330330
github.com/filecoin-project/go-crypto v0.1.0 h1:Pob2MphoipMbe/ksxZOMcQvmBHAd3sI/WEqcbpIsGI0=
331331
github.com/filecoin-project/go-crypto v0.1.0/go.mod h1:K9UFXvvoyAVvB+0Le7oGlKiT9mgA5FHOJdYQXEE8IhI=
332+
github.com/filecoin-project/go-data-segment v0.0.1 h1:1wmDxOG4ubWQm3ZC1XI5nCon5qgSq7Ra3Rb6Dbu10Gs=
333+
github.com/filecoin-project/go-data-segment v0.0.1/go.mod h1:H0/NKbsRxmRFBcLibmABv+yFNHdmtl5AyplYLnb0Zv4=
332334
github.com/filecoin-project/go-data-transfer/v2 v2.0.0-rc7 h1:v+zJS5B6pA3ptWZS4t8tbt1Hz9qENnN4nVr1w99aSWc=
333335
github.com/filecoin-project/go-data-transfer/v2 v2.0.0-rc7/go.mod h1:V3Y4KbttaCwyg1gwkP7iai8CbQx4mZUGjd3h9GZWLKE=
334336
github.com/filecoin-project/go-ds-versioning v0.1.2 h1:to4pTadv3IeV1wvgbCbN6Vqd+fu+7tveXgv/rCEZy6w=
@@ -1119,6 +1121,8 @@ github.com/nkovacs/streamquote v1.0.0/go.mod h1:BN+NaZ2CmdKqUuTUXUEm9j95B2TRbpOW
11191121
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
11201122
github.com/nxadm/tail v1.4.11 h1:8feyoE3OzPrcshW5/MJ4sGESc5cqmGkGCWlco4l0bqY=
11211123
github.com/nxadm/tail v1.4.11/go.mod h1:OTaG3NK980DZzxbRq6lEuzgU+mug70nY11sMd4JXXHc=
1124+
github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4=
1125+
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
11221126
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
11231127
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
11241128
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
CREATE TABLE ddo_contracts (
2+
address TEXT NOT NULL PRIMARY KEY,
3+
abi TEXT NOT NULL
4+
);
5+
6+
CREATE TABLE market_mk20_deal (
7+
created_at TIMESTAMPTZ NOT NULL DEFAULT TIMEZONE('UTC', NOW()),
8+
id TEXT PRIMARY KEY,
9+
piece_cid TEXT NOT NULL,
10+
size BIGINT NOT NULL,
11+
12+
format JSONB NOT NULL,
13+
source_http JSONB NOT NULL DEFAULT 'null',
14+
source_aggregate JSONB NOT NULL DEFAULT 'null',
15+
source_offline JSONB NOT NULL DEFAULT 'null',
16+
17+
ddov1 JSONB NOT NULL DEFAULT 'null',
18+
market_deal_id TEXT DEFAULT NULL
19+
);
20+
21+
CREATE TABLE market_mk20_pipeline (
22+
created_at TIMESTAMPTZ NOT NULL DEFAULT TIMEZONE('UTC', NOW()),
23+
id TEXT NOT NULL,
24+
sp_id BIGINT NOT NULL,
25+
contract TEXT NOT NULL,
26+
client TEXT NOT NULL,
27+
piece_cid TEXT NOT NULL,
28+
piece_size BIGINT NOT NULL,
29+
raw_size BIGINT NOT NULL,
30+
offline BOOLEAN NOT NULL,
31+
url TEXT DEFAULT NULL,
32+
indexing BOOLEAN NOT NULL,
33+
announce BOOLEAN NOT NULL,
34+
allocation_id BIGINT DEFAULT NULL,
35+
duration BIGINT NOT NULL,
36+
piece_aggregation INT DEFAULT 0,
37+
38+
started BOOLEAN DEFAULT FALSE,
39+
40+
downloaded BOOLEAN DEFAULT FALSE,
41+
42+
commp_task_id BIGINT DEFAULT NULL,
43+
after_commp BOOLEAN DEFAULT FALSE,
44+
45+
deal_aggregation INT DEFAULT 0,
46+
aggr_index BIGINT DEFAULT 0,
47+
agg_task_id BIGINT DEFAULT NULL,
48+
aggregated BOOLEAN DEFAULT FALSE,
49+
50+
sector BIGINT DEFAULT NULL,
51+
reg_seal_proof INT DEFAULT NULL,
52+
sector_offset BIGINT DEFAULT NULL, -- padded offset
53+
54+
sealed BOOLEAN DEFAULT FALSE,
55+
56+
indexing_created_at TIMESTAMPTZ DEFAULT NULL,
57+
indexing_task_id BIGINT DEFAULT NULL,
58+
indexed BOOLEAN DEFAULT FALSE,
59+
60+
complete BOOLEAN NOT NULL DEFAULT FALSE,
61+
62+
PRIMARY KEY (id, aggr_index)
63+
);
64+
65+
CREATE TABLE market_mk20_pipeline_waiting (
66+
id TEXT NOT NULL PRIMARY KEY
67+
);
68+
69+
CREATE TABLE market_mk20_download_pipeline (
70+
id TEXT NOT NULL,
71+
piece_cid TEXT NOT NULL,
72+
piece_size BIGINT NOT NULL,
73+
ref_ids BIGINT[] NOT NULL,
74+
PRIMARY KEY (id, piece_cid, piece_size)
75+
);
76+
77+
CREATE TABLE market_mk20_offline_urls (
78+
id TEXT NOT NULL,
79+
piece_cid TEXT NOT NULL,
80+
piece_size BIGINT NOT NULL,
81+
url TEXT NOT NULL,
82+
headers jsonb NOT NULL DEFAULT '{}',
83+
raw_size BIGINT NOT NULL,
84+
CONSTRAINT market_mk20_offline_urls_id_fk FOREIGN KEY (id)
85+
REFERENCES market_mk20_deal_pipeline (id)
86+
ON DELETE CASCADE,
87+
CONSTRAINT market_mk20_offline_urls_id_unique UNIQUE (id)
88+
);
89+
90+
91+
92+
93+

0 commit comments

Comments
 (0)