mirror of
https://github.com/luxfi/node.git
synced 2026-10-30 15:24:05 +00:00
49 lines
1.3 KiB
Go
49 lines
1.3 KiB
Go
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package validators
|
|
|
|
import (
|
|
"context"
|
|
"sync"
|
|
|
|
"github.com/luxfi/ids"
|
|
validators "github.com/luxfi/validators"
|
|
)
|
|
|
|
// NewLockedState creates a new locked validator state
|
|
func NewLockedState(lock sync.Locker, state validators.State) validators.State {
|
|
return &lockedState{
|
|
lock: lock,
|
|
State: state,
|
|
}
|
|
}
|
|
|
|
type lockedState struct {
|
|
lock sync.Locker
|
|
validators.State
|
|
}
|
|
|
|
func (ls *lockedState) GetCurrentHeight(ctx context.Context) (uint64, error) {
|
|
ls.lock.Lock()
|
|
defer ls.lock.Unlock()
|
|
return ls.State.GetCurrentHeight(ctx)
|
|
}
|
|
|
|
func (ls *lockedState) GetValidatorSet(ctx context.Context, height uint64, chainID ids.ID) (map[ids.NodeID]*validators.GetValidatorOutput, error) {
|
|
ls.lock.Lock()
|
|
defer ls.lock.Unlock()
|
|
return ls.State.GetValidatorSet(ctx, height, chainID)
|
|
}
|
|
|
|
func (ls *lockedState) GetCurrentValidators(ctx context.Context, height uint64, chainID ids.ID) (map[ids.NodeID]*validators.GetValidatorOutput, error) {
|
|
ls.lock.Lock()
|
|
defer ls.lock.Unlock()
|
|
if state, ok := ls.State.(interface {
|
|
GetCurrentValidators(context.Context, uint64, ids.ID) (map[ids.NodeID]*validators.GetValidatorOutput, error)
|
|
}); ok {
|
|
return state.GetCurrentValidators(ctx, height, chainID)
|
|
}
|
|
return ls.State.GetValidatorSet(ctx, height, chainID)
|
|
}
|