Skip to content

Commit

Permalink
manual legacy deal IPNI announcement (#1879)
Browse files Browse the repository at this point in the history
  • Loading branch information
LexLuthr authored Feb 13, 2024
1 parent 5348fa5 commit e552e7c
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 14 deletions.
1 change: 1 addition & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type Boost interface {
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
BoostIndexerAnnounceLegacyDeal(ctx context.Context, proposalCid 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.
63 changes: 49 additions & 14 deletions cmd/boostd/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"strings"

bcli "github.com/filecoin-project/boost/cli"
lcli "github.com/filecoin-project/lotus/cli"
Expand Down Expand Up @@ -133,7 +134,7 @@ var indexProvAnnounceLatestHttp = &cli.Command{

var indexProvAnnounceDealRemovalAd = &cli.Command{
Name: "announce-remove-deal",
Usage: "Published a removal ad for given deal UUID or Proposal CID (legacy deals)",
Usage: "Published a removal ad for given deal UUID or Signed Proposal CID (legacy deals)",
Action: func(cctx *cli.Context) error {
ctx := lcli.ReqContext(cctx)

Expand Down Expand Up @@ -193,7 +194,7 @@ var indexProvAnnounceDealRemovalAd = &cli.Command{

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

Expand All @@ -209,29 +210,63 @@ var indexProvAnnounceDeal = &cli.Command{

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

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", id)
return fmt.Errorf("could not parse '%s' as deal uuid or proposal cid", id)
}
proposalCid = propCid
}

deal, err := napi.BoostDeal(ctx, dealUuid)
if err != nil {
return fmt.Errorf("deal not found with UUID %s: %w", dealUuid.String(), err)
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)
}
ad, err := napi.BoostIndexerAnnounceDeal(ctx, deal)
if err != nil {
return fmt.Errorf("failed to announce the deal: %w", err)
}
if ad.Defined() {
fmt.Printf("Announced the deal with Ad cid %s\n", ad)
return nil
}
fmt.Printf("Deal already announced\n")
return nil
}

cid, err := napi.BoostIndexerAnnounceDeal(ctx, deal)
_, err = napi.BoostLegacyDealByProposalCid(ctx, proposalCid)
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)
// If the error is anything other than a Not Found error,
// return the error
if !strings.Contains(err.Error(), "not found") {
return fmt.Errorf("locating legacy deal %s: %w", proposalCid, err)
}
// If not found, check for Boost deals by proposal CID
deal, err := napi.BoostDealBySignedProposalCid(ctx, proposalCid)
if err != nil {
return fmt.Errorf("locating Boost or legacy deal by proposal CID %s: %w", proposalCid, err)
}
// Announce Boost deal
ad, err := napi.BoostIndexerAnnounceDeal(ctx, deal)
if err != nil {
return fmt.Errorf("failed to announce the deal: %w", err)
}
if ad.Defined() {
fmt.Printf("Announced the deal with Ad cid %s\n", ad)
return nil
}
fmt.Printf("Deal already announced\n")
return nil
}

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

// Announce legacy deal
err = napi.BoostIndexerAnnounceLegacyDeal(ctx, proposalCid)
if err != nil {
return fmt.Errorf("announcing legacy deal with proposal CID %s: %w", proposalCid, err)
}
fmt.Printf("Announced the legacy deal")
return nil
},
}
17 changes: 17 additions & 0 deletions documentation/en/api-v1-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* [BoostIndexerAnnounceDealRemoved](#boostindexerannouncedealremoved)
* [BoostIndexerAnnounceLatest](#boostindexerannouncelatest)
* [BoostIndexerAnnounceLatestHttp](#boostindexerannouncelatesthttp)
* [BoostIndexerAnnounceLegacyDeal](#boostindexerannouncelegacydeal)
* [BoostIndexerListMultihashes](#boostindexerlistmultihashes)
* [BoostLegacyDealByProposalCid](#boostlegacydealbyproposalcid)
* [BoostMakeDeal](#boostmakedeal)
Expand Down Expand Up @@ -723,6 +724,22 @@ Response:
}
```

### BoostIndexerAnnounceLegacyDeal


Perms: admin

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

Response: `{}`

### BoostIndexerListMultihashes


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

func (sm *BoostAPI) BoostIndexerAnnounceLegacyDeal(ctx context.Context, proposalCid cid.Cid) error {
return sm.LegacyStorageProvider.AnnounceDealToIndexer(ctx, proposalCid)
}

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

0 comments on commit e552e7c

Please sign in to comment.