Skip to content

Commit

Permalink
- Consider ClientCollateral when validating deal proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
ingar committed Sep 19, 2020
1 parent ccb2cbf commit bcf46a9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
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

0 comments on commit bcf46a9

Please sign in to comment.