migrator

package
v1.2.8 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2023 License: Apache-2.0 Imports: 28 Imported by: 1

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")
)
View Source
var ErrEmptyBundle = errors.New("empty bundle")

ErrEmptyBundle is returned when a bundle contains no transaction.

View Source
var (
	// ErrInvalidReceiptServiceState is returned when the state of the ReceiptService is invalid.
	ErrInvalidReceiptServiceState = errors.New("invalid receipt service state")
)

Functions

func MigratedFundsCaller

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

MigratedFundsCaller is an event caller which gets migrated funds passed.

Types

type LegacyAPI

type LegacyAPI interface {
	GetNodeInfo() (*api.GetNodeInfoResponse, error)
	GetWhiteFlagConfirmation(milestoneIndex uint32) (*api.WhiteFlagConfirmation, error)
}

LegacyAPI defines the calls of the legacy API that are used.

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 *uint32, utxoManager *utxo.Manager) 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

func (s *MigratorService) Receipt() *iotago.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(uint32) ([]*iotago.MigratedFundsEntry, error)
	QueryNextMigratedFunds(uint32) (uint32, []*iotago.MigratedFundsEntry, error)
}

Queryer defines the interface used to query the migrated funds.

type ReceiptPersistFunc

type ReceiptPersistFunc func(r *iotago.Receipt) error

ReceiptPersistFunc is a function which persists a receipt.

type ReceiptService

type ReceiptService struct {
	// Whether the service is configured to back up receipts.
	BackupEnabled bool
	// Whether the service is configured to validate receipts.
	ValidationEnabled bool
	// Whether the service should ignore soft errors.
	IgnoreSoftErrors bool
	// contains filtered or unexported fields
}

ReceiptService is in charge of persisting and validating a batch of receipts.

func NewReceiptService

func NewReceiptService(validator *Validator, utxoManager *utxo.Manager, validationEnabled bool, backupEnabled bool, ignoreSoftErrors bool, backupFolder string) *ReceiptService

NewReceiptService creates a new ReceiptService.

func (*ReceiptService) Backup

func (rs *ReceiptService) Backup(r *utxo.ReceiptTuple) error

Backup backups the given receipt to disk.

func (*ReceiptService) Init

func (rs *ReceiptService) Init() error

Init initializes the ReceiptService and returns the amount of receipts currently stored.

func (*ReceiptService) ValidateWithoutLocking

func (rs *ReceiptService) ValidateWithoutLocking(r *iotago.Receipt) error

ValidateWithoutLocking validates the given receipt against data fetched from a legacy node. The UTXO ledger should be locked outside of this function. If the receipt has the final flag set to true, then the entire batch of receipts with the same migrated_at index are collected and it is checked whether they migrated all the funds of the given white-flag confirmation.

type ReceiptValidateFunc

type ReceiptValidateFunc func(r *iotago.Receipt) error

ReceiptValidateFunc is a function which validates a receipt.

type State

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

State stores the latest state of the MigratorService.

type Validator

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

Validator takes care of fetching and validating white-flag confirmation data from legacy nodes and wrapping them into receipts.

func NewValidator

func NewValidator(api LegacyAPI, coordinatorAddress trinary.Hash, coordinatorMerkleTreeDepth int) *Validator

NewValidator creates a new Validator.

func (*Validator) QueryMigratedFunds

func (m *Validator) QueryMigratedFunds(milestoneIndex uint32) ([]*iotago.MigratedFundsEntry, error)

QueryMigratedFunds queries the legacy network for the white-flag confirmation data for the given milestone index, verifies the signatures of the milestone and included bundles and then compiles a slice of migrated fund entries.

func (*Validator) QueryNextMigratedFunds

func (m *Validator) QueryNextMigratedFunds(startIndex uint32) (uint32, []*iotago.MigratedFundsEntry, error)

QueryNextMigratedFunds queries the next existing migrations starting from milestone index startIndex. It returns the migrations as well as milestone index that confirmed those migrations. If there are currently no more migrations, it returns the latest milestone index that was checked.

Jump to

Keyboard shortcuts

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