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

Update specs-actors, enforce provider deal collateral bounds #345

Merged
merged 2 commits into from
Jul 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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