Documentation
¶
Index ¶
- Constants
- Variables
- type DealConfig
- type DealMaker
- type DealMakerImpl
- func (d DealMakerImpl) Close() error
- func (d DealMakerImpl) GetMinCollateral(ctx context.Context, pieceSize int64, verified bool) (big.Int, error)
- func (d DealMakerImpl) GetProtocols(ctx context.Context, minerInfo peer.AddrInfo) ([]protocol.ID, error)
- func (d DealMakerImpl) GetProviderInfo(ctx context.Context, provider string) (*MinerInfo, error)
- func (d DealMakerImpl) MakeDeal(ctx context.Context, actorObj model.Actor, car model.Car, ...) (*model.Deal, error)
- func (d DealMakerImpl) MakeDeal111(ctx context.Context, deal market.ClientDealProposal, dealConfig DealConfig, ...) (*network.SignedResponse, error)
- func (d DealMakerImpl) MakeDeal120(ctx context.Context, deal market.ClientDealProposal, dealID uuid.UUID, ...) (*boostly.DealResponse, error)
- type DealProviderCollateralBound
- type MinerInfo
- type MinerInfoFetcher
- type ProposalSigner
Constants ¶
const ( StorageProposalV120 = "/fil/storage/mk/1.2.0" StorageProposalV111 = "/fil/storage/mk/1.1.1" )
Variables ¶
var ErrFileSizeNotSpecifiedForOnlineDeal = errors.New("file size must be specified for online deal")
var ErrNoSupportedProtocols = errors.New("no supported protocols")
Functions ¶
This section is empty.
Types ¶
type DealConfig ¶ added in v0.2.23
type DealConfig struct {
Provider string
StartDelay time.Duration
Duration time.Duration
Verified bool
HTTPHeaders map[string]string
URLTemplate string
KeepUnsealed bool
AnnounceToIPNI bool
PricePerDeal float64
PricePerGB float64
PricePerGBEpoch float64
WalletID *uint
}
DealConfig represents the configuration parameters for a storage deal in a Filecoin-like network.
Fields:
- Provider: The Filecoin address of the storage provider (miner) with whom the deal is being made.
- StartDelay: The duration before the deal is expected to start. It gives the miner time to prepare for the deal.
- Duration: The duration for which the deal will be in effect, i.e., the time period the data is stored.
- Verified: A flag indicating whether the deal is for verified storage.
- HTTPHeaders: Custom HTTP headers to be used when fetching data from a URL.
- URLTemplate: A URL template string which can be used to fetch data for storage.
- KeepUnsealed: A flag indicating whether the miner should keep the data unsealed (quick retrieval) or not.
- AnnounceToIPNI: A flag indicating whether the deal should be announced to the InterPlanetary Name Identifier (IPNI).
- PricePerDeal: The upfront cost of the deal, independent of the amount of data being stored, in FIL (or a smaller unit like attoFIL).
- PricePerGB: The upfront cost per GB of data being stored, in FIL (or a smaller unit like attoFIL).
- PricePerGBEpoch: The cost per GB per epoch (e.g., per block or per minute), in FIL (or a smaller unit like attoFIL).
func (DealConfig) GetPrice ¶ added in v0.2.23
GetPrice calculates the price of a deal based on the size of the piece being stored, the duration of the storage, and various price parameters that are part of the DealConfig.
The method considers three potential price calculations:
- Price based on the size of the piece (in GB), the duration of the deal (in epochs), and a price rate per GB per epoch.
- Price based on the size of the piece (in GB) and a flat price rate per GB.
- A flat price per deal, independent of the size and duration.
The method returns the maximum of these three calculated prices.
Parameters:
- pieceSize int64: The size of the piece to be stored, in bytes.
- duration time.Duration: The duration for which the piece will be stored.
Returns:
- big.Int: The calculated price for the deal in attoFIL (1e-18 FIL).
type DealMakerImpl ¶ added in v0.2.23
type DealMakerImpl struct {
// contains filtered or unexported fields
}
DealMakerImpl is an implementation of a deal-making component for a Filecoin-like network. It is responsible for negotiating storage deals between a client and a provider (miner).
Fields:
- lotusClient: A JSON-RPC client to interact with a Filecoin Lotus node. This client is used to query the blockchain and interact with the Filecoin network.
- host: A libp2p host used for networking operations, such as connecting to miners and sending/receiving deal proposals.
- requestTimeout: The maximum duration that the DealMakerImpl should wait for a response from the miner when making a deal. After this timeout, the deal request is considered as failed.
- minerInfoCache: A cache that stores information about miners. The key is the miner's address, and the value is a struct containing detailed information about the miner.
- protocolsCache: A cache that stores the supported protocols of different peers in the network. The key is the peer ID of the node, and the value is a slice of supported protocol IDs.
- collateralCache: A cache that stores the minimum required collateral for making a deal. The key is a string representing some parameters of the deal, and the value is the minimum required collateral in attoFIL (or similar units).
func NewDealMaker ¶
func (DealMakerImpl) Close ¶ added in v0.2.23
func (d DealMakerImpl) Close() error
func (DealMakerImpl) GetMinCollateral ¶ added in v0.3.0
func (d DealMakerImpl) GetMinCollateral(ctx context.Context, pieceSize int64, verified bool) (big.Int, error)
GetMinCollateral retrieves the minimum collateral that a Filecoin miner needs to put up in order to make a deal, considering the given piece size and whether the deal is verified.
This function checks a cache for the minimum collateral based on the piece size and verified flag. If a valid cached value is found, it returns this value. Otherwise, it performs the following steps:
- Makes a call to the Lotus client (Filecoin node) to fetch the deal provider collateral bounds for the specified piece size and verified flag.
- Parses the minimum bound from the response and converts it into a big.Int.
- Stores the newly fetched minimum collateral in the cache with a default TTL.
Parameters:
- ctx context.Context: The context for the function, allowing for cancellation and timeouts.
- pieceSize int64: The size of the piece (in bytes) for which to retrieve the minimum collateral.
- verified bool: A flag indicating whether the deal is verified.
func (DealMakerImpl) GetProtocols ¶ added in v0.3.0
func (d DealMakerImpl) GetProtocols(ctx context.Context, minerInfo peer.AddrInfo) ([]protocol.ID, error)
GetProtocols retrieves the supported protocols of a given Filecoin miner.
This function checks a cache for the miner's supported protocols. If the protocols for the given miner are found in the cache and are not expired, it returns the cached protocols. Otherwise, it performs the following steps:
- Adds the miner's multiaddresses to the peerstore with a temporary TTL (Time To Live).
- Attempts to establish a network connection with the miner using the host's Connect method.
- Queries the host's peerstore for the supported protocols of the miner.
- Stores the newly fetched protocols in the cache with a default TTL.
Parameters:
- ctx context.Context: The context to use when connecting to the miner, allowing for cancellation and timeouts.
- minerInfo peer.AddrInfo: A structure containing the peer ID and multiaddresses of the miner whose supported protocols are to be retrieved.
Returns:
- []protocol.ID: A slice of protocol IDs representing the protocols supported by the miner.
- error: An error that will be returned if any issues were encountered while trying to retrieve the miner's supported protocols. This could be due to errors in connecting to the miner or fetching protocols from the peerstore.
func (DealMakerImpl) GetProviderInfo ¶ added in v0.3.0
GetProviderInfo retrieves information about a given Filecoin provider (miner).
This function checks a cache for the requested miner's information. If the miner information is found in the cache and is not expired, it returns the cached information. Otherwise, it queries the information using the Lotus client, decodes multiaddresses and peer ID, and stores this newly fetched information in the cache with a default TTL (Time To Live).
Parameters:
- ctx context.Context: The context to use for the Lotus client call, allowing for cancellation and timeouts.
- provider string: The address of the provider (miner) whose information is to be retrieved.
Returns:
- *MinerInfo: A pointer to the MinerInfo structure that contains various details about the provider (miner), including its multiaddresses and peer ID.
- error: An error that will be returned if any issues were encountered while trying to retrieve the provider's information. This could be due to errors in communicating with the Lotus client, decoding base64 encoded multiaddresses, creating new multiaddresses, or decoding the peer ID.
func (DealMakerImpl) MakeDeal ¶ added in v0.2.23
func (d DealMakerImpl) MakeDeal(ctx context.Context, actorObj model.Actor, car model.Car, dealConfig DealConfig, signer ProposalSigner, ) (*model.Deal, error)
MakeDeal initiates a storage deal between a client and a provider in a Filecoin-like network.
It constructs a deal proposal based on input parameters including a car file, a wallet, a deal configuration, and more. It connects to the provider (miner), negotiates the deal terms based on the protocols supported by the provider, signs the deal proposal using the client's private key, and then sends the proposal to the provider.
Parameters:
- ctx context.Context: The context to use for timeouts and cancellation.
- actorObj model.Actor: The on-chain actor identity for deal signing.
- car model.Car: The car file that contains the data to be stored.
- dealConfig DealConfig: The configuration for the deal, including price and duration.
Returns:
- *model.Deal: The resulting deal object, if the deal was successful. Contains various details about the deal, including its state and price.
- error: An error if the deal could not be completed, or nil if the deal was successful.
Possible Errors:
Failed to parse wallet or provider addresses.
Failed to get provider info or supported protocol.
Failed to connect to the provider.
Failed to serialize the deal proposal.
Failed to sign the deal proposal.
Deal proposal rejected by the provider.
No supported protocol found between client and provider.
func (DealMakerImpl) MakeDeal111 ¶ added in v0.3.0
func (d DealMakerImpl) MakeDeal111( ctx context.Context, deal market.ClientDealProposal, dealConfig DealConfig, rootCID cid.Cid, minerInfo peer.AddrInfo, ) (*network.SignedResponse, error)
MakeDeal111 attempts to make a storage deal with a Filecoin miner, following the version 1.1.1 deal making protocol. It constructs and sends the deal proposal to the miner, and waits for a response.
The function accepts various parameters related to the deal, including the deal proposal, deal configuration, the root CID of the data, and miner network information. It also generates a proposal object based on the input parameters and sends this to the miner.
Parameters:
- ctx context.Context: The context for the function, allowing for cancellation and timeouts.
- deal market.ClientDealProposal: The storage deal proposal to be sent to the miner.
- dealConfig DealConfig: Configuration options for this deal.
- rootCID cid.Cid: The root CID of the data to be stored in this deal.
- minerInfo peer.AddrInfo: Network information for the miner with whom the deal is made.
Returns:
- *network.SignedResponse: A pointer to the signed response from the miner regarding the proposed deal, including whether it was accepted and any associated messages.
- error: An error that will be returned if any issues were encountered while making the deal. This could be due to communication errors with the miner, serialization/deserialization issues, or stream handling errors.
func (DealMakerImpl) MakeDeal120 ¶ added in v0.3.0
func (d DealMakerImpl) MakeDeal120( ctx context.Context, deal market.ClientDealProposal, dealID uuid.UUID, dealConfig DealConfig, fileSize int64, rootCID cid.Cid, minerInfo peer.AddrInfo, ) (*boostly.DealResponse, error)
MakeDeal120 attempts to make a storage deal with a Filecoin miner, following the version 1.2.0 deal making protocol. It constructs and sends the deal proposal and associated data transfer instructions to the miner, and waits for a response.
The function accepts various parameters related to the deal, including deal proposal, deal configuration, file size, root CID of the data, and miner information. It also generates a transfer object based on the input parameters, which includes instructions for how the miner should retrieve the data.
Parameters:
- ctx context.Context: The context for the function, allowing for cancellation and timeouts.
- deal market.ClientDealProposal: The storage deal proposal to be sent to the miner.
- dealID uuid.UUID: The unique identifier for this deal.
- dealConfig DealConfig: Configuration options for this deal.
- fileSize int64: The size of the file (in bytes) being stored in this deal.
- rootCID cid.Cid: The root CID of the data to be stored in this deal.
- minerInfo peer.AddrInfo: Network information for the miner with whom the deal is made.
Returns:
- *boostly.DealResponse: A pointer to the response from the miner regarding the proposed deal, including whether it was accepted and any associated messages.
- error: An error that will be returned if any issues were encountered while making the deal. This could be due to communication errors with the miner, serialization/deserialization issues, or stream handling errors.
type MinerInfoFetcher ¶ added in v0.5.1
func (MinerInfoFetcher) GetProviderInfo ¶ added in v0.5.1
type ProposalSigner ¶ added in v1.0.0
ProposalSigner signs deal proposal bytes and returns a filecoin signature. Callers construct this from a keystore + wallet before calling MakeDeal, keeping the deal maker decoupled from database and key storage.