2019-08-02 14:09:54 +00:00
|
|
|
package deals
|
|
|
|
|
|
|
|
import (
|
2019-10-31 03:00:02 +00:00
|
|
|
"bytes"
|
|
|
|
"errors"
|
|
|
|
|
2019-10-21 18:12:11 +00:00
|
|
|
"github.com/filecoin-project/lotus/api"
|
2019-10-18 04:47:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/actors"
|
|
|
|
"github.com/filecoin-project/lotus/chain/address"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
2019-11-07 14:11:39 +00:00
|
|
|
"github.com/filecoin-project/lotus/lib/cborutil"
|
2019-10-22 10:20:43 +00:00
|
|
|
"github.com/ipfs/go-cid"
|
2019-08-02 14:09:54 +00:00
|
|
|
)
|
|
|
|
|
2019-10-31 03:00:02 +00:00
|
|
|
var (
|
|
|
|
// ErrWrongVoucherType means the voucher was not the correct type can validate against
|
|
|
|
ErrWrongVoucherType = errors.New("cannot validate voucher type")
|
|
|
|
|
|
|
|
// ErrNoPushAccepted just means clients do not accept pushes for storage deals
|
|
|
|
ErrNoPushAccepted = errors.New("Client should not receive data for a storage deal")
|
|
|
|
|
|
|
|
// ErrNoPullAccepted just means providers do not accept pulls for storage deals
|
|
|
|
ErrNoPullAccepted = errors.New("Provider should not send data for a storage deal")
|
|
|
|
|
|
|
|
// ErrNoDeal means no active deal was found for this vouchers proposal cid
|
|
|
|
ErrNoDeal = errors.New("No deal found for this proposal")
|
|
|
|
|
|
|
|
// ErrWrongPeer means that the other peer for this data transfer request does not match
|
|
|
|
// the other peer for the deal
|
|
|
|
ErrWrongPeer = errors.New("Data Transfer peer id and Deal peer id do not match")
|
|
|
|
|
|
|
|
// ErrWrongPiece means that the pieceref for this data transfer request does not match
|
|
|
|
// the one specified in the deal
|
|
|
|
ErrWrongPiece = errors.New("Base CID for deal does not match CID for piece")
|
|
|
|
|
|
|
|
// ErrInacceptableDealState means the deal for this transfer is not in a deal state
|
|
|
|
// where transfer can be performed
|
|
|
|
ErrInacceptableDealState = errors.New("Deal is not a in a state where deals are accepted")
|
|
|
|
|
|
|
|
// AcceptableDealStates are the states in which it would make sense to actually start a data transfer
|
|
|
|
AcceptableDealStates = []api.DealState{api.DealAccepted, api.DealUnknown}
|
|
|
|
)
|
|
|
|
|
2019-11-06 17:38:42 +00:00
|
|
|
const DealProtocolID = "/fil/storage/mk/1.0.1"
|
|
|
|
const AskProtocolID = "/fil/storage/ask/1.0.1"
|
2019-09-10 12:35:43 +00:00
|
|
|
|
2019-10-21 18:12:11 +00:00
|
|
|
type Proposal struct {
|
2019-11-06 17:38:42 +00:00
|
|
|
DealProposal *actors.StorageDealProposal
|
|
|
|
|
|
|
|
Piece cid.Cid // Used for retrieving from the client
|
2019-08-02 14:09:54 +00:00
|
|
|
}
|
|
|
|
|
2019-10-22 10:20:43 +00:00
|
|
|
type Response struct {
|
2019-09-10 14:13:24 +00:00
|
|
|
State api.DealState
|
2019-08-02 14:09:54 +00:00
|
|
|
|
2019-10-21 18:12:11 +00:00
|
|
|
// DealProposalRejected
|
2019-08-02 14:09:54 +00:00
|
|
|
Message string
|
|
|
|
Proposal cid.Cid
|
|
|
|
|
2019-10-21 18:12:11 +00:00
|
|
|
// DealAccepted
|
2019-10-23 12:59:57 +00:00
|
|
|
StorageDeal *actors.StorageDeal
|
|
|
|
PublishMessage *cid.Cid
|
2019-08-02 14:09:54 +00:00
|
|
|
}
|
|
|
|
|
2019-10-21 18:12:11 +00:00
|
|
|
// TODO: Do we actually need this to be signed?
|
2019-10-22 10:20:43 +00:00
|
|
|
type SignedResponse struct {
|
|
|
|
Response Response
|
2019-08-02 14:09:54 +00:00
|
|
|
|
2019-08-02 16:25:10 +00:00
|
|
|
Signature *types.Signature
|
2019-08-02 14:09:54 +00:00
|
|
|
}
|
2019-09-13 21:00:36 +00:00
|
|
|
|
2019-11-07 14:09:11 +00:00
|
|
|
func (r *SignedResponse) Verify(addr address.Address) error {
|
2019-11-07 14:11:39 +00:00
|
|
|
b, err := cborutil.Dump(&r.Response)
|
2019-11-07 14:09:11 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return r.Signature.Verify(addr, b)
|
|
|
|
}
|
|
|
|
|
2019-09-13 21:00:36 +00:00
|
|
|
type AskRequest struct {
|
|
|
|
Miner address.Address
|
|
|
|
}
|
|
|
|
|
|
|
|
type AskResponse struct {
|
|
|
|
Ask *types.SignedStorageAsk
|
|
|
|
}
|
2019-10-31 03:00:02 +00:00
|
|
|
|
|
|
|
// StorageDataTransferVoucher is the voucher type for data transfers
|
|
|
|
// used by the storage market
|
|
|
|
type StorageDataTransferVoucher struct {
|
|
|
|
Proposal cid.Cid
|
|
|
|
}
|
|
|
|
|
|
|
|
// ToBytes converts the StorageDataTransferVoucher to raw bytes
|
|
|
|
func (dv *StorageDataTransferVoucher) ToBytes() ([]byte, error) {
|
|
|
|
var buf bytes.Buffer
|
|
|
|
err := dv.MarshalCBOR(&buf)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return buf.Bytes(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// FromBytes converts the StorageDataTransferVoucher to raw bytes
|
|
|
|
func (dv *StorageDataTransferVoucher) FromBytes(raw []byte) error {
|
|
|
|
r := bytes.NewReader(raw)
|
|
|
|
return dv.UnmarshalCBOR(r)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Identifier is the unique string identifier for a StorageDataTransferVoucher
|
|
|
|
func (dv *StorageDataTransferVoucher) Identifier() string {
|
|
|
|
return "StorageDataTransferVoucher"
|
|
|
|
}
|