core

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2022 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeAttestationAggSignedData

func DecodeAttestationAggSignedData(data AggSignedData) (*eth2p0.Attestation, error)

DecodeAttestationAggSignedData returns the attestation from the encoded AggSignedData.

func DecodeAttestationParSignedData

func DecodeAttestationParSignedData(data ParSignedData) (*eth2p0.Attestation, error)

DecodeAttestationParSignedData returns the attestation from the encoded ParSignedData.

func DecodeAttesterFetchArg

func DecodeAttesterFetchArg(fetchArg FetchArg) (*eth2v1.AttesterDuty, error)

DecodeAttesterFetchArg return the attester duty from the encoded FetchArg.

func DecodeBlockAggSignedData added in v0.4.0

func DecodeBlockAggSignedData(data AggSignedData) (*spec.VersionedSignedBeaconBlock, error)

DecodeBlockAggSignedData returns the partially signed block data from the encoded AggSignedData.

func DecodeBlockParSignedData added in v0.3.0

func DecodeBlockParSignedData(data ParSignedData) (*spec.VersionedSignedBeaconBlock, error)

DecodeBlockParSignedData returns the partially signed block data from the encoded ParSignedData.

func DecodeProposerFetchArg

func DecodeProposerFetchArg(fetchArg FetchArg) (*eth2v1.ProposerDuty, error)

DecodeProposerFetchArg return the proposer duty from the encoded FetchArg.

func DecodeProposerUnsignedData

func DecodeProposerUnsignedData(unsignedData UnsignedData) (*spec.VersionedBeaconBlock, error)

DecodeProposerUnsignedData returns the proposer data from the encoded UnsignedData.

func DecodeRandaoAggSignedData

func DecodeRandaoAggSignedData(data AggSignedData) eth2p0.BLSSignature

DecodeRandaoAggSignedData returns the RANDAO reveal from the encoded AggSignedData as BLS Signature.

func DecodeRandaoParSignedData

func DecodeRandaoParSignedData(data ParSignedData) eth2p0.BLSSignature

DecodeRandaoParSignedData returns the RANDAO reveal from the encoded ParSignedData as BLS signature.

func DutyToProto added in v0.3.0

func DutyToProto(duty Duty) *pbv1.Duty

DutyToProto returns the duty as a protobuf.

func ParSignedDataSetToProto added in v0.3.0

func ParSignedDataSetToProto(set ParSignedDataSet) *pbv1.ParSignedDataSet

ParSignedDataSetToProto returns the set as a protobuf.

func ParSignedDataToProto added in v0.3.0

func ParSignedDataToProto(data ParSignedData) *pbv1.ParSignedData

ParSignedDataToProto returns the data as a protobuf.

func StartDutyTrace

func StartDutyTrace(ctx context.Context, duty Duty, spanName string, opts ...trace.SpanStartOption) (context.Context, trace.Span)

StartDutyTrace returns a context and span rooted to the duty traceID and wrapped in a duty span. This creates a new trace root and should generally only be called when a new duty is scheduled or when a duty is received from the VC or peer.

func UnsignedDataSetToProto added in v0.4.0

func UnsignedDataSetToProto(set UnsignedDataSet) *pbv1.UnsignedDataSet

UnsignedDataSetToProto returns the set as a protobuf.

func Wire

func Wire(sched Scheduler,
	fetch Fetcher,
	cons Consensus,
	dutyDB DutyDB,
	vapi ValidatorAPI,
	parSigDB ParSigDB,
	parSigEx ParSigEx,
	sigAgg SigAgg,
	aggSigDB AggSigDB,
	bcast Broadcaster,
	opts ...WireOption,
)

Wire wires the workflow components together.

Types

type AggSigDB

type AggSigDB interface {
	// Store stores aggregated signed duty data.
	Store(context.Context, Duty, PubKey, AggSignedData) error

	// Await blocks and returns the aggregated signed duty data when available.
	Await(context.Context, Duty, PubKey) (AggSignedData, error)
}

AggSigDB persists aggregated signed duty data.

type AggSignedData

type AggSignedData struct {
	// Data is the signed duty data to be sent to beacon chain.
	Data []byte
	// Signature is the result of tbls aggregation and is inserted into the data.
	Signature Signature
}

AggSignedData is an aggregated signed duty data. Aggregated refers to it being signed by the aggregated BLS threshold signing scheme.

func EncodeAttestationAggSignedData

func EncodeAttestationAggSignedData(att *eth2p0.Attestation) (AggSignedData, error)

EncodeAttestationAggSignedData returns the attestation as an encoded AggSignedData.

func EncodeBlockAggSignedData added in v0.4.0

func EncodeBlockAggSignedData(block *spec.VersionedSignedBeaconBlock) (AggSignedData, error)

EncodeBlockAggSignedData returns the partially signed block data as an encoded AggSignedData.

func EncodeRandaoAggSignedData

func EncodeRandaoAggSignedData(randao eth2p0.BLSSignature) AggSignedData

EncodeRandaoAggSignedData returns the RANDAO reveal as an encoded AggSignedData.

func (AggSignedData) Equal

func (a AggSignedData) Equal(b AggSignedData) bool

type AttestationData

type AttestationData struct {
	Data eth2p0.AttestationData
	Duty eth2v1.AttesterDuty
}

AttestationData wraps the eth2 attestation data and adds the original duty. The original duty allows mapping the partial signed response from the VC backed to the validator pubkey via the aggregation bits field.

func DecodeAttesterUnsignedData

func DecodeAttesterUnsignedData(unsignedData UnsignedData) (*AttestationData, error)

DecodeAttesterUnsignedData return the attestation data from the encoded UnsignedData.

type Broadcaster

type Broadcaster interface {
	Broadcast(context.Context, Duty, PubKey, AggSignedData) error
}

Broadcaster broadcasts aggregated signed duty data to the beacon node.

type Consensus

type Consensus interface {
	// Propose triggers consensus game of the proposed duty unsigned data set.
	Propose(context.Context, Duty, UnsignedDataSet) error

	// Subscribe registers a callback for resolved (reached consensus) duty unsigned data set.
	Subscribe(func(context.Context, Duty, UnsignedDataSet) error)
}

Consensus comes to consensus on proposed duty data.

type Duty

type Duty struct {
	// Slot is the Ethereum consensus layer slot.
	Slot int64
	// Type is the duty type performed in the slot.
	Type DutyType
}

Duty is the unit of work of the core workflow.

func DutyFromProto added in v0.3.0

func DutyFromProto(duty *pbv1.Duty) Duty

DutyFromProto returns the duty from a protobuf.

func NewAttesterDuty

func NewAttesterDuty(slot int64) Duty

NewAttesterDuty returns a new attester duty. It is a convenience function that is slightly more readable and concise than the struct literal equivalent:

core.Duty{Slot: slot, Type: core.DutyAttester}
vs
core.NewAttesterDuty(slot)

func NewProposerDuty added in v0.3.0

func NewProposerDuty(slot int64) Duty

NewProposerDuty returns a new proposer duty. It is a convenience function that is slightly more readable and concise than the struct literal equivalent:

core.Duty{Slot: slot, Type: core.DutyProposer}
vs
core.NewProposerDuty(slot)

func NewRandaoDuty added in v0.3.0

func NewRandaoDuty(slot int64) Duty

NewRandaoDuty returns a new randao duty. It is a convenience function that is slightly more readable and concise than the struct literal equivalent:

core.Duty{Slot: slot, Type: core.DutyRandao}
vs
core.NewRandaoDuty(slot)

func (Duty) String

func (d Duty) String() string

type DutyDB

type DutyDB interface {
	// Store stores the unsigned duty data set.
	Store(context.Context, Duty, UnsignedDataSet) error

	// AwaitBeaconBlock blocks and returns the proposed beacon block
	// for the slot when available.
	AwaitBeaconBlock(ctx context.Context, slot int64) (*spec.VersionedBeaconBlock, error)

	// AwaitAttestation blocks and returns the attestation data
	// for the slot and committee index when available.
	AwaitAttestation(ctx context.Context, slot, commIdx int64) (*eth2p0.AttestationData, error)

	// PubKeyByAttestation returns the validator PubKey for the provided attestation data
	// slot, committee index and validator committee index. This allows mapping of attestation
	// data response to validator.
	PubKeyByAttestation(ctx context.Context, slot, commIdx, valCommIdx int64) (PubKey, error)
}

DutyDB persists unsigned duty data sets and makes it available for querying. It also acts as slashing database.

type DutyType

type DutyType int

DutyType enumerates the different types of duties.

const (
	DutyUnknown  DutyType = 0
	DutyProposer DutyType = 1
	DutyAttester DutyType = 2
	DutyRandao   DutyType = 3
)

func AllDutyTypes

func AllDutyTypes() []DutyType

AllDutyTypes returns a list of all valid duty types.

func (DutyType) String

func (d DutyType) String() string

func (DutyType) Valid

func (d DutyType) Valid() bool

type FetchArg

type FetchArg []byte

FetchArg contains the arguments required to fetch the duty data, it is the result of resolving duties at the start of an epoch.

func EncodeAttesterFetchArg

func EncodeAttesterFetchArg(attDuty *eth2v1.AttesterDuty) (FetchArg, error)

EncodeAttesterFetchArg return the attester duty as an encoded FetchArg.

func EncodeProposerFetchArg

func EncodeProposerFetchArg(proDuty *eth2v1.ProposerDuty) (FetchArg, error)

EncodeProposerFetchArg return the proposer duty as an encoded FetchArg.

type FetchArgSet

type FetchArgSet map[PubKey]FetchArg

FetchArgSet is a set of fetch args, one per validator.

type Fetcher

type Fetcher interface {
	// Fetch triggers fetching of a proposed duty data set.
	Fetch(context.Context, Duty, FetchArgSet) error

	// Subscribe registers a callback for proposed unsigned duty data sets.
	Subscribe(func(context.Context, Duty, UnsignedDataSet) error)

	// RegisterAggSigDB registers a function to get resolved aggregated
	// signed data from the AggSigDB (e.g., randao reveals).
	RegisterAggSigDB(func(context.Context, Duty, PubKey) (AggSignedData, error))
}

Fetcher fetches proposed unsigned duty data.

type ParSigDB

type ParSigDB interface {
	// StoreInternal stores an internally received partially signed duty data set.
	StoreInternal(context.Context, Duty, ParSignedDataSet) error

	// StoreExternal stores an externally received partially signed duty data set.
	StoreExternal(context.Context, Duty, ParSignedDataSet) error

	// SubscribeInternal registers a callback when an internal
	// partially signed duty set is stored.
	SubscribeInternal(func(context.Context, Duty, ParSignedDataSet) error)

	// SubscribeThreshold registers a callback when *threshold*
	// partially signed duty is reached for a DV.
	SubscribeThreshold(func(context.Context, Duty, PubKey, []ParSignedData) error)
}

ParSigDB persists partial signatures and sends them to the partial signature exchange and aggregation.

type ParSigEx

type ParSigEx interface {
	// Broadcast broadcasts the partially signed duty data set to all peers.
	Broadcast(context.Context, Duty, ParSignedDataSet) error

	// Subscribe registers a callback when a partially signed duty set
	// is received from a peer.
	Subscribe(func(context.Context, Duty, ParSignedDataSet) error)
}

ParSigEx exchanges partially signed duty data sets.

type ParSignedData

type ParSignedData struct {
	// Data is the partially signed duty data received from VC.
	Data []byte
	// Signature of tbls share extracted from data.
	Signature Signature
	// ShareIdx of the tbls share.
	ShareIdx int
}

ParSignedData is a partially signed duty data. Partial refers to it being signed by a single share of the BLS threshold signing scheme.

func EncodeAttestationParSignedData

func EncodeAttestationParSignedData(att *eth2p0.Attestation, shareIdx int) (ParSignedData, error)

EncodeAttestationParSignedData returns the attestation as an encoded ParSignedData.

func EncodeBlockParSignedData added in v0.3.0

func EncodeBlockParSignedData(block *spec.VersionedSignedBeaconBlock, shareIdx int) (ParSignedData, error)

EncodeBlockParSignedData returns the partially signed block data as an encoded ParSignedData.

func EncodeRandaoParSignedData

func EncodeRandaoParSignedData(randao eth2p0.BLSSignature, shareIdx int) ParSignedData

EncodeRandaoParSignedData returns the RANDAO reveal as an encoded ParSignedData.

func ParSignedDataFromProto added in v0.3.0

func ParSignedDataFromProto(data *pbv1.ParSignedData) ParSignedData

ParSignedDataFromProto returns the data from a protobuf.

type ParSignedDataSet

type ParSignedDataSet map[PubKey]ParSignedData

ParSignedDataSet is a set of partially signed duty data objects, one per validator.

func ParSignedDataSetFromProto added in v0.3.0

func ParSignedDataSetFromProto(set *pbv1.ParSignedDataSet) ParSignedDataSet

ParSignedDataSetFromProto returns the set from a protobuf.

type PubKey

type PubKey string

PubKey is the DV root public key, the identifier of a validator in the core workflow. It is a hex formatted string, e.g. "0xb82bc680e...".

func PubKeyFromBytes

func PubKeyFromBytes(bytes []byte) (PubKey, error)

PubKeyFromBytes returns a new public key from raw bytes.

func (PubKey) Bytes

func (k PubKey) Bytes() ([]byte, error)

Bytes returns the public key as raw bytes.

func (PubKey) String

func (k PubKey) String() string

String returns a concise logging friendly version of the public key, e.g. "b82_97f".

func (PubKey) ToETH2

func (k PubKey) ToETH2() (eth2p0.BLSPubKey, error)

ToETH2 returns the public key as an eth2 phase0 public key.

type Scheduler

type Scheduler interface {
	// Subscribe registers a callback for fetching a duty.
	Subscribe(func(context.Context, Duty, FetchArgSet) error)

	// GetDuty returns the argSet for a duty if resolved already.
	GetDuty(context.Context, Duty) (FetchArgSet, error)
}

Scheduler triggers the start of a duty workflow.

type SigAgg

type SigAgg interface {
	// Aggregate aggregates the partially signed duty data for the DV.
	Aggregate(context.Context, Duty, PubKey, []ParSignedData) error

	// Subscribe registers a callback for aggregated signed duty data.
	Subscribe(func(context.Context, Duty, PubKey, AggSignedData) error)
}

SigAgg aggregates threshold partial signatures.

type Signature

type Signature []byte

Signature is a BLS12-381 Signature.

func SigFromETH2

func SigFromETH2(sig eth2p0.BLSSignature) Signature

SigFromETH2 returns a new signature from eth2 phase0 BLSSignature.

func (Signature) ToETH2

func (s Signature) ToETH2() eth2p0.BLSSignature

ToETH2 returns the signature as an eth2 phase0 BLSSignature.

type UnsignedData

type UnsignedData []byte

UnsignedData represents an unsigned duty data object.

func EncodeAttesterUnsignedData

func EncodeAttesterUnsignedData(attData *AttestationData) (UnsignedData, error)

EncodeAttesterUnsignedData returns the attestation data as an encoded UnsignedData.

func EncodeProposerUnsignedData

func EncodeProposerUnsignedData(proData *spec.VersionedBeaconBlock) (UnsignedData, error)

EncodeProposerUnsignedData returns the proposer data as an encoded UnsignedData.

type UnsignedDataSet

type UnsignedDataSet map[PubKey]UnsignedData

UnsignedDataSet is a set of unsigned duty data objects, one per validator.

func UnsignedDataSetFromProto added in v0.4.0

func UnsignedDataSetFromProto(set *pbv1.UnsignedDataSet) UnsignedDataSet

UnsignedDataSetFromProto returns the set from a protobuf.

type ValidatorAPI

type ValidatorAPI interface {
	// RegisterAwaitBeaconBlock registers a function to query a unsigned beacon block by slot.
	RegisterAwaitBeaconBlock(func(ctx context.Context, slot int64) (*spec.VersionedBeaconBlock, error))

	// RegisterAwaitAttestation registers a function to query attestation data.
	RegisterAwaitAttestation(func(ctx context.Context, slot, commIdx int64) (*eth2p0.AttestationData, error))

	// RegisterPubKeyByAttestation registers a function to query validator by attestation.
	RegisterPubKeyByAttestation(func(ctx context.Context, slot, commIdx, valCommIdx int64) (PubKey, error))

	// RegisterGetDutyFunc registers a function to query duty data.
	RegisterGetDutyFunc(func(context.Context, Duty) (FetchArgSet, error))

	// RegisterParSigDB registers a function to store partially signed data sets.
	RegisterParSigDB(func(context.Context, Duty, ParSignedDataSet) error)
}

ValidatorAPI provides a beacon node API to validator clients. It serves duty data from the DutyDB and stores partial signed data in the ParSigDB.

type WireOption

type WireOption func(*wireFuncs)

WireOption defines a functional option to configure wiring.

func WithAsyncRetry added in v0.3.0

func WithAsyncRetry(retryer *retry.Retryer) WireOption

WithAsyncRetry wraps component input functions with the async Retryer adding robustness to network issues.

func WithTracing

func WithTracing() WireOption

WithTracing wraps component input functions with tracing spans.

Directories

Path Synopsis
Package bcast provides the core workflow's broadcaster component that broadcasts/submits aggregated singed duty data to the beacon-node.
Package bcast provides the core workflow's broadcaster component that broadcasts/submits aggregated singed duty data to the beacon-node.
corepb
v1
Package qbft is an implementation of the https://arxiv.org/pdf/2002.03613.pdf paper referenced by the QBFT spec https://github.com/ConsenSys/qbft-formal-spec-and-verification.
Package qbft is an implementation of the https://arxiv.org/pdf/2002.03613.pdf paper referenced by the QBFT spec https://github.com/ConsenSys/qbft-formal-spec-and-verification.
Package sigagg provides the sigagg core workflow component that aggregates *threshold* partial signed duty data objects into an aggregated signed duty data object ready to be broadcasted to the beacon chain.
Package sigagg provides the sigagg core workflow component that aggregates *threshold* partial signed duty data objects into an aggregated signed duty data object ready to be broadcasted to the beacon chain.
Package validatorapi defines validator facing API that serves the subset of endpoints related to distributed validation and reverse-proxies the rest to the upstream beacon client.
Package validatorapi defines validator facing API that serves the subset of endpoints related to distributed validation and reverse-proxies the rest to the upstream beacon client.

Jump to

Keyboard shortcuts

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