2019-09-10 12:35:43 +00:00
|
|
|
package deals
|
|
|
|
|
|
|
|
import (
|
|
|
|
"runtime"
|
|
|
|
|
|
|
|
"github.com/ipfs/go-cid"
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
2019-10-18 04:47:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/lib/cborrpc"
|
2019-09-10 12:35:43 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (c *Client) failDeal(id cid.Cid, cerr error) {
|
|
|
|
if cerr == nil {
|
|
|
|
_, f, l, _ := runtime.Caller(1)
|
|
|
|
cerr = xerrors.Errorf("unknown error (fail called at %s:%d)", f, l)
|
|
|
|
}
|
|
|
|
|
|
|
|
s, ok := c.conns[id]
|
|
|
|
if ok {
|
|
|
|
_ = s.Reset()
|
|
|
|
delete(c.conns, id)
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: store in some sort of audit log
|
|
|
|
log.Errorf("deal %s failed: %s", id, cerr)
|
|
|
|
}
|
|
|
|
|
2019-10-22 10:20:43 +00:00
|
|
|
func (c *Client) readStorageDealResp(deal ClientDeal) (*Response, error) {
|
2019-09-10 12:35:43 +00:00
|
|
|
s, ok := c.conns[deal.ProposalCid]
|
|
|
|
if !ok {
|
|
|
|
// TODO: Try to re-establish the connection using query protocol
|
|
|
|
return nil, xerrors.Errorf("no connection to miner")
|
|
|
|
}
|
|
|
|
|
2019-10-22 10:20:43 +00:00
|
|
|
var resp SignedResponse
|
2019-09-10 12:35:43 +00:00
|
|
|
if err := cborrpc.ReadCborRPC(s, &resp); err != nil {
|
2019-10-22 10:20:43 +00:00
|
|
|
log.Errorw("failed to read Response message", "error", err)
|
2019-09-10 12:35:43 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: verify signature
|
|
|
|
|
|
|
|
if resp.Response.Proposal != deal.ProposalCid {
|
|
|
|
return nil, xerrors.New("miner responded to a wrong proposal")
|
|
|
|
}
|
|
|
|
|
|
|
|
return &resp.Response, nil
|
|
|
|
}
|