2019-08-02 14:09:54 +00:00
|
|
|
package deals
|
|
|
|
|
|
|
|
import (
|
2019-10-31 03:00:02 +00:00
|
|
|
"bytes"
|
|
|
|
"errors"
|
|
|
|
|
2019-12-19 20:13:17 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
2020-01-07 14:00:10 +00:00
|
|
|
"github.com/filecoin-project/go-cbor-util"
|
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/types"
|
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
|
2019-11-11 21:02:49 +00:00
|
|
|
ErrWrongVoucherType = errors.New("cannot validate voucher type.")
|
2019-10-31 03:00:02 +00:00
|
|
|
|
|
|
|
// ErrNoPushAccepted just means clients do not accept pushes for storage deals
|
2019-11-11 21:02:49 +00:00
|
|
|
ErrNoPushAccepted = errors.New("client should not receive data for a storage deal.")
|
2019-10-31 03:00:02 +00:00
|
|
|
|
|
|
|
// ErrNoPullAccepted just means providers do not accept pulls for storage deals
|
2019-11-11 21:02:49 +00:00
|
|
|
ErrNoPullAccepted = errors.New("provider should not send data for a storage deal.")
|
2019-10-31 03:00:02 +00:00
|
|
|
|
|
|
|
// ErrNoDeal means no active deal was found for this vouchers proposal cid
|
2019-11-11 21:02:49 +00:00
|
|
|
ErrNoDeal = errors.New("no deal found for this proposal.")
|
2019-10-31 03:00:02 +00:00
|
|
|
|
|
|
|
// ErrWrongPeer means that the other peer for this data transfer request does not match
|
|
|
|
// the other peer for the deal
|
2019-11-11 21:02:49 +00:00
|
|
|
ErrWrongPeer = errors.New("data Transfer peer id and Deal peer id do not match.")
|
2019-10-31 03:00:02 +00:00
|
|
|
|
|
|
|
// ErrWrongPiece means that the pieceref for this data transfer request does not match
|
|
|
|
// the one specified in the deal
|
2019-11-11 21:02:49 +00:00
|
|
|
ErrWrongPiece = errors.New("base CID for deal does not match CID for piece.")
|
2019-10-31 03:00:02 +00:00
|
|
|
|
|
|
|
// ErrInacceptableDealState means the deal for this transfer is not in a deal state
|
|
|
|
// where transfer can be performed
|
2019-11-11 21:02:49 +00:00
|
|
|
ErrInacceptableDealState = errors.New("deal is not a in a state where deals are accepted.")
|
2019-10-31 03:00:02 +00:00
|
|
|
|
2019-11-11 20:25:19 +00:00
|
|
|
// DataTransferStates are the states in which it would make sense to actually start a data transfer
|
2019-11-11 20:08:15 +00:00
|
|
|
DataTransferStates = []api.DealState{api.DealAccepted, api.DealUnknown}
|
2019-10-31 03:00:02 +00:00
|
|
|
)
|
|
|
|
|
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-12-07 14:12:10 +00:00
|
|
|
StorageDealSubmission *types.SignedMessage
|
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
|
2019-12-01 20:07:42 +00:00
|
|
|
DealID uint64
|
2019-10-31 03:00:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
}
|
|
|
|
|
feat(datatransfer): implement and extract
feat(datatransfer): setup implementation path
Sets up a path to implementation, offering both the dagservice implementation and a future graphsync
implement, establishes message interfaces and network layer, and isolates the datatransfer module
from the app
WIP using CBOR encoding for dataxfermsg
* Bring cbor-gen stuff into datatransfer package
* make transferRequest private struct
* add transferResponse + funcs
* Rename VoucherID to VoucherType
* more tests passing
WIP trying out some stuff
* Embed request/response in message so all the interfaces work AND the CBOR unmarshaling works: this is more like the spec anyway
* get rid of pb stuff
all message tests passing, some others in datatransfer
Some cleanup for PR
Cleanup for PR, clarifying and additional comments
mod tidy
Respond to PR comments:
* Make DataTransferRequest/Response be returned in from Net
* Regenerate cbor_gen and fix the generator caller so it works better
* Please the linters
Fix tests
Initiate push and pull requests (#536)
* add issue link for data TransferID generation
* comment out failing but not relevant tests
* finish voucher rename from Identifier --> Type
tests passing
cleanup for PR
remove unused fmt import in graphsync_test
a better reflection
send data transfer response
other tests passing
feat(datatransfer): milestone 2 infrastructure
Setup test path for all tickets for milestone 2
responses alert subscribers when request is not accepted (#607)
Graphsync response is scheduled when a valid push request is received (#625)
fix(datatransfer): fix tests
fix an error with read buffers in tests
fix(deps): fix go.sum
Feat/dt graphsync pullreqs (#627)
* graphsync responses to pull requests
Feat/dt initiator cleanup (#645)
* ChannelID.To --> ChannelID.Initiator
* We now store our peer ID (from host.ID()) so it can be used when creating ChannelIDs.
* InProgressChannels returns all of impl.channels, currently just for testing
* Implements go-data-transfer issue
* Some assertions were changed based on the above.
* Renamed some variables and added some assertions based on the new understanding
* Updated SHA for graphsync module
* Updated fakeGraphSync test structs to use new interfaces from new SHA above
Techdebt/dt split graphsync impl receiver (#651)
* Split up graphsyncImpl and graphsyncReceiver
* rename graphsync to utils
DTM sends data over graphsync for validated push requests (#665)
* create channels when a request is received. register push request hook with graphsync. fix tests.
* better NewReaders
* use mutex lock around impl.channels access
* fix(datatransfer): fix test uncertainty
* fix a data race and also don't use random bytes in basic block which can fail
* privatize 3 funcs
with @hannahhoward
Feat/dt gs pullrequests (#693)
* Implements DTM Sends Data Over Graphsync For Validated Pull Requests
* rename a field in a test struct
* refactor a couple of private functions (one was refactored out of existence)
Feat/dt subscribe, file Xfer round trip (#720)
Implements the rest of Subscriber Is Notified When Request Completed #24:
* send a graphsync message within a go func and consume responses until error or transfer is complete.
* notify subscribers of results.
* Rename datatransfer.Event to EventCode.
* datatransfer.Event is now a struct that includes a message and a timestamp as well as the Event.Code int, formerly Event, update all uses
* Add extension data to graphsync request hook, gsReq
* rename sendRequest to sendDtRequest, to distinguish it from sendGsRequest, where Dt = datatransfer, Gs = graphsync
* use a mutex lock for last transfer ID
* obey the linter
Don't respond with error in gsReqRcdHook when we can't find the datatransfer extension. (#754)
* update to correct graphsync version, update tests & code to call the new graphsync hooks
* getExtensionData returns an empty struct + nil if we can't find our extension
* Don't respond with error when we can't find the extension.
* Test for same
* mod tidy
minor fix to go.sum
feat(datatransfer): switch to graphsync implementation
Move over to real graphsync implementation of data transfer, add constructors for graphsync
instances on client and miner side
fix(datatransfer): Fix validators
Validators were checking payload cid against commP -- which are not the same any more. Added a
payloadCid to client deal to maintain the record, fixed validator logic
Feat/dt extraction use go-fil-components/datatransfer (#770)
* Initial commit after changing to go-fil-components/datatransfer
* blow away the datatransfer dir
* use go-fil-components master after its PR #1 was merged
* go mod tidy
use a package
updates after rebase with master
2019-10-30 02:42:16 +00:00
|
|
|
// Type is the unique string identifier for a StorageDataTransferVoucher
|
|
|
|
func (dv *StorageDataTransferVoucher) Type() string {
|
2019-10-31 03:00:02 +00:00
|
|
|
return "StorageDataTransferVoucher"
|
|
|
|
}
|