txcache

package
v1.0.101 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2020 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrMapsSyncInconsistency = fmt.Errorf("maps sync inconsistency between 'txByHash' and 'txListBySender'")

ErrMapsSyncInconsistency signals that there's an inconsistency between the internal maps on which the cache relies

View Source
var ErrTxNotFound = fmt.Errorf("tx not found in cache")

ErrTxNotFound signals that the transactions was not found in the cache

Functions

This section is empty.

Types

type CacheConfig

type CacheConfig struct {
	Name                       string
	NumChunksHint              uint32
	EvictionEnabled            bool
	NumBytesThreshold          uint32
	CountThreshold             uint32
	NumSendersToEvictInOneStep uint32
	LargeNumOfTxsForASender    uint32
	NumTxsToEvictFromASender   uint32
	MinGasPriceMicroErd        uint32
}

CacheConfig holds cache configuration

type ForEachSender

type ForEachSender func(key string, value *txListForSender)

ForEachSender is an iterator callback

type ForEachTransaction

type ForEachTransaction func(txHash []byte, value *WrappedTransaction)

ForEachTransaction is an iterator callback

type TxCache

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

TxCache represents a cache-like structure (it has a fixed capacity and implements an eviction mechanism) for holding transactions

func NewTxCache

func NewTxCache(config CacheConfig) *TxCache

NewTxCache creates a new transaction cache

func (*TxCache) AddTx

func (cache *TxCache) AddTx(tx *WrappedTransaction) (ok bool, added bool)

AddTx adds a transaction in the cache Eviction happens if maximum capacity is reached

func (*TxCache) Clear

func (cache *TxCache) Clear()

Clear clears the cache

func (*TxCache) CountSenders

func (cache *TxCache) CountSenders() int64

CountSenders gets the number of senders in the cache

func (*TxCache) CountTx

func (cache *TxCache) CountTx() int64

CountTx gets the number of transactions in the cache

func (*TxCache) ForEachTransaction

func (cache *TxCache) ForEachTransaction(function ForEachTransaction)

ForEachTransaction iterates over the transactions in the cache

func (*TxCache) Get

func (cache *TxCache) Get(key []byte) (value interface{}, ok bool)

Get gets a transaction by hash

func (*TxCache) GetByTxHash

func (cache *TxCache) GetByTxHash(txHash []byte) (*WrappedTransaction, bool)

GetByTxHash gets the transaction by hash

func (*TxCache) Has

func (cache *TxCache) Has(key []byte) bool

Has is not implemented

func (*TxCache) HasOrAdd

func (cache *TxCache) HasOrAdd(key []byte, value interface{}) (ok, evicted bool)

HasOrAdd is not implemented

func (*TxCache) IsInterfaceNil

func (cache *TxCache) IsInterfaceNil() bool

IsInterfaceNil returns true if there is no value under the interface

func (*TxCache) Keys

func (cache *TxCache) Keys() [][]byte

Keys returns the tx hashes in the cache

func (*TxCache) Len

func (cache *TxCache) Len() int

Len is an alias for CountTx

func (*TxCache) MaxSize

func (cache *TxCache) MaxSize() int

MaxSize is not implemented

func (*TxCache) NotifyAccountNonce

func (cache *TxCache) NotifyAccountNonce(accountKey []byte, nonce uint64)

NotifyAccountNonce should be called by external components (such as interceptors and transactions processor) in order to inform the cache about initial nonce gap phenomena

func (*TxCache) NumBytes

func (cache *TxCache) NumBytes() int64

NumBytes gets the approximate number of bytes stored in the cache

func (*TxCache) Peek

func (cache *TxCache) Peek(key []byte) (value interface{}, ok bool)

Peek gets a transaction by hash

func (*TxCache) Put

func (cache *TxCache) Put(key []byte, value interface{}) (evicted bool)

Put is not implemented

func (*TxCache) RegisterHandler

func (cache *TxCache) RegisterHandler(func(key []byte, value interface{}))

RegisterHandler is not implemented

func (*TxCache) Remove

func (cache *TxCache) Remove(key []byte)

Remove removes tx by hash

func (*TxCache) RemoveOldest

func (cache *TxCache) RemoveOldest()

RemoveOldest is not implemented

func (*TxCache) RemoveTxByHash

func (cache *TxCache) RemoveTxByHash(txHash []byte) error

RemoveTxByHash removes tx by hash

func (*TxCache) SelectTransactions

func (cache *TxCache) SelectTransactions(numRequested int, batchSizePerSender int) []*WrappedTransaction

SelectTransactions selects a reasonably fair list of transactions to be included in the next miniblock It returns at most "numRequested" transactions Each sender gets the chance to give at least "batchSizePerSender" transactions, unless "numRequested" limit is reached before iterating over all senders

type WrappedTransaction

type WrappedTransaction struct {
	Tx              data.TransactionHandler
	TxHash          []byte
	SenderShardID   uint32
	ReceiverShardID uint32
}

WrappedTransaction contains a transaction, its hash and extra information

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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