Skip to content

Commit

Permalink
Update specs-actors, enforce provider deal collateral bounds (#345)
Browse files Browse the repository at this point in the history
* Update specs-actors, enforce provider deal collateral bounds

* fix(storagemarket): fix integration tests

Fix integration test with two changes: 1. for some reason we were using the provider address as the
client addr. 2. The non-blocking test was failing due to minimum bounds on deals being 0 (we were
waitng to see funds added)

Co-authored-by: hannahhoward <hannah@hannahhoward.net>
  • Loading branch information
arajasek and hannahhoward committed Jul 30, 2020
1 parent c0f7c40 commit adf60de
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 37 deletions.
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ require (
github.com/filecoin-project/go-statemachine v0.0.0-20200730031800-c3336614d2a7
github.com/filecoin-project/go-statestore v0.1.0
github.com/filecoin-project/go-storedcounter v0.0.0-20200421200003-1c99c62e8a5b
github.com/filecoin-project/sector-storage v0.0.0-20200615154852-728a47ab99d6
github.com/filecoin-project/specs-actors v0.8.1-0.20200720115956-cd051eabf328
github.com/filecoin-project/sector-storage v0.0.0-20200730050024-3ee28c3b6d9a
github.com/filecoin-project/specs-actors v0.8.2
github.com/hannahhoward/cbor-gen-for v0.0.0-20200723175505-5892b522820a
github.com/hannahhoward/go-pubsub v0.0.0-20200423002714-8d62886cc36e
github.com/ipfs/go-block-format v0.0.2
Expand All @@ -26,7 +26,7 @@ require (
github.com/ipfs/go-ipfs-ds-help v1.0.0
github.com/ipfs/go-ipfs-exchange-offline v0.0.1
github.com/ipfs/go-ipfs-files v0.0.8
github.com/ipfs/go-ipld-cbor v0.0.4
github.com/ipfs/go-ipld-cbor v0.0.5-0.20200204214505-252690b78669
github.com/ipfs/go-ipld-format v0.2.0
github.com/ipfs/go-log/v2 v2.0.5
github.com/ipfs/go-merkledag v0.3.1
Expand All @@ -40,7 +40,7 @@ require (
github.com/stretchr/testify v1.6.1
github.com/whyrusleeping/cbor-gen v0.0.0-20200723182808-cb5de1c427f5
golang.org/x/exp v0.0.0-20190121172915-509febef88a4
golang.org/x/net v0.0.0-20190923162816-aa69164e4478
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543
)

Expand Down
71 changes: 42 additions & 29 deletions go.sum

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion storagemarket/impl/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,11 @@ func (c *Client) ProposeStorageDeal(ctx context.Context, params storagemarket.Pr
return nil, fmt.Errorf("cannot propose a deal whose piece size (%d) is greater than sector size (%d)", pieceSize.Padded(), params.Info.SectorSize)
}

pcMin, _, err := c.node.DealProviderCollateralBounds(ctx, pieceSize.Padded(), params.VerifiedDeal)
if err != nil {
return nil, xerrors.Errorf("computing deal provider collateral bound failed: %w", err)
}

dealProposal := market.DealProposal{
PieceCID: commP,
PieceSize: pieceSize.Padded(),
Expand All @@ -337,7 +342,7 @@ func (c *Client) ProposeStorageDeal(ctx context.Context, params storagemarket.Pr
StartEpoch: params.StartEpoch,
EndEpoch: params.EndEpoch,
StoragePricePerEpoch: params.Price,
ProviderCollateral: abi.NewTokenAmount(int64(pieceSize)), // TODO: real calc
ProviderCollateral: pcMin,
ClientCollateral: big.Zero(),
VerifiedDeal: params.VerifiedDeal,
}
Expand Down
13 changes: 12 additions & 1 deletion storagemarket/impl/providerstates/provider_states.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,18 @@ func ValidateDealProposal(ctx fsm.Context, environment ProviderDealEnvironment,
return ctx.Trigger(storagemarket.ProviderEventDealRejected, xerrors.Errorf("incorrect provider for deal"))
}

// TODO: check StorageCollateral
pcMin, pcMax, err := environment.Node().DealProviderCollateralBounds(ctx.Context(), proposal.PieceSize, proposal.VerifiedDeal)
if err != nil {
return ctx.Trigger(storagemarket.ProviderEventDealRejected, xerrors.Errorf("node error getting collateral bounds: %w", err))
}

if proposal.ProviderCollateral.LessThan(pcMin) {
return ctx.Trigger(storagemarket.ProviderEventDealRejected, xerrors.Errorf("proposed provider collateral below minimum: %s < %s", proposal.ProviderCollateral, pcMin))
}

if proposal.ProviderCollateral.GreaterThan(pcMax) {
return ctx.Trigger(storagemarket.ProviderEventDealRejected, xerrors.Errorf("proposed provider collateral above maximum: %s > %s", proposal.ProviderCollateral, pcMax))
}

minPrice := big.Div(big.Mul(environment.Ask().Price, abi.NewTokenAmount(int64(proposal.PieceSize))), abi.NewTokenAmount(1<<30))
if proposal.StoragePricePerEpoch.LessThan(minPrice) {
Expand Down
4 changes: 3 additions & 1 deletion storagemarket/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ type harness struct {
PayloadCid cid.Cid
StoreID *multistore.StoreID
ProviderAddr address.Address
ClientAddr address.Address
Client storagemarket.StorageClient
ClientNode *testnodes.FakeClientNode
Provider storagemarket.StorageProvider
Expand Down Expand Up @@ -481,6 +482,7 @@ func newHarnessWithTestData(t *testing.T, ctx context.Context, td *shared_testut
Epoch: epoch,
PayloadCid: payloadCid,
StoreID: storeID,
ClientAddr: clientNode.ClientAddr,
ProviderAddr: providerAddr,
Client: client,
ClientNode: &clientNode,
Expand All @@ -494,7 +496,7 @@ func newHarnessWithTestData(t *testing.T, ctx context.Context, td *shared_testut

func (h *harness) ProposeStorageDeal(t *testing.T, dataRef *storagemarket.DataRef, fastRetrieval, verifiedDeal bool) *storagemarket.ProposeStorageDealResult {
result, err := h.Client.ProposeStorageDeal(h.Ctx, storagemarket.ProposeStorageDealParams{
Addr: h.ProviderAddr,
Addr: h.ClientAddr,
Info: &h.ProviderInfo,
Data: dataRef,
StartEpoch: h.Epoch + 100,
Expand Down
3 changes: 3 additions & 0 deletions storagemarket/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ type StorageCommon interface {
// SignsBytes signs the given data with the given address's private key
SignBytes(ctx context.Context, signer address.Address, b []byte) (*crypto.Signature, error)

// DealProviderCollateralBounds returns the min and max collateral a storage provider can issue.
DealProviderCollateralBounds(ctx context.Context, size abi.PaddedPieceSize, isVerified bool) (abi.TokenAmount, abi.TokenAmount, error)

// OnDealSectorCommitted waits for a deal's sector to be sealed and proved, indicating the deal is active
OnDealSectorCommitted(ctx context.Context, provider address.Address, dealID abi.DealID, cb DealSectorCommittedCallback) error

Expand Down
4 changes: 4 additions & 0 deletions storagemarket/testnodes/testnodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ func (n *FakeCommonNode) SignBytes(ctx context.Context, signer address.Address,
return nil, n.SignBytesError
}

func (n *FakeCommonNode) DealProviderCollateralBounds(ctx context.Context, size abi.PaddedPieceSize, isVerified bool) (abi.TokenAmount, abi.TokenAmount, error) {
return abi.NewTokenAmount(5000), abi.TotalFilecoin, nil
}

// OnDealSectorCommitted returns immediately, and returns stubbed errors
func (n *FakeCommonNode) OnDealSectorCommitted(ctx context.Context, provider address.Address, dealID abi.DealID, cb storagemarket.DealSectorCommittedCallback) error {
if n.DealCommittedSyncError == nil {
Expand Down

0 comments on commit adf60de

Please sign in to comment.