ssv

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2022 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AggregatorValueCheck

func AggregatorValueCheck(signer types.BeaconSigner, network types.BeaconNetwork) qbft.ProposedValueCheckF

func BeaconAttestationValueCheck

func BeaconAttestationValueCheck(signer types.BeaconSigner, network types.BeaconNetwork) qbft.ProposedValueCheckF

func BeaconBlockValueCheck

func BeaconBlockValueCheck(signer types.BeaconSigner, network types.BeaconNetwork) qbft.ProposedValueCheckF

func SyncCommitteeContributionValueCheck

func SyncCommitteeContributionValueCheck(signer types.BeaconSigner, network types.BeaconNetwork) qbft.ProposedValueCheckF

func SyncCommitteeValueCheck

func SyncCommitteeValueCheck(signer types.BeaconSigner, network types.BeaconNetwork) qbft.ProposedValueCheckF

Types

type AggregatorCalls

type AggregatorCalls interface {
	// SubmitAggregateSelectionProof returns an AggregateAndProof object
	SubmitAggregateSelectionProof(slot phase0.Slot, committeeIndex phase0.CommitteeIndex, slotSig []byte) (*phase0.AggregateAndProof, error)
	// SubmitSignedAggregateSelectionProof broadcasts a signed aggregator msg
	SubmitSignedAggregateSelectionProof(msg *phase0.SignedAggregateAndProof) error
}

AggregatorCalls interface has all attestation aggregator duty specific calls

type AttesterCalls

type AttesterCalls interface {
	// GetAttestationData returns attestation data by the given slot and committee index
	GetAttestationData(slot phase0.Slot, committeeIndex phase0.CommitteeIndex) (*phase0.AttestationData, error)
	// SubmitAttestation submit the attestation to the node
	SubmitAttestation(attestation *phase0.Attestation) error
}

AttesterCalls interface has all attester duty specific calls

type BeaconNode

type BeaconNode interface {
	// GetBeaconNetwork returns the beacon network the node is on
	GetBeaconNetwork() types.BeaconNetwork
	AttesterCalls
	ProposerCalls
	AggregatorCalls
	SyncCommitteeCalls
	SyncCommitteeContributionCalls
}

type DutyRunners

type DutyRunners map[types.BeaconRole]*Runner

DutyRunners is a map of duty runners mapped by msg id hex.

func (DutyRunners) DutyRunnerForMsgID

func (ci DutyRunners) DutyRunnerForMsgID(msgID types.MessageID) *Runner

DutyRunnerForMsgID returns a Runner from the provided msg ID, or nil if not found

type Network

type Network interface {
	Broadcast(message types.Encoder) error
}

type PartialSigContainer

type PartialSigContainer struct {
	Signatures map[string]map[types.OperatorID][]byte
	// Quorum is the number of min signatures needed for quorum
	Quorum uint64
}

func NewPartialSigContainer

func NewPartialSigContainer(quorum uint64) *PartialSigContainer

func (*PartialSigContainer) AddSignature

func (ps *PartialSigContainer) AddSignature(sigMsg *PartialSignatureMessage) error

func (*PartialSigContainer) HasQuorum

func (ps *PartialSigContainer) HasQuorum(root []byte) bool

func (*PartialSigContainer) ReconstructSignature

func (ps *PartialSigContainer) ReconstructSignature(root, validatorPubKey []byte) ([]byte, error)

type PartialSigMsgType

type PartialSigMsgType uint64
const (
	// PostConsensusPartialSig is a partial signature over a decided duty (attestation data, block, etc)
	PostConsensusPartialSig PartialSigMsgType = iota
	// RandaoPartialSig is a partial signature over randao reveal
	RandaoPartialSig
	// SelectionProofPartialSig is a partial signature for aggregator selection proof
	SelectionProofPartialSig
	// ContributionProofs is the partial selection proofs for sync committee contributions (it's an array of sigs)
	ContributionProofs
)

type PartialSignatureMessage

type PartialSignatureMessage struct {
	Slot             spec.Slot // Slot represents the slot for which the partial BN signature is for
	PartialSignature []byte    // The beacon chain partial Signature for a duty
	SigningRoot      []byte    // the root signed in PartialSignature
	Signers          []types.OperatorID
	MetaData         *PartialSignatureMetaData
}

PartialSignatureMessage is a msg for partial beacon chain related signatures (like partial attestation, block, randao sigs)

func (*PartialSignatureMessage) Decode

func (pcsm *PartialSignatureMessage) Decode(data []byte) error

Decode returns error if decoding failed

func (*PartialSignatureMessage) Encode

func (pcsm *PartialSignatureMessage) Encode() ([]byte, error)

Encode returns a msg encoded bytes or error

func (*PartialSignatureMessage) GetRoot

func (pcsm *PartialSignatureMessage) GetRoot() ([]byte, error)

func (*PartialSignatureMessage) Validate

func (pcsm *PartialSignatureMessage) Validate() error

type PartialSignatureMessages

type PartialSignatureMessages []*PartialSignatureMessage

func (*PartialSignatureMessages) Decode

func (msgs *PartialSignatureMessages) Decode(data []byte) error

Decode returns error if decoding failed

func (*PartialSignatureMessages) Encode

func (msgs *PartialSignatureMessages) Encode() ([]byte, error)

Encode returns a msg encoded bytes or error

func (PartialSignatureMessages) GetRoot

func (msgs PartialSignatureMessages) GetRoot() ([]byte, error)

GetRoot returns the root used for signing and verification

type PartialSignatureMetaData

type PartialSignatureMetaData struct {
	ContributionSubCommitteeIndex uint64
}

type ProposerCalls

type ProposerCalls interface {
	// GetBeaconBlock returns beacon block by the given slot and committee index
	GetBeaconBlock(slot phase0.Slot, committeeIndex phase0.CommitteeIndex, graffiti, randao []byte) (*altair.BeaconBlock, error)
	// SubmitBeaconBlock submit the block to the node
	SubmitBeaconBlock(block *altair.SignedBeaconBlock) error
}

ProposerCalls interface has all block proposer duty specific calls

type Runner

type Runner struct {
	BeaconRoleType types.BeaconRole
	BeaconNetwork  types.BeaconNetwork
	Share          *types.Share
	// State holds all relevant params for a full duty execution (consensus & post consensus)
	State *State
	// CurrentDuty is the current executing duty, changes once StartNewDuty is called
	CurrentDuty    *types.Duty
	QBFTController *qbft.Controller
	// contains filtered or unexported fields
}

Runner is manages the execution of a duty from start to finish, it can only execute 1 duty at a time. Prev duty must finish before the next one can start.

func NewDutyRunner

func NewDutyRunner(
	beaconRoleType types.BeaconRole,
	beaconNetwork types.BeaconNetwork,
	share *types.Share,
	qbftController *qbft.Controller,
	storage Storage,
	valCheck qbft.ProposedValueCheckF,
) *Runner

func (*Runner) CanStartNewDuty

func (dr *Runner) CanStartNewDuty(duty *types.Duty) error

CanStartNewDuty returns nil if no running instance exists or already decided. Pre- / Post-consensus signature collections do not block a new duty from starting

func (*Runner) Decide

func (dr *Runner) Decide(input *types.ConsensusData) error

Decide starts a new consensus instance for input value

func (*Runner) Decode

func (dr *Runner) Decode(data []byte) error

Decode returns error if decoding failed

func (*Runner) Encode

func (dr *Runner) Encode() ([]byte, error)

Encode returns the encoded struct in bytes or error

func (*Runner) GetRoot

func (dr *Runner) GetRoot() ([]byte, error)

GetRoot returns the root used for signing and verification

func (*Runner) ProcessConsensusMessage

func (dr *Runner) ProcessConsensusMessage(msg *qbft.SignedMessage) (decided bool, decidedValue *types.ConsensusData, err error)

func (*Runner) ProcessContributionProofsMessage

func (dr *Runner) ProcessContributionProofsMessage(signedMsg *SignedPartialSignatureMessage) (bool, [][]byte, error)

ProcessContributionProofsMessage process contribution proofs msg (an array), returns true if it has quorum for partial signatures. returns true only once (first time quorum achieved)

func (*Runner) ProcessPostConsensusMessage

func (dr *Runner) ProcessPostConsensusMessage(signedMsg *SignedPartialSignatureMessage) (bool, [][]byte, error)

ProcessPostConsensusMessage process post consensus msg, returns true if it has quorum for partial signatures. returns true only once (first time quorum achieved) returns signed message roots for which there is a quorum

func (*Runner) ProcessRandaoMessage

func (dr *Runner) ProcessRandaoMessage(signedMsg *SignedPartialSignatureMessage) (bool, [][]byte, error)

ProcessRandaoMessage process randao msg, returns true if it has quorum for partial signatures. returns true only once (first time quorum achieved)

func (*Runner) ProcessSelectionProofMessage

func (dr *Runner) ProcessSelectionProofMessage(signedMsg *SignedPartialSignatureMessage) (bool, [][]byte, error)

ProcessSelectionProofMessage process selection proof msg, returns true if it has quorum for partial signatures. returns true only once (first time quorum achieved)

func (*Runner) SignDutyPostConsensus

func (dr *Runner) SignDutyPostConsensus(decidedValue *types.ConsensusData, signer types.KeyManager) (PartialSignatureMessages, error)

SignDutyPostConsensus sets the Decided duty and partially signs the Decided data, returns a PartialSignatureMessage to be broadcasted or error

func (*Runner) SignRandaoPreConsensus

func (dr *Runner) SignRandaoPreConsensus(epoch spec.Epoch, slot spec.Slot, signer types.KeyManager) (*PartialSignatureMessage, error)

func (*Runner) SignSlotWithSelectionProofPreConsensus

func (dr *Runner) SignSlotWithSelectionProofPreConsensus(slot spec.Slot, signer types.KeyManager) (*PartialSignatureMessage, error)

func (*Runner) SignSyncSubCommitteeContributionProof

func (dr *Runner) SignSyncSubCommitteeContributionProof(slot spec.Slot, indexes []uint64, signer types.KeyManager) (PartialSignatureMessages, error)

func (*Runner) StartNewDuty

func (dr *Runner) StartNewDuty(duty *types.Duty) error

type SignedPartialSignatureMessage

type SignedPartialSignatureMessage struct {
	Type      PartialSigMsgType
	Messages  PartialSignatureMessages
	Signature types.Signature
	Signers   []types.OperatorID
}

SignedPartialSignatureMessage is an operator's signature over PartialSignatureMessage

func (*SignedPartialSignatureMessage) Aggregate

func (spcsm *SignedPartialSignatureMessage) Aggregate(signedMsg types.MessageSignature) error

func (*SignedPartialSignatureMessage) Decode

func (spcsm *SignedPartialSignatureMessage) Decode(data []byte) error

Decode returns error if decoding failed

func (*SignedPartialSignatureMessage) Encode

func (spcsm *SignedPartialSignatureMessage) Encode() ([]byte, error)

Encode returns a msg encoded bytes or error

func (*SignedPartialSignatureMessage) GetRoot

func (spcsm *SignedPartialSignatureMessage) GetRoot() ([]byte, error)

func (*SignedPartialSignatureMessage) GetSignature

func (spcsm *SignedPartialSignatureMessage) GetSignature() types.Signature

func (*SignedPartialSignatureMessage) GetSigners

func (spcsm *SignedPartialSignatureMessage) GetSigners() []types.OperatorID

func (*SignedPartialSignatureMessage) MatchedSigners

func (spcsm *SignedPartialSignatureMessage) MatchedSigners(ids []types.OperatorID) bool

MatchedSigners returns true if the provided signer ids are equal to GetSignerIds() without order significance

func (*SignedPartialSignatureMessage) Validate

func (spcsm *SignedPartialSignatureMessage) Validate() error

type State

type State struct {
	// pre consensus signatures
	SelectionProofPartialSig        *PartialSigContainer
	RandaoPartialSig                *PartialSigContainer
	ContributionProofs              *PartialSigContainer
	ContributionSubCommitteeIndexes map[string]uint64 // maps contribution sig root to subcommittee index
	PostConsensusPartialSig         *PartialSigContainer

	// consensus
	RunningInstance *qbft.Instance
	DecidedValue    *types.ConsensusData

	// post consensus signed objects
	SignedAttestation   *spec.Attestation
	SignedProposal      *altair.SignedBeaconBlock
	SignedAggregate     *spec.SignedAggregateAndProof
	SignedSyncCommittee *altair.SyncCommitteeMessage
	SignedContributions map[string]*altair.SignedContributionAndProof // maps contribution root to signed contribution

	// flags
	Finished bool // Finished marked true when there is a full successful cycle (pre, consensus and post) with quorum
}

State holds all the relevant progress the duty execution progress

func NewDutyExecutionState

func NewDutyExecutionState(quorum uint64) *State

func (*State) Decode

func (pcs *State) Decode(data []byte) error

Decode returns error if decoding failed

func (*State) Encode

func (pcs *State) Encode() ([]byte, error)

Encode returns the encoded struct in bytes or error

func (*State) GetRoot

func (pcs *State) GetRoot() ([]byte, error)

GetRoot returns the root used for signing and verification

func (*State) ReconstructAttestationSig

func (pcs *State) ReconstructAttestationSig(root, validatorPubKey []byte) (*spec.Attestation, error)

ReconstructAttestationSig aggregates collected partial sigs, reconstructs a valid sig and returns an attestation obj with the reconstructed sig

func (*State) ReconstructBeaconBlockSig

func (pcs *State) ReconstructBeaconBlockSig(root, validatorPubKey []byte) (*altair.SignedBeaconBlock, error)

ReconstructBeaconBlockSig aggregates collected partial sigs, reconstructs a valid sig and returns a SignedBeaconBlock with the reconstructed sig

func (*State) ReconstructContributionProofSig

func (pcs *State) ReconstructContributionProofSig(root, validatorPubKey []byte) ([]byte, uint64, error)

ReconstructContributionProofSig aggregates collected partial contribution proof sigs, reconstructs a valid sig and returns it

func (*State) ReconstructContributionSig

func (pcs *State) ReconstructContributionSig(root, validatorPubKey []byte) (*altair.SignedContributionAndProof, error)

ReconstructContributionSig aggregates collected partial contribution sigs, reconstructs a valid sig and returns it

func (*State) ReconstructRandaoSig

func (pcs *State) ReconstructRandaoSig(root, validatorPubKey []byte) ([]byte, error)

ReconstructRandaoSig aggregates collected partial randao sigs, reconstructs a valid sig and returns it

func (*State) ReconstructSelectionProofSig

func (pcs *State) ReconstructSelectionProofSig(root, validatorPubKey []byte) ([]byte, error)

ReconstructSelectionProofSig aggregates collected partial selection proof sigs, reconstructs a valid sig and returns it

func (*State) ReconstructSignedAggregateSelectionProofSig

func (pcs *State) ReconstructSignedAggregateSelectionProofSig(root, validatorPubKey []byte) (*spec.SignedAggregateAndProof, error)

ReconstructSignedAggregateSelectionProofSig aggregates collected partial signed aggregate selection proof sigs, reconstructs a valid sig and returns it

func (*State) ReconstructSyncCommitteeSig

func (pcs *State) ReconstructSyncCommitteeSig(root, validatorPubKey []byte) (*altair.SyncCommitteeMessage, error)

ReconstructSyncCommitteeSig aggregates collected partial sync committee sigs, reconstructs a valid sig and returns it

type Storage

type Storage interface {
}

Storage is a persistent storage for the SSV

type SyncCommitteeCalls

type SyncCommitteeCalls interface {
	// GetSyncMessageBlockRoot returns beacon block root for sync committee
	GetSyncMessageBlockRoot() (phase0.Root, error)
	// SubmitSyncMessage submits a signed sync committee msg
	SubmitSyncMessage(msg *altair.SyncCommitteeMessage) error
}

SyncCommitteeCalls interface has all sync committee duty specific calls

type SyncCommitteeContributionCalls

type SyncCommitteeContributionCalls interface {
	// GetSyncSubcommitteeIndex returns sync committee indexes for aggregator
	GetSyncSubcommitteeIndex(slot phase0.Slot, pubKey phase0.BLSPubKey) ([]uint64, error)
	// IsSyncCommitteeAggregator returns tru if aggregator
	IsSyncCommitteeAggregator(proof []byte) (bool, error)
	// SyncCommitteeSubnetID returns sync committee subnet ID from subcommittee index
	SyncCommitteeSubnetID(subCommitteeID uint64) (uint64, error)
	// GetSyncCommitteeContribution returns
	GetSyncCommitteeContribution(slot phase0.Slot, subnetID uint64, pubKey phase0.BLSPubKey) (*altair.SyncCommitteeContribution, error)
	// SubmitSignedContributionAndProof broadcasts to the network
	SubmitSignedContributionAndProof(contribution *altair.SignedContributionAndProof) error
}

SyncCommitteeContributionCalls interface has all sync committee contribution duty specific calls

type Validator

type Validator struct {
	DutyRunners DutyRunners
	// contains filtered or unexported fields
}

Validator represents an SSV ETH consensus validator share assigned, coordinates duty execution and more. Every validator has a validatorID which is validator's public key. Each validator has multiple DutyRunners, for each duty type.

func NewValidator

func NewValidator(
	network Network,
	beacon BeaconNode,
	storage Storage,
	share *types.Share,
	signer types.KeyManager,
) *Validator

func (*Validator) ProcessMessage

func (v *Validator) ProcessMessage(msg *types.SSVMessage) error

ProcessMessage processes network Messages of all types

func (*Validator) StartDuty

func (v *Validator) StartDuty(duty *types.Duty) error

StartDuty starts a duty for the validator

Jump to

Keyboard shortcuts

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