validation

package
v1.2.2-unstable Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2023 License: GPL-3.0 Imports: 34 Imported by: 0

Documentation

Overview

Package validation provides functions and structures for validating messages.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyData                           = Error{/* contains filtered or unexported fields */}
	ErrWrongDomain                         = Error{/* contains filtered or unexported fields */}
	ErrNoShareMetadata                     = Error{/* contains filtered or unexported fields */}
	ErrUnknownValidator                    = Error{/* contains filtered or unexported fields */}
	ErrValidatorLiquidated                 = Error{/* contains filtered or unexported fields */}
	ErrValidatorNotAttesting               = Error{/* contains filtered or unexported fields */}
	ErrSlotAlreadyAdvanced                 = Error{/* contains filtered or unexported fields */}
	ErrRoundAlreadyAdvanced                = Error{/* contains filtered or unexported fields */}
	ErrRoundTooHigh                        = Error{/* contains filtered or unexported fields */} // TODO: enable reject
	ErrEarlyMessage                        = Error{/* contains filtered or unexported fields */}
	ErrLateMessage                         = Error{/* contains filtered or unexported fields */}
	ErrTooManySameTypeMessagesPerRound     = Error{/* contains filtered or unexported fields */}
	ErrRSADecryption                       = Error{/* contains filtered or unexported fields */}
	ErrOperatorNotFound                    = Error{/* contains filtered or unexported fields */}
	ErrPubSubMessageHasNoData              = Error{/* contains filtered or unexported fields */}
	ErrPubSubDataTooBig                    = Error{/* contains filtered or unexported fields */}
	ErrMalformedPubSubMessage              = Error{/* contains filtered or unexported fields */}
	ErrEmptyPubSubMessage                  = Error{/* contains filtered or unexported fields */}
	ErrTopicNotFound                       = Error{/* contains filtered or unexported fields */}
	ErrSSVDataTooBig                       = Error{/* contains filtered or unexported fields */}
	ErrInvalidRole                         = Error{/* contains filtered or unexported fields */}
	ErrUnexpectedConsensusMessage          = Error{/* contains filtered or unexported fields */}
	ErrNoSigners                           = Error{/* contains filtered or unexported fields */}
	ErrWrongSignatureSize                  = Error{/* contains filtered or unexported fields */}
	ErrZeroSignature                       = Error{/* contains filtered or unexported fields */}
	ErrZeroSigner                          = Error{/* contains filtered or unexported fields */}
	ErrSignerNotInCommittee                = Error{/* contains filtered or unexported fields */}
	ErrDuplicatedSigner                    = Error{/* contains filtered or unexported fields */}
	ErrSignerNotLeader                     = Error{/* contains filtered or unexported fields */}
	ErrSignersNotSorted                    = Error{/* contains filtered or unexported fields */}
	ErrUnexpectedSigner                    = Error{/* contains filtered or unexported fields */}
	ErrInvalidHash                         = Error{/* contains filtered or unexported fields */}
	ErrEstimatedRoundTooFar                = Error{/* contains filtered or unexported fields */}
	ErrMalformedMessage                    = Error{/* contains filtered or unexported fields */}
	ErrMalformedSignedMessage              = Error{/* contains filtered or unexported fields */}
	ErrUnknownSSVMessageType               = Error{/* contains filtered or unexported fields */}
	ErrUnknownQBFTMessageType              = Error{/* contains filtered or unexported fields */}
	ErrUnknownPartialMessageType           = Error{/* contains filtered or unexported fields */}
	ErrPartialSignatureTypeRoleMismatch    = Error{/* contains filtered or unexported fields */}
	ErrNonDecidedWithMultipleSigners       = Error{/* contains filtered or unexported fields */}
	ErrWrongSignersLength                  = Error{/* contains filtered or unexported fields */}
	ErrDuplicatedProposalWithDifferentData = Error{/* contains filtered or unexported fields */}
	ErrEventMessage                        = Error{/* contains filtered or unexported fields */}
	ErrDKGMessage                          = Error{/* contains filtered or unexported fields */}
	ErrMalformedPrepareJustifications      = Error{/* contains filtered or unexported fields */}
	ErrUnexpectedPrepareJustifications     = Error{/* contains filtered or unexported fields */}
	ErrMalformedRoundChangeJustifications  = Error{/* contains filtered or unexported fields */}
	ErrUnexpectedRoundChangeJustifications = Error{/* contains filtered or unexported fields */}
	ErrInvalidJustifications               = Error{/* contains filtered or unexported fields */}
	ErrTooManyDutiesPerEpoch               = Error{/* contains filtered or unexported fields */}
	ErrNoDuty                              = Error{/* contains filtered or unexported fields */}
	ErrDeserializePublicKey                = Error{/* contains filtered or unexported fields */}
	ErrNoPartialMessages                   = Error{/* contains filtered or unexported fields */}
	ErrDuplicatedPartialSignatureMessage   = Error{/* contains filtered or unexported fields */}
)

Functions

This section is empty.

Types

type ConsensusDescriptor

type ConsensusDescriptor struct {
	Round           specqbft.Round
	QBFTMessageType specqbft.MessageType
	Signers         []spectypes.OperatorID
	Committee       []*spectypes.Operator
}

ConsensusDescriptor provides details about the consensus for a message. It's used for logging and metrics.

type ConsensusID

type ConsensusID struct {
	PubKey phase0.BLSPubKey
	Role   spectypes.BeaconRole
}

ConsensusID uniquely identifies a public key and role pair to keep track of state.

type ConsensusState

type ConsensusState struct {
	// TODO: consider evicting old data to avoid excessive memory consumption
	Signers *hashmap.Map[spectypes.OperatorID, *SignerState]
}

ConsensusState keeps track of the signers for a given public key and role.

func (*ConsensusState) CreateSignerState

func (cs *ConsensusState) CreateSignerState(signer spectypes.OperatorID) *SignerState

CreateSignerState initializes and sets a new SignerState for the given signer.

func (*ConsensusState) GetSignerState

func (cs *ConsensusState) GetSignerState(signer spectypes.OperatorID) *SignerState

GetSignerState retrieves the state for the given signer. Returns nil if the signer is not found.

type Descriptor

type Descriptor struct {
	ValidatorPK    spectypes.ValidatorPK
	Role           spectypes.BeaconRole
	SSVMessageType spectypes.MsgType
	Slot           phase0.Slot
	Consensus      *ConsensusDescriptor
}

Descriptor provides details about a message. It's used for logging and metrics.

func (Descriptor) Fields

func (d Descriptor) Fields() []zapcore.Field

Fields returns zap logging fields for the descriptor.

func (Descriptor) String

func (d Descriptor) String() string

String provides a string representation of the descriptor. It may be useful for logging.

type Error

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

func (Error) Error

func (e Error) Error() string

func (Error) Reject

func (e Error) Reject() bool

func (Error) Silent

func (e Error) Silent() bool

func (Error) Text

func (e Error) Text() string

type MessageCounts

type MessageCounts struct {
	PreConsensus  int
	Proposal      int
	Prepare       int
	Commit        int
	Decided       int
	RoundChange   int
	PostConsensus int
}

MessageCounts tracks the number of various message types received for validation.

func (*MessageCounts) RecordConsensusMessage

func (c *MessageCounts) RecordConsensusMessage(msg *specqbft.SignedMessage)

RecordConsensusMessage updates the counts based on the provided consensus message type.

func (*MessageCounts) RecordPartialSignatureMessage

func (c *MessageCounts) RecordPartialSignatureMessage(msg *spectypes.SignedPartialSignatureMessage)

RecordPartialSignatureMessage updates the counts based on the provided partial signature message type.

func (*MessageCounts) String

func (c *MessageCounts) String() string

String provides a formatted representation of the MessageCounts.

func (*MessageCounts) ValidateConsensusMessage

func (c *MessageCounts) ValidateConsensusMessage(msg *specqbft.SignedMessage, limits MessageCounts) error

ValidateConsensusMessage checks if the provided consensus message exceeds the set limits. Returns an error if the message type exceeds its respective count limit.

func (*MessageCounts) ValidatePartialSignatureMessage

func (c *MessageCounts) ValidatePartialSignatureMessage(m *spectypes.SignedPartialSignatureMessage, limits MessageCounts) error

ValidatePartialSignatureMessage checks if the provided partial signature message exceeds the set limits. Returns an error if the message type exceeds its respective count limit.

type MessageValidator

type MessageValidator interface {
	PubsubMessageValidator
	SSVMessageValidator
}

MessageValidator is an interface that combines both PubsubMessageValidator and SSVMessageValidator.

func NewMessageValidator

func NewMessageValidator(netCfg networkconfig.NetworkConfig, opts ...Option) MessageValidator

NewMessageValidator returns a new MessageValidator with the given network configuration and options.

type Option

type Option func(validator *messageValidator)

Option represents a functional option for configuring a messageValidator.

func WithDutyStore

func WithDutyStore(dutyStore *dutystore.Store) Option

WithDutyStore sets the duty store for the messageValidator.

func WithLogger

func WithLogger(logger *zap.Logger) Option

WithLogger sets the logger for the messageValidator.

func WithMetrics

func WithMetrics(metrics metricsreporter.MetricsReporter) Option

WithMetrics sets the metrics for the messageValidator.

func WithNodeStorage added in v1.2.0

func WithNodeStorage(nodeStorage operatorstorage.Storage) Option

WithNodeStorage sets the node storage for the messageValidator.

func WithOwnOperatorID

func WithOwnOperatorID(id spectypes.OperatorID) Option

WithOwnOperatorID sets the operator ID for the messageValidator.

func WithSelfAccept added in v1.2.0

func WithSelfAccept(selfPID peer.ID, selfAccept bool) Option

WithSelfAccept blindly accepts messages sent from self. Useful for testing.

type PubsubMessageValidator

type PubsubMessageValidator interface {
	ValidatorForTopic(topic string) func(ctx context.Context, p peer.ID, pmsg *pubsub.Message) pubsub.ValidationResult
	ValidatePubsubMessage(ctx context.Context, p peer.ID, pmsg *pubsub.Message) pubsub.ValidationResult
}

PubsubMessageValidator defines methods for validating pubsub messages.

type SSVMessageValidator

type SSVMessageValidator interface {
	ValidateSSVMessage(ssvMessage *spectypes.SSVMessage) (*queue.DecodedSSVMessage, Descriptor, error)
}

SSVMessageValidator defines methods for validating SSV messages.

type SignerState

type SignerState struct {
	Start         time.Time
	Slot          phase0.Slot
	Round         specqbft.Round
	MessageCounts MessageCounts
	ProposalData  []byte
	EpochDuties   int
}

SignerState represents the state of a signer, including its start time, slot, round, message counts, proposal data, and the number of duties performed in the current epoch.

func (*SignerState) ResetRound

func (s *SignerState) ResetRound(round specqbft.Round)

ResetRound resets the state's round, message counts, and proposal data to the given values. It also updates the start time to the current time.

func (*SignerState) ResetSlot

func (s *SignerState) ResetSlot(slot phase0.Slot, round specqbft.Round, newEpoch bool)

ResetSlot resets the state's slot, round, message counts, and proposal data to the given values. It also updates the start time to the current time and increments the epoch duties count if it's a new epoch.

Jump to

Keyboard shortcuts

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