queue

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2023 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Atomic

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DecodedSSVMessage

type DecodedSSVMessage struct {
	*types.SSVMessage

	// Body is the decoded Data.
	Body interface{} // *SignedMessage | *SignedPartialSignatureMessage
}

DecodedSSVMessage is a bundle of SSVMessage and it's decoding.

func DecodeSSVMessage

func DecodeSSVMessage(m *types.SSVMessage) (*DecodedSSVMessage, error)

DecodeSSVMessage decodes an SSVMessage and returns a DecodedSSVMessage.

type Filter

type Filter func(*DecodedSSVMessage) bool

Filter is a function that returns true if the given message should be included.

func FilterRole

func FilterRole(role types.BeaconRole) Filter

FilterRole returns a Filter which returns true for messages whose BeaconRole matches the given role.

type MessagePrioritizer

type MessagePrioritizer interface {
	// Prior returns true if message A should be prioritized over B.
	Prior(a, b *DecodedSSVMessage) bool
}

MessagePrioritizer is an interface for prioritizing messages.

func NewMessagePrioritizer

func NewMessagePrioritizer(state *State) MessagePrioritizer

NewMessagePrioritizer returns a standard implementation for MessagePrioritizer which prioritizes messages according to the given State.

type Pop

type Pop func()

Pop removes a message from the queue

type PriorityQueue

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

PriorityQueue implements Queue, it manages a lock-free linked list of DecodedSSVMessage. Implemented using atomic CAS (CompareAndSwap) operations to handle multiple goroutines that add/pop messages.

func (*PriorityQueue) IsEmpty

func (q *PriorityQueue) IsEmpty() bool

func (*PriorityQueue) Pop

func (q *PriorityQueue) Pop(prioritizer MessagePrioritizer) *DecodedSSVMessage

func (*PriorityQueue) Push

func (q *PriorityQueue) Push(msg *DecodedSSVMessage)

func (*PriorityQueue) WaitAndPop

func (q *PriorityQueue) WaitAndPop(ctx context.Context, priority MessagePrioritizer) *DecodedSSVMessage

type Queue

type Queue interface {
	// Push inserts a message to the queue
	Push(*DecodedSSVMessage)
	// Pop removes & returns the highest priority message which matches the given filter.
	// Returns nil if no message is found.
	Pop(MessagePrioritizer) *DecodedSSVMessage
	// IsEmpty checks if the q is empty
	IsEmpty() bool

	// WaitAndPop waits for a message to be pushed to the queue and then returns it.
	WaitAndPop(context.Context, MessagePrioritizer) *DecodedSSVMessage
}

Queue objective is to receive messages and pop the right msg by to specify priority.

func New

func New() Queue

New initialized a PriorityQueue with the given MessagePrioritizer. If prioritizer is nil, the messages will be returned in the order they were pushed.

type State

type State struct {
	HasRunningInstance bool
	Height             qbft.Height
	Round              qbft.Round
	Slot               phase0.Slot
	Quorum             uint64
}

State represents a portion of the the current state that is relevant to the prioritization of messages.

Jump to

Keyboard shortcuts

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