provider

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2022 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Events = map[Event]string{
	EventOpen:                   "ProviderEventOpen",
	EventDealNotFound:           "ProviderEventDealNotFound",
	EventDealRejected:           "ProviderEventDealRejected",
	EventDealAccepted:           "ProviderEventDealAccepted",
	EventBlockSent:              "ProviderEventBlockSent",
	EventBlocksCompleted:        "ProviderEventBlocksCompleted",
	EventPaymentRequested:       "ProviderEventPaymentRequested",
	EventSaveVoucherFailed:      "ProviderEventSaveVoucherFailed",
	EventPartialPaymentReceived: "ProviderEventPartialPaymentReceived",
	EventPaymentReceived:        "ProviderEventPaymentReceived",
	EventComplete:               "ProviderEventComplete",
	EventUnsealError:            "ProviderEventUnsealError",
	EventUnsealComplete:         "ProviderEventUnsealComplete",
	EventDataTransferError:      "ProviderEventDataTransferError",
	EventCancelComplete:         "ProviderEventCancelComplete",
	EventCleanupComplete:        "ProviderEventCleanupComplete",
	EventMultiStoreError:        "ProviderEventMultiStoreError",
	EventClientCancelled:        "ProviderEventClientCancelled",
}

Events is a human readable map of provider event name -> event description

View Source
var FSMEvents = fsm.Events{

	fsm.Event(EventOpen).
		From(deal.StatusNew).ToNoChange(),

	fsm.Event(EventDealAccepted).
		From(deal.StatusNew).To(deal.StatusOngoing),

	fsm.Event(EventBlockSent).
		FromMany(deal.StatusOngoing).ToNoChange().
		Action(func(ds *deal.ProviderState, totalSent uint64) error {
			ds.TotalSent = totalSent
			return nil
		}),
	fsm.Event(EventBlocksCompleted).
		FromMany(deal.StatusOngoing).To(deal.StatusBlocksComplete),

	fsm.Event(EventPaymentRequested).
		From(deal.StatusOngoing).To(deal.StatusFundsNeeded).
		From(deal.StatusFundsNeeded).ToJustRecord().
		From(deal.StatusBlocksComplete).To(deal.StatusFundsNeededLastPayment).
		Action(func(ds *deal.ProviderState, totalSent uint64) error {
			ds.TotalSent = totalSent
			return nil
		}),

	fsm.Event(EventSaveVoucherFailed).
		FromMany(deal.StatusFundsNeeded, deal.StatusFundsNeededLastPayment).To(deal.StatusFailing).
		Action(recordError),
	fsm.Event(EventPartialPaymentReceived).
		FromMany(deal.StatusFundsNeeded, deal.StatusFundsNeededLastPayment).ToNoChange().
		Action(func(ds *deal.ProviderState, fundsReceived abi.TokenAmount, ch address.Address) error {
			ds.FundsReceived = big.Add(ds.FundsReceived, fundsReceived)
			ds.PayCh = &ch
			return nil
		}),
	fsm.Event(EventPaymentReceived).
		From(deal.StatusFundsNeeded).To(deal.StatusOngoing).
		From(deal.StatusFundsNeededLastPayment).To(deal.StatusFinalizing).
		FromMany(deal.StatusBlocksComplete, deal.StatusOngoing, deal.StatusFinalizing).ToJustRecord().
		Action(func(ds *deal.ProviderState, fundsReceived abi.TokenAmount, ch address.Address) error {
			ds.FundsReceived = big.Add(ds.FundsReceived, fundsReceived)
			ds.CurrentInterval = ds.NextInterval()
			ds.PayCh = &ch
			return nil
		}),

	fsm.Event(EventComplete).FromMany(deal.StatusBlocksComplete, deal.StatusFinalizing).To(deal.StatusCompleting),
	fsm.Event(EventCleanupComplete).From(deal.StatusCompleting).To(deal.StatusCompleted),

	fsm.Event(EventCancelComplete).
		From(deal.StatusCancelling).To(deal.StatusCancelled).
		From(deal.StatusFailing).To(deal.StatusErrored),

	fsm.Event(EventDataTransferError).
		FromAny().To(deal.StatusErrored).
		Action(recordError),

	fsm.Event(EventMultiStoreError).
		FromAny().To(deal.StatusErrored).
		Action(recordError),

	fsm.Event(EventClientCancelled).
		From(deal.StatusFailing).ToJustRecord().
		From(deal.StatusCancelling).ToJustRecord().
		FromAny().To(deal.StatusCancelling).Action(
		func(ds *deal.ProviderState) error {
			if ds.Status != deal.StatusFailing {
				ds.Message = "Client cancelled retrieval"
			}
			return nil
		},
	),
}

FSMEvents is the state chart defining the events that can happen in a retrieval provider it is almost identical to go-fil-markets except we don't have to unseal pieces

FinalityStates are the terminal states for a retrieval provider

StateEntryFuncs are the handlers for different states in a retrieval provider

Functions

func CancelDeal

func CancelDeal(ctx fsm.Context, environment DealEnvironment, ds deal.ProviderState) error

CancelDeal clears a deal that went wrong for an unknown reason

func CleanupDeal

func CleanupDeal(ctx fsm.Context, environment DealEnvironment, ds deal.ProviderState) error

CleanupDeal runs to do memory cleanup for an in progress deal

func DataTransferSubscriber

func DataTransferSubscriber(deals EventReceiver, host peer.ID) datatransfer.Subscriber

DataTransferSubscriber is the function called when an event occurs in a data transfer received by a provider -- it reads the voucher to verify this event occurred in a storage market deal, then, based on the data transfer event that occurred, it generates and update message for the deal -- either moving to staged for a completion event or moving to error if a data transfer error occurs

func Dispatcher

func Dispatcher(evt pubsub.Event, subscriberFn pubsub.SubscriberFn) error

Dispatcher will publish a pubsub event cast as Provider event

func TrackTransfer

func TrackTransfer(ctx fsm.Context, environment DealEnvironment, ds deal.ProviderState) error

TrackTransfer keeps track of a transfer during revalidation

Types

type DealEnvironment

type DealEnvironment interface {
	TrackTransfer(deal.ProviderState) error
	UntrackTransfer(deal.ProviderState) error
	DeleteStore(multistore.StoreID) error
	ResumeDataTransfer(context.Context, datatransfer.ChannelID) error
	CloseDataTransfer(context.Context, datatransfer.ChannelID) error
}

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

type Event

type Event uint64

Event that occurs in a deal lifecycle on the provider

const (
	// EventOpen indicates a new deal was received from a client
	EventOpen Event = iota

	// EventDealNotFound happens when the provider cannot find the piece for the
	// deal proposed by the client
	EventDealNotFound

	// EventDealRejected happens when a provider rejects a deal proposed
	// by the client
	EventDealRejected

	// EventDealAccepted happens when a provider accepts a deal
	EventDealAccepted

	// EventBlockSent happens when the provider reads another block
	// in the piece
	EventBlockSent

	// EventBlocksCompleted happens when the provider reads the last block
	// in the piece
	EventBlocksCompleted

	// EventPaymentRequested happens when a provider asks for payment from
	// a client for blocks sent
	EventPaymentRequested

	// EventSaveVoucherFailed happens when an attempt to save a payment
	// voucher fails
	EventSaveVoucherFailed

	// EventPartialPaymentReceived happens when a provider receives and processes
	// a payment that is less than what was requested to proceed with the deal
	EventPartialPaymentReceived

	// EventPaymentReceived happens when a provider receives a payment
	// and resumes processing a deal
	EventPaymentReceived

	// EventComplete indicates a retrieval deal was completed for a client
	EventComplete

	// EventUnsealError emits when something wrong occurs while unsealing data
	EventUnsealError

	// EventUnsealComplete emits when the unsealing process is done
	EventUnsealComplete

	// EventDataTransferError emits when something go wrong at the data transfer level
	EventDataTransferError

	// EventCancelComplete happens when a deal cancellation is transmitted to the provider
	EventCancelComplete

	// EventCleanupComplete happens when a deal is finished cleaning up and enters a complete state
	EventCleanupComplete

	// EventMultiStoreError occurs when an error happens attempting to operate on the multistore
	EventMultiStoreError

	// EventClientCancelled happens when the provider gets a cancel message from the client's data transfer
	EventClientCancelled
)

type EventReceiver

type EventReceiver interface {
	Has(id interface{}) (bool, error)
	Send(id interface{}, name fsm.EventName, args ...interface{}) (err error)
}

EventReceiver is any thing that can receive FSM events

type InternalEvent

type InternalEvent struct {
	Evt   Event
	State deal.ProviderState
}

InternalEvent wraps a provider event and the associated deal state

type Subscriber

type Subscriber func(event Event, state deal.ProviderState)

Subscriber is a callback that is registered to listen for retrieval events on a provider

Jump to

Keyboard shortcuts

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