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

Consider ClientCollateral when validating deal proposal #408

Merged
merged 1 commit into from
Sep 23, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion storagemarket/impl/providerstates/provider_states.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func ValidateDealProposal(ctx fsm.Context, environment ProviderDealEnvironment,

// This doesn't guarantee that the client won't withdraw / lock those funds
// but it's a decent first filter
if clientMarketBalance.Available.LessThan(proposal.TotalStorageFee()) {
if clientMarketBalance.Available.LessThan(proposal.ClientBalanceRequirement()) {
return ctx.Trigger(storagemarket.ProviderEventDealRejected, xerrors.New("clientMarketBalance.Available too small"))
}

Expand Down
18 changes: 17 additions & 1 deletion storagemarket/impl/providerstates/provider_states_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,19 @@ func TestValidateDealProposal(t *testing.T) {
},
"Not enough funds": {
nodeParams: nodeParams{
ClientMarketBalance: abi.NewTokenAmount(150 * 10000),
ClientMarketBalance: big.NewInt(200*10000 - 1),
},
dealInspector: func(t *testing.T, deal storagemarket.MinerDeal, env *fakeEnvironment) {
tut.AssertDealState(t, storagemarket.StorageDealRejecting, deal.State)
require.Equal(t, "deal rejected: clientMarketBalance.Available too small", deal.Message)
},
},
"Not enough funds due to client collateral": {
nodeParams: nodeParams{
ClientMarketBalance: big.NewInt(200*10000 + 99),
},
dealParams: dealParams{
ClientCollateral: big.NewInt(100),
},
dealInspector: func(t *testing.T, deal storagemarket.MinerDeal, env *fakeEnvironment) {
tut.AssertDealState(t, storagemarket.StorageDealRejecting, deal.State)
Expand Down Expand Up @@ -968,6 +980,7 @@ type dealParams struct {
DataRef *storagemarket.DataRef
StoragePricePerEpoch abi.TokenAmount
ProviderCollateral abi.TokenAmount
ClientCollateral abi.TokenAmount
PieceSize abi.PaddedPieceSize
StartEpoch abi.ChainEpoch
EndEpoch abi.ChainEpoch
Expand Down Expand Up @@ -1081,6 +1094,9 @@ func makeExecutor(ctx context.Context,
if !dealParams.ProviderCollateral.Nil() {
proposal.ProviderCollateral = dealParams.ProviderCollateral
}
if !dealParams.ClientCollateral.Nil() {
proposal.ClientCollateral = dealParams.ClientCollateral
}
if dealParams.StartEpoch != abi.ChainEpoch(0) {
proposal.StartEpoch = dealParams.StartEpoch
}
Expand Down