Skip to content

Commit b97aa6d

Browse files
dirkmcnonsense
andauthored
Consolidate import-data commands into one (#594)
* feat: consolidate import-data commands into one * Update cmd/boostd/import_data.go Co-authored-by: Anton Evangelatov <[email protected]> * Update cmd/boostd/import_data.go Co-authored-by: Anton Evangelatov <[email protected]> Co-authored-by: Anton Evangelatov <[email protected]>
1 parent 5cffbec commit b97aa6d

File tree

9 files changed

+141
-67
lines changed

9 files changed

+141
-67
lines changed

api/api.go

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type Boost interface {
3636
BoostIndexerAnnounceAllDeals(ctx context.Context) error //perm:admin
3737
BoostOfflineDealWithData(ctx context.Context, dealUuid uuid.UUID, filePath string) (*ProviderDealRejectionInfo, error) //perm:admin
3838
BoostDeal(ctx context.Context, dealUuid uuid.UUID) (*smtypes.ProviderDealState, error) //perm:admin
39+
BoostDealBySignedProposalCid(ctx context.Context, proposalCid cid.Cid) (*smtypes.ProviderDealState, error) //perm:admin
3940
BoostDummyDeal(context.Context, smtypes.DealParams) (*ProviderDealRejectionInfo, error) //perm:admin
4041
BoostDagstoreRegisterShard(ctx context.Context, key string) error //perm:admin
4142
BoostDagstoreInitializeShard(ctx context.Context, key string) error //perm:admin

api/proxy_gen.go

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/openrpc/boost.json.gz

84 Bytes
Binary file not shown.

cmd/boostd/import_data.go

+48-20
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,77 @@ package main
22

33
import (
44
"fmt"
5+
"github.com/ipfs/go-cid"
6+
"strings"
57

68
bcli "github.com/filecoin-project/boost/cli"
79
"github.com/google/uuid"
810
"github.com/urfave/cli/v2"
911
)
1012

1113
var importDataCmd = &cli.Command{
12-
Name: "import-data",
13-
Usage: "Import data for offline deal made with Boost",
14-
Flags: []cli.Flag{
15-
&cli.StringFlag{
16-
Name: "deal-uuid",
17-
Usage: "uuid of the offline deal",
18-
Required: true,
19-
},
20-
&cli.StringFlag{
21-
Name: "filepath",
22-
Usage: "path of the file containing the offline deal data",
23-
Required: true,
24-
},
25-
},
14+
Name: "import-data",
15+
Usage: "Import data for offline deal made with Boost",
16+
ArgsUsage: "<proposal CID> <file> or <deal UUID> <file>",
2617
Action: func(cctx *cli.Context) error {
18+
if cctx.Args().Len() < 2 {
19+
return fmt.Errorf("must specify proposal CID / deal UUID and file path")
20+
}
21+
22+
id := cctx.Args().Get(0)
23+
filePath := cctx.Args().Get(1)
24+
25+
// Parse the first parameter as a deal UUID or a proposal CID
26+
var proposalCid *cid.Cid
27+
dealUuid, err := uuid.Parse(id)
28+
if err != nil {
29+
propCid, err := cid.Decode(id)
30+
if err != nil {
31+
return fmt.Errorf("could not parse '%s' as deal uuid or proposal cid", id)
32+
}
33+
proposalCid = &propCid
34+
}
35+
2736
napi, closer, err := bcli.GetBoostAPI(cctx)
2837
if err != nil {
2938
return err
3039
}
3140
defer closer()
3241

33-
filePath := cctx.String("filepath")
34-
id := cctx.String("deal-uuid")
42+
// If the user has supplied a signed proposal cid
43+
if proposalCid != nil {
44+
// Look up the deal in the boost database
45+
deal, err := napi.BoostDealBySignedProposalCid(cctx.Context, *proposalCid)
46+
if err != nil {
47+
// If the error is anything other than a Not Found error,
48+
// return the error
49+
if !strings.Contains(err.Error(), "not found") {
50+
return err
51+
}
3552

36-
dealUuid, err := uuid.Parse(id)
37-
if err != nil {
38-
return fmt.Errorf("failed to parse deal uuid '%s'", id)
53+
// The deal is not in the boost database, try the legacy
54+
// markets datastore (v1.1.0 deal)
55+
err := napi.MarketImportDealData(cctx.Context, *proposalCid, filePath)
56+
if err != nil {
57+
return fmt.Errorf("couldnt import v1.1.0 deal, or find boost deal: %w", err)
58+
}
59+
fmt.Printf("Offline deal import for v1.1.0 deal %s scheduled for execution\n", proposalCid.String())
60+
return nil
61+
}
62+
63+
// Get the deal UUID from the deal
64+
dealUuid = deal.DealUuid
3965
}
66+
67+
// Deal proposal by deal uuid (v1.2.0 deal)
4068
rej, err := napi.BoostOfflineDealWithData(cctx.Context, dealUuid, filePath)
4169
if err != nil {
4270
return fmt.Errorf("failed to execute offline deal: %w", err)
4371
}
4472
if rej != nil && rej.Reason != "" {
4573
return fmt.Errorf("offline deal %s rejected: %s", dealUuid, rej.Reason)
4674
}
47-
fmt.Println("Offline deal accepted and scheduled for execution")
75+
fmt.Printf("Offline deal import for v1.2.0 deal %s scheduled for execution\n", dealUuid)
4876
return nil
4977
},
5078
}

cmd/boostd/legacy_deals.go

-46
This file was deleted.

cmd/boostd/main.go

-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ func main() {
4040
backupCmd,
4141
restoreCmd,
4242
dummydealCmd,
43-
storageDealsCmd,
4443
dataTransfersCmd,
4544
retrievalDealsCmd,
4645
indexProvCmd,

documentation/en/api-v1-methods.md

+66
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* [BoostDagstoreRecoverShard](#boostdagstorerecovershard)
1313
* [BoostDagstoreRegisterShard](#boostdagstoreregistershard)
1414
* [BoostDeal](#boostdeal)
15+
* [BoostDealBySignedProposalCid](#boostdealbysignedproposalcid)
1516
* [BoostDummyDeal](#boostdummydeal)
1617
* [BoostIndexerAnnounceAllDeals](#boostindexerannouncealldeals)
1718
* [BoostOfflineDealWithData](#boostofflinedealwithdata)
@@ -296,6 +297,71 @@ Response:
296297
}
297298
```
298299

300+
### BoostDealBySignedProposalCid
301+
302+
303+
Perms: admin
304+
305+
Inputs:
306+
```json
307+
[
308+
{
309+
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
310+
}
311+
]
312+
```
313+
314+
Response:
315+
```json
316+
{
317+
"DealUuid": "07070707-0707-0707-0707-070707070707",
318+
"CreatedAt": "0001-01-01T00:00:00Z",
319+
"ClientDealProposal": {
320+
"Proposal": {
321+
"PieceCID": {
322+
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
323+
},
324+
"PieceSize": 1032,
325+
"VerifiedDeal": true,
326+
"Client": "f01234",
327+
"Provider": "f01234",
328+
"Label": "string value",
329+
"StartEpoch": 10101,
330+
"EndEpoch": 10101,
331+
"StoragePricePerEpoch": "0",
332+
"ProviderCollateral": "0",
333+
"ClientCollateral": "0"
334+
},
335+
"ClientSignature": {
336+
"Type": 2,
337+
"Data": "Ynl0ZSBhcnJheQ=="
338+
}
339+
},
340+
"IsOffline": true,
341+
"ClientPeerID": "12D3KooWGzxzKZYveHXtpG6AsrUJBcWxHBFS2HsEoGTxrMLvKXtf",
342+
"DealDataRoot": {
343+
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
344+
},
345+
"InboundFilePath": "string value",
346+
"Transfer": {
347+
"Type": "string value",
348+
"ClientID": "string value",
349+
"Params": "Ynl0ZSBhcnJheQ==",
350+
"Size": 42
351+
},
352+
"ChainDealID": 5432,
353+
"PublishCID": null,
354+
"SectorID": 9,
355+
"Offset": 1032,
356+
"Length": 1032,
357+
"Checkpoint": 1,
358+
"CheckpointAt": "0001-01-01T00:00:00Z",
359+
"Err": "string value",
360+
"Retry": "auto",
361+
"NBytesReceived": 9
362+
}
363+
```
364+
299365
### BoostDummyDeal
300366

301367

node/impl/boost.go

+4
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ func (sm *BoostAPI) BoostDeal(ctx context.Context, dealUuid uuid.UUID) (*types.P
118118
return sm.StorageProvider.Deal(ctx, dealUuid)
119119
}
120120

121+
func (sm *BoostAPI) BoostDealBySignedProposalCid(ctx context.Context, proposalCid cid.Cid) (*types.ProviderDealState, error) {
122+
return sm.StorageProvider.DealBySignedProposalCid(ctx, proposalCid)
123+
}
124+
121125
func (sm *BoostAPI) BoostIndexerAnnounceAllDeals(ctx context.Context) error {
122126
return sm.IndexProvider.IndexerAnnounceAllDeals(ctx)
123127
}

storagemarket/provider.go

+9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"database/sql"
66
"errors"
77
"fmt"
8+
"github.com/ipfs/go-cid"
89
"io"
910
"os"
1011
"sync"
@@ -172,6 +173,14 @@ func (p *Provider) Deal(ctx context.Context, dealUuid uuid.UUID) (*types.Provide
172173
return deal, nil
173174
}
174175

176+
func (p *Provider) DealBySignedProposalCid(ctx context.Context, propCid cid.Cid) (*types.ProviderDealState, error) {
177+
deal, err := p.dealsDB.BySignedProposalCID(ctx, propCid)
178+
if errors.Is(err, sql.ErrNoRows) {
179+
return nil, fmt.Errorf("getting deal %s: %w", propCid, ErrDealNotFound)
180+
}
181+
return deal, nil
182+
}
183+
175184
func (p *Provider) NBytesReceived(dealUuid uuid.UUID) uint64 {
176185
return p.transfers.getBytes(dealUuid)
177186
}

0 commit comments

Comments
 (0)