processor

package
v0.10.3 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2023 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BalanceStorageHandler

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

BalanceStorageHandler is invoked whenever a block is added or removed from block storage so that balance changes can be sent to other functions (ex: reconciler).

func NewBalanceStorageHandler

func NewBalanceStorageHandler(
	logger *logger.Logger,
	reconciler *reconciler.Reconciler,
	counterStorage *modules.CounterStorage,
	reconcile bool,
	interestingAccount *types.AccountCurrency,
) *BalanceStorageHandler

NewBalanceStorageHandler returns a new *BalanceStorageHandler.

func (*BalanceStorageHandler) AccountsReconciled added in v0.6.1

func (h *BalanceStorageHandler) AccountsReconciled(
	ctx context.Context,
	dbTx database.Transaction,
	count int,
) error

AccountsReconciled updates the total accounts reconciled by count.

func (*BalanceStorageHandler) AccountsSeen added in v0.6.1

func (h *BalanceStorageHandler) AccountsSeen(
	ctx context.Context,
	dbTx database.Transaction,
	count int,
) error

AccountsSeen updates the total accounts seen by count.

func (*BalanceStorageHandler) BlockAdded

func (h *BalanceStorageHandler) BlockAdded(
	ctx context.Context,
	block *types.Block,
	changes []*parser.BalanceChange,
) error

BlockAdded is called whenever a block is committed to BlockStorage.

func (*BalanceStorageHandler) BlockRemoved

func (h *BalanceStorageHandler) BlockRemoved(
	ctx context.Context,
	block *types.Block,
	changes []*parser.BalanceChange,
) error

BlockRemoved is called whenever a block is removed from BlockStorage.

type BalanceStorageHelper

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

BalanceStorageHelper implements the storage.Helper interface.

func NewBalanceStorageHelper

func NewBalanceStorageHelper(
	network *types.NetworkIdentifier,
	fetcher *fetcher.Fetcher,
	counterStorage *modules.CounterStorage,
	lookupBalanceByBlock bool,
	exemptAccounts []*types.AccountCurrency,
	interestingOnly bool,
	balanceExemptions []*types.BalanceExemption,
	initialFetchDisabled bool,
) *BalanceStorageHelper

NewBalanceStorageHelper returns a new BalanceStorageHelper.

func (*BalanceStorageHelper) AccountBalance

func (h *BalanceStorageHelper) AccountBalance(
	ctx context.Context,
	account *types.AccountIdentifier,
	currency *types.Currency,
	lookupBlock *types.BlockIdentifier,
) (*types.Amount, error)

AccountBalance attempts to fetch the balance for a missing account in storage. This is necessary for running the "check" command at an arbitrary height instead of syncing from genesis.

func (*BalanceStorageHelper) AccountsReconciled added in v0.6.1

func (h *BalanceStorageHelper) AccountsReconciled(
	ctx context.Context,
	dbTx database.Transaction,
) (*big.Int, error)

AccountsReconciled returns the total accounts reconciled by count.

func (*BalanceStorageHelper) AccountsSeen added in v0.6.1

func (h *BalanceStorageHelper) AccountsSeen(
	ctx context.Context,
	dbTx database.Transaction,
) (*big.Int, error)

AccountsSeen returns the total accounts seen by count.

func (*BalanceStorageHelper) AddInterestingAddress

func (h *BalanceStorageHelper) AddInterestingAddress(address string)

AddInterestingAddress adds an address to track the balance of. This is often done after generating an account.

func (*BalanceStorageHelper) Asserter

func (h *BalanceStorageHelper) Asserter() *asserter.Asserter

Asserter returns a *asserter.Asserter.

func (*BalanceStorageHelper) BalanceExemptions added in v0.5.15

func (h *BalanceStorageHelper) BalanceExemptions() []*types.BalanceExemption

BalanceExemptions returns a list of *types.BalanceExemption.

func (*BalanceStorageHelper) ExemptFunc

ExemptFunc returns a parser.ExemptOperation.

type BroadcastStorageHandler

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

BroadcastStorageHandler is invoked whenever a block is added or removed from block storage so that balance changes can be sent to other functions (ex: reconciler).

func NewBroadcastStorageHandler

func NewBroadcastStorageHandler(
	config *configuration.Configuration,
	blockStorage *modules.BlockStorage,
	counterStorage *modules.CounterStorage,
	coordinator *coordinator.Coordinator,
	parser *parser.Parser,
) *BroadcastStorageHandler

NewBroadcastStorageHandler returns a new *BroadcastStorageHandler.

func (*BroadcastStorageHandler) BroadcastFailed

func (h *BroadcastStorageHandler) BroadcastFailed(
	ctx context.Context,
	dbTx database.Transaction,
	identifier string,
	transactionIdentifier *types.TransactionIdentifier,
	intent []*types.Operation,
) error

BroadcastFailed is called when another transaction broadcast would put it over the provided broadcast limit.

func (*BroadcastStorageHandler) TransactionConfirmed

func (h *BroadcastStorageHandler) TransactionConfirmed(
	ctx context.Context,
	dbTx database.Transaction,
	identifier string,
	blockIdentifier *types.BlockIdentifier,
	transaction *types.Transaction,
	intent []*types.Operation,
	intentMetadata map[string]interface{},
) error

TransactionConfirmed is called when a transaction is observed on-chain for the last time at a block height < current block height - confirmationDepth.

func (*BroadcastStorageHandler) TransactionStale

func (h *BroadcastStorageHandler) TransactionStale(
	ctx context.Context,
	dbTx database.Transaction,
	identifier string,
	transactionIdentifier *types.TransactionIdentifier,
) error

TransactionStale is called when a transaction has not yet been seen on-chain and is considered stale. This occurs when current block height - last broadcast > staleDepth.

type BroadcastStorageHelper

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

BroadcastStorageHelper implements the storage.Helper interface.

func NewBroadcastStorageHelper

func NewBroadcastStorageHelper(
	network *types.NetworkIdentifier,
	blockStorage *modules.BlockStorage,
	fetcher *fetcher.Fetcher,
) *BroadcastStorageHelper

NewBroadcastStorageHelper returns a new BroadcastStorageHelper.

func (*BroadcastStorageHelper) AtTip

func (h *BroadcastStorageHelper) AtTip(
	ctx context.Context,
	tipDelay int64,
) (bool, error)

AtTip is called before transaction broadcast to determine if we are at tip.

func (*BroadcastStorageHelper) BroadcastTransaction

func (h *BroadcastStorageHelper) BroadcastTransaction(
	ctx context.Context,
	networkIdentifier *types.NetworkIdentifier,
	networkTransaction string,
) (*types.TransactionIdentifier, error)

BroadcastTransaction broadcasts a transaction to a Rosetta implementation and returns the *types.TransactionIdentifier returned by the implementation.

func (*BroadcastStorageHelper) CurrentBlockIdentifier

func (h *BroadcastStorageHelper) CurrentBlockIdentifier(
	ctx context.Context,
) (*types.BlockIdentifier, error)

CurrentBlockIdentifier is called before transaction broadcast and is used to determine if a transaction broadcast is stale.

func (*BroadcastStorageHelper) FindTransaction

func (h *BroadcastStorageHelper) FindTransaction(
	ctx context.Context,
	transactionIdentifier *types.TransactionIdentifier,
	txn database.Transaction,
) (*types.BlockIdentifier, *types.Transaction, error)

FindTransaction looks for the provided TransactionIdentifier in processed blocks and returns the block identifier containing the most recent sighting and the transaction seen in that block.

type CoinStorageHelper

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

CoinStorageHelper implements the storage.CoinStorageHelper interface.

func NewCoinStorageHelper

func NewCoinStorageHelper(blockStorage *modules.BlockStorage) *CoinStorageHelper

NewCoinStorageHelper returns a new *CoinStorageHelper.

func (*CoinStorageHelper) CurrentBlockIdentifier

func (c *CoinStorageHelper) CurrentBlockIdentifier(
	ctx context.Context,
	transaction database.Transaction,
) (*types.BlockIdentifier, error)

CurrentBlockIdentifier returns the head *types.BlockIdentifier in the context of a storage.DatabaseTransaction.

type CoordinatorHandler added in v0.5.0

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

CoordinatorHandler is invoked by the Coordinator when addresses are created or transactions are created.

func NewCoordinatorHandler added in v0.5.0

func NewCoordinatorHandler(
	counterStorage *modules.CounterStorage,
) *CoordinatorHandler

NewCoordinatorHandler returns a new *CoordinatorHandler.

func (*CoordinatorHandler) TransactionCreated added in v0.5.0

func (h *CoordinatorHandler) TransactionCreated(
	ctx context.Context,
	jobIdentifier string,
	transactionIdentifier *types.TransactionIdentifier,
) error

TransactionCreated increments the TransactionsCreatedCounter in CounterStorage.

type CoordinatorHelper added in v0.5.0

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

CoordinatorHelper implements the Coordinator.Helper interface.

func NewCoordinatorHelper added in v0.5.0

func NewCoordinatorHelper(
	offlineFetcher *fetcher.Fetcher,
	onlineFetcher *fetcher.Fetcher,
	database database.Database,
	blockStorage *modules.BlockStorage,
	keyStorage *modules.KeyStorage,
	balanceStorage *modules.BalanceStorage,
	coinStorage *modules.CoinStorage,
	broadcastStorage *modules.BroadcastStorage,
	balanceStorageHelper *BalanceStorageHelper,
	counterStorage *modules.CounterStorage,
	quiet bool,
) *CoordinatorHelper

NewCoordinatorHelper returns a new *CoordinatorHelper.

func (*CoordinatorHelper) AllAccounts added in v0.5.1

AllAccounts returns a slice of all known accounts.

func (*CoordinatorHelper) AllBroadcasts added in v0.5.0

func (c *CoordinatorHelper) AllBroadcasts(ctx context.Context) ([]*modules.Broadcast, error)

AllBroadcasts returns a slice of all in-progress broadcasts in BroadcastStorage.

func (*CoordinatorHelper) Balance added in v0.5.0

func (c *CoordinatorHelper) Balance(
	ctx context.Context,
	dbTx database.Transaction,
	accountIdentifier *types.AccountIdentifier,
	currency *types.Currency,
) (*types.Amount, error)

Balance returns the balance for a provided address using BalanceStorage. If the address balance does not exist, 0 will be returned.

func (*CoordinatorHelper) Broadcast added in v0.5.0

func (c *CoordinatorHelper) Broadcast(
	ctx context.Context,
	dbTx database.Transaction,
	identifier string,
	network *types.NetworkIdentifier,
	intent []*types.Operation,
	transactionIdentifier *types.TransactionIdentifier,
	payload string,
	confirmationDepth int64,
	transactionMetadata map[string]interface{},
) error

Broadcast enqueues a particular intent for broadcast.

func (*CoordinatorHelper) BroadcastAll added in v0.5.0

func (c *CoordinatorHelper) BroadcastAll(
	ctx context.Context,
) error

BroadcastAll attempts to broadcast all ready transactions.

func (*CoordinatorHelper) ClearBroadcasts added in v0.5.0

func (c *CoordinatorHelper) ClearBroadcasts(ctx context.Context) ([]*modules.Broadcast, error)

ClearBroadcasts deletes all pending broadcasts.

func (*CoordinatorHelper) Coins added in v0.5.0

func (c *CoordinatorHelper) Coins(
	ctx context.Context,
	dbTx database.Transaction,
	accountIdentifier *types.AccountIdentifier,
	currency *types.Currency,
) ([]*types.Coin, error)

Coins returns all *types.Coin owned by an account.

func (*CoordinatorHelper) Combine added in v0.5.0

func (c *CoordinatorHelper) Combine(
	ctx context.Context,
	networkIdentifier *types.NetworkIdentifier,
	unsignedTransaction string,
	signatures []*types.Signature,
) (string, error)

Combine calls the /construction/combine endpoint using the offline node.

func (*CoordinatorHelper) DatabaseTransaction added in v0.5.0

func (c *CoordinatorHelper) DatabaseTransaction(ctx context.Context) database.Transaction

DatabaseTransaction returns a new write-ready database.Transaction.

func (*CoordinatorHelper) Derive added in v0.5.0

func (c *CoordinatorHelper) Derive(
	ctx context.Context,
	networkIdentifier *types.NetworkIdentifier,
	publicKey *types.PublicKey,
	metadata map[string]interface{},
) (*types.AccountIdentifier, map[string]interface{}, error)

Derive returns a new address for a provided publicKey.

func (*CoordinatorHelper) GetBlob added in v0.6.5

func (c *CoordinatorHelper) GetBlob(
	ctx context.Context,
	dbTx database.Transaction,
	key string,
) (bool, []byte, error)

GetBlob transactionally retrieves a key and value.

func (*CoordinatorHelper) GetKey added in v0.5.1

GetKey is called to get the *types.KeyPair associated with an address.

func (*CoordinatorHelper) Hash added in v0.5.0

func (c *CoordinatorHelper) Hash(
	ctx context.Context,
	networkIdentifier *types.NetworkIdentifier,
	networkTransaction string,
) (*types.TransactionIdentifier, error)

Hash calls the /construction/hash endpoint using the offline node.

func (*CoordinatorHelper) HeadBlockExists added in v0.5.0

func (c *CoordinatorHelper) HeadBlockExists(ctx context.Context) bool

HeadBlockExists returns a boolean indicating if a block has been synced by BlockStorage.

func (*CoordinatorHelper) LockedAccounts added in v0.5.1

func (c *CoordinatorHelper) LockedAccounts(
	ctx context.Context,
	dbTx database.Transaction,
) ([]*types.AccountIdentifier, error)

LockedAccounts returns a slice of all accounts currently sending or receiving funds.

func (*CoordinatorHelper) Metadata added in v0.5.0

func (c *CoordinatorHelper) Metadata(
	ctx context.Context,
	networkIdentifier *types.NetworkIdentifier,
	metadataRequest map[string]interface{},
	publicKeys []*types.PublicKey,
) (map[string]interface{}, []*types.Amount, error)

Metadata calls the /construction/metadata endpoint using the online node.

func (*CoordinatorHelper) Parse added in v0.5.0

func (c *CoordinatorHelper) Parse(
	ctx context.Context,
	networkIdentifier *types.NetworkIdentifier,
	signed bool,
	transaction string,
) ([]*types.Operation, []*types.AccountIdentifier, map[string]interface{}, error)

Parse calls the /construction/parse endpoint using the offline node.

func (*CoordinatorHelper) Payloads added in v0.5.0

func (c *CoordinatorHelper) Payloads(
	ctx context.Context,
	networkIdentifier *types.NetworkIdentifier,
	intent []*types.Operation,
	requiredMetadata map[string]interface{},
	publicKeys []*types.PublicKey,
) (string, []*types.SigningPayload, error)

Payloads calls the /construction/payloads endpoint using the offline node.

func (*CoordinatorHelper) Preprocess added in v0.5.0

func (c *CoordinatorHelper) Preprocess(
	ctx context.Context,
	networkIdentifier *types.NetworkIdentifier,
	intent []*types.Operation,
	metadata map[string]interface{},
) (map[string]interface{}, []*types.AccountIdentifier, error)

Preprocess calls the /construction/preprocess endpoint on an offline node.

func (*CoordinatorHelper) SetBlob added in v0.6.5

func (c *CoordinatorHelper) SetBlob(
	ctx context.Context,
	dbTx database.Transaction,
	key string,
	value []byte,
) error

SetBlob transactionally persists a key and value.

func (*CoordinatorHelper) Sign added in v0.5.0

func (c *CoordinatorHelper) Sign(
	ctx context.Context,
	payloads []*types.SigningPayload,
) ([]*types.Signature, error)

Sign invokes the KeyStorage backend to sign some payloads.

func (*CoordinatorHelper) StoreKey added in v0.5.0

func (c *CoordinatorHelper) StoreKey(
	ctx context.Context,
	dbTx database.Transaction,
	account *types.AccountIdentifier,
	keyPair *keys.KeyPair,
) error

StoreKey stores a KeyPair and address in KeyStorage.

type ReconcilerHandler

type ReconcilerHandler struct {
	InactiveFailure      *types.AccountCurrency
	InactiveFailureBlock *types.BlockIdentifier

	ActiveFailureBlock *types.BlockIdentifier
	// contains filtered or unexported fields
}

ReconcilerHandler implements the Reconciler.Handler interface.

func NewReconcilerHandler

func NewReconcilerHandler(
	logger *logger.Logger,
	counterStorage *modules.CounterStorage,
	balanceStorage *modules.BalanceStorage,
	haltOnReconciliationError bool,
) *ReconcilerHandler

NewReconcilerHandler creates a new ReconcilerHandler.

func (*ReconcilerHandler) ReconciliationExempt added in v0.5.8

func (h *ReconcilerHandler) ReconciliationExempt(
	ctx context.Context,
	reconciliationType string,
	account *types.AccountIdentifier,
	currency *types.Currency,
	computedBalance string,
	liveBalance string,
	block *types.BlockIdentifier,
	exemption *types.BalanceExemption,
) error

ReconciliationExempt is called each time a reconciliation fails but is considered exempt because of provided []*types.BalanceExemption.

func (*ReconcilerHandler) ReconciliationFailed

func (h *ReconcilerHandler) ReconciliationFailed(
	ctx context.Context,
	reconciliationType string,
	account *types.AccountIdentifier,
	currency *types.Currency,
	computedBalance string,
	liveBalance string,
	block *types.BlockIdentifier,
) error

ReconciliationFailed is called each time a reconciliation fails. In this Handler implementation, we halt if haltOnReconciliationError was set to true. We also cancel the context.

func (*ReconcilerHandler) ReconciliationSkipped added in v0.5.15

func (h *ReconcilerHandler) ReconciliationSkipped(
	ctx context.Context,
	reconciliationType string,
	account *types.AccountIdentifier,
	currency *types.Currency,
	cause string,
) error

ReconciliationSkipped is called each time a reconciliation is skipped.

func (*ReconcilerHandler) ReconciliationSucceeded

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

ReconciliationSucceeded is called each time a reconciliation succeeds.

func (*ReconcilerHandler) UpdateCounts added in v0.6.1

func (h *ReconcilerHandler) UpdateCounts(ctx context.Context) error

UpdateCounts forces cached counts to be written to modules.

func (*ReconcilerHandler) Updater added in v0.6.1

func (h *ReconcilerHandler) Updater(ctx context.Context) error

Updater periodically updates modules.with cached counts.

type ReconcilerHelper

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

ReconcilerHelper implements the Reconciler.Helper interface.

func NewReconcilerHelper

func NewReconcilerHelper(
	config *configuration.Configuration,
	network *types.NetworkIdentifier,
	fetcher *fetcher.Fetcher,
	database database.Database,
	blockStorage *modules.BlockStorage,
	balanceStorage *modules.BalanceStorage,
	forceInactiveReconciliation *bool,
) *ReconcilerHelper

NewReconcilerHelper returns a new ReconcilerHelper.

func (*ReconcilerHelper) CanonicalBlock added in v0.5.14

func (h *ReconcilerHelper) CanonicalBlock(
	ctx context.Context,
	dbTx database.Transaction,
	block *types.BlockIdentifier,
) (bool, error)

CanonicalBlock returns a boolean indicating if a block is in the canonical chain. This is necessary to reconcile across reorgs. If the block returned on an account balance fetch does not exist, reconciliation will be skipped.

func (*ReconcilerHelper) ComputedBalance added in v0.5.0

func (h *ReconcilerHelper) ComputedBalance(
	ctx context.Context,
	dbTx database.Transaction,
	account *types.AccountIdentifier,
	currency *types.Currency,
	index int64,
) (*types.Amount, error)

ComputedBalance returns the balance of an account in block storage. It is necessary to perform this check outside of the Reconciler package to allow for separation from a default storage backend.

func (*ReconcilerHelper) CurrentBlock

func (h *ReconcilerHelper) CurrentBlock(
	ctx context.Context,
	dbTx database.Transaction,
) (*types.BlockIdentifier, error)

CurrentBlock returns the last processed block and is used to determine which block to check account balances at during inactive reconciliation.

func (*ReconcilerHelper) DatabaseTransaction added in v0.5.19

func (h *ReconcilerHelper) DatabaseTransaction(
	ctx context.Context,
) database.Transaction

DatabaseTransaction returns a new read-only database.Transaction.

func (*ReconcilerHelper) ForceInactiveReconciliation added in v0.6.3

func (h *ReconcilerHelper) ForceInactiveReconciliation(
	ctx context.Context,
	account *types.AccountIdentifier,
	currency *types.Currency,
	lastChecked *types.BlockIdentifier,
) bool

ForceInactiveReconciliation overrides the default calculation to determine if an account should be reconciled inactively.

func (*ReconcilerHelper) IndexAtTip added in v0.5.20

func (h *ReconcilerHelper) IndexAtTip(
	ctx context.Context,
	index int64,
) (bool, error)

IndexAtTip returns a boolean indicating if a block index is at tip (provided some acceptable tip delay). If the index is ahead of the head block and the head block is at tip, we consider the index at tip.

func (*ReconcilerHelper) LiveBalance added in v0.5.0

func (h *ReconcilerHelper) LiveBalance(
	ctx context.Context,
	account *types.AccountIdentifier,
	currency *types.Currency,
	index int64,
) (*types.Amount, *types.BlockIdentifier, error)

LiveBalance returns the live balance of an account.

func (*ReconcilerHelper) PruneBalances added in v0.5.17

func (h *ReconcilerHelper) PruneBalances(
	ctx context.Context,
	account *types.AccountIdentifier,
	currency *types.Currency,
	index int64,
) error

PruneBalances removes all historical balance states <= some index. This can significantly reduce storage usage in scenarios where historical balances are only retrieved once (like reconciliation).

Jump to

Keyboard shortcuts

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