Skip to content

Commit

Permalink
Verify CommP and store CARed/padded path in MinerDeal
Browse files Browse the repository at this point in the history
  • Loading branch information
ingar committed Jan 10, 2020
1 parent ec7a7ec commit 606bbfb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
13 changes: 6 additions & 7 deletions storagemarket/impl/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@ import (
"github.com/ipfs/go-cid"
"github.com/ipfs/go-datastore"
"github.com/ipfs/go-datastore/namespace"
ipld "github.com/ipfs/go-ipld-format"
"github.com/libp2p/go-libp2p-core/host"
inet "github.com/libp2p/go-libp2p-core/network"
"golang.org/x/xerrors"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-cbor-util"
"github.com/filecoin-project/go-data-transfer"
"github.com/filecoin-project/go-statestore"

"github.com/filecoin-project/go-fil-components/pieceio"
"github.com/filecoin-project/go-fil-components/shared/tokenamount"
"github.com/filecoin-project/go-fil-components/shared/types"
"github.com/filecoin-project/go-fil-components/storagemarket"
"github.com/filecoin-project/go-statestore"
)

var ProviderDsPrefix = "/deals/provider"
Expand All @@ -40,9 +41,7 @@ type Provider struct {

spn storagemarket.StorageProviderNode

// TODO: This will go away once storage market module + CAR
// is implemented
dag ipld.DAGService
pio pieceio.PieceIO

// dataTransfer is the manager of data transfers used by this storage provider
dataTransfer datatransfer.Manager
Expand Down Expand Up @@ -72,7 +71,7 @@ var (
ErrDataTransferFailed = errors.New("deal data transfer failed")
)

func NewProvider(ds datastore.Batching, dag ipld.DAGService, dataTransfer datatransfer.Manager, spn storagemarket.StorageProviderNode) (storagemarket.StorageProvider, error) {
func NewProvider(ds datastore.Batching, pio pieceio.PieceIO, dataTransfer datatransfer.Manager, spn storagemarket.StorageProviderNode) (storagemarket.StorageProvider, error) {
addr, err := ds.Get(datastore.NewKey("miner-address"))
if err != nil {
return nil, err
Expand All @@ -83,7 +82,7 @@ func NewProvider(ds datastore.Batching, dag ipld.DAGService, dataTransfer datatr
}

h := &Provider{
dag: dag,
pio: pio,
dataTransfer: dataTransfer,
spn: spn,

Expand Down
17 changes: 17 additions & 0 deletions storagemarket/impl/provider_states.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package storageimpl

import (
"bytes"
"context"

ipldfree "github.com/ipld/go-ipld-prime/impl/free"
Expand Down Expand Up @@ -134,6 +135,21 @@ func (p *Provider) accept(ctx context.Context, deal MinerDeal) (func(*MinerDeal)
// STAGED

func (p *Provider) staged(ctx context.Context, deal MinerDeal) (func(*MinerDeal), error) {
// entire DAG selector
ssb := builder.NewSelectorSpecBuilder(ipldfree.NodeBuilder())
allSelector := ssb.ExploreRecursive(selector.RecursionLimitNone(),
ssb.ExploreAll(ssb.ExploreRecursiveEdge())).Node()

commp, path, err := p.pio.GeneratePieceCommitment(deal.Ref, allSelector)
if err != nil {
return nil, err
}

// Verify CommP matches
if !bytes.Equal(commp, deal.Proposal.PieceRef) {
return nil, xerrors.Errorf("proposal CommP doesn't match calculated CommP")
}

sectorID, err := p.spn.OnDealComplete(
ctx,
storagemarket.MinerDeal{
Expand All @@ -153,6 +169,7 @@ func (p *Provider) staged(ctx context.Context, deal MinerDeal) (func(*MinerDeal)

return func(deal *MinerDeal) {
deal.SectorID = sectorID
deal.Path = path
}, nil
}

Expand Down
2 changes: 2 additions & 0 deletions storagemarket/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-cbor-util"
"github.com/filecoin-project/go-fil-components/filestore"
"github.com/filecoin-project/go-fil-components/shared/tokenamount"
"github.com/filecoin-project/go-fil-components/shared/types"
)
Expand Down Expand Up @@ -143,6 +144,7 @@ type MinerDeal struct {
Miner peer.ID
Client peer.ID
State DealState
Path filestore.Path

Ref cid.Cid

Expand Down

0 comments on commit 606bbfb

Please sign in to comment.