2023-04-25 15:07:24 +00:00
|
|
|
package consensus_types
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
2023-10-06 01:10:05 +00:00
|
|
|
"sync/atomic"
|
2023-04-25 15:07:24 +00:00
|
|
|
|
|
|
|
errors2 "github.com/pkg/errors"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/runtime/version"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
// ErrNilObjectWrapped is returned in a constructor when the underlying object is nil.
|
|
|
|
ErrNilObjectWrapped = errors.New("attempted to wrap nil object")
|
2023-05-23 09:38:52 +00:00
|
|
|
// ErrUnsupportedField is returned when a getter/setter access is not supported.
|
|
|
|
ErrUnsupportedField = errors.New("unsupported getter")
|
2023-10-06 01:10:05 +00:00
|
|
|
// ErrOutOfBounds is returned when a slice or array index does not exist.
|
|
|
|
ErrOutOfBounds = errors.New("index out of bounds")
|
2023-04-25 15:07:24 +00:00
|
|
|
)
|
|
|
|
|
2023-05-23 09:38:52 +00:00
|
|
|
// ErrNotSupported constructs a message informing about an unsupported field access.
|
2023-04-25 15:07:24 +00:00
|
|
|
func ErrNotSupported(funcName string, ver int) error {
|
2023-05-23 09:38:52 +00:00
|
|
|
return errors2.Wrap(ErrUnsupportedField, fmt.Sprintf("%s is not supported for %s", funcName, version.String(ver)))
|
2023-04-25 15:07:24 +00:00
|
|
|
}
|
2023-10-06 01:10:05 +00:00
|
|
|
|
|
|
|
// ThreadSafeEnumerator is a thread-safe counter of all objects created since the node's start.
|
|
|
|
type ThreadSafeEnumerator struct {
|
|
|
|
counter uint64
|
|
|
|
}
|
|
|
|
|
|
|
|
// Inc increments the enumerator and returns the new object count.
|
|
|
|
func (c *ThreadSafeEnumerator) Inc() uint64 {
|
|
|
|
return atomic.AddUint64(&c.counter, 1)
|
|
|
|
}
|