Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/module docs #83 #267

Merged
merged 37 commits into from
May 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
b928ba9
start of storagemarket docs
shannonwells May 22, 2020
a909708
add links to modules, will later display the README when added.
shannonwells May 22, 2020
93cd33d
delete usage + links and direct readers to links in #components
shannonwells May 22, 2020
effe78f
Update README for storagemarket
shannonwells May 22, 2020
e1656c5
improve readability, add retrievalmarket README
shannonwells May 26, 2020
fb7b2af
block code formatting in storagemarket doc
shannonwells May 26, 2020
e1671cb
reduce scrolling
shannonwells May 26, 2020
7efbed1
more tweaks
shannonwells May 26, 2020
f2f17ee
more tweaks2
shannonwells May 26, 2020
661c9b3
more content to README
shannonwells May 26, 2020
1e17a11
README files, some content, some cleanup
shannonwells May 27, 2020
6c04b11
formatting
shannonwells May 27, 2020
66bfd45
fix broken link
shannonwells May 27, 2020
ccf7643
more content, retrieval market, remove links to design docs
shannonwells May 27, 2020
1bd35b7
formatting
shannonwells May 27, 2020
dbd9de9
add Construct a RetrievalProvider section
shannonwells May 27, 2020
ed2a3eb
Oxford frigging comma, darn right
shannonwells May 27, 2020
7d678d7
move or remove most piecestore doc
shannonwells May 28, 2020
ada80b0
add other puropse info to piecestore
shannonwells May 28, 2020
674769f
flesh out other module READMEs, some cleanup
shannonwells May 28, 2020
5720854
correct filestore entry on main README
shannonwells May 28, 2020
8c99793
add suggestions from @mishmosh
shannonwells May 28, 2020
ef07063
add ToC for storage and retrieval markets
shannonwells May 28, 2020
d141cc8
some consistency cleanup
shannonwells May 28, 2020
dc2e4d1
fix links
shannonwells May 28, 2020
792bd90
fix links2
shannonwells May 28, 2020
f6e465c
final touches?
shannonwells May 28, 2020
d9271d7
add some links
shannonwells May 28, 2020
49a8bad
fill in the blank
shannonwells May 28, 2020
761674c
another correction
shannonwells May 28, 2020
8ed2054
Update storagemarket/README.md
shannonwells May 28, 2020
ef4376d
Update storagemarket/README.md
shannonwells May 28, 2020
4bf5452
Update storagemarket/README.md
shannonwells May 28, 2020
7594156
Update storagemarket/README.md
shannonwells May 28, 2020
2cb63a2
include suggestions from @ingar
shannonwells May 28, 2020
9654c62
tweaks
shannonwells May 28, 2020
2132c05
added some detail
shannonwells May 28, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 19 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,36 @@
[![CircleCI](https://circleci.com/gh/filecoin-project/go-fil-markets.svg?style=svg)](https://circleci.com/gh/filecoin-project/go-fil-markets)
[![codecov](https://codecov.io/gh/filecoin-project/go-fil-markets/branch/master/graph/badge.svg)](https://codecov.io/gh/filecoin-project/go-fil-markets)

This repository contains modular implementations of the [storage and retrieval market subsystems](https://filecoin-project.github.io/specs/#systems__filecoin_markets) of Filecoin. They are guided by the [v1.0 and 1.1 Filecoin specification updates](https://filecoin-project.github.io/specs/#intro__changelog).
This repository contains modular implementations of the [storage and retrieval market subsystems](https://filecoin-project.github.io/specs/#systems__filecoin_markets) of Filecoin.
They are guided by the [v1.0 and 1.1 Filecoin specification updates](https://filecoin-project.github.io/specs/#intro__changelog).

Separating implementations into a blockchain component and one or more mining and market components presents an opportunity to encourage implementation diversity while reusing non-security-critical components.

## Components
shannonwells marked this conversation as resolved.
Show resolved Hide resolved

* **[filestore](./filestore)**: a submodule branch that is a side effect of using the ffi to generate commP
* **[pieceio](./pieceio)**: utilities that take IPLD graphs and turn them into pieces
* **[piecestore](/.piecestore)**:
* **[storage market](./storagemarket)**: for finding, negotiating, and consummating deals to store data between clients and providers (storage miners)
* **[retrieval market](./retrievalmarket)**: for finding, negotiating, and consummating deals to retrieve data between clients and providers (retrieval miners)
* **[storagemarket](./storagemarket)**: for finding, negotiating, and consummating deals to
store data between clients and providers (storage miners).
* **[retrievalmarket](./retrievalmarket)**: for finding, negotiating, and consummating deals to
retrieve data between clients and providers (retrieval miners).
* **[filestore](./filestore)**: a wrapper around os.File for use by pieceio, storagemarket, and retrievalmarket.
* **[pieceio](./pieceio)**: utilities that take IPLD graphs and turn them into pieces. Used by storagemarket.
* **[piecestore](./piecestore)**: a database for storing deal-related PieceInfo and CIDInfo.
Used by storagemarket and retrievalmarket.

Related components in other repos:
* **[data transfer](https://github.com/filecoin-project/go-data-transfer)**: for exchanging piece data between clients and miners, used by storage & retrieval market modules.
* **[go-data-transfer](https://github.com/filecoin-project/go-data-transfer)**: for exchanging piece data between clients and miners, used by storage & retrieval market modules.

### Background reading
* The [Markets in Filecoin](https://filecoin-project.github.io/specs/#systems__filecoin_markets) section of the Filecoin Specification contains the canonical spec
* The [Storage Market Module design doc](https://docs.google.com/document/d/1FfMUpW8vanR9FrXsybxBBbba7DzeyuCIN2uAXgE7J8U) is a more specific overview of these component implementations
* The [Markets in Filecoin](https://filecoin-project.github.io/specs/#systems__filecoin_markets)
section of the Filecoin Specification contains the canonical spec.

shannonwells marked this conversation as resolved.
Show resolved Hide resolved
## Usage

**Requires go 1.13**

Install the go-fil-markets module(s) that you want to use. Available modules are:
* `filestore`
* `pieceio`
* `piecestore`
* `retrievalmarket`
* `storagemarket`
## Installation
```bash
go get "github.com/filecoin-project/go-fil-markets/<MODULENAME>"`
```

Install with:
`go get "github.com/filecoin-project/go-fil-markets/<MODULENAME>"`

TODO: usage for each module (maybe in subdirectories)
## Usage
Documentation is in the README for each module, listed in [Components](#Components).

## Contributing
Issues and PRs are welcome! Please first read the [background reading](#background-reading) and [CONTRIBUTING](.go-fil-markets/CONTRIBUTING.md) guide, and look over the current code. PRs against master require approval of at least two maintainers.
Expand Down
29 changes: 29 additions & 0 deletions filestore/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# filestore

The `filestore` module is a simple wrapper for os.File. It is used by [pieceio](../pieceio),
[retrievialmarket](../retrievalmarket), and [storagemarket](../storagemarket).
Comment on lines +3 to +4
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would add the following:

Suggested change
The `filestore` module is a simple wrapper for os.File. It is used by [pieceio](../pieceio),
[retrievialmarket](../retrievalmarket), and [storagemarket](../storagemarket).
The `filestore` module is a simple wrapper for os.File. It's primary purpose to wrap a specific local directory configured by the node. It is used by [pieceio](../pieceio),
[retrievialmarket](../retrievalmarket), and [storagemarket](../storagemarket).


## Installation
```bash
go get github.com/filecoin-project/go-fil-markets/filestore
```

## FileStore
FileStore is the primary export of this module.

### Usage
To create a new local filestore mounted on a given local directory path, use:
```go
package filestore

func NewLocalFileStore(basedirectory OsPath) (FileStore, error)
```

A FileStore provides the following functions:
* [`Open`](filestore.go)
* [`Create`](filestore.go)
* [`Store`](filestore.go)
* [`Delete`](filestore.go)
* [`CreateTemp`](filestore.go)

Please the [tests](filestore_test.go) for more information about expected behavior.
54 changes: 54 additions & 0 deletions pieceio/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# pieceio

The pieceio module is a collection of structs for generating piece commitments (a.k.a. CommP) and
storing pieces for storage market deals. It is used by the
[`storagemarket`](../storagemarket) module.

## Installation
```bash
go get github.com/filecoin-project/go-fil-markets/pieceio
```

## PieceIO
`PieceIO` is used by [`storagemarket`](../storagemarket) client for proposing deals.

**To initialize a PieceIO:**
```go
package pieceio

func NewPieceIO(carIO CarIO, bs blockstore.Blockstore) PieceIO
```
**Parameters**
* `carIO` is a [CarIO](#CarIO) from this module
* `bs` is an IPFS blockstore for storing and retrieving data for deals. See
[github.com/ipfs/go-ipfs-blockstore](github.com/ipfs/go-ipfs-blockstore).

## PieceIOWithStore
`PieceIOWithStore` is `PieceIO` with a [`filestore`](../filestore). It is used by
[`storagemarket`](../storagemarket) provider to store pieces, and to generate and store piece commitments
and piece metadata for deals.

**To initialize a PieceIOWithStore:**

```go
package pieceio

func NewPieceIOWithStore(carIO CarIO, store filestore.FileStore, bs blockstore.Blockstore) PieceIOWithStore
```
**Parameters**
* `carIO` is a [CarIO](#CarIO) from this module
* `store` is a [FileStore](../filestore) from this go-fil-markets repo.
* `bs` is an IPFS blockstore for storing and retrieving data for deals. See
[github.com/ipfs/go-ipfs-blockstore](github.com/ipfs/go-ipfs-blockstore).

## CarIO
CarIO is a utility module that wraps [github.com/ipld/go-car](https://github.com/ipld/go-car) for use by storagemarket.

**To initialize a CarIO:**
```go
package cario

func NewCarIO() pieceio.CarIO
```

Please the [tests](pieceio_test.go) for more information about expected behavior.
48 changes: 48 additions & 0 deletions piecestore/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# piecestore

The `piecestore` module is a simple encapsulation of two data stores, one for `PieceInfo` and
another for `CIDInfo`. The piecestore's main goal is to help
[storagemarket module](../storagemarket) and [retrievalmarket module](../retrievalmarket)
find where sealed data lives inside of sectors. Storage market writes the
data, and retrieval market reads it.

Both markets use `CIDInfo` to look up a Piece that contains the payload, and then
use `PieceInfo` to find the sector that contains the piece.

The storage market has to write this data before it completes the deal in order to later
look up the payload when the data is served.

## Installation
```bash
go get github.com/filecoin-project/go-fil-markets/piecestore
```

### PieceStore
`PieceStore` is primary export of this module. It is a database
of piece info that can be modified and queried. The PieceStore
interface is implemented in [piecestore.go](./piecestore.go).

It has two stores, one for `PieceInfo` keyed by `pieceCID`, and another for
`CIDInfo`, keyed by `payloadCID`. These keys are of type `cid.CID`; see
[github.com/ipfs/go-cid](https://github.com/ipfs/go-cid).

**To initialize a PieceStore**
```go
func NewPieceStore(ds datastore.Batching) PieceStore
```

**Parameters**
* `ds datastore.Batching` is a datastore for the deal's state machine. It is
typically the node's own datastore that implements the IPFS datastore.Batching interface.
See
[github.com/ipfs/go-datastore](https://github.com/ipfs/go-datastore).


`PieceStore` implements the following functions:

* [`AddDealForPiece`](./piecestore.go)
* [`AddPieceBlockLocations`](./piecestore.go)
* [`GetPieceInfo`](./piecestore.go)
* [`GetCIDInfo`](./piecestore.go)

Please the [tests](piecestore_test.go) for more information about expected behavior.
4 changes: 4 additions & 0 deletions piecestore/piecestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type pieceStore struct {
cidInfos *statestore.StateStore
}

// Store `dealInfo` in the PieceStore with key `pieceCID`.
shannonwells marked this conversation as resolved.
Show resolved Hide resolved
func (ps *pieceStore) AddDealForPiece(pieceCID cid.Cid, dealInfo DealInfo) error {
return ps.mutatePieceInfo(pieceCID, func(pi *PieceInfo) error {
for _, di := range pi.Deals {
Expand All @@ -38,6 +39,7 @@ func (ps *pieceStore) AddDealForPiece(pieceCID cid.Cid, dealInfo DealInfo) error
})
}

// Store the map of blockLocations in the PieceStore's CIDInfo store, with key `pieceCID`
func (ps *pieceStore) AddPieceBlockLocations(pieceCID cid.Cid, blockLocations map[cid.Cid]BlockLocation) error {
for c, blockLocation := range blockLocations {
err := ps.mutateCIDInfo(c, func(ci *CIDInfo) error {
Expand All @@ -56,6 +58,7 @@ func (ps *pieceStore) AddPieceBlockLocations(pieceCID cid.Cid, blockLocations ma
return nil
}

// Retrieve the PieceInfo associated with `pieceCID` from the piece info store.
func (ps *pieceStore) GetPieceInfo(pieceCID cid.Cid) (PieceInfo, error) {
var out PieceInfo
if err := ps.pieces.Get(pieceCID).Get(&out); err != nil {
Expand All @@ -64,6 +67,7 @@ func (ps *pieceStore) GetPieceInfo(pieceCID cid.Cid) (PieceInfo, error) {
return out, nil
}

// Retrieve the CIDInfo associated with `pieceCID` from the CID info store.
func (ps *pieceStore) GetCIDInfo(payloadCID cid.Cid) (CIDInfo, error) {
var out CIDInfo
if err := ps.cidInfos.Get(payloadCID).Get(&out); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion piecestore/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

//go:generate cbor-gen-for PieceInfo DealInfo BlockLocation PieceBlockLocation CIDInfo

// DealInfo is information about a single deal for a give piece
// DealInfo is information about a single deal for a given piece
type DealInfo struct {
DealID abi.DealID
SectorID uint64
Expand Down
Loading