pool

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: May 2, 2020 License: LGPL-3.0 Imports: 19 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrReplaceUnderpriced is returned if a element is attempted to be replaced
	// with a different one without the required price bump.
	ErrReplaceUnderpriced = errors.New("replacement element underpriced")

	// ErrNonceTooLow is returned if the nonce of a transaction is lower than the
	// one present in the local chain.
	ErrNonceTooLow = errors.New("nonce too low")

	ErrInsufficientFunds = errors.New("insufficient funds for gas limit * price + value")

	ErrIsNotAPacker = errors.New("this transaction should be sent to a packer")
)

Functions

This section is empty.

Types

type BlockChain

type BlockChain interface {
	CurrentBlock() *types.Block
	GetBlock(hash common.Hash) *types.Block
	StateAt(root common.Hash) (*state.StateDB, error)
	GetStateBeforeCacheHeight(block *types.Block, cacheHeight uint8) (*state.StateDB, *types.Block, bool)
	SubscribeChainUpdateEvent(ch chan<- types.ChainUpdateEvent) event.Subscription
	MinAvailablePackageHeight() (uint64, error)
	GetChainID() uint64
	GetGreedy() uint8
}

type EleByNonce

type EleByNonce []Element

func (EleByNonce) Len

func (s EleByNonce) Len() int

func (EleByNonce) Less

func (s EleByNonce) Less(i, j int) bool

func (EleByNonce) Swap

func (s EleByNonce) Swap(i, j int)

type EleByPrice

type EleByPrice []ElementWithFrom

func (EleByPrice) Len

func (s EleByPrice) Len() int

func (EleByPrice) Less

func (s EleByPrice) Less(i, j int) bool

func (*EleByPrice) Pop

func (s *EleByPrice) Pop() interface{}

func (*EleByPrice) Push

func (s *EleByPrice) Push(x interface{})

func (EleByPrice) Swap

func (s EleByPrice) Swap(i, j int)

type EleList

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

EleList is a "list" of elements belonging to an account, sorted by account nonce. The same type can be used both for storing contiguous elements for the queue; and for storing gapped elements for the queue, with minor behavioral changes.

func (*EleList) Add

func (l *EleList) Add(ele Element, priceBump uint64) (bool, Element)

Add tries to insert a new element into the list, returning whether the element was accepted, and if yes, any previous element it replaced.

func (*EleList) Cap

func (l *EleList) Cap(threshold int) []Element

Cap places a hard limit on the number of items, returning all elements exceeding that limit.

func (*EleList) Empty

func (l *EleList) Empty() bool

Empty returns whether the list of elements is empty or not.

func (*EleList) Filter

func (l *EleList) Filter(filter func(Element) bool) []Element

Filter iterates over the list of elements and removes all of them for which the specified function evaluates to true.

func (*EleList) Flatten

func (l *EleList) Flatten() []Element

Flatten creates a nonce-sorted slice of elements based on the loosely sorted internal representation. The result of the sorting is cached in case it's requested again before any modifications are made to the contents.

func (*EleList) Forward

func (l *EleList) Forward(threshold uint64) []Element

Forward removes all elements from the list with a nonce lower than the provided threshold. Every removed element is returned for any post-removal maintenance.

func (*EleList) Len

func (l *EleList) Len() int

Len returns the length of the element list.

func (*EleList) Overlaps

func (l *EleList) Overlaps(ele Element) bool

Overlaps returns whether the element specified has the same nonce as one already contained within the list.

func (*EleList) Remove

func (l *EleList) Remove(ele Element) (bool, []Element)

Remove deletes a element from the maintained list, returning whether the element was found, and also returning any element invalidated due to the deletion (strict mode only).

type Element

type Element interface {
	Nonce() uint64
	Hash() common.Hash
	GasPrice() *big.Int
}

type ElementWithFrom

type ElementWithFrom struct {
	Element
	From common.Address
}

type ElementsByPriceAndNonce

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

func NewElementsByPriceAndNonce

func NewElementsByPriceAndNonce(eles map[common.Address][]Element) *ElementsByPriceAndNonce

NewElementsByPriceAndNonce creates a element set that can retrieve price sorted elements in a nonce-honouring way.

Note, the input map is reowned so the caller should not interact any more with it after providing it to the constructor.

func (*ElementsByPriceAndNonce) Peek

Peek returns the next element by price.

func (*ElementsByPriceAndNonce) Shift

func (t *ElementsByPriceAndNonce) Shift()

Shift replaces the current best head with the next one from the same account.

type Helper

type Helper interface {
	Reset(pool Pool, block *types.Block)                                           // Invoked when a new block coming, Reset already surrounded by pool's lock.
	Validate(pool Pool, ele Element, currentState StateDB, chain BlockChain) error // When add a new element into pool, pool's user can provide some Validate logic.
	Sender(ele Element) (common.Address, error)                                    // Sender is used to find the from address of the element.
}

type NewElemEvent

type NewElemEvent struct {
	Ems []Element
}

type Pool

type Pool interface {
	// AddRemotes enqueues a batch of elements into the pool if they are valid.
	// If the senders are not among the locally tracked ones, full pricing constraints
	// will apply.
	AddRemotes(eles []Element) []error

	// AddLocals enqueues a batch of elements into the pool if they are valid,
	// marking the senders as a local ones in the mean time, ensuring they go around
	// the local pricing constraints.
	AddLocals(eles []Element) []error

	// AddRemote enqueues a single element into the pool if it is valid. If the
	// Sender is not among the locally tracked ones, full pricing constraints will
	// apply.
	AddRemote(ele Element) error

	// AddLocal enqueues a single element into the pool if it is valid, marking
	// the Sender as a local one in the mean time, ensuring it goes around the local
	// pricing constraints.
	AddLocal(ele Element) error

	// AddUnsafe enqueues a batch of elements into the pool if they are valid.
	// But AddUnsafe is NOT thread safe.
	AddUnsafe(eles []Element, local bool) []error

	// Get returns a element if it is contained in the pool
	// and nil otherwise.
	Get(hash common.Hash) Element

	// Locals retrieves the accounts currently considered local by the pool.
	Locals() []common.Address

	// Content retrieves the data content of the element pool, returning all the
	// pending elements, grouped by account and sorted by nonce.
	Content() map[common.Address][]Element
	ContentForPack() map[common.Address][]Element

	// Stats retrieves the current pool stats, namely the number of pending elements.
	Stats() int

	// GetNonce returns the nonce of the element pool for the related address.
	// If get function is not provided, getNonce return the transaction nonce by default.
	GetNonce(from common.Address, get func(from common.Address, state *state.ManagedState) uint64) uint64

	// StateUnsafe return the virtual managed state of the element pool.
	// But it is NOT thread safe.
	StateUnsafe() *state.ManagedState

	// GetStateBeforeCacheHeight return the last stable block's state.
	GetStateBeforeCacheHeight() (*state.StateDB, *types.Block, bool)

	// SubscribeNewElemEvent registers a subscription of NewElemEvent and
	// starts sending event to the given channel.
	SubscribeNewElemEvent(ch chan<- NewElemEvent) event.Subscription

	// Stop terminates the element pool.
	Stop()
}

func NewFakePool

func NewFakePool(startCleanTime int64, cleanPeriod int64, leftEleNumEachAddr int, helper Helper) Pool

NewFakePool creates a fake transaction pool

func NewPool

func NewPool(conf config.PoolConfig, chain BlockChain, elemType reflect.Type, helper Helper) Pool

NewPool creates a new element pool to gather, sort and filter inbound elements from the network.

type StateDB

type StateDB interface {
	GetBalance(addr common.Address) *big.Int
	GetTradableBalance(addr common.Address, currentRound uint64) *big.Int
}

Jump to

Keyboard shortcuts

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