reconciler

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2020 License: Apache-2.0 Imports: 11 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 Handler added in v0.2.0

type Handler interface {
	ReconciliationFailed(
		ctx context.Context,
		reconciliationType string,
		account *types.AccountIdentifier,
		currency *types.Currency,
		computedBalance string,
		nodeBalance string,
		block *types.BlockIdentifier,
	) error

	ReconciliationSucceeded(
		ctx context.Context,
		reconciliationType string,
		account *types.AccountIdentifier,
		currency *types.Currency,
		balance string,
		block *types.BlockIdentifier,
	) error
}

Handler is called by Reconciler after a reconciliation is performed. When a reconciliation failure is observed, it is up to the client to halt syncing or log the result.

type Helper added in v0.2.0

type Helper interface {
	BlockExists(
		ctx context.Context,
		block *types.BlockIdentifier,
	) (bool, error)

	CurrentBlock(
		ctx context.Context,
	) (*types.BlockIdentifier, error)

	AccountBalance(
		ctx context.Context,
		account *types.AccountIdentifier,
		currency *types.Currency,
		headBlock *types.BlockIdentifier,
	) (*types.Amount, *types.BlockIdentifier, error)
}

Helper functions are used by Reconciler to compare computed balances from a block with the balance calculated by the node. Defining an interface allows the client to determine what sort of storage layer they want to use to provide the required information.

type Reconciler

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

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

func NewReconciler added in v0.2.0

func NewReconciler(
	network *types.NetworkIdentifier,
	helper Helper,
	handler Handler,
	fetcher *fetcher.Fetcher,
	accountConcurrency uint64,
	lookupBalanceByBlock bool,
	interestingAccounts []*AccountCurrency,

) *Reconciler

NewReconciler creates a new Reconciler.

func (*Reconciler) CompareBalance added in v0.2.0

func (r *Reconciler) CompareBalance(
	ctx context.Context,
	account *types.AccountIdentifier,
	currency *types.Currency,
	amount string,
	liveBlock *types.BlockIdentifier,
) (string, 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 (*Reconciler) QueueChanges

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

QueueChanges enqueues a slice of *BalanceChanges for reconciliation.

func (*Reconciler) Reconcile

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

Reconcile starts the active and inactive Reconciler 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