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

Integrate new FundManager #445

Merged
merged 3 commits into from
Nov 11, 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
14 changes: 7 additions & 7 deletions docs/storageclient.mmd
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ stateDiagram-v2
state "StorageDealExpired" as 8
state "StorageDealSlashed" as 9
state "StorageDealFailing" as 11
state "StorageDealFundsEnsured" as 12
state "StorageDealFundsReserved" as 12
state "StorageDealCheckForAcceptance" as 13
state "StorageDealStartDataTransfer" as 16
state "StorageDealTransferring" as 17
state "StorageDealEnsureClientFunds" as 21
state "StorageDealReserveClientFunds" as 21
state "StorageDealClientFunding" as 23
state "StorageDealError" as 26
state "StorageDealClientTransferRestart" as 28
Expand All @@ -21,7 +21,7 @@ stateDiagram-v2
12 : On entry runs ProposeDeal
13 : On entry runs CheckForDealAcceptance
16 : On entry runs InitiateDataTransfer
21 : On entry runs EnsureClientFunds
21 : On entry runs ReserveClientFunds
23 : On entry runs WaitForFunding
28 : On entry runs RestartDataTransfer
[*] --> 0
Expand All @@ -33,10 +33,10 @@ stateDiagram-v2
end note
0 --> 21 : ClientEventOpen
21 --> 23 : ClientEventFundingInitiated
21 --> 11 : ClientEventEnsureFundsFailed
23 --> 11 : ClientEventEnsureFundsFailed
21 --> 12 : ClientEventFundsEnsured
23 --> 12 : ClientEventFundsEnsured
21 --> 11 : ClientEventReserveFundsFailed
23 --> 11 : ClientEventReserveFundsFailed
21 --> 12 : ClientEventFundingComplete
23 --> 12 : ClientEventFundingComplete
12 --> 26 : ClientEventWriteProposalFailed
12 --> 11 : ClientEventReadResponseFailed
12 --> 11 : ClientEventResponseVerificationFailed
Expand Down
4 changes: 2 additions & 2 deletions docs/storageprovider.mmd
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ stateDiagram-v2
state "StorageDealTransferring" as 17
state "StorageDealWaitingForData" as 18
state "StorageDealVerifyData" as 19
state "StorageDealEnsureProviderFunds" as 20
state "StorageDealReserveProviderFunds" as 20
state "StorageDealProviderFunding" as 22
state "StorageDealPublish" as 24
state "StorageDealPublishing" as 25
Expand All @@ -28,7 +28,7 @@ stateDiagram-v2
14 : On entry runs ValidateDealProposal
15 : On entry runs DecideOnProposal
19 : On entry runs VerifyData
20 : On entry runs EnsureProviderFunds
20 : On entry runs ReserveProviderFunds
22 : On entry runs WaitForFunding
24 : On entry runs PublishDeal
25 : On entry runs WaitForPublish
Expand Down
Binary file modified docs/storageprovider.mmd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions docs/storageprovider.mmd.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ require (
github.com/ipfs/go-blockservice v0.1.4-0.20200624145336-a978cec6e834
github.com/ipfs/go-cid v0.0.7
github.com/ipfs/go-datastore v0.4.5
github.com/ipfs/go-graphsync v0.4.2
github.com/ipfs/go-graphsync v0.4.3
github.com/ipfs/go-ipfs-blockstore v1.0.1
github.com/ipfs/go-ipfs-blocksutil v0.0.1
github.com/ipfs/go-ipfs-chunker v0.0.5
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ github.com/ipfs/go-graphsync v0.1.0 h1:RjLk7ha1tJtDXktqoxOjhvx4lDuzzIU+xQ+PEi74r
github.com/ipfs/go-graphsync v0.1.0/go.mod h1:jMXfqIEDFukLPZHqDPp8tJMbHO9Rmeb9CEGevngQbmE=
github.com/ipfs/go-graphsync v0.4.2 h1:Y/jt5r619yj0LI7OLtGKh4jYm8goYUcuJ09y7TZ3zMo=
github.com/ipfs/go-graphsync v0.4.2/go.mod h1:/VmbZTUdUMTbNkgzAiCEucIIAU3BkLE2cZrDCVUhyi0=
github.com/ipfs/go-graphsync v0.4.3 h1:2t+oCpufufs1oqChoWiIK7V5uC1XCtf06PK9nqMV6pM=
github.com/ipfs/go-graphsync v0.4.3/go.mod h1:mPOwDYv128gf8gxPFgXnz4fNrSYPsWyqisJ7ych+XDY=
github.com/ipfs/go-hamt-ipld v0.1.1 h1:0IQdvwnAAUKmDE+PMJa5y1QiwOPHpI9+eAbQEEEYthk=
github.com/ipfs/go-hamt-ipld v0.1.1/go.mod h1:1EZCr2v0jlCnhpa+aZ0JZYp8Tt2w16+JJOAVz17YcDk=
github.com/ipfs/go-ipfs-blockstore v0.0.1/go.mod h1:d3WClOmRQKFnJ0Jz/jj/zmksX0ma1gROTlovZKBmN08=
Expand Down
4 changes: 0 additions & 4 deletions shared_testutil/test_deal_funds.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package shared_testutil
import (
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"

"github.com/filecoin-project/go-fil-markets/storagemarket/impl/funds"
)

func NewTestDealFunds() *TestDealFunds {
Expand Down Expand Up @@ -34,5 +32,3 @@ func (f *TestDealFunds) Release(amount abi.TokenAmount) (abi.TokenAmount, error)
f.ReleaseCalls = append(f.ReleaseCalls, amount)
return f.reserved, nil
}

var _ funds.DealFunds = &TestDealFunds{}
20 changes: 14 additions & 6 deletions storagemarket/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ Implement the [`StorageCommon`](#StorageCommon), [`StorageProviderNode`](#Storag
functions are:
* [`GetChainHead`](#GetChainHead)
* [`AddFunds`](#AddFunds)
* [`EnsureFunds`](#EnsureFunds)
* [`ReserveFunds`](#ReserveFunds)
* [`ReleaseFunds`](#ReleaseFunds)
* [`GetBalance`](#GetBalance)
* [`VerifySignature`](#VerifySignature)
* [`WaitForMessage`](#WaitForMessage)
Expand All @@ -76,14 +77,21 @@ func AddFunds(ctx context.Context, addr address.Address, amount abi.TokenAmount)

Send `amount` to `addr` by posting a message on chain. Return the message CID.

#### EnsureFunds
#### ReserveFunds
```go
func EnsureFunds(ctx context.Context, addr, wallet address.Address, amount abi.TokenAmount,
tok shared.TipSetToken) (cid.Cid, error)
func ReserveFunds(ctx context.Context, addr, wallet address.Address, amount abi.TokenAmount) (cid.Cid, error)
```

Make sure `addr` has `amount` funds and if not, `wallet` should send any needed balance to
`addr` by posting a message on chain. Returns the message CID.
Add `amount` to the total reserved funds for `addr`. If total available balance for `addr` in StorageMarketActor is not greater than total reserved, `wallet` should send any needed balance to `addr` by posting a message on chain. Returns the message CID.

#### ReserveFunds
```go
func ReleaseFunds(ctx context.Context, addr address.Address, amount abi.TokenAmount) (cid.Cid, error)
```

Release `amount` funds from reserved total for `addr`. No withdrawal is performed for `addr` in the storage market actor but the funds released become
available for future withdrawal
(if new total reserved < total available in SMA)

#### GetBalance
```go
Expand Down
18 changes: 9 additions & 9 deletions storagemarket/dealstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ const (
// StorageDealError
StorageDealFailing

// StorageDealFundsEnsured means we've deposited funds as necessary to create a deal, ready to move forward
StorageDealFundsEnsured
// StorageDealFundsReserved means we've deposited funds as necessary to create a deal, ready to move forward
StorageDealFundsReserved

// StorageDealCheckForAcceptance means the client is waiting for a provider to seal and publish a deal
StorageDealCheckForAcceptance
Expand All @@ -72,11 +72,11 @@ const (
// StorageDealVerifyData means data has been transferred and we are attempting to verify it against the PieceCID
StorageDealVerifyData

// StorageDealEnsureProviderFunds means that provider is making sure it has adequate funds for the deal in the StorageMarketActor
StorageDealEnsureProviderFunds
// StorageDealReserveProviderFunds means that provider is making sure it has adequate funds for the deal in the StorageMarketActor
StorageDealReserveProviderFunds

// StorageDealEnsureClientFunds means that client is making sure it has adequate funds for the deal in the StorageMarketActor
StorageDealEnsureClientFunds
// StorageDealReserveClientFunds means that client is making sure it has adequate funds for the deal in the StorageMarketActor
StorageDealReserveClientFunds

// StorageDealProviderFunding means that the provider has deposited funds in the StorageMarketActor and it is waiting
// to see the funds appear in its balance
Expand Down Expand Up @@ -119,14 +119,14 @@ var DealStates = map[StorageDealStatus]string{
StorageDealSlashed: "StorageDealSlashed",
StorageDealRejecting: "StorageDealRejecting",
StorageDealFailing: "StorageDealFailing",
StorageDealFundsEnsured: "StorageDealFundsEnsured",
StorageDealFundsReserved: "StorageDealFundsReserved",
StorageDealCheckForAcceptance: "StorageDealCheckForAcceptance",
StorageDealValidating: "StorageDealValidating",
StorageDealTransferring: "StorageDealTransferring",
StorageDealWaitingForData: "StorageDealWaitingForData",
StorageDealVerifyData: "StorageDealVerifyData",
StorageDealEnsureProviderFunds: "StorageDealEnsureProviderFunds",
StorageDealEnsureClientFunds: "StorageDealEnsureClientFunds",
StorageDealReserveProviderFunds: "StorageDealReserveProviderFunds",
StorageDealReserveClientFunds: "StorageDealReserveClientFunds",
StorageDealProviderFunding: "StorageDealProviderFunding",
StorageDealClientFunding: "StorageDealClientFunding",
StorageDealPublish: "StorageDealPublish",
Expand Down
12 changes: 6 additions & 6 deletions storagemarket/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const (
// ClientEventOpen indicates a new deal was started
ClientEventOpen ClientEvent = iota

// ClientEventEnsureFundsFailed happens when attempting to ensure the client has enough funds available fails
ClientEventEnsureFundsFailed
// ClientEventReserveFundsFailed happens when attempting to reserve funds for a deal fails
ClientEventReserveFundsFailed

// ClientEventFundingInitiated happens when a client has sent a message adding funds to its balance
ClientEventFundingInitiated
Expand All @@ -19,8 +19,8 @@ const (
// ClientEventFundsReleased happens when a client released funds for a deal (updating our tracked funds)
ClientEventFundsReleased

// ClientEventFundsEnsured happens when a client successfully ensures it has funds for a deal
ClientEventFundsEnsured
// ClientEventFundingComplete happens when a client successfully reserves funds for a deal
ClientEventFundingComplete

// ClientEventWriteProposalFailed indicates an attempt to send a deal proposal to a provider failed
ClientEventWriteProposalFailed
Expand Down Expand Up @@ -101,11 +101,11 @@ const (
// ClientEvents maps client event codes to string names
var ClientEvents = map[ClientEvent]string{
ClientEventOpen: "ClientEventOpen",
ClientEventEnsureFundsFailed: "ClientEventEnsureFundsFailed",
ClientEventReserveFundsFailed: "ClientEventReserveFundsFailed",
ClientEventFundingInitiated: "ClientEventFundingInitiated",
ClientEventFundsReserved: "ClientEventFundsReserved",
ClientEventFundsReleased: "ClientEventFundsReleased",
ClientEventFundsEnsured: "ClientEventFundsEnsured",
ClientEventFundingComplete: "ClientEventFundingComplete",
ClientEventWriteProposalFailed: "ClientEventWriteProposalFailed",
ClientEventInitiateDataTransfer: "ClientEventInitiateDataTransfer",
ClientEventDataTransferInitiated: "ClientEventDataTransferInitiated",
Expand Down
4 changes: 0 additions & 4 deletions storagemarket/impl/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"github.com/filecoin-project/go-fil-markets/storagemarket/impl/clientstates"
"github.com/filecoin-project/go-fil-markets/storagemarket/impl/clientutils"
"github.com/filecoin-project/go-fil-markets/storagemarket/impl/dtutils"
"github.com/filecoin-project/go-fil-markets/storagemarket/impl/funds"
"github.com/filecoin-project/go-fil-markets/storagemarket/impl/requestvalidation"
"github.com/filecoin-project/go-fil-markets/storagemarket/migrations"
"github.com/filecoin-project/go-fil-markets/storagemarket/network"
Expand All @@ -61,7 +60,6 @@ type Client struct {
statemachines fsm.Group
migrateStateMachines func(context.Context) error
pollingInterval time.Duration
dealFunds funds.DealFunds

unsubDataTransfer datatransfer.Unsubscribe
}
Expand All @@ -86,7 +84,6 @@ func NewClient(
discovery *discoveryimpl.Local,
ds datastore.Batching,
scn storagemarket.StorageClientNode,
dealFunds funds.DealFunds,
options ...StorageClientOption,
) (*Client, error) {
carIO := cario.NewCarIO()
Expand All @@ -101,7 +98,6 @@ func NewClient(
pubSub: pubsub.New(clientDispatcher),
readySub: pubsub.New(shared.ReadyDispatcher),
pollingInterval: DefaultPollingInterval,
dealFunds: dealFunds,
}
storageMigrations, err := migrations.ClientMigrations.Build()
if err != nil {
Expand Down
5 changes: 0 additions & 5 deletions storagemarket/impl/client_environments.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/filecoin-project/go-multistore"

"github.com/filecoin-project/go-fil-markets/storagemarket"
"github.com/filecoin-project/go-fil-markets/storagemarket/impl/funds"
"github.com/filecoin-project/go-fil-markets/storagemarket/network"
)

Expand Down Expand Up @@ -50,10 +49,6 @@ func (c *clientDealEnvironment) PollingInterval() time.Duration {
return c.c.pollingInterval
}

func (c *clientDealEnvironment) DealFunds() funds.DealFunds {
return c.c.dealFunds
}

type clientStoreGetter struct {
c *Client
}
Expand Down
1 change: 0 additions & 1 deletion storagemarket/impl/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ func TestClient_Migrations(t *testing.T) {
deps.PeerResolver,
clientDs,
deps.ClientNode,
deps.ClientDealFunds,
storageimpl.DealPollingInterval(0),
)
require.NoError(t, err)
Expand Down
28 changes: 14 additions & 14 deletions storagemarket/impl/clientstates/client_fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ import (
// ClientEvents are the events that can happen in a storage client
var ClientEvents = fsm.Events{
fsm.Event(storagemarket.ClientEventOpen).
From(storagemarket.StorageDealUnknown).To(storagemarket.StorageDealEnsureClientFunds),
From(storagemarket.StorageDealUnknown).To(storagemarket.StorageDealReserveClientFunds),
fsm.Event(storagemarket.ClientEventFundingInitiated).
From(storagemarket.StorageDealEnsureClientFunds).To(storagemarket.StorageDealClientFunding).
From(storagemarket.StorageDealReserveClientFunds).To(storagemarket.StorageDealClientFunding).
Action(func(deal *storagemarket.ClientDeal, mcid cid.Cid) error {
deal.AddFundsCid = &mcid
return nil
}),
fsm.Event(storagemarket.ClientEventEnsureFundsFailed).
FromMany(storagemarket.StorageDealClientFunding, storagemarket.StorageDealEnsureClientFunds).To(storagemarket.StorageDealFailing).
fsm.Event(storagemarket.ClientEventReserveFundsFailed).
FromMany(storagemarket.StorageDealClientFunding, storagemarket.StorageDealReserveClientFunds).To(storagemarket.StorageDealFailing).
Action(func(deal *storagemarket.ClientDeal, err error) error {
deal.Message = xerrors.Errorf("adding market funds failed: %w", err).Error()
return nil
}),
fsm.Event(storagemarket.ClientEventFundsReserved).
From(storagemarket.StorageDealEnsureClientFunds).ToJustRecord().
From(storagemarket.StorageDealReserveClientFunds).ToJustRecord().
Action(func(deal *storagemarket.ClientDeal, fundsReserved abi.TokenAmount) error {
if deal.FundsReserved.Nil() {
deal.FundsReserved = fundsReserved
Expand All @@ -44,31 +44,31 @@ var ClientEvents = fsm.Events{
deal.FundsReserved = big.Subtract(deal.FundsReserved, fundsReleased)
return nil
}),
fsm.Event(storagemarket.ClientEventFundsEnsured).
FromMany(storagemarket.StorageDealEnsureClientFunds, storagemarket.StorageDealClientFunding).To(storagemarket.StorageDealFundsEnsured),
fsm.Event(storagemarket.ClientEventFundingComplete).
FromMany(storagemarket.StorageDealReserveClientFunds, storagemarket.StorageDealClientFunding).To(storagemarket.StorageDealFundsReserved),
fsm.Event(storagemarket.ClientEventWriteProposalFailed).
From(storagemarket.StorageDealFundsEnsured).To(storagemarket.StorageDealError).
From(storagemarket.StorageDealFundsReserved).To(storagemarket.StorageDealError).
Action(func(deal *storagemarket.ClientDeal, err error) error {
deal.Message = xerrors.Errorf("sending proposal to storage provider failed: %w", err).Error()
return nil
}),
fsm.Event(storagemarket.ClientEventReadResponseFailed).
From(storagemarket.StorageDealFundsEnsured).To(storagemarket.StorageDealFailing).
From(storagemarket.StorageDealFundsReserved).To(storagemarket.StorageDealFailing).
Action(func(deal *storagemarket.ClientDeal, err error) error {
deal.Message = xerrors.Errorf("error reading Response message: %w", err).Error()
return nil
}),
fsm.Event(storagemarket.ClientEventResponseVerificationFailed).
From(storagemarket.StorageDealFundsEnsured).To(storagemarket.StorageDealFailing).
From(storagemarket.StorageDealFundsReserved).To(storagemarket.StorageDealFailing).
Action(func(deal *storagemarket.ClientDeal) error {
deal.Message = "unable to verify signature on deal response"
return nil
}),
fsm.Event(storagemarket.ClientEventInitiateDataTransfer).
From(storagemarket.StorageDealFundsEnsured).To(storagemarket.StorageDealStartDataTransfer),
From(storagemarket.StorageDealFundsReserved).To(storagemarket.StorageDealStartDataTransfer),

fsm.Event(storagemarket.ClientEventUnexpectedDealState).
From(storagemarket.StorageDealFundsEnsured).To(storagemarket.StorageDealFailing).
From(storagemarket.StorageDealFundsReserved).To(storagemarket.StorageDealFailing).
Action(func(deal *storagemarket.ClientDeal, status storagemarket.StorageDealStatus, providerMessage string) error {
deal.Message = xerrors.Errorf("unexpected deal status while waiting for data request: %d (%s). Provider message: %s", status, storagemarket.DealStates[status], providerMessage).Error()
return nil
Expand Down Expand Up @@ -187,9 +187,9 @@ var ClientEvents = fsm.Events{

// ClientStateEntryFuncs are the handlers for different states in a storage client
var ClientStateEntryFuncs = fsm.StateEntryFuncs{
storagemarket.StorageDealEnsureClientFunds: EnsureClientFunds,
storagemarket.StorageDealReserveClientFunds: ReserveClientFunds,
storagemarket.StorageDealClientFunding: WaitForFunding,
storagemarket.StorageDealFundsEnsured: ProposeDeal,
storagemarket.StorageDealFundsReserved: ProposeDeal,
storagemarket.StorageDealStartDataTransfer: InitiateDataTransfer,
storagemarket.StorageDealClientTransferRestart: RestartDataTransfer,
storagemarket.StorageDealCheckForAcceptance: CheckForDealAcceptance,
Expand Down
Loading