Documentation ¶
Index ¶
- Variables
- type BlockChain
- type EleByNonce
- type EleByPrice
- type EleList
- func (l *EleList) Add(ele Element, priceBump uint64) (bool, Element)
- func (l *EleList) Cap(threshold int) []Element
- func (l *EleList) Empty() bool
- func (l *EleList) Filter(filter func(Element) bool) []Element
- func (l *EleList) Flatten() []Element
- func (l *EleList) Forward(threshold uint64) []Element
- func (l *EleList) Len() int
- func (l *EleList) Overlaps(ele Element) bool
- func (l *EleList) Remove(ele Element) (bool, []Element)
- type Element
- type ElementWithFrom
- type ElementsByPriceAndNonce
- type Helper
- type NewElemEvent
- type Pool
- type StateDB
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
Cap places a hard limit on the number of items, returning all elements exceeding that limit.
func (*EleList) Filter ¶
Filter iterates over the list of elements and removes all of them for which the specified function evaluates to true.
func (*EleList) Flatten ¶
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 ¶
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.
type ElementWithFrom ¶
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 ¶
func (t *ElementsByPriceAndNonce) Peek() ElementWithFrom
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.