Documentation ¶
Index ¶
- Constants
- Variables
- func ContainsAccountCurrency(m map[string]struct{}, change *AccountCurrency) bool
- func Err(err error) bool
- type AccountCurrency
- type Handler
- type Helper
- type InactiveEntry
- type Option
- func WithActiveConcurrency(concurrency int) Option
- func WithBalanceExemptions(exemptions []*types.BalanceExemption) Option
- func WithDebugLogging(debug bool) Option
- func WithInactiveConcurrency(concurrency int) Option
- func WithInactiveFrequency(blocks int64) Option
- func WithInterestingAccounts(interesting []*AccountCurrency) Option
- func WithLookupBalanceByBlock(lookup bool) Option
- func WithSeenAccounts(seen []*AccountCurrency) Option
- type Reconciler
Constants ¶
const ( // ActiveReconciliation is included in the reconciliation // error message if reconciliation failed during active // reconciliation. ActiveReconciliation = "ACTIVE" // InactiveReconciliation is included in the reconciliation // error message if reconciliation failed during inactive // reconciliation. InactiveReconciliation = "INACTIVE" )
Variables ¶
var ( // ErrHeadBlockBehindLive is returned when the processed // head is behind the live head. Sometimes, it is // preferable 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") ErrGetCurrentBlockFailed = errors.New("unable to get current block for reconciliation") ErrBlockExistsFailed = errors.New("unable to check if block exists") ErrGetComputedBalanceFailed = errors.New("unable to get computed balance") ErrLiveBalanceLookupFailed = errors.New("unable to lookup live balance") )
Named error types for Reconciler errors
Functions ¶
func ContainsAccountCurrency ¶
func ContainsAccountCurrency( m map[string]struct{}, change *AccountCurrency, ) bool
ContainsAccountCurrency returns a boolean indicating if a AccountCurrency set already contains an Account and Currency combination.
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 ¶
type Handler interface { ReconciliationFailed( ctx context.Context, reconciliationType string, account *types.AccountIdentifier, currency *types.Currency, computedBalance string, liveBalance string, block *types.BlockIdentifier, ) error ReconciliationSucceeded( ctx context.Context, reconciliationType string, account *types.AccountIdentifier, currency *types.Currency, balance string, block *types.BlockIdentifier, ) error ReconciliationExempt( ctx context.Context, reconciliationType string, account *types.AccountIdentifier, currency *types.Currency, computedBalance string, liveBalance string, block *types.BlockIdentifier, exemption *types.BalanceExemption, ) 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 ¶
type Helper interface { BlockExists( ctx context.Context, block *types.BlockIdentifier, ) (bool, error) CurrentBlock( ctx context.Context, ) (*types.BlockIdentifier, error) ComputedBalance( ctx context.Context, account *types.AccountIdentifier, currency *types.Currency, headBlock *types.BlockIdentifier, ) (*types.Amount, *types.BlockIdentifier, error) LiveBalance( ctx context.Context, account *types.AccountIdentifier, currency *types.Currency, block *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 InactiveEntry ¶ added in v0.3.0
type InactiveEntry struct { Entry *AccountCurrency LastCheck *types.BlockIdentifier }
InactiveEntry is used to track the last time that an *AccountCurrency was reconciled.
type Option ¶ added in v0.3.0
type Option func(r *Reconciler)
Option is used to overwrite default values in Reconciler construction. Any Option not provided falls back to the default value.
func WithActiveConcurrency ¶ added in v0.3.0
WithActiveConcurrency overrides the default active concurrency.
func WithBalanceExemptions ¶ added in v0.5.0
func WithBalanceExemptions(exemptions []*types.BalanceExemption) Option
WithBalanceExemptions is which reconciliation errors to skip.
func WithDebugLogging ¶ added in v0.3.1
WithDebugLogging determines if verbose logs should be printed.
func WithInactiveConcurrency ¶ added in v0.3.0
WithInactiveConcurrency overrides the default inactive concurrency.
func WithInactiveFrequency ¶ added in v0.3.1
WithInactiveFrequency is how many blocks the reconciler should wait between inactive reconciliations on each account.
func WithInterestingAccounts ¶ added in v0.3.0
func WithInterestingAccounts(interesting []*AccountCurrency) Option
WithInterestingAccounts adds interesting accounts to check at each block.
func WithLookupBalanceByBlock ¶ added in v0.3.0
WithLookupBalanceByBlock sets lookupBlockByBalance and instantiates the correct changeQueue.
func WithSeenAccounts ¶ added in v0.3.0
func WithSeenAccounts(seen []*AccountCurrency) Option
WithSeenAccounts adds accounts to the seenAccounts slice and inactiveQueue for inactive reconciliation.
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 New ¶ added in v0.3.0
func New( helper Helper, handler Handler, options ...Option, ) *Reconciler
New creates a new Reconciler.
func (*Reconciler) CompareBalance ¶
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.