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
DealSealing
DealComplete
// Client specific
DealError // deal failed with an unexpected error
DealExpired
)
// 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) {
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
err := c.deals.MutateClient(update.id, func(d *ClientDeal) error {
d.State = update.newState
deal = *d
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 {
c.failDeal(update.id, err)
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) {
go func() {
err := cb(ctx, deal)
if err != nil {
next = api.DealError
}
select {
case c.updated <- clientDealUpdate{
newState: next,

View File

@ -17,10 +17,6 @@ import (
)
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 {
_, f, l, _ := runtime.Caller(1)
cerr = xerrors.Errorf("unknown error (fail called at %s:%d)", f, l)

View File

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