mirror of
https://github.com/luxfi/consensus.git
synced 2026-09-24 00:26:58 +00:00
50 lines
958 B
Go
50 lines
958 B
Go
package tracker
|
|
|
|
import (
|
|
"github.com/luxfi/ids"
|
|
)
|
|
|
|
// Tracker tracks consensus state
|
|
type Tracker interface {
|
|
// IsBootstrapped checks if bootstrapped
|
|
IsBootstrapped() bool
|
|
|
|
// Bootstrapped marks as bootstrapped
|
|
Bootstrapped(ids.ID)
|
|
|
|
// OnBootstrapCompleted called when bootstrap completes
|
|
OnBootstrapCompleted() chan ids.ID
|
|
}
|
|
|
|
// tracker implementation
|
|
type tracker struct {
|
|
bootstrapped bool
|
|
completed chan ids.ID
|
|
}
|
|
|
|
// NewTracker creates a new tracker
|
|
func NewTracker() Tracker {
|
|
return &tracker{
|
|
completed: make(chan ids.ID, 1),
|
|
}
|
|
}
|
|
|
|
// IsBootstrapped checks if bootstrapped
|
|
func (t *tracker) IsBootstrapped() bool {
|
|
return t.bootstrapped
|
|
}
|
|
|
|
// Bootstrapped marks as bootstrapped
|
|
func (t *tracker) Bootstrapped(chainID ids.ID) {
|
|
t.bootstrapped = true
|
|
select {
|
|
case t.completed <- chainID:
|
|
default:
|
|
}
|
|
}
|
|
|
|
// OnBootstrapCompleted returns completion channel
|
|
func (t *tracker) OnBootstrapCompleted() chan ids.ID {
|
|
return t.completed
|
|
}
|