mirror of
https://github.com/luxfi/consensus.git
synced 2026-09-24 00:26:58 +00:00
- Add state.SerializerConfig and state.NewSerializer for vertex serialization - Add state.Manager interface extending State with DAG operations - Add bootstrap.Config with all required interfaces (Blocker, Halter, LinearizableVM) - Add bootstrap.Bootstrapper implementing BootstrapableEngine - Add bootstrap/queue.Queue for job processing - Add getter.Handler and getter.Getter interfaces This enables the DAG consensus engine to be properly wired up in the node.
50 lines
992 B
Go
50 lines
992 B
Go
// Package queue provides a simple blocking queue for DAG bootstrap
|
|
package queue
|
|
|
|
import "sync"
|
|
|
|
// Queue is a simple blocking queue for DAG vertices during bootstrap
|
|
type Queue struct {
|
|
mu sync.Mutex
|
|
items []interface{}
|
|
}
|
|
|
|
// NewQueue creates a new empty queue
|
|
func NewQueue() *Queue {
|
|
return &Queue{
|
|
items: make([]interface{}, 0),
|
|
}
|
|
}
|
|
|
|
// Push adds an item to the queue
|
|
func (q *Queue) Push(item interface{}) {
|
|
q.mu.Lock()
|
|
defer q.mu.Unlock()
|
|
q.items = append(q.items, item)
|
|
}
|
|
|
|
// Pop removes and returns the first item from the queue
|
|
// Returns nil if the queue is empty
|
|
func (q *Queue) Pop() interface{} {
|
|
q.mu.Lock()
|
|
defer q.mu.Unlock()
|
|
if len(q.items) == 0 {
|
|
return nil
|
|
}
|
|
item := q.items[0]
|
|
q.items = q.items[1:]
|
|
return item
|
|
}
|
|
|
|
// Len returns the number of items in the queue
|
|
func (q *Queue) Len() int {
|
|
q.mu.Lock()
|
|
defer q.mu.Unlock()
|
|
return len(q.items)
|
|
}
|
|
|
|
// IsEmpty returns true if the queue is empty
|
|
func (q *Queue) IsEmpty() bool {
|
|
return q.Len() == 0
|
|
}
|