From 9ec17c89e980ecee5578333941c64bae96263684 Mon Sep 17 00:00:00 2001 From: alvin-reyes Date: Mon, 27 Feb 2023 01:47:05 -0500 Subject: [PATCH 1/2] initial --- deal/deal.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/deal/deal.go b/deal/deal.go index 897f3375..c9b98e91 100644 --- a/deal/deal.go +++ b/deal/deal.go @@ -288,6 +288,11 @@ func (m *manager) makeDealsForContent(ctx context.Context, contID uint64, dealsT )) defer span.End() + // set up delta as a separate instance but use the same BLOCKSTORE + // get the content id + // get the list of miners + // make deal for each content + content, err := m.contMgr.GetContent(contID) if err != nil { return err From b2564526ad585f39397bc7283fb83b24df89221e Mon Sep 17 00:00:00 2001 From: alvin-reyes Date: Mon, 27 Feb 2023 02:05:03 -0500 Subject: [PATCH 2/2] quick POC --- deal/deal.go | 47 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/deal/deal.go b/deal/deal.go index c9b98e91..819f6a1f 100644 --- a/deal/deal.go +++ b/deal/deal.go @@ -3,7 +3,9 @@ package deal import ( "bytes" "context" + "encoding/json" "fmt" + "net/http" "sync" "time" @@ -281,6 +283,14 @@ func (m *manager) CheckContentReadyForDealMaking(ctx context.Context, content *u return nil } +type DeltaRequest struct { + Cid string `json:"cid"` + Miner string `json:"miner"` + ConnectionMode string `json:"connection_mode"` + RemoveUnsealedCopies bool `json:"remove_unsealed_copies"` + SkipIpniAnnounce bool `json:"skip_ipni_announce"` +} + func (m *manager) makeDealsForContent(ctx context.Context, contID uint64, dealsToBeMade int) error { ctx, span := m.tracer.Start(ctx, "makeDealsForContent", trace.WithAttributes( attribute.Int64("content", int64(contID)), @@ -288,12 +298,14 @@ func (m *manager) makeDealsForContent(ctx context.Context, contID uint64, dealsT )) defer span.End() + var deltaRequest DeltaRequest // set up delta as a separate instance but use the same BLOCKSTORE // get the content id // get the list of miners // make deal for each content content, err := m.contMgr.GetContent(contID) + deltaRequest.Cid = content.Cid.CID.String() if err != nil { return err } @@ -337,14 +349,39 @@ func (m *manager) makeDealsForContent(ctx context.Context, contID uint64, dealsT continue } - if _, err := m.MakeDealWithMiner(ctx, content, mn.Address); err != nil { - m.log.Warnf("failed to make deal for cont: %d, with miner: %s - %s", contID, mn.Address, err) - continue + //if _, err := m.MakeDealWithMiner(ctx, content, mn.Address); err != nil { + // m.log.Warnf("failed to make deal for cont: %d, with miner: %s - %s", contID, mn.Address, err) + // continue + //} + + //if err := m.dealQueueMgr.MadeOneDeal(contID, m.db); err != nil { + // return err + //} + fmt.Println("making deal with miner: ", mn.Address.String()) + deltaRequest.Miner = mn.Address.String() + deltaRequest.ConnectionMode = "e2e" + deltaRequest.RemoveUnsealedCopies = true + deltaRequest.SkipIpniAnnounce = true + + // make the deal + payloadBytes, err := json.Marshal(deltaRequest) + if err != nil { + // handle err + } + body := bytes.NewReader(payloadBytes) + + req, err := http.NewRequest("POST", "http://localhost:1414/api/v1/deal/existing/content", body) + if err != nil { + // handle err } + req.Header.Set("Authorization", "Bearer [ESTUARY_API_KEY]") + req.Header.Set("Content-Type", "application/json") - if err := m.dealQueueMgr.MadeOneDeal(contID, m.db); err != nil { - return err + resp, err := http.DefaultClient.Do(req) + if err != nil { + // handle err } + defer resp.Body.Close() excludedMiners[mn.Address] = true break