reconciler

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2020 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrHeadBlockBehindLive is returned when the processed
	// head is behind the live head. Sometimes, it is
	// preferrable to sleep and wait to catch up when
	// we are close to the live head (waitToCheckDiff).
	ErrHeadBlockBehindLive = errors.New("head block behind")

	// ErrAccountUpdated is returned when the
	// account was updated at a height later than
	// the live height (when the account balance was fetched).
	ErrAccountUpdated = errors.New("account updated")

	// ErrBlockGone is returned when the processed block
	// head is greater than the live head but the block
	// does not exist in the store. This likely means
	// that the block was orphaned.
	ErrBlockGone = errors.New("block gone")
)

Functions

func ContainsAccountCurrency

func ContainsAccountCurrency(
	arr []*AccountCurrency,
	change *AccountCurrency,
) bool

ContainsAccountCurrency returns a boolean indicating if a AccountCurrency slice already contains an Account and Currency combination.

func ExtractAmount

func ExtractAmount(
	balances []*types.Amount,
	currency *types.Currency,
) (*types.Amount, error)

ExtractAmount returns the types.Amount from a slice of types.Balance pertaining to an AccountAndCurrency.

func GetCurrencyBalance

func GetCurrencyBalance(
	ctx context.Context,
	fetcher *fetcher.Fetcher,
	network *types.NetworkIdentifier,
	account *types.AccountIdentifier,
	currency *types.Currency,
	block *types.PartialBlockIdentifier,
) (*types.BlockIdentifier, string, error)

GetCurrencyBalance fetches the balance of a *types.AccountIdentifier for a particular *types.Currency.

Types

type AccountCurrency

type AccountCurrency struct {
	Account  *types.AccountIdentifier `json:"account_identifier,omitempty"`
	Currency *types.Currency          `json:"currency,omitempty"`
}

AccountCurrency is a simple struct combining a *types.Account and *types.Currency. This can be useful for looking up balances.

type Reconciler

type Reconciler interface {
	QueueChanges(
		ctx context.Context,
		block *types.BlockIdentifier,
		changes []*storage.BalanceChange,
	) error

	Reconcile(ctx context.Context) error
}

Reconciler defines an interface for comparing computed balances with node balances.

type StatefulReconciler

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

StatefulReconciler contains all logic to reconcile balances of types.AccountIdentifiers returned in types.Operations by a Rosetta Server.

func NewStateful

func NewStateful(
	network *types.NetworkIdentifier,
	blockStorage *storage.BlockStorage,
	fetcher *fetcher.Fetcher,
	logger *logger.Logger,
	accountConcurrency uint64,
	lookupBalanceByBlock bool,
	haltOnReconciliationError bool,
) *StatefulReconciler

NewStateful creates a new StatefulReconciler.

func (*StatefulReconciler) CompareBalance

func (r *StatefulReconciler) CompareBalance(
	ctx context.Context,
	account *types.AccountIdentifier,
	currency *types.Currency,
	amount string,
	liveBlock *types.BlockIdentifier,
) (string, int64, error)

CompareBalance checks to see if the computed balance of an account is equal to the live balance of an account. This function ensures balance is checked correctly in the case of orphaned blocks.

func (*StatefulReconciler) QueueChanges

func (r *StatefulReconciler) QueueChanges(
	ctx context.Context,
	block *types.BlockIdentifier,
	balanceChanges []*storage.BalanceChange,
) error

QueueChanges enqueues a slice of *storage.BalanceChanges for reconciliation.

func (*StatefulReconciler) Reconcile

func (r *StatefulReconciler) Reconcile(ctx context.Context) error

Reconcile starts the active and inactive StatefulReconciler goroutines. If any goroutine errors, the function will return an error.

type StatelessReconciler

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

StatelessReconciler compares computed balances with the node balance without using any sort of persistent state. If it is not possible to lookup a balance by block, you must use the StatefulReconciler. If you want to perform inactive reconciliation (check for balance changes that occurred that were not in blocks), you must also use the StatefulReconciler. Lastly, the StatelessReconciler does not support re-orgs.

func NewStateless

func NewStateless(
	network *types.NetworkIdentifier,
	fetcher *fetcher.Fetcher,
	logger *logger.Logger,
	accountConcurrency uint64,
	haltOnReconciliationError bool,
	interestingAccounts []*AccountCurrency,
) *StatelessReconciler

NewStateless returns a new StatelessReconciler.

func (*StatelessReconciler) QueueChanges

func (r *StatelessReconciler) QueueChanges(
	ctx context.Context,
	block *types.BlockIdentifier,
	balanceChanges []*storage.BalanceChange,
) error

QueueChanges enqueues a slice of *storage.BalanceChanges for reconciliation.

func (*StatelessReconciler) Reconcile

func (r *StatelessReconciler) Reconcile(ctx context.Context) error

Reconcile starts the active StatelessReconciler goroutines. If any goroutine errors, the function will return an error.

Jump to

Keyboard shortcuts

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