txcache

package
v1.0.82 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2020 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) Clear added in v1.0.74

func (m *ConcurrentMap) Clear()

Clear clears the 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) 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) Keys added in v1.0.74

func (m *ConcurrentMap) Keys() []string

Keys returns all keys as []string

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.

func (*ConcurrentMap) SetIfAbsent added in v1.0.74

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

SetIfAbsent sets the given value under the specified key if no value was associated with it.

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 ForEachTransaction

type ForEachTransaction func(txHash []byte, value data.TransactionHandler)

ForEachTransaction 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) (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) (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, [][]byte)

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

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

Jump to

Keyboard shortcuts

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