replication

package
v0.5.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2024 License: Apache-2.0, MIT Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StorageProposalV120 = "/fil/storage/mk/1.2.0"
	StorageProposalV111 = "/fil/storage/mk/1.1.1"
)

Variables

View Source
var ErrFileSizeNotSpecifiedForOnlineDeal = errors.New("file size must be specified for online deal")
View Source
var ErrNoDatacap = errors.New("no wallets have enough datacap")
View Source
var ErrNoSupportedProtocols = errors.New("no supported protocols")
View Source
var ErrNoWallet = errors.New("no wallets to choose from")

Functions

This section is empty.

Types

type DatacapWalletChooser added in v0.2.21

type DatacapWalletChooser struct {
	// contains filtered or unexported fields
}

func NewDatacapWalletChooser added in v0.2.21

func NewDatacapWalletChooser(db *gorm.DB, cacheTTL time.Duration,
	lotusAPI string, lotusToken string, min uint64) DatacapWalletChooser

func (DatacapWalletChooser) Choose added in v0.2.21

func (w DatacapWalletChooser) Choose(ctx context.Context, wallets []model.Wallet) (model.Wallet, error)

Choose selects a random Wallet from the provided slice of Wallets based on certain criteria.

The Choose function of the DatacapWalletChooser type filters the given slice of Wallets based on a specific criterion, which is whether the datacap for the wallet minus the pending deals for the wallet is greater or equal to a minimum threshold (w.min). From the filtered eligible Wallets, the function then randomly selects one Wallet. It uses a cryptographically secure random number generator to make the selection. If the initial slice of Wallets is empty, or if no Wallets meet the criteria, the function returns an error.

Parameters:

  • ctx context.Context: The context to use for cancellation and deadlines, used in the datacap and pending deals fetching operations.
  • wallets []model.Wallet: A slice of Wallet objects from which a random Wallet will be chosen based on the criteria.

Returns:

  • model.Wallet: The randomly chosen Wallet object from the filtered eligible Wallets.
  • error: An error that will be returned if any issues were encountered while trying to choose a Wallet. This includes the case when the input slice is empty, in which case ErrNoWallet will be returned, when no Wallets meet the criteria, in which case ErrNoDatacap will be returned, or if there is an issue generating a random number.

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
}

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

func (d DealConfig) GetPrice(pieceSize int64, duration time.Duration) big.Int

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:

  1. 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.
  2. Price based on the size of the piece (in GB) and a flat price rate per GB.
  3. 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 DealMaker

type DealMaker interface {
	MakeDeal(ctx context.Context, walletObj model.Wallet, car model.Car, dealConfig DealConfig) (*model.Deal, error)
}

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 NewDealMaker(
	lotusClient jsonrpc.RPCClient,
	libp2p host.Host,
	cacheTTL time.Duration,
	requestTimeout time.Duration,
) DealMakerImpl

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:

  1. Makes a call to the Lotus client (Filecoin node) to fetch the deal provider collateral bounds for the specified piece size and verified flag.
  2. Parses the minimum bound from the response and converts it into a big.Int.
  3. 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:

  1. Adds the miner's multiaddresses to the peerstore with a temporary TTL (Time To Live).
  2. Attempts to establish a network connection with the miner using the host's Connect method.
  3. Queries the host's peerstore for the supported protocols of the miner.
  4. 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

func (d DealMakerImpl) GetProviderInfo(ctx context.Context, provider string) (*MinerInfo, error)

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, walletObj model.Wallet,
	car model.Car, dealConfig DealConfig,
) (*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.
  • walletObj model.Wallet: The client's wallet, containing the client's addresses and private key.
  • 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 DealProviderCollateralBound

type DealProviderCollateralBound struct {
	Min string
	Max string
}

type MinerInfo

type MinerInfo struct {
	PeerIDEncoded           string `json:"PeerID"`
	PeerID                  peer.ID
	MultiaddrsBase64Encoded []string `json:"Multiaddrs"`
	Multiaddrs              []multiaddr.Multiaddr
}

type MinerInfoFetcher added in v0.5.1

type MinerInfoFetcher struct {
	Client jsonrpc.RPCClient
}

func (MinerInfoFetcher) GetProviderInfo added in v0.5.1

func (m MinerInfoFetcher) GetProviderInfo(ctx context.Context, provider string) (*MinerInfo, error)

type RandomWalletChooser added in v0.3.0

type RandomWalletChooser struct{}

func (RandomWalletChooser) Choose added in v0.3.0

func (w RandomWalletChooser) Choose(ctx context.Context, wallets []model.Wallet) (model.Wallet, error)

Choose selects a random Wallet from the provided slice of Wallets.

The Choose function of the RandomWalletChooser type randomly selects a Wallet from a given slice of Wallets. If the slice is empty, the function returns an error. It uses a cryptographically secure random number generator to make the selection.

Parameters:

  • ctx context.Context: The context to use for cancellation and deadlines, although it is not used in this implementation.
  • wallets []model.Wallet: A slice of Wallet objects from which a random Wallet will be chosen.

Returns:

  • model.Wallet: The randomly chosen Wallet object from the provided slice.
  • error: An error that will be returned if any issues were encountered while trying to choose a Wallet. This includes the case when the input slice is empty, in which case ErrNoWallet will be returned, or if there is an issue generating a random number.

type WalletChooser

type WalletChooser interface {
	Choose(ctx context.Context, wallets []model.Wallet) (model.Wallet, error)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL