mapper

package
v0.31.14 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = Config{
	BootstrapState: false,
	SkipRegisters:  false,
	WaitInterval:   10 * time.Millisecond,
}

DefaultConfig is the default configuration for the Mapper.

Functions

func WithTransition

func WithTransition(status Status, transition TransitionFunc) func(*FSM)

WithTransition specifies which TransitionFunc should be used when the state machine has the given status.

Types

type Config

type Config struct {
	BootstrapState bool
	SkipRegisters  bool
	WaitInterval   time.Duration
}

Config contains optional parameters for the Mapper.

type FSM

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

FSM is a finite state machine which is used to map block data from multiple sources into the DPS index.

func NewFSM

func NewFSM(state *State, options ...func(*FSM)) *FSM

NewFSM returns a new FSM using the given state and options.

func (*FSM) Run

func (f *FSM) Run() error

Run starts the state machine.

func (*FSM) Stop

func (f *FSM) Stop() error

Stop gracefully stops the state machine.

type Loader

type Loader interface {
	Trie() (*trie.MTrie, error)
}

Loader represents something that loads its checkpoint and builds it into a trie.

type Option

type Option func(*Config)

Option is an option that can be given to the mapper to configure optional parameters on initialization.

func WithBootstrapState

func WithBootstrapState(bootstrap bool) Option

WithBootstrapState makes the mapper bootstrap the state from a root checkpoint. If not set, it will resume indexing from a previous trie.

func WithSkipRegisters

func WithSkipRegisters(skip bool) Option

WithSkipRegisters makes the mapper skip indexing of all ledger registers, which speeds up the run significantly and can be used for debugging purposes.

func WithWaitInterval

func WithWaitInterval(interval time.Duration) Option

WithWaitInterval sets the wait interval that we will wait before retrying to retrieve a trie update when it wasn't available.

type State

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

State is the state machine's state for the current block being processed

func EmptyState

func EmptyState(checkpointFile string) *State

EmptyState returns a new empty state

type Status

type Status uint8

Status is a representation of the state machine's status.

const (
	StatusInitialize Status = iota + 1
	StatusBootstrap
	StatusResume
	StatusUpdate
	StatusCollect
	StatusMap
	StatusIndex
	StatusForward
)

The following is an enumeration of all possible statuses the state machine can have. The order in the enum reflects the order of normal transitions in the FSM

func (Status) String

func (s Status) String() string

String implements the Stringer interface. In order of

type TransitionFunc

type TransitionFunc func(*State) error

TransitionFunc is a function that is applied onto the state machine's state.

type Transitions

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

Transitions is what applies transitions to the state of an FSM.

func NewTransitions

func NewTransitions(log zerolog.Logger, chain archive.Chain, updates TrieUpdates, read archive.Reader, write archive.Writer, options ...Option) *Transitions

NewTransitions returns a Transitions component using the given dependencies and using the given options The states are, in order: Initialize -> Bootstrap -> Resume -> Update -> Collect -> Map -> Index -> Forward

func (*Transitions) BootstrapState

func (t *Transitions) BootstrapState(s *State) error

BootstrapState bootstraps the state by loading the checkpoint if there is one and initializing the elements subsequently used by the FSM.

func (*Transitions) CollectRegisters

func (t *Transitions) CollectRegisters(s *State) error

CollectRegisters reads the payloads for the next block to be indexed from the state's forest, unless payload indexing is disabled.

func (*Transitions) ForwardHeight

func (t *Transitions) ForwardHeight(s *State) error

ForwardHeight increments the height at which the mapping operates, and updates the last indexed height.

func (*Transitions) IndexChain

func (t *Transitions) IndexChain(s *State) error

IndexChain indexes chain data for the current height.

func (*Transitions) InitializeMapper

func (t *Transitions) InitializeMapper(s *State) error

InitializeMapper initializes the mapper by either going into bootstrapping or into resuming, depending on the configuration.

func (*Transitions) MapRegisters

func (t *Transitions) MapRegisters(s *State) error

MapRegisters maps the collected registers to the current block.

func (*Transitions) ResumeIndexing

func (t *Transitions) ResumeIndexing(s *State) error

ResumeIndexing resumes indexing the data from a previous run.

func (*Transitions) UpdateTree

func (t *Transitions) UpdateTree(s *State) error

UpdateTree gets all trie updates and stores it in the state

type TrieUpdates added in v0.31.4

type TrieUpdates interface {
	AllUpdates() ([]*ledger.TrieUpdate, error)
}

TrieUpdates represents something to get trie updates in block-height order.

Jump to

Keyboard shortcuts

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