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

Consolidate import-data commands into one #594

Merged
merged 3 commits into from
Jun 15, 2022
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
1 change: 1 addition & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Boost interface {
BoostIndexerAnnounceAllDeals(ctx context.Context) error //perm:admin
BoostOfflineDealWithData(ctx context.Context, dealUuid uuid.UUID, filePath string) (*ProviderDealRejectionInfo, error) //perm:admin
BoostDeal(ctx context.Context, dealUuid uuid.UUID) (*smtypes.ProviderDealState, error) //perm:admin
BoostDealBySignedProposalCid(ctx context.Context, proposalCid cid.Cid) (*smtypes.ProviderDealState, error) //perm:admin
BoostDummyDeal(context.Context, smtypes.DealParams) (*ProviderDealRejectionInfo, error) //perm:admin
BoostDagstoreRegisterShard(ctx context.Context, key string) error //perm:admin
BoostDagstoreInitializeShard(ctx context.Context, key string) error //perm:admin
Expand Down
13 changes: 13 additions & 0 deletions api/proxy_gen.go

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

Binary file modified build/openrpc/boost.json.gz
Binary file not shown.
68 changes: 48 additions & 20 deletions cmd/boostd/import_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,77 @@ package main

import (
"fmt"
"github.com/ipfs/go-cid"
"strings"

bcli "github.com/filecoin-project/boost/cli"
"github.com/google/uuid"
"github.com/urfave/cli/v2"
)

var importDataCmd = &cli.Command{
Name: "import-data",
Usage: "Import data for offline deal made with Boost",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "deal-uuid",
Usage: "uuid of the offline deal",
Required: true,
},
&cli.StringFlag{
Name: "filepath",
Usage: "path of the file containing the offline deal data",
Required: true,
},
},
Name: "import-data",
Usage: "Import data for offline deal made with Boost",
ArgsUsage: "<proposal CID> <file> or <deal UUID> <file>",
Action: func(cctx *cli.Context) error {
if cctx.Args().Len() < 2 {
return fmt.Errorf("must specify proposal CID / deal UUID and file path")
}

id := cctx.Args().Get(0)
filePath := cctx.Args().Get(1)

// Parse the first parameter as a deal UUID or a proposal CID
var proposalCid *cid.Cid
dealUuid, err := uuid.Parse(id)
if err != nil {
propCid, err := cid.Decode(id)
if err != nil {
return fmt.Errorf("could not parse '%s' as deal uuid or proposal cid", id)
}
proposalCid = &propCid
}

napi, closer, err := bcli.GetBoostAPI(cctx)
if err != nil {
return err
}
defer closer()

filePath := cctx.String("filepath")
id := cctx.String("deal-uuid")
// If the user has supplied a signed proposal cid
if proposalCid != nil {
// Look up the deal in the boost database
deal, err := napi.BoostDealBySignedProposalCid(cctx.Context, *proposalCid)
if err != nil {
// If the error is anything other than a Not Found error,
// return the error
if !strings.Contains(err.Error(), "not found") {
return err
}

dealUuid, err := uuid.Parse(id)
if err != nil {
return fmt.Errorf("failed to parse deal uuid '%s'", id)
// The deal is not in the boost database, try the legacy
// markets datastore (v1.1.0 deal)
err := napi.MarketImportDealData(cctx.Context, *proposalCid, filePath)
if err != nil {
return fmt.Errorf("couldnt import v1.1.0 deal, or find boost deal: %w", err)
}
fmt.Printf("Offline deal import for v1.1.0 deal %s scheduled for execution\n", proposalCid.String())
return nil
}

// Get the deal UUID from the deal
dealUuid = deal.DealUuid
}

// Deal proposal by deal uuid (v1.2.0 deal)
rej, err := napi.BoostOfflineDealWithData(cctx.Context, dealUuid, filePath)
if err != nil {
return fmt.Errorf("failed to execute offline deal: %w", err)
}
if rej != nil && rej.Reason != "" {
return fmt.Errorf("offline deal %s rejected: %s", dealUuid, rej.Reason)
}
fmt.Println("Offline deal accepted and scheduled for execution")
fmt.Printf("Offline deal import for v1.2.0 deal %s scheduled for execution\n", dealUuid)
return nil
},
}
46 changes: 0 additions & 46 deletions cmd/boostd/legacy_deals.go

This file was deleted.

1 change: 0 additions & 1 deletion cmd/boostd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func main() {
backupCmd,
restoreCmd,
dummydealCmd,
storageDealsCmd,
dataTransfersCmd,
retrievalDealsCmd,
indexProvCmd,
Expand Down
66 changes: 66 additions & 0 deletions documentation/en/api-v1-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* [BoostDagstoreRecoverShard](#boostdagstorerecovershard)
* [BoostDagstoreRegisterShard](#boostdagstoreregistershard)
* [BoostDeal](#boostdeal)
* [BoostDealBySignedProposalCid](#boostdealbysignedproposalcid)
* [BoostDummyDeal](#boostdummydeal)
* [BoostIndexerAnnounceAllDeals](#boostindexerannouncealldeals)
* [BoostOfflineDealWithData](#boostofflinedealwithdata)
Expand Down Expand Up @@ -296,6 +297,71 @@ Response:
}
```

### BoostDealBySignedProposalCid


Perms: admin

Inputs:
```json
[
{
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
}
]
```

Response:
```json
{
"DealUuid": "07070707-0707-0707-0707-070707070707",
"CreatedAt": "0001-01-01T00:00:00Z",
"ClientDealProposal": {
"Proposal": {
"PieceCID": {
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
},
"PieceSize": 1032,
"VerifiedDeal": true,
"Client": "f01234",
"Provider": "f01234",
"Label": "string value",
"StartEpoch": 10101,
"EndEpoch": 10101,
"StoragePricePerEpoch": "0",
"ProviderCollateral": "0",
"ClientCollateral": "0"
},
"ClientSignature": {
"Type": 2,
"Data": "Ynl0ZSBhcnJheQ=="
}
},
"IsOffline": true,
"ClientPeerID": "12D3KooWGzxzKZYveHXtpG6AsrUJBcWxHBFS2HsEoGTxrMLvKXtf",
"DealDataRoot": {
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
},
"InboundFilePath": "string value",
"Transfer": {
"Type": "string value",
"ClientID": "string value",
"Params": "Ynl0ZSBhcnJheQ==",
"Size": 42
},
"ChainDealID": 5432,
"PublishCID": null,
"SectorID": 9,
"Offset": 1032,
"Length": 1032,
"Checkpoint": 1,
"CheckpointAt": "0001-01-01T00:00:00Z",
"Err": "string value",
"Retry": "auto",
"NBytesReceived": 9
}
```

### BoostDummyDeal


Expand Down
4 changes: 4 additions & 0 deletions node/impl/boost.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ func (sm *BoostAPI) BoostDeal(ctx context.Context, dealUuid uuid.UUID) (*types.P
return sm.StorageProvider.Deal(ctx, dealUuid)
}

func (sm *BoostAPI) BoostDealBySignedProposalCid(ctx context.Context, proposalCid cid.Cid) (*types.ProviderDealState, error) {
return sm.StorageProvider.DealBySignedProposalCid(ctx, proposalCid)
}

func (sm *BoostAPI) BoostIndexerAnnounceAllDeals(ctx context.Context) error {
return sm.IndexProvider.IndexerAnnounceAllDeals(ctx)
}
Expand Down
9 changes: 9 additions & 0 deletions storagemarket/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"database/sql"
"errors"
"fmt"
"github.com/ipfs/go-cid"
"io"
"os"
"sync"
Expand Down Expand Up @@ -172,6 +173,14 @@ func (p *Provider) Deal(ctx context.Context, dealUuid uuid.UUID) (*types.Provide
return deal, nil
}

func (p *Provider) DealBySignedProposalCid(ctx context.Context, propCid cid.Cid) (*types.ProviderDealState, error) {
deal, err := p.dealsDB.BySignedProposalCID(ctx, propCid)
if errors.Is(err, sql.ErrNoRows) {
return nil, fmt.Errorf("getting deal %s: %w", propCid, ErrDealNotFound)
}
return deal, nil
}

func (p *Provider) NBytesReceived(dealUuid uuid.UUID) uint64 {
return p.transfers.getBytes(dealUuid)
}
Expand Down