txcache

package
v1.0.66 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2019 License: GPL-3.0 Imports: 8 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 ConcurrentMap added in v1.0.64

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

ConcurrentMap is a thread safe map of type string:Anything. To avoid lock bottlenecks this map is divided to several map chunks.

func NewConcurrentMap added in v1.0.64

func NewConcurrentMap(nChunks uint32) *ConcurrentMap

NewConcurrentMap creates a new concurrent map.

func (*ConcurrentMap) Count added in v1.0.64

func (m *ConcurrentMap) Count() int

Count returns the number of elements within the map.

func (*ConcurrentMap) Get added in v1.0.64

func (m *ConcurrentMap) Get(key string) (interface{}, bool)

Get retrieves an element from map under given key.

func (*ConcurrentMap) Has added in v1.0.64

func (m *ConcurrentMap) Has(key string) bool

Has looks up an item under specified key.

func (*ConcurrentMap) IsEmpty added in v1.0.64

func (m *ConcurrentMap) IsEmpty() bool

IsEmpty checks if map is empty.

func (*ConcurrentMap) IterCb added in v1.0.64

func (m *ConcurrentMap) IterCb(fn IterCb)

IterCb iterates over the map (cheapest way to read all elements in a map)

func (*ConcurrentMap) Remove added in v1.0.64

func (m *ConcurrentMap) Remove(key string)

Remove removes an element from the map.

func (*ConcurrentMap) Set added in v1.0.64

func (m *ConcurrentMap) Set(key string, value interface{})

Set sets the given value under the specified key.

type EvictionConfig added in v1.0.64

type EvictionConfig struct {
	Enabled                         bool
	CountThreshold                  uint32
	ThresholdEvictSenders           uint32
	NumOldestSendersToEvict         uint32
	ALotOfTransactionsForASender    uint32
	NumTxsToEvictForASenderWithALot uint32
}

EvictionConfig is a cache eviction model

type ForEachSender

type ForEachSender func(key string, value *txListForSender)

ForEachSender is an iterator callback

type IterCb added in v1.0.64

type IterCb func(key string, v interface{})

IterCb 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(nChunksHint uint32) *TxCache

NewTxCache creates a new transaction cache "nChunksHint" is used to configure the internal concurrent maps on which the implementation relies

func NewTxCacheWithEviction added in v1.0.64

func NewTxCacheWithEviction(nChunksHint uint32, evictionConfig EvictionConfig) *TxCache

NewTxCacheWithEviction creates a new transaction cache with eviction

func (*TxCache) AddTx

func (cache *TxCache) AddTx(txHash []byte, tx data.TransactionHandler)

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

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) GetByTxHash

func (cache *TxCache) GetByTxHash(txHash []byte) (data.TransactionHandler, bool)

GetByTxHash gets the transaction by hash

func (*TxCache) GetTransactions added in v1.0.64

func (cache *TxCache) GetTransactions(numRequested int, batchSizePerSender int) []data.TransactionHandler

GetTransactions gets 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

func (*TxCache) RemoveTxByHash

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

RemoveTxByHash removes

Jump to

Keyboard shortcuts

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