common

package
v2.0.5-testnet Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2024 License: Apache-2.0, MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultBeaconID = "default"

DefaultBeaconID is the value used when beacon id has an empty value. This value should not be changed for backward-compatibility reasons

View Source
const DefaultChainHash = "default"

DefaultChainHash is the value used when chain hash has an empty value on requests from clients. This value should not be changed for backward-compatibility reasons

View Source
const LogsToSkip = 300

LogsToSkip is used to reduce log verbosity when doing bulk processes, issuing logs only every LogsToSkip steps this is currently set so that when processing past beacons it will give a log every ~2 seconds

View Source
const MultiBeaconFolder = "multibeacon"

MultiBeaconFolder is the name of the folder where the multi-beacon data is stored

View Source
const TimeOfRoundErrorValue = math.MaxInt64 - maxTimeBuffer

TimeOfRoundErrorValue is the value returned by `TimeOfRound` when an invalid round is specified.

Variables

View Source
var (
	COMMIT    = ""
	BUILDDATE = ""
)

Set via -ldflags. Example:

go install -ldflags "-X common.BUILDDATE=`date -u +%d/%m/%Y@%H:%M:%S` -X common.GITCOMMIT=`git rev-parse HEAD`

See the Makefile and the Dockerfile in the root directory of the repo

View Source
var ErrEmptyClientUnsupportedGet = errors.New("not supported")
View Source
var ErrInvalidChainHash = errors.New("incorrect chain hash")

ErrInvalidChainHash means there was an error or a mismatch with the chain hash

View Source
var ErrNotPartOfGroup = errors.New("this node is not part of the group")

ErrNotPartOfGroup indicates that this node is not part of the group for a specific beacon ID

View Source
var ErrPeerNotFound = errors.New("peer not found")

ErrPeerNotFound indicates that a peer is not part of any group that this node knows of

Functions

func CompareBeaconIDs

func CompareBeaconIDs(id1, id2 string) bool

CompareBeaconIDs indicates if two different beacon ids are equivalent or not. It handles default values too.

func CurrentRound

func CurrentRound(now int64, period time.Duration, genesis int64) uint64

CurrentRound calculates the active round at `now`

func GetCanonicalBeaconID

func GetCanonicalBeaconID(id string) string

GetCanonicalBeaconID returns the correct beacon id.

func IsDefaultBeaconID

func IsDefaultBeaconID(beaconID string) bool

IsDefaultBeaconID indicates if the beacon id received is the default one or not. There is a direct relationship between an empty string and the reserved id "default". Internally, empty string is translated to "default" so we can create the beacon folder with a valid name.

func NextRound

func NextRound(now int64, period time.Duration, genesis int64) (nextRound uint64, nextTime int64)

NextRound returns the next upcoming round and its UNIX time given the genesis time and the period. round at time genesis = round 1. Round 0 is fixed.

func TimeOfRound

func TimeOfRound(period time.Duration, genesis int64, round uint64) int64

TimeOfRound is returning the time the current round should happen

Types

type Beacon

type Beacon struct {
	// PreviousSig is the previous signature generated
	PreviousSig HexBytes `json:"previous_signature,omitempty"`
	// Round is the round number this beacon is tied to
	Round uint64 `json:"round"`
	// Signature is the BLS deterministic signature as per the crypto.Scheme used
	Signature HexBytes `json:"signature"`
}

Beacon holds the randomness as well as the info to verify it.

func (*Beacon) Equal

func (b *Beacon) Equal(b2 *Beacon) bool

Equal indicates if two beacons are equal

func (*Beacon) GetPreviousSignature

func (b *Beacon) GetPreviousSignature() []byte

GetPreviousSignature returns the previous signature if it's non-nil or nil otherwise

func (*Beacon) GetRandomness

func (b *Beacon) GetRandomness() []byte

func (*Beacon) GetRound

func (b *Beacon) GetRound() uint64

GetRound provides the round of the beacon

func (*Beacon) GetSignature

func (b *Beacon) GetSignature() []byte

GetSignature returns the signature if it's non-nil or nil otherwise

func (*Beacon) Marshal

func (b *Beacon) Marshal() ([]byte, error)

Marshal provides a JSON encoding of a beacon. Careful, this is not the one rendered by the public endpoints.

func (*Beacon) Randomness

func (b *Beacon) Randomness() []byte

Randomness returns the hashed signature. The choice of the hash determines the size of the output.

func (*Beacon) String

func (b *Beacon) String() string

func (*Beacon) Unmarshal

func (b *Beacon) Unmarshal(buff []byte) error

Unmarshal decodes a beacon from JSON

type HexBytes

type HexBytes []byte

HexBytes ensures that JSON marshallers marshal to hex rather than base64 to keep compatibility with old store formats

func (*HexBytes) MarshalJSON

func (h *HexBytes) MarshalJSON() ([]byte, error)

func (*HexBytes) UnmarshalJSON

func (h *HexBytes) UnmarshalJSON(data []byte) error

UnmarshalJSON converts a hexadecimal string from JSON to a byte slice

type Version

type Version struct {
	Major      uint32
	Minor      uint32
	Patch      uint32
	Prerelease string
}

func GetAppVersion

func GetAppVersion() Version

func (Version) IsCompatible

func (v Version) IsCompatible(verRcv Version) bool

func (Version) String

func (v Version) String() string

func (Version) ToProto

func (v Version) ToProto() *pbcommon.NodeVersion

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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