deals: don't throw away failed deals

This commit is contained in:
Łukasz Magiera 2019-09-13 21:43:33 +02:00
parent 9c276e5331
commit 1ba1df3cac
5 changed files with 15 additions and 9 deletions

View File

@ -17,6 +17,11 @@ const (
DealStaged DealStaged
DealSealing DealSealing
DealComplete DealComplete
// Client specific
DealError // deal failed with an unexpected error
DealExpired
) )
// TODO: check if this exists anywhere else // TODO: check if this exists anywhere else

View File

@ -132,17 +132,17 @@ func (c *Client) onIncoming(deal ClientDeal) {
func (c *Client) onUpdated(ctx context.Context, update clientDealUpdate) { func (c *Client) onUpdated(ctx context.Context, update clientDealUpdate) {
log.Infof("Deal %s updated state to %d", update.id, update.newState) log.Infof("Deal %s updated state to %d", update.id, update.newState)
if update.err != nil {
log.Errorf("deal %s failed: %s", update.id, update.err)
c.failDeal(update.id, update.err)
return
}
var deal ClientDeal var deal ClientDeal
err := c.deals.MutateClient(update.id, func(d *ClientDeal) error { err := c.deals.MutateClient(update.id, func(d *ClientDeal) error {
d.State = update.newState d.State = update.newState
deal = *d deal = *d
return nil return nil
}) })
if update.err != nil {
log.Errorf("deal %s failed: %s", update.id, update.err)
c.failDeal(update.id, update.err)
return
}
if err != nil { if err != nil {
c.failDeal(update.id, err) c.failDeal(update.id, err)
return return

View File

@ -15,6 +15,9 @@ type clientHandlerFunc func(ctx context.Context, deal ClientDeal) error
func (c *Client) handle(ctx context.Context, deal ClientDeal, cb clientHandlerFunc, next api.DealState) { func (c *Client) handle(ctx context.Context, deal ClientDeal, cb clientHandlerFunc, next api.DealState) {
go func() { go func() {
err := cb(ctx, deal) err := cb(ctx, deal)
if err != nil {
next = api.DealError
}
select { select {
case c.updated <- clientDealUpdate{ case c.updated <- clientDealUpdate{
newState: next, newState: next,

View File

@ -17,10 +17,6 @@ import (
) )
func (c *Client) failDeal(id cid.Cid, cerr error) { func (c *Client) failDeal(id cid.Cid, cerr error) {
if err := c.deals.End(id); err != nil {
log.Warnf("deals.End: %s", err)
}
if cerr == nil { if cerr == nil {
_, f, l, _ := runtime.Caller(1) _, f, l, _ := runtime.Caller(1)
cerr = xerrors.Errorf("unknown error (fail called at %s:%d)", f, l) cerr = xerrors.Errorf("unknown error (fail called at %s:%d)", f, l)

View File

@ -11,6 +11,8 @@ const dealStates = [
"Staged", "Staged",
"Sealing", "Sealing",
"Complete", "Complete",
"Error",
"Expired"
] ]