types

package
v1.4.4 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2021 License: GPL-3.0 Imports: 4 Imported by: 33

Documentation

Overview

Package types includes important type definitions for slashable objects detected by slasher.

Index

Constants

This section is empty.

Variables

View Source
var ErrWrongSize = errors.New("wrong data length for min max span byte array")

ErrWrongSize appears when attempting to use epoch store byte array with size that is not a multiple of spanner encoded length.

View Source
var SpannerEncodedLength = uint64(7)

SpannerEncodedLength the byte length of validator span data structure.

Functions

This section is empty.

Types

type DetectionKind

type DetectionKind uint8

DetectionKind defines an enum type that gives us information on the type of slashable offense found when analyzing validator min-max spans.

const (
	// DoubleVote denotes a slashable offense in which
	// a validator cast two conflicting attestations within
	// the same target epoch.
	DoubleVote DetectionKind = iota
	// SurroundVote denotes a slashable offense in which
	// a validator surrounded or was surrounded by a previous
	// attestation created by the same validator.
	SurroundVote
)

type DetectionResult

type DetectionResult struct {
	ValidatorIndex uint64
	SlashableEpoch types.Epoch
	Kind           DetectionKind
	SigBytes       [2]byte
}

DetectionResult tells us the kind of slashable offense found from detecting on min-max spans + the slashable epoch for the offense. Also includes the signature bytes for assistance in finding the attestation for the slashing proof.

func (*DetectionResult) Marshal added in v0.3.4

func (r *DetectionResult) Marshal() []byte

Marshal the result into bytes, used for removing duplicates.

type EpochStore added in v1.0.0

type EpochStore struct {
	// contains filtered or unexported fields
}

EpochStore defines an implementation of the slasher data access interface using byte array as data source to extract and put validator spans into.

func EpochStoreFromMap added in v1.0.0

func EpochStoreFromMap(spanMap map[uint64]Span) (*EpochStore, error)

EpochStoreFromMap is a helper function to turn a map into a epoch store, mainly used for testing.

func NewEpochStore added in v1.0.0

func NewEpochStore(spans []byte) (*EpochStore, error)

NewEpochStore initialize epoch store from a byte array returns error if byte length is not a multiple of encoded spanner length.

func (*EpochStore) Bytes added in v1.0.0

func (es *EpochStore) Bytes() []byte

Bytes returns the underlying bytes of an EpochStore.

func (*EpochStore) GetValidatorSpan added in v1.0.0

func (es *EpochStore) GetValidatorSpan(idx uint64) (Span, error)

GetValidatorSpan unmarshal a span from an encoded, flattened array.

func (*EpochStore) HighestObservedIdx added in v1.0.0

func (es *EpochStore) HighestObservedIdx() uint64

HighestObservedIdx returns the highest idx the EpochStore has been used for.

func (*EpochStore) SetValidatorSpan added in v1.0.0

func (es *EpochStore) SetValidatorSpan(idx uint64, newSpan Span) (*EpochStore, error)

SetValidatorSpan marshal a validator span into an encoded, flattened array.

func (*EpochStore) ToMap added in v1.0.0

func (es *EpochStore) ToMap() (map[uint64]Span, error)

ToMap is a helper function to convert an epoch store to a map, mainly used for testing.

type Span

type Span struct {
	MinSpan     uint16
	MaxSpan     uint16
	SigBytes    [2]byte
	HasAttested bool
}

Span defines the structure used for detecting surround and double votes.

func UnmarshalSpan added in v1.0.0

func UnmarshalSpan(enc []byte) (Span, error)

UnmarshalSpan returns a span from an encoded, flattened byte array. Note: This is a very often used function, so it is as optimized as possible.

func (Span) Marshal added in v1.0.0

func (s Span) Marshal() []byte

Marshal converts the span struct into a flattened byte array. Note: This is a very often used function, so it is as optimized as possible.

Jump to

Keyboard shortcuts

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