Skip to content

Commit

Permalink
Update specs-actors, enforce provider deal collateral bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
arajasek committed Jul 30, 2020
1 parent c4c6b77 commit bb00702
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 36 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-20200714194326-a77c3ae20989
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 @@ -325,6 +325,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 @@ -333,7 +338,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 @@ -64,7 +64,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
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 big.Zero(), 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 bb00702

Please sign in to comment.