Skip to content

Commit c8932a6

Browse files
committed
add indexer remove all
1 parent 85004d5 commit c8932a6

File tree

8 files changed

+162
-6
lines changed

8 files changed

+162
-6
lines changed

api/api.go

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type Boost interface {
2626
Net
2727

2828
// MethodGroup: Boost
29+
BoostIndexerRemoveAll(ctx context.Context) ([]cid.Cid, error) //perm:admin
2930
BoostIndexerAnnounceAllDeals(ctx context.Context) error //perm:admin
3031
BoostIndexerListMultihashes(ctx context.Context, contextID []byte) ([]multihash.Multihash, error) //perm:admin
3132
BoostIndexerAnnounceLatest(ctx context.Context) (cid.Cid, 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

63 Bytes
Binary file not shown.

cmd/boostd/index.go

+27
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ var indexProvCmd = &cli.Command{
2222
indexProvAnnounceLatestHttp,
2323
indexProvAnnounceDealRemovalAd,
2424
indexProvAnnounceDeal,
25+
indexProvRemoveAllCmd,
2526
},
2627
}
2728

@@ -303,3 +304,29 @@ var indexProvAnnounceDeal = &cli.Command{
303304
return nil
304305
},
305306
}
307+
308+
var indexProvRemoveAllCmd = &cli.Command{
309+
Name: "remove-all",
310+
Usage: "Announce all removal ad for all contextIDs",
311+
Flags: []cli.Flag{},
312+
Action: func(cctx *cli.Context) error {
313+
ctx := lcli.ReqContext(cctx)
314+
315+
// get boost api
316+
napi, closer, err := bcli.GetBoostAPI(cctx)
317+
if err != nil {
318+
return err
319+
}
320+
defer closer()
321+
322+
// announce markets and boost deals
323+
cids, err := napi.BoostIndexerRemoveAll(ctx)
324+
if err != nil {
325+
return err
326+
}
327+
for _, c := range cids {
328+
fmt.Println("Published the removal ad with CID", c.String())
329+
}
330+
return nil
331+
},
332+
}

cmd/migrate-curio/ipni.go

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/filecoin-project/boost/node/repo"
7+
lotus_repo "github.com/filecoin-project/lotus/node/repo"
8+
"github.com/mitchellh/go-homedir"
9+
"github.com/urfave/cli/v2"
10+
)
11+
12+
var removeIPNICmd = &cli.Command{
13+
Name: "remove-ipni",
14+
Description: "Sends remove ad for all the currently published Ads to IPNI",
15+
Usage: "migrate-curio remove-ipni",
16+
Before: before,
17+
Action: func(cctx *cli.Context) error {
18+
ctx := cctx.Context
19+
20+
repoDir, err := homedir.Expand(cctx.String(FlagBoostRepo))
21+
if err != nil {
22+
return err
23+
}
24+
25+
r, err := lotus_repo.NewFS(repoDir)
26+
if err != nil {
27+
return err
28+
}
29+
ok, err := r.Exists()
30+
if err != nil {
31+
return err
32+
}
33+
if !ok {
34+
return fmt.Errorf("repo at '%s' is not initialized", cctx.String(FlagBoostRepo))
35+
}
36+
37+
lr, err := r.Lock(repo.Boost)
38+
if err != nil {
39+
return err
40+
}
41+
42+
mds, err := lr.Datastore(ctx, "/metadata")
43+
if err != nil {
44+
return err
45+
}
46+
47+
return migrate(cctx, repoDir)
48+
},
49+
}

documentation/en/api-v1-methods.md

+16-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* [BoostIndexerAnnounceLatestHttp](#boostindexerannouncelatesthttp)
2121
* [BoostIndexerAnnounceLegacyDeal](#boostindexerannouncelegacydeal)
2222
* [BoostIndexerListMultihashes](#boostindexerlistmultihashes)
23+
* [BoostIndexerRemoveAll](#boostindexerremoveall)
2324
* [BoostLegacyDealByProposalCid](#boostlegacydealbyproposalcid)
2425
* [BoostOfflineDealWithData](#boostofflinedealwithdata)
2526
* [I](#i)
@@ -374,7 +375,7 @@ Response:
374375
```
375376

376377
### BoostIndexerAnnounceAllDeals
377-
There are not yet any comments for this method.
378+
378379

379380
Perms: admin
380381

@@ -513,6 +514,20 @@ Response:
513514
]
514515
```
515516

517+
### BoostIndexerRemoveAll
518+
There are not yet any comments for this method.
519+
520+
Perms: admin
521+
522+
Inputs: `null`
523+
524+
Response:
525+
```json
526+
[
527+
null
528+
]
529+
```
530+
516531
### BoostLegacyDealByProposalCid
517532

518533

indexprovider/wrapper.go

+52-5
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ import (
1818
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
1919
chainTypes "github.com/filecoin-project/lotus/chain/types"
2020
"github.com/google/uuid"
21-
cbor "github.com/ipfs/go-ipld-cbor"
22-
"go.uber.org/fx"
23-
2421
"github.com/ipfs/go-datastore"
22+
cbor "github.com/ipfs/go-ipld-cbor"
2523
"github.com/ipld/go-ipld-prime"
24+
"github.com/ipni/go-libipni/ingest/schema"
25+
"go.uber.org/fx"
2626

2727
"github.com/filecoin-project/boost/db"
2828
bdtypes "github.com/filecoin-project/boost/extern/boostd-data/svc/types"
@@ -126,8 +126,6 @@ func (w *Wrapper) Start(_ context.Context) {
126126
}()
127127

128128
log.Info("starting index provider")
129-
130-
go w.checkForUpdates(runCtx)
131129
}
132130

133131
func (w *Wrapper) checkForUpdates(ctx context.Context) {
@@ -867,3 +865,52 @@ func (w *Wrapper) AnnounceBoostDirectDealRemoved(ctx context.Context, dealUUID u
867865
}
868866
return annCid, err
869867
}
868+
869+
func (w *Wrapper) AnnounceRemoveAll(ctx context.Context) ([]cid.Cid, error) {
870+
var allAds []*schema.Advertisement
871+
_, ad, err := w.prov.GetLatestAdv(ctx)
872+
if err != nil {
873+
return nil, err
874+
}
875+
allAds = append(allAds, ad)
876+
877+
prev, err := cid.Parse(ad.PreviousID.String())
878+
if err != nil {
879+
return nil, err
880+
}
881+
882+
for prev != cid.Undef {
883+
ad, err := w.prov.GetAdv(ctx, prev)
884+
if err != nil {
885+
return nil, err
886+
}
887+
888+
prev, err = cid.Parse(ad.PreviousID.String())
889+
if err != nil {
890+
return nil, err
891+
}
892+
}
893+
894+
var entryAds []*schema.Advertisement
895+
896+
for _, ad := range allAds {
897+
if !ad.IsRm {
898+
entryAds = append(entryAds, ad)
899+
}
900+
}
901+
902+
var newAds []cid.Cid
903+
904+
for _, ad := range entryAds {
905+
a, err := w.prov.NotifyRemove(ctx, w.h.ID(), ad.ContextID)
906+
if err != nil {
907+
if !errors.Is(err, provider.ErrContextIDNotFound) {
908+
return nil, fmt.Errorf("failed to publish the removal ad: %w", err)
909+
}
910+
}
911+
newAds = append(newAds, a)
912+
}
913+
914+
return newAds, nil
915+
916+
}

node/impl/boost.go

+4
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,7 @@ func (sm *BoostAPI) PdCleanup(ctx context.Context) error {
231231
func (sm *BoostAPI) MarketGetAsk(ctx context.Context) (*legacytypes.SignedStorageAsk, error) {
232232
return sm.StorageProvider.GetAsk(), nil
233233
}
234+
235+
func (sm *BoostAPI) BoostIndexerRemoveAll(ctx context.Context) ([]cid.Cid, error) {
236+
return sm.IndexProvider.AnnounceRemoveAll(ctx)
237+
}

0 commit comments

Comments
 (0)