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: add deal IPNI announce command #1877

Merged
merged 2 commits into from
Feb 2, 2024
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 @@ -42,6 +42,7 @@ type Boost interface {
BoostDealBySignedProposalCid(ctx context.Context, proposalCid cid.Cid) (*smtypes.ProviderDealState, error) //perm:admin
BoostDummyDeal(context.Context, smtypes.DealParams) (*ProviderDealRejectionInfo, error) //perm:admin
BoostIndexerAnnounceDealRemoved(ctx context.Context, propCid cid.Cid) (cid.Cid, error) //perm:admin
BoostIndexerAnnounceDeal(ctx context.Context, deal *smtypes.ProviderDealState) (cid.Cid, error) //perm:admin
BoostLegacyDealByProposalCid(ctx context.Context, propCid cid.Cid) (storagemarket.MinerDeal, error) //perm:admin
BoostDagstoreRegisterShard(ctx context.Context, key string) error //perm:admin
BoostDagstoreDestroyShard(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.
64 changes: 56 additions & 8 deletions cmd/boostd/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var indexProvCmd = &cli.Command{
indexProvAnnounceLatest,
indexProvAnnounceLatestHttp,
indexProvAnnounceDealRemovalAd,
indexProvAnnounceDeal,
},
}

Expand Down Expand Up @@ -148,37 +149,39 @@ var indexProvAnnounceDealRemovalAd = &cli.Command{

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

var proposalCid *cid.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
proposalCid = propCid
}

if proposalCid == nil {
if !proposalCid.Defined() {
deal, err := napi.BoostDeal(ctx, dealUuid)
if err != nil {
return fmt.Errorf("deal not found with UUID %s: %w", dealUuid.String(), err)
}
prop, err := deal.ClientDealProposal.Proposal.Cid()
prop, err := deal.SignedProposalCid()
if err != nil {
return fmt.Errorf("generating proposal cid for deal %s: %w", dealUuid.String(), err)
}
proposalCid = &prop
proposalCid = prop
} else {
_, err = napi.BoostLegacyDealByProposalCid(ctx, *proposalCid)
_, err = napi.BoostLegacyDealByProposalCid(ctx, proposalCid)
if err != nil {
_, err := napi.BoostDealBySignedProposalCid(ctx, *proposalCid)
_, err := napi.BoostDealBySignedProposalCid(ctx, proposalCid)
if err != nil {
return fmt.Errorf("no deal with proposal CID %s found in boost and legacy database", proposalCid.String())
}
}
}

cid, err := napi.BoostIndexerAnnounceDealRemoved(ctx, *proposalCid)
fmt.Printf("the proposal cid is %s\n", proposalCid)

cid, err := napi.BoostIndexerAnnounceDealRemoved(ctx, proposalCid)
if err != nil {
return fmt.Errorf("failed to send removal ad: %w", err)
}
Expand All @@ -187,3 +190,48 @@ var indexProvAnnounceDealRemovalAd = &cli.Command{
return nil
},
}

var indexProvAnnounceDeal = &cli.Command{
Name: "announce-deal",
Usage: "Publish an ad for given deal UUID (Boost deals only)",
Action: func(cctx *cli.Context) error {
ctx := lcli.ReqContext(cctx)

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

if cctx.Args().Len() != 1 {
return fmt.Errorf("must specify only one deal UUID")
}

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

dealUuid, err := uuid.Parse(id)
if err != nil {
if err != nil {
return fmt.Errorf("could not parse '%s' as deal uuid", id)
}
}

deal, err := napi.BoostDeal(ctx, dealUuid)
if err != nil {
return fmt.Errorf("deal not found with UUID %s: %w", dealUuid.String(), err)
}

cid, err := napi.BoostIndexerAnnounceDeal(ctx, deal)
if err != nil {
return fmt.Errorf("failed to announce the deal: %w", err)
}
if cid.Defined() {
fmt.Printf("Announced the deal with Ad cid %s\n", cid)
return nil
}

fmt.Printf("Deal already announced\n")

return nil
},
}
69 changes: 69 additions & 0 deletions documentation/en/api-v1-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* [BoostDirectDeal](#boostdirectdeal)
* [BoostDummyDeal](#boostdummydeal)
* [BoostIndexerAnnounceAllDeals](#boostindexerannouncealldeals)
* [BoostIndexerAnnounceDeal](#boostindexerannouncedeal)
* [BoostIndexerAnnounceDealRemoved](#boostindexerannouncedealremoved)
* [BoostIndexerAnnounceLatest](#boostindexerannouncelatest)
* [BoostIndexerAnnounceLatestHttp](#boostindexerannouncelatesthttp)
Expand Down Expand Up @@ -598,6 +599,74 @@ Inputs: `null`

Response: `{}`

### BoostIndexerAnnounceDeal


Perms: admin

Inputs:
```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": "",
"StartEpoch": 10101,
"EndEpoch": 10101,
"StoragePricePerEpoch": "0",
"ProviderCollateral": "0",
"ClientCollateral": "0"
},
"ClientSignature": {
"Type": 2,
"Data": "Ynl0ZSBhcnJheQ=="
}
},
"IsOffline": true,
"CleanupData": 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,
"FastRetrieval": true,
"AnnounceToIPNI": true
}
]
```

Response:
```json
{
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
}
```

### BoostIndexerAnnounceDealRemoved


Expand Down
4 changes: 4 additions & 0 deletions node/impl/boost.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ func (sm *BoostAPI) BoostIndexerAnnounceDealRemoved(ctx context.Context, propCid
return sm.IndexProvider.AnnounceBoostDealRemoved(ctx, propCid)
}

func (sm *BoostAPI) BoostIndexerAnnounceDeal(ctx context.Context, deal *types.ProviderDealState) (cid.Cid, error) {
return sm.IndexProvider.AnnounceBoostDeal(ctx, deal)
}

func (sm *BoostAPI) BoostLegacyDealByProposalCid(ctx context.Context, propCid cid.Cid) (gfm_storagemarket.MinerDeal, error) {
return sm.LegacyStorageProvider.GetLocalDeal(propCid)
}
Expand Down
Loading