transaction

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2022 License: LGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTransactionExists = errors.New("transaction is already in queue")

ErrTransactionExists is returned when trying to add a transaction to the queue that already exists

Functions

This section is empty.

Types

type Item added in v0.2.0

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

An Item is something we manage in a priority queue.

type Pool

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

Pool represents the transaction pool

func NewPool added in v0.2.0

func NewPool() *Pool

NewPool returns a new empty Pool

func (*Pool) Get added in v0.7.0

func (p *Pool) Get(extHash common.Hash) *ValidTransaction

Get returns a pointer to ValidTransaction or nil given an extinsic hash

func (*Pool) Insert added in v0.2.0

func (p *Pool) Insert(tx *ValidTransaction) common.Hash

Insert inserts a transaction into the pool

func (*Pool) Len added in v0.7.0

func (p *Pool) Len() int

Len return the current length of the pool

func (*Pool) Remove added in v0.2.0

func (p *Pool) Remove(hash common.Hash)

Remove removes a transaction from the pool

func (*Pool) Transactions added in v0.2.0

func (p *Pool) Transactions() []*ValidTransaction

Transactions returns all the transactions in the pool

type PriorityQueue

type PriorityQueue struct {
	sync.Mutex
	// contains filtered or unexported fields
}

PriorityQueue is a thread safe wrapper over `priorityQueue`

func NewPriorityQueue

func NewPriorityQueue() *PriorityQueue

NewPriorityQueue creates new instance of PriorityQueue

func (*PriorityQueue) Exists added in v0.7.0

func (spq *PriorityQueue) Exists(extHash common.Hash) bool

Exists returns true if a hash is in the txs map, false otherwise

func (*PriorityQueue) Len added in v0.7.0

func (spq *PriorityQueue) Len() int

Len return the current length of the queue

func (*PriorityQueue) Peek

func (spq *PriorityQueue) Peek() *ValidTransaction

Peek returns the next item without removing it from the queue

func (*PriorityQueue) Pending

func (spq *PriorityQueue) Pending() []*ValidTransaction

Pending returns all the transactions currently in the queue

func (*PriorityQueue) Pop

func (spq *PriorityQueue) Pop() *ValidTransaction

Pop removes the transaction with has the highest priority value from the queue and returns it. If there are multiple transaction with same priority value then it return them in FIFO order.

func (*PriorityQueue) PopWithTimer added in v0.7.0

func (spq *PriorityQueue) PopWithTimer(timerCh <-chan time.Time) (transaction *ValidTransaction)

PopWithTimer returns the next valid transaction from the queue. When the timer expires, it returns `nil`.

func (*PriorityQueue) Push

func (spq *PriorityQueue) Push(txn *ValidTransaction) (common.Hash, error)

Push inserts a valid transaction with priority p into the queue

func (*PriorityQueue) RemoveExtrinsic

func (spq *PriorityQueue) RemoveExtrinsic(ext types.Extrinsic)

RemoveExtrinsic removes an extrinsic from the queue

type Status added in v0.7.0

type Status int64

Status represents possible transaction statuses.

The status events can be grouped based on their kinds as: 1. Entering/Moving within the pool:

  • `Future`
  • `Ready`

2. Inside `Ready` queue:

  • `Broadcast`

3. Leaving the pool:

  • `InBlock`
  • `Invalid`
  • `Usurped`
  • `Dropped` 4. Re-entering the pool:
  • `Retracted` 5. Block finalized:
  • `Finalized`
  • `FinalityTimeout`
const (
	// Future status occurs when transaction is part of the future queue.
	Future Status = iota
	// Ready status occurs when transaction is part of the ready queue.
	Ready
	// Broadcast status occurs when transaction has been broadcast to the given peers.
	Broadcast
	// InBlock status occurs when transaction has been included in block with given
	// hash.
	InBlock
	// Retracted status occurs when the block this transaction was included in has
	// been retracted.
	Retracted
	// FinalityTimeout status occurs when the maximum number of finality watchers
	// has been reached,
	// old watchers are being removed.
	FinalityTimeout
	// Finalized status occurs when transaction has been finalized by a finality-gadget,
	// e.g GRANDPA
	Finalized
	// Usurped status occurs when transaction has been replaced in the pool, by another
	// transaction that provides the same tags. (e.g. same (sender, nonce)).
	Usurped
	// Dropped status occurs when transaction has been dropped from the pool because
	// of the limit.
	Dropped
	// Invalid status occurs when transaction is no longer valid in the current state.
	Invalid
)

func (Status) String added in v0.7.0

func (s Status) String() string

String returns string representation of current status.

type ValidTransaction

type ValidTransaction struct {
	Extrinsic types.Extrinsic
	Validity  *Validity
}

ValidTransaction struct

func NewValidTransaction

func NewValidTransaction(extrinsic types.Extrinsic, validity *Validity) *ValidTransaction

NewValidTransaction returns ValidTransaction

type Validity

type Validity struct {
	Priority  uint64
	Requires  [][]byte
	Provides  [][]byte
	Longevity uint64
	Propagate bool
}

Validity struct see https://github.com/paritytech/substrate/blob/5420de3face1349a97eb954ae71c5b0b940c31de/core/sr-primitives/src/transaction_validity.rs#L178

func NewValidity

func NewValidity(priority uint64, requires, provides [][]byte, longevity uint64, propagate bool) *Validity

NewValidity returns Validity

Jump to

Keyboard shortcuts

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