deals: don't throw away failed deals
This commit is contained in:
parent
9c276e5331
commit
1ba1df3cac
@ -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
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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)
|
||||
|
@ -11,6 +11,8 @@ const dealStates = [
|
||||
"Staged",
|
||||
"Sealing",
|
||||
"Complete",
|
||||
"Error",
|
||||
"Expired"
|
||||
]
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user