Skip to content

Commit 6cf7ef6

Browse files
author
LexLuthr
committed
index and announce
1 parent 6ae5bfc commit 6cf7ef6

File tree

4 files changed

+103
-17
lines changed

4 files changed

+103
-17
lines changed

indexprovider/wrapper.go

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ func (w *Wrapper) handleUpdates(ctx context.Context, sectorUpdates map[abi.Secto
190190
FastRetrieval: sectorSealState == db.SealStateUnsealed,
191191
VerifiedDeal: deal.DealProposal.Proposal.VerifiedDeal,
192192
}
193-
announceCid, err := w.AnnounceBoostDealMetadata(ctx, md, propCid)
193+
announceCid, err := w.AnnounceBoostDealMetadata(ctx, md, propCid.Bytes())
194194
if err != nil {
195195
log.Errorf("announcing deal %s to index provider: %w", deal.DealID, err)
196196
} else {
@@ -282,25 +282,27 @@ func (w *Wrapper) Enabled() bool {
282282
// The advertisement published by this function covers 2 protocols:
283283
//
284284
// Bitswap:
285-
// 1. bitswap is completely disabled: in which case an advertisement is
285+
//
286+
// 1. bitswap is completely disabled: in which case an advertisement is
286287
// published with http(or empty if http is disabled) extended providers
287288
// that should wipe previous support on indexer side.
288289
//
289-
// 2. bitswap is enabled with public addresses: in which case publish an
290+
// 2. bitswap is enabled with public addresses: in which case publish an
290291
// advertisement with extended providers records corresponding to the
291292
// public addresses. Note, according the IPNI spec, the host ID will
292293
// also be added to the extended providers for signing reasons with empty
293294
// metadata making a total of 2 extended provider records.
294295
//
295-
// 3. bitswap with boostd address: in which case public an advertisement
296+
// 3. bitswap with boostd address: in which case public an advertisement
296297
// with one extended provider record that just adds bitswap metadata.
297298
//
298299
// HTTP:
299-
// 1. http is completely disabled: in which case an advertisement is
300+
//
301+
// 1. http is completely disabled: in which case an advertisement is
300302
// published with bitswap(or empty if bitswap is disabled) extended providers
301303
// that should wipe previous support on indexer side
302304
//
303-
// 2. http is enabled: in which case an advertisement is published with
305+
// 2. http is enabled: in which case an advertisement is published with
304306
// bitswap and http(or only http if bitswap is disabled) extended providers
305307
// that should wipe previous support on indexer side
306308
//
@@ -632,10 +634,10 @@ func (w *Wrapper) AnnounceBoostDeal(ctx context.Context, deal *types.ProviderDea
632634
FastRetrieval: deal.FastRetrieval,
633635
VerifiedDeal: deal.ClientDealProposal.Proposal.VerifiedDeal,
634636
}
635-
return w.AnnounceBoostDealMetadata(ctx, md, propCid)
637+
return w.AnnounceBoostDealMetadata(ctx, md, propCid.Bytes())
636638
}
637639

638-
func (w *Wrapper) AnnounceBoostDealMetadata(ctx context.Context, md metadata.GraphsyncFilecoinV1, propCid cid.Cid) (cid.Cid, error) {
640+
func (w *Wrapper) AnnounceBoostDealMetadata(ctx context.Context, md metadata.GraphsyncFilecoinV1, contextID []byte) (cid.Cid, error) {
639641
if !w.enabled {
640642
return cid.Undef, errors.New("cannot announce deal: index provider is disabled")
641643
}
@@ -648,7 +650,7 @@ func (w *Wrapper) AnnounceBoostDealMetadata(ctx context.Context, md metadata.Gra
648650

649651
// Announce deal to network Indexer
650652
fm := metadata.Default.New(&md)
651-
annCid, err := w.prov.NotifyPut(ctx, nil, propCid.Bytes(), fm)
653+
annCid, err := w.prov.NotifyPut(ctx, nil, contextID, fm)
652654
if err != nil {
653655
// Check if the error is because the deal was already advertised
654656
// (we can safely ignore this error)
@@ -684,3 +686,19 @@ type basicDealInfo struct {
684686
SectorID abi.SectorID
685687
DealProposal storagemarket.ClientDealProposal
686688
}
689+
690+
func (w *Wrapper) AnnounceBoostDirectDeal(ctx context.Context, entry *types.DirectDeal) (cid.Cid, error) {
691+
// Filter out deals that should not be announced
692+
if !entry.AnnounceToIPNI {
693+
return cid.Undef, nil
694+
}
695+
696+
contextID := []byte(entry.AllocationID.Key())
697+
698+
md := metadata.GraphsyncFilecoinV1{
699+
PieceCID: entry.PieceCID,
700+
FastRetrieval: entry.KeepUnsealedCopy,
701+
VerifiedDeal: true,
702+
}
703+
return w.AnnounceBoostDealMetadata(ctx, md, contextID)
704+
}

node/modules/directdeals.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func NewDirectDealsProvider(provAddr address.Address, cfg *config.Boost) func(lc
6060
RemoteCommp: cfg.Dealmaking.RemoteCommp,
6161
}
6262

63-
prov := storagemarket.NewDirectDealsProvider(ddpCfg, fullnodeApi, secb, commpc, directDealsDB, dl)
63+
prov := storagemarket.NewDirectDealsProvider(ddpCfg, fullnodeApi, secb, commpc, directDealsDB, dl, piecedirectory, ip)
6464
return prov, nil
6565
}
6666
}

storagemarket/direct_deals_provider.go

Lines changed: 73 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ import (
1212
"github.com/davecgh/go-spew/spew"
1313
"github.com/filecoin-project/boost/api"
1414
"github.com/filecoin-project/boost/db"
15+
"github.com/filecoin-project/boost/indexprovider"
16+
"github.com/filecoin-project/boost/piecedirectory"
1517
"github.com/filecoin-project/boost/storagemarket/logs"
1618
"github.com/filecoin-project/boost/storagemarket/types"
1719
smtypes "github.com/filecoin-project/boost/storagemarket/types"
1820
"github.com/filecoin-project/boost/storagemarket/types/dealcheckpoints"
21+
"github.com/filecoin-project/boostd-data/model"
1922
"github.com/filecoin-project/go-address"
2023
"github.com/filecoin-project/go-state-types/abi"
2124
"github.com/filecoin-project/go-state-types/builtin/v12/miner"
@@ -52,9 +55,13 @@ type DirectDealsProvider struct {
5255

5356
runningLk sync.RWMutex
5457
running map[uuid.UUID]struct{}
58+
59+
piecedirectory *piecedirectory.PieceDirectory
60+
ip *indexprovider.Wrapper
5561
}
5662

57-
func NewDirectDealsProvider(cfg DDPConfig, fullnodeApi v1api.FullNode, pieceAdder types.PieceAdder, commpCalc smtypes.CommpCalculator, directDealsDB *db.DirectDataDB, dealLogger *logs.DealLogger) *DirectDealsProvider {
63+
func NewDirectDealsProvider(cfg DDPConfig, fullnodeApi v1api.FullNode, pieceAdder types.PieceAdder, commpCalc smtypes.CommpCalculator, directDealsDB *db.DirectDataDB, dealLogger *logs.DealLogger,
64+
piecedirectory *piecedirectory.PieceDirectory, ip *indexprovider.Wrapper) *DirectDealsProvider {
5865
return &DirectDealsProvider{
5966
config: cfg,
6067
fullnodeApi: fullnodeApi,
@@ -66,8 +73,10 @@ func NewDirectDealsProvider(cfg DDPConfig, fullnodeApi v1api.FullNode, pieceAdde
6673
//logsSqlDB: logsSqlDB,
6774
//logsDB: logsDB,
6875

69-
dealLogger: dealLogger,
70-
running: make(map[uuid.UUID]struct{}),
76+
dealLogger: dealLogger,
77+
running: make(map[uuid.UUID]struct{}),
78+
piecedirectory: piecedirectory,
79+
ip: ip,
7180
}
7281
}
7382

@@ -295,6 +304,8 @@ func (ddp *DirectDealsProvider) execDeal(ctx context.Context, entry *smtypes.Dir
295304
}
296305
}
297306

307+
entry.InboundFileSize = fstat.Size()
308+
298309
log.Infow("direct deal details", "filepath", entry.InboundFilePath, "supplied-piececid", entry.PieceCID, "calculated-piececid", generatedPieceInfo.PieceCID, "calculated-piecesize", generatedPieceInfo.Size, "os stat size", fstat.Size())
299310

300311
if !entry.PieceCID.Equals(generatedPieceInfo.PieceCID) {
@@ -399,9 +410,19 @@ func (ddp *DirectDealsProvider) execDeal(ctx context.Context, entry *smtypes.Dir
399410
}
400411
}
401412

402-
if entry.Checkpoint <= dealcheckpoints.AddedPiece {
403-
// add index and announce
404-
ddp.dealLogger.Infow(dealUuid, "index and announce")
413+
// Index and announce the deal
414+
if entry.Checkpoint < dealcheckpoints.IndexedAndAnnounced {
415+
if err := ddp.indexAndAnnounce(ctx, entry); err != nil {
416+
err.error = fmt.Errorf("failed to add index and announce deal: %w", err.error)
417+
return err
418+
}
419+
if entry.AnnounceToIPNI {
420+
ddp.dealLogger.Infow(entry.ID, "deal successfully indexed and announced")
421+
} else {
422+
ddp.dealLogger.Infow(entry.ID, "deal successfully indexed")
423+
}
424+
} else {
425+
ddp.dealLogger.Infow(entry.ID, "deal has already been indexed and announced")
405426
}
406427

407428
return nil
@@ -507,3 +528,49 @@ func (ddp *DirectDealsProvider) FailPausedDeal(ctx context.Context, id uuid.UUID
507528

508529
return nil
509530
}
531+
532+
func (ddp *DirectDealsProvider) indexAndAnnounce(ctx context.Context, entry *smtypes.DirectDeal) *dealMakingError {
533+
// add deal to piece metadata store
534+
ddp.dealLogger.Infow(entry.ID, "about to add direct deal for piece in LID")
535+
if err := ddp.piecedirectory.AddDealForPiece(ctx, entry.PieceCID, model.DealInfo{
536+
DealUuid: entry.ID.String(),
537+
ChainDealID: abi.DealID(entry.AllocationID), // Convert the type to avoid migration as underlying types are same
538+
MinerAddr: entry.Provider,
539+
SectorID: entry.SectorID,
540+
PieceOffset: entry.Offset,
541+
PieceLength: entry.Length,
542+
CarLength: uint64(entry.InboundFileSize),
543+
}); err != nil {
544+
return &dealMakingError{
545+
retry: types.DealRetryAuto,
546+
error: fmt.Errorf("failed to add deal to piece metadata store: %w", err),
547+
}
548+
}
549+
ddp.dealLogger.Infow(entry.ID, "direct deal successfully added to LID")
550+
551+
// if the index provider is enabled
552+
if ddp.ip.Enabled() {
553+
if entry.AnnounceToIPNI {
554+
// announce to the network indexer but do not fail the deal if the announcement fails,
555+
// just retry the next time boost restarts
556+
annCid, err := ddp.ip.AnnounceBoostDirectDeal(ctx, entry)
557+
if err != nil {
558+
return &dealMakingError{
559+
retry: types.DealRetryAuto,
560+
error: fmt.Errorf("failed to announce deal to network indexer: %w", err),
561+
}
562+
}
563+
ddp.dealLogger.Infow(entry.ID, "announced the direct deal to network indexer", "announcement-cid", annCid)
564+
} else {
565+
ddp.dealLogger.Infow(entry.ID, "didn't announce the direct deal as requested in the deal proposal")
566+
}
567+
} else {
568+
ddp.dealLogger.Infow(entry.ID, "didn't announce the direct deal because network indexer is disabled")
569+
}
570+
571+
if derr := ddp.updateCheckpoint(ctx, entry, dealcheckpoints.IndexedAndAnnounced); derr != nil {
572+
return derr
573+
}
574+
575+
return nil
576+
}

storagemarket/types/direct_data.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/filecoin-project/go-state-types/abi"
1010
verifregtypes "github.com/filecoin-project/go-state-types/builtin/v9/verifreg"
1111
"github.com/google/uuid"
12-
cid "github.com/ipfs/go-cid"
12+
"github.com/ipfs/go-cid"
1313
)
1414

1515
// DirectDeal is the local state tracked for direct data onboard.
@@ -32,6 +32,7 @@ type DirectDeal struct {
3232

3333
// InboundCARPath is the file-path where the storage provider will persist the CAR file sent by the client.
3434
InboundFilePath string
35+
InboundFileSize int64
3536

3637
// sector packing info
3738
SectorID abi.SectorNumber

0 commit comments

Comments
 (0)