providerstates

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2020 License: Apache-2.0, MIT Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ProviderEvents = fsm.Events{
	fsm.Event(rm.ProviderEventOpen).
		From(rm.DealStatusNew).ToNoChange().
		Action(
			func(deal *rm.ProviderDealState) error {
				deal.TotalSent = 0
				deal.FundsReceived = abi.NewTokenAmount(0)
				return nil
			},
		),
	fsm.Event(rm.ProviderEventDealReceived).
		From(rm.DealStatusNew).To(rm.DealStatusAwaitingAcceptance),
	fsm.Event(rm.ProviderEventWriteResponseFailed).
		FromAny().To(rm.DealStatusErrored).
		Action(func(deal *rm.ProviderDealState, err error) error {
			deal.Message = xerrors.Errorf("writing deal response: %w", err).Error()
			return nil
		}),
	fsm.Event(rm.ProviderEventDecisioningError).
		From(rm.DealStatusAwaitingAcceptance).To(rm.DealStatusErrored).
		Action(recordError),
	fsm.Event(rm.ProviderEventReadPaymentFailed).
		FromAny().To(rm.DealStatusErrored).
		Action(recordError),
	fsm.Event(rm.ProviderEventGetPieceSizeErrored).
		From(rm.DealStatusNew).To(rm.DealStatusFailed).
		Action(recordError),
	fsm.Event(rm.ProviderEventDealNotFound).
		From(rm.DealStatusNew).To(rm.DealStatusDealNotFound).
		Action(func(deal *rm.ProviderDealState) error {
			deal.Message = rm.ErrNotFound.Error()
			return nil
		}),
	fsm.Event(rm.ProviderEventDealRejected).
		FromMany(rm.DealStatusNew, rm.DealStatusAwaitingAcceptance).To(rm.DealStatusRejected).
		Action(recordError),
	fsm.Event(rm.ProviderEventDealAccepted).
		From(rm.DealStatusAwaitingAcceptance).To(rm.DealStatusAccepted).
		Action(func(deal *rm.ProviderDealState, dealProposal rm.DealProposal) error {
			deal.DealProposal = dealProposal
			deal.CurrentInterval = deal.PaymentInterval
			return nil
		}),
	fsm.Event(rm.ProviderEventBlockErrored).
		FromMany(rm.DealStatusAccepted, rm.DealStatusOngoing).To(rm.DealStatusFailed).
		Action(recordError),
	fsm.Event(rm.ProviderEventBlocksCompleted).
		FromMany(rm.DealStatusAccepted, rm.DealStatusOngoing).To(rm.DealStatusBlocksComplete),
	fsm.Event(rm.ProviderEventPaymentRequested).
		FromMany(rm.DealStatusAccepted, rm.DealStatusOngoing).To(rm.DealStatusFundsNeeded).
		From(rm.DealStatusBlocksComplete).To(rm.DealStatusFundsNeededLastPayment).
		Action(func(deal *rm.ProviderDealState, totalSent uint64) error {
			fmt.Println("Requesting payment")
			deal.TotalSent = totalSent
			return nil
		}),
	fsm.Event(rm.ProviderEventSaveVoucherFailed).
		FromMany(rm.DealStatusFundsNeeded, rm.DealStatusFundsNeededLastPayment).To(rm.DealStatusFailed).
		Action(recordError),
	fsm.Event(rm.ProviderEventPartialPaymentReceived).
		FromMany(rm.DealStatusFundsNeeded, rm.DealStatusFundsNeededLastPayment).ToNoChange().
		Action(func(deal *rm.ProviderDealState, fundsReceived abi.TokenAmount) error {
			deal.FundsReceived = big.Add(deal.FundsReceived, fundsReceived)
			return nil
		}),
	fsm.Event(rm.ProviderEventPaymentReceived).
		From(rm.DealStatusFundsNeeded).To(rm.DealStatusOngoing).
		From(rm.DealStatusFundsNeededLastPayment).To(rm.DealStatusFinalizing).
		Action(func(deal *rm.ProviderDealState, fundsReceived abi.TokenAmount) error {
			deal.FundsReceived = big.Add(deal.FundsReceived, fundsReceived)
			deal.CurrentInterval += deal.PaymentIntervalIncrease
			return nil
		}),
	fsm.Event(rm.ProviderEventComplete).
		From(rm.DealStatusFinalizing).To(rm.DealStatusCompleted),
}

ProviderEvents are the events that can happen in a retrieval provider

ProviderStateEntryFuncs are the handlers for different states in a retrieval provider

Functions

func DecideOnDeal added in v0.3.0

func DecideOnDeal(ctx fsm.Context, env ProviderDealEnvironment, state rm.ProviderDealState) error

DecideOnDeal runs any custom deal decider and if it passes, tell client it's accepted, and move to the next state

func Finalize

func Finalize(ctx fsm.Context, environment ProviderDealEnvironment, deal rm.ProviderDealState) error

Finalize completes a deal

func ProcessPayment

func ProcessPayment(ctx fsm.Context, environment ProviderDealEnvironment, deal rm.ProviderDealState) error

ProcessPayment processes a payment from the client and resumes the deal if successful

func ReceiveDeal

func ReceiveDeal(ctx fsm.Context, environment ProviderDealEnvironment, deal rm.ProviderDealState) error

ReceiveDeal receives and evaluates a deal proposal

func SendBlocks

func SendBlocks(ctx fsm.Context, environment ProviderDealEnvironment, deal rm.ProviderDealState) error

SendBlocks sends blocks to the client until funds are needed

func SendFailResponse

func SendFailResponse(ctx fsm.Context, environment ProviderDealEnvironment, deal rm.ProviderDealState) error

SendFailResponse sends a failure response before closing the deal

Types

type ProviderDealEnvironment

type ProviderDealEnvironment interface {
	Node() rm.RetrievalProviderNode
	GetPieceSize(c cid.Cid) (uint64, error)
	DealStream(id rm.ProviderDealIdentifier) rmnet.RetrievalDealStream
	NextBlock(context.Context, rm.ProviderDealIdentifier) (rm.Block, bool, error)
	CheckDealParams(pricePerByte abi.TokenAmount, paymentInterval uint64, paymentIntervalIncrease uint64) error
	RunDealDecisioningLogic(ctx context.Context, state rm.ProviderDealState) (bool, string, error)
}

ProviderDealEnvironment is a bridge to the environment a provider deal is executing in

Jump to

Keyboard shortcuts

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