migrator

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2023 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

This section is empty.

Types

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 Service added in v1.0.0

type Service struct {
	Events *ServiceEvents
	// contains filtered or unexported fields
}

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

func NewService

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

NewService creates a new MigratorService.

func (*Service) InitState added in v1.0.0

func (s *Service) 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 (*Service) PersistState added in v1.0.0

func (s *Service) 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 (*Service) Receipt added in v1.0.0

func (s *Service) Receipt() *iotago.ReceiptMilestoneOpt

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 (*Service) Start added in v1.0.0

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

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

type ServiceEvents added in v1.0.0

type ServiceEvents struct {
	// SoftError is triggered when a soft error is encountered.
	SoftError *event.Event1[error]
	// MigratedFundsFetched is triggered when new migration funds were fetched from a legacy node.
	MigratedFundsFetched *event.Event1[[]*iotago.MigratedFundsEntry]
}

ServiceEvents are events happening around a MigratorService.

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