migrator

package
v1.0.0-beta.5 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SensibleMaxEntriesCount defines an amount of entries within receipts which allows a milestone with 8 parents and 2 sigs/pub keys
	// to fly under the next pow requirement step.
	SensibleMaxEntriesCount = 110
)

Variables

View Source
var (
	// ErrStateFileAlreadyExists is returned when a new state is tried to be initialized but a state file already exists.
	ErrStateFileAlreadyExists = errors.New("migrator state file already exists")
	// ErrInvalidState is returned when the content of the state file is invalid.
	ErrInvalidState = errors.New("invalid migrator state")
)

Functions

func MigratedFundsCaller

func MigratedFundsCaller(handler interface{}, params ...interface{})

MigratedFundsCaller is an event caller which gets migrated funds passed.

Types

type MigratorService

type MigratorService struct {
	Events *MigratorServiceEvents
	// contains filtered or unexported fields
}

MigratorService is a service querying and validating batches of migrated funds.

func NewService

func NewService(queryer Queryer, stateFilePath string, receiptMaxEntries int) *MigratorService

NewService creates a new MigratorService.

func (*MigratorService) InitState

func (s *MigratorService) InitState(msIndex *iotago.MilestoneIndex) error

InitState initializes the state of s. If msIndex is not nil, s is bootstrapped using that index as its initial state, otherwise the state is loaded from file. The optional utxoManager is used to validate the initialized state against the DB. InitState must be called before Start.

func (*MigratorService) PersistState

func (s *MigratorService) PersistState(sendingReceipt bool) error

PersistState persists the current state to a file. PersistState must be called when the receipt returned by the last call of Receipt has been send to the network.

func (*MigratorService) Receipt

Receipt returns the next receipt of migrated funds. Each receipt can only consists of migrations confirmed by one milestone, it will never be larger than MaxMigratedFundsEntryCount. Receipt returns nil, if there are currently no new migrations available. Although the actual API calls and validations happen in the background, Receipt might block until the next receipt is ready. When s is stopped, Receipt will always return nil.

func (*MigratorService) Start

func (s *MigratorService) Start(ctx context.Context, onError OnServiceErrorFunc)

Start stats the MigratorService s, it stops when the given context is done.

type MigratorServiceEvents

type MigratorServiceEvents struct {
	// SoftError is triggered when a soft error is encountered.
	SoftError *events.Event
	// MigratedFundsFetched is triggered when new migration funds were fetched from a legacy node.
	MigratedFundsFetched *events.Event
}

MigratorServiceEvents are events happening around a MigratorService.

type OnServiceErrorFunc

type OnServiceErrorFunc func(err error) (terminate bool)

OnServiceErrorFunc is a function which is called when the service encounters an error which prevents it from functioning properly. Returning false from the error handler tells the service to terminate.

type Queryer

type Queryer interface {
	QueryMigratedFunds(iotago.MilestoneIndex) ([]*iotago.MigratedFundsEntry, error)
	QueryNextMigratedFunds(iotago.MilestoneIndex) (iotago.MilestoneIndex, []*iotago.MigratedFundsEntry, error)
}

Queryer defines the interface used to query the migrated funds.

type State

type State struct {
	LatestMigratedAtIndex iotago.MilestoneIndex `json:"latestMigratedAtIndex"`
	LatestIncludedIndex   uint32                `json:"latestIncludedIndex"`
	SendingReceipt        bool                  `json:"sendingReceipt"`
}

State stores the latest state of the MigratorService.

Jump to

Keyboard shortcuts

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