Storage Provider #


The StorageProvider is a module that handles incoming queries for Asks and proposals for Deals from a StorageClient. It also tracks deals as they move through the deal flow, handling off chain actions during the negotiation phases of the deal and ultimately telling the StorageMarketActor to publish on chain. The StorageProvider's last action is to handoff a published deal for storage and sealing to the Storage Mining Subsystem. Note that any address registered as a StorageMarketParticipant with the StorageMarketActor can be used with the StorageClient. A single participant can be a client, provider, or both at the same time.

Because most of what a Storage Provider does is respond to actions initiated by a StorageClient, most of its public facing methods relate to getting current status on deals, as opposed to initiating new actions. However, a user of the StorageProvider module can update the current Ask for the provider.

import ipld "github.com/filecoin-project/specs/libraries/ipld"
import abi "github.com/filecoin-project/specs-actors/actors/abi"
import addr "github.com/filecoin-project/go-address"
import dt "github.com/filecoin-project/specs/systems/filecoin_files/data_transfer"
import peer "github.com/libp2p/go-libp2p-core/peer"
import cid "github.com/ipfs/go-cid"
import smarkact "github.com/filecoin-project/specs-actors/actors/builtin/storage_market"

// ProviderLocalDealInfo is the information that a storage provider tracks locally about
// a deal. It contains not only the storage proposal but the state of the deal
// as it moves throught the system. It is persisted to local storage and updated 
// as the deal goes through stages leading up to its being published (and afterward)
type ProviderLocalDealInfo struct {
    ProposalCid   &smarkact.StorageDealProposal
    Proposal      smarkact.StorageDealProposal
    MinerPeerID   peer.ID
    ClientPeerID  peer.ID
    Status        StorageDealStatus

    PayloadID     cid.Cid

    DealID        abi.DealID
    SectorID      abi.SectorID  // Set when State >= DealStaged
}

// The interface provided for storage providers
type StorageProvider struct {
    AddAsk(price abi.TokenAmount, ttlsecs int64) error

    // ListAsks lists current asks
    ListAsks(addrress addr.Address) [StorageAsk]

    // ListDeals lists on-chain deals associated with this provider
    ListDeals()            (deals [smarkact.StorageDeal], error)

    // ListIncompleteDeals lists deals that are in progress or rejected
    ListIncompleteDeals()  (deals [ProviderLocalDealInfo], error)

    // AddStorageCollateral adds storage collateral
    AddStorageCollateral(amount abi.TokenAmount) error

    // GetStorageCollateral returns the current collateral balance
    GetStorageCollateral() (abi.TokenAmount, error)

    // DataTransferValidator methods
    ValidatePush(
        sender    peer.ID
        voucher   dt.DataTransferVoucher
        PieceRef  cid.Cid
        Selector  ipld.Selector
    )
    ValidatePull(
        receiver  peer.ID
        voucher   dt.DataTransferVoucher
        PieceRef  cid.Cid
        Selector  ipld.Selector
    )

    // Data Transfer Listener
    OnDataTransferEvent(event dt.DataTransferEvent, channelState dt.DataTransferState)

    // libp2p listener on storage deal query
    OnStorageQueryAsk(request AskProtocolRequest)
    OnStorageDealProposal(response DealProtocolRequest)
}