sequence

package
v0.0.0-...-798156f Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2018 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package sequence providers helpers to manage sequence numbers on behalf of frontier clients. See Manager for more details on the api.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoMoreRoom  = errors.New("queue full")
	ErrBadSequence = errors.New("bad sequence")
)

Functions

This section is empty.

Types

type Manager

type Manager struct {
	MaxSize int
	// contains filtered or unexported fields
}

Manager provides a system for tracking the transaction submission queue for a set of addresses. Requests to submit at a certain sequence number are registered using the Push() method, and as the system is updated with account sequence information (through the Update() method) requests are notified that they can safely submit to digitalbits-core.

func NewManager

func NewManager() *Manager

NewManager returns a new manager

func (*Manager) Addresses

func (m *Manager) Addresses() []string

func (*Manager) Push

func (m *Manager) Push(address string, sequence uint64) <-chan error

Push registers an intent to submit a transaction for the provided address at the provided sequence. A channel is returned that will be written to when the requester should attempt the submission.

func (*Manager) Size

func (m *Manager) Size() int

Size returns the count of submissions buffered within this manager.

func (*Manager) String

func (m *Manager) String() string

func (*Manager) Update

func (m *Manager) Update(updates map[string]uint64)

Update notifies the manager of newly loaded account sequence information. The manager uses this information to notify requests to submit that they should proceed. See Queue#Update for the actual meat of the logic.

type Queue

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

Queue manages the submission queue for a single source account. The transaction system uses Push to enqueue submissions for given sequence numbers.

Queue maintains a priority queue of pending submissions, and when updated (via the Update() method) with the current sequence number of the account being managed, queued submissions that can be acted upon will be unblocked.

func NewQueue

func NewQueue() *Queue

NewQueue creates a new *Queue

func (*Queue) Push

func (q *Queue) Push(sequence uint64) <-chan error

Push enqueues the intent to submit a transaction at the provided sequence number and returns a channel that will emit when it is safe for the client to do so.

Push does not perform any triggering (which occurs in Update(), even if the current sequence number for this queue is the same as the provided sequence, to keep internal complexity much lower. Given that, the recommended usage pattern is:

  1. Push the submission onto the queue
  2. Load the current sequence number for the source account from the DB
  3. Call Update() with the result from step 2 to trigger the submission if possible

func (*Queue) Size

func (q *Queue) Size() int

Size returns the count of currently buffered submissions in the queue.

func (*Queue) Update

func (q *Queue) Update(sequence uint64)

Update notifies the queue that the provided sequence number is the latest seen value for the account that this queue manages submissions for.

This function is monotonic... calling it with a sequence number lower than the latest seen sequence number is a noop.

Jump to

Keyboard shortcuts

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