Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Drop active retrieval check #764

Merged
merged 1 commit into from
Nov 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 1 addition & 34 deletions retrievalmarket/impl/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package retrievalimpl
import (
"context"
"errors"
"fmt"
"sync"

"github.com/hannahhoward/go-pubsub"
Expand Down Expand Up @@ -256,14 +255,7 @@ func (c *Client) Retrieve(
c.retrieveLk.Lock()
defer c.retrieveLk.Unlock()

// Check if there's already an active retrieval deal with the same peer
// for the same payload CID
err := c.checkForActiveDeal(payloadCID, p.ID)
if err != nil {
return 0, err
}

err = c.addMultiaddrs(ctx, p)
err := c.addMultiaddrs(ctx, p)
if err != nil {
return 0, err
}
Expand Down Expand Up @@ -307,31 +299,6 @@ func (c *Client) Retrieve(
return id, nil
}

// Check if there's already an active retrieval deal with the same peer
// for the same payload CID
func (c *Client) checkForActiveDeal(payloadCID cid.Cid, pid peer.ID) error {
var deals []retrievalmarket.ClientDealState
err := c.stateMachines.List(&deals)
if err != nil {
return err
}

for _, deal := range deals {
match := deal.Sender == pid && deal.PayloadCID == payloadCID
active := !clientstates.IsFinalityState(deal.Status)
if match && active {
msg := fmt.Sprintf("there is an active retrieval deal with peer %s ", pid)
msg += fmt.Sprintf("for payload CID %s ", payloadCID)
msg += fmt.Sprintf("(retrieval deal ID %d, state %s) - ",
deal.ID, retrievalmarket.DealStatuses[deal.Status])
msg += "existing deal must be cancelled before starting a new retrieval deal"
err := xerrors.Errorf(msg)
return err
}
}
return nil
}

func (c *Client) notifySubscribers(eventName fsm.EventName, state fsm.StateType) {
evt := eventName.(retrievalmarket.ClientEvent)
ds := state.(retrievalmarket.ClientDealState)
Expand Down