Skip to content

Commit 5348fa5

Browse files
authored
feat: add deal IPNI announce command (#1877)
* add deal announce command * fix removal ad cmd
1 parent 8f6f6ff commit 5348fa5

File tree

6 files changed

+143
-8
lines changed

6 files changed

+143
-8
lines changed

api/api.go

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type Boost interface {
4242
BoostDealBySignedProposalCid(ctx context.Context, proposalCid cid.Cid) (*smtypes.ProviderDealState, error) //perm:admin
4343
BoostDummyDeal(context.Context, smtypes.DealParams) (*ProviderDealRejectionInfo, error) //perm:admin
4444
BoostIndexerAnnounceDealRemoved(ctx context.Context, propCid cid.Cid) (cid.Cid, error) //perm:admin
45+
BoostIndexerAnnounceDeal(ctx context.Context, deal *smtypes.ProviderDealState) (cid.Cid, error) //perm:admin
4546
BoostLegacyDealByProposalCid(ctx context.Context, propCid cid.Cid) (storagemarket.MinerDeal, error) //perm:admin
4647
BoostDagstoreRegisterShard(ctx context.Context, key string) error //perm:admin
4748
BoostDagstoreDestroyShard(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

83 Bytes
Binary file not shown.

cmd/boostd/index.go

+56-8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ var indexProvCmd = &cli.Command{
1919
indexProvAnnounceLatest,
2020
indexProvAnnounceLatestHttp,
2121
indexProvAnnounceDealRemovalAd,
22+
indexProvAnnounceDeal,
2223
},
2324
}
2425

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

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

151-
var proposalCid *cid.Cid
152+
var proposalCid cid.Cid
152153
dealUuid, err := uuid.Parse(id)
153154
if err != nil {
154155
propCid, err := cid.Decode(id)
155156
if err != nil {
156157
return fmt.Errorf("could not parse '%s' as deal uuid or proposal cid", id)
157158
}
158-
proposalCid = &propCid
159+
proposalCid = propCid
159160
}
160161

161-
if proposalCid == nil {
162+
if !proposalCid.Defined() {
162163
deal, err := napi.BoostDeal(ctx, dealUuid)
163164
if err != nil {
164165
return fmt.Errorf("deal not found with UUID %s: %w", dealUuid.String(), err)
165166
}
166-
prop, err := deal.ClientDealProposal.Proposal.Cid()
167+
prop, err := deal.SignedProposalCid()
167168
if err != nil {
168169
return fmt.Errorf("generating proposal cid for deal %s: %w", dealUuid.String(), err)
169170
}
170-
proposalCid = &prop
171+
proposalCid = prop
171172
} else {
172-
_, err = napi.BoostLegacyDealByProposalCid(ctx, *proposalCid)
173+
_, err = napi.BoostLegacyDealByProposalCid(ctx, proposalCid)
173174
if err != nil {
174-
_, err := napi.BoostDealBySignedProposalCid(ctx, *proposalCid)
175+
_, err := napi.BoostDealBySignedProposalCid(ctx, proposalCid)
175176
if err != nil {
176177
return fmt.Errorf("no deal with proposal CID %s found in boost and legacy database", proposalCid.String())
177178
}
178179
}
179180
}
180181

181-
cid, err := napi.BoostIndexerAnnounceDealRemoved(ctx, *proposalCid)
182+
fmt.Printf("the proposal cid is %s\n", proposalCid)
183+
184+
cid, err := napi.BoostIndexerAnnounceDealRemoved(ctx, proposalCid)
182185
if err != nil {
183186
return fmt.Errorf("failed to send removal ad: %w", err)
184187
}
@@ -187,3 +190,48 @@ var indexProvAnnounceDealRemovalAd = &cli.Command{
187190
return nil
188191
},
189192
}
193+
194+
var indexProvAnnounceDeal = &cli.Command{
195+
Name: "announce-deal",
196+
Usage: "Publish an ad for given deal UUID (Boost deals only)",
197+
Action: func(cctx *cli.Context) error {
198+
ctx := lcli.ReqContext(cctx)
199+
200+
napi, closer, err := bcli.GetBoostAPI(cctx)
201+
if err != nil {
202+
return err
203+
}
204+
defer closer()
205+
206+
if cctx.Args().Len() != 1 {
207+
return fmt.Errorf("must specify only one deal UUID")
208+
}
209+
210+
id := cctx.Args().Get(0)
211+
212+
dealUuid, err := uuid.Parse(id)
213+
if err != nil {
214+
if err != nil {
215+
return fmt.Errorf("could not parse '%s' as deal uuid", id)
216+
}
217+
}
218+
219+
deal, err := napi.BoostDeal(ctx, dealUuid)
220+
if err != nil {
221+
return fmt.Errorf("deal not found with UUID %s: %w", dealUuid.String(), err)
222+
}
223+
224+
cid, err := napi.BoostIndexerAnnounceDeal(ctx, deal)
225+
if err != nil {
226+
return fmt.Errorf("failed to announce the deal: %w", err)
227+
}
228+
if cid.Defined() {
229+
fmt.Printf("Announced the deal with Ad cid %s\n", cid)
230+
return nil
231+
}
232+
233+
fmt.Printf("Deal already announced\n")
234+
235+
return nil
236+
},
237+
}

documentation/en/api-v1-methods.md

+69
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* [BoostDirectDeal](#boostdirectdeal)
2525
* [BoostDummyDeal](#boostdummydeal)
2626
* [BoostIndexerAnnounceAllDeals](#boostindexerannouncealldeals)
27+
* [BoostIndexerAnnounceDeal](#boostindexerannouncedeal)
2728
* [BoostIndexerAnnounceDealRemoved](#boostindexerannouncedealremoved)
2829
* [BoostIndexerAnnounceLatest](#boostindexerannouncelatest)
2930
* [BoostIndexerAnnounceLatestHttp](#boostindexerannouncelatesthttp)
@@ -598,6 +599,74 @@ Inputs: `null`
598599

599600
Response: `{}`
600601

602+
### BoostIndexerAnnounceDeal
603+
604+
605+
Perms: admin
606+
607+
Inputs:
608+
```json
609+
[
610+
{
611+
"DealUuid": "07070707-0707-0707-0707-070707070707",
612+
"CreatedAt": "0001-01-01T00:00:00Z",
613+
"ClientDealProposal": {
614+
"Proposal": {
615+
"PieceCID": {
616+
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
617+
},
618+
"PieceSize": 1032,
619+
"VerifiedDeal": true,
620+
"Client": "f01234",
621+
"Provider": "f01234",
622+
"Label": "",
623+
"StartEpoch": 10101,
624+
"EndEpoch": 10101,
625+
"StoragePricePerEpoch": "0",
626+
"ProviderCollateral": "0",
627+
"ClientCollateral": "0"
628+
},
629+
"ClientSignature": {
630+
"Type": 2,
631+
"Data": "Ynl0ZSBhcnJheQ=="
632+
}
633+
},
634+
"IsOffline": true,
635+
"CleanupData": true,
636+
"ClientPeerID": "12D3KooWGzxzKZYveHXtpG6AsrUJBcWxHBFS2HsEoGTxrMLvKXtf",
637+
"DealDataRoot": {
638+
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
639+
},
640+
"InboundFilePath": "string value",
641+
"Transfer": {
642+
"Type": "string value",
643+
"ClientID": "string value",
644+
"Params": "Ynl0ZSBhcnJheQ==",
645+
"Size": 42
646+
},
647+
"ChainDealID": 5432,
648+
"PublishCID": null,
649+
"SectorID": 9,
650+
"Offset": 1032,
651+
"Length": 1032,
652+
"Checkpoint": 1,
653+
"CheckpointAt": "0001-01-01T00:00:00Z",
654+
"Err": "string value",
655+
"Retry": "auto",
656+
"NBytesReceived": 9,
657+
"FastRetrieval": true,
658+
"AnnounceToIPNI": true
659+
}
660+
]
661+
```
662+
663+
Response:
664+
```json
665+
{
666+
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
667+
}
668+
```
669+
601670
### BoostIndexerAnnounceDealRemoved
602671

603672

node/impl/boost.go

+4
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ func (sm *BoostAPI) BoostIndexerAnnounceDealRemoved(ctx context.Context, propCid
187187
return sm.IndexProvider.AnnounceBoostDealRemoved(ctx, propCid)
188188
}
189189

190+
func (sm *BoostAPI) BoostIndexerAnnounceDeal(ctx context.Context, deal *types.ProviderDealState) (cid.Cid, error) {
191+
return sm.IndexProvider.AnnounceBoostDeal(ctx, deal)
192+
}
193+
190194
func (sm *BoostAPI) BoostLegacyDealByProposalCid(ctx context.Context, propCid cid.Cid) (gfm_storagemarket.MinerDeal, error) {
191195
return sm.LegacyStorageProvider.GetLocalDeal(propCid)
192196
}

0 commit comments

Comments
 (0)