Documentation ¶
Overview ¶
Package beaconmock provides a mock beacon node server and client primarily for testing.
beaconmock.Mock validatorapi.Router ┌────┬──────────┐ ┌───────────┐ │ │HTTPServer◄──────┤ proxy │ │ └────▲─────┐ http │ │ VC │ │ │ │ ◄────────── (validatormock) │ │http │ │ served │ http (lighthouse) │ ┌──┴─────┤ │ endpoints │ (teku) │ │HTTPMock│ └────┬──────┘ └──────┴────────┘ │go ▲ │ │ ┌─────────────────▼──────┐ │go│ │ └──┤core workflow components│ │ │ └────────────────────────┘ HTTPServer: Serves stubs and static.json endpoints. Used by Mock and proxy. HTTPMock: *eth2http.Service client connected to HTTPServer. Mock: Wraps HTTPMock, adds customisable logic. Used by simnet core workflow components.
Index ¶
- Variables
- type HTTPMock
- type Mock
- func (m Mock) Address() string
- func (m Mock) AggregateAttestation(ctx context.Context, slot eth2p0.Slot, attestationDataRoot eth2p0.Root) (*eth2p0.Attestation, error)
- func (m Mock) AggregateBeaconCommitteeSelections(ctx context.Context, selections []*eth2exp.BeaconCommitteeSelection) ([]*eth2exp.BeaconCommitteeSelection, error)
- func (m Mock) AggregateSyncCommitteeSelections(ctx context.Context, selections []*eth2exp.SyncCommitteeSelection) ([]*eth2exp.SyncCommitteeSelection, error)
- func (m Mock) AttestationData(ctx context.Context, slot eth2p0.Slot, committeeIndex eth2p0.CommitteeIndex) (*eth2p0.AttestationData, error)
- func (m Mock) AttesterDuties(ctx context.Context, epoch eth2p0.Epoch, ...) ([]*eth2v1.AttesterDuty, error)
- func (m Mock) BeaconBlockProposal(ctx context.Context, slot eth2p0.Slot, randaoReveal eth2p0.BLSSignature, ...) (*spec.VersionedBeaconBlock, error)
- func (m Mock) BeaconBlockRoot(ctx context.Context, blockID string) (*eth2p0.Root, error)
- func (m Mock) BeaconCommittees(ctx context.Context, stateID string) ([]*eth2v1.BeaconCommittee, error)
- func (m Mock) BlindedBeaconBlockProposal(ctx context.Context, slot eth2p0.Slot, randaoReveal eth2p0.BLSSignature, ...) (*eth2api.VersionedBlindedBeaconBlock, error)
- func (m Mock) BlockAttestations(ctx context.Context, stateID string) ([]*eth2p0.Attestation, error)
- func (m Mock) Close() error
- func (m Mock) Events(ctx context.Context, topics []string, handler eth2client.EventHandlerFunc) error
- func (m Mock) GenesisTime(ctx context.Context) (time.Time, error)
- func (Mock) Name() string
- func (m Mock) NodeSyncing(ctx context.Context) (*eth2v1.SyncState, error)
- func (m Mock) ProposerDuties(ctx context.Context, epoch eth2p0.Epoch, ...) ([]*eth2v1.ProposerDuty, error)
- func (m Mock) SignedBeaconBlock(ctx context.Context, blockID string) (*spec.VersionedSignedBeaconBlock, error)
- func (m Mock) SlotsPerEpoch(ctx context.Context) (uint64, error)
- func (m Mock) SubmitAggregateAttestations(ctx context.Context, aggregateAndProofs []*eth2p0.SignedAggregateAndProof) error
- func (m Mock) SubmitAttestations(ctx context.Context, attestations []*eth2p0.Attestation) error
- func (m Mock) SubmitBeaconBlock(ctx context.Context, block *spec.VersionedSignedBeaconBlock) error
- func (m Mock) SubmitBeaconCommitteeSubscriptions(ctx context.Context, subscriptions []*eth2v1.BeaconCommitteeSubscription) error
- func (m Mock) SubmitBlindedBeaconBlock(ctx context.Context, block *eth2api.VersionedSignedBlindedBeaconBlock) error
- func (m Mock) SubmitProposalPreparations(ctx context.Context, preparations []*eth2v1.ProposalPreparation) error
- func (m Mock) SubmitSyncCommitteeContributions(ctx context.Context, ...) error
- func (m Mock) SubmitSyncCommitteeMessages(ctx context.Context, messages []*altair.SyncCommitteeMessage) error
- func (m Mock) SubmitSyncCommitteeSubscriptions(ctx context.Context, subscriptions []*eth2v1.SyncCommitteeSubscription) error
- func (m Mock) SubmitValidatorRegistrations(ctx context.Context, ...) error
- func (m Mock) SubmitVoluntaryExit(ctx context.Context, exit *eth2p0.SignedVoluntaryExit) error
- func (m Mock) SyncCommitteeContribution(ctx context.Context, slot eth2p0.Slot, subcommitteeIndex uint64, ...) (*altair.SyncCommitteeContribution, error)
- func (m Mock) SyncCommitteeDuties(ctx context.Context, epoch eth2p0.Epoch, ...) ([]*eth2v1.SyncCommitteeDuty, error)
- func (Mock) TekuProposerConfig(context.Context) (validatorapi.TekuProposerConfigResponse, error)
- func (m Mock) Validators(ctx context.Context, stateID string, validatorIndices []eth2p0.ValidatorIndex) (map[eth2p0.ValidatorIndex]*eth2v1.Validator, error)
- func (m Mock) ValidatorsByPubKey(ctx context.Context, stateID string, validatorPubKeys []eth2p0.BLSPubKey) (map[eth2p0.ValidatorIndex]*eth2v1.Validator, error)
- type Option
- func WithClock(clock clockwork.Clock) Option
- func WithDeterministicAttesterDuties(factor int) Option
- func WithDeterministicProposerDuties(factor int) Option
- func WithDeterministicSyncCommDuties(n, k int) Option
- func WithEndpoint(endpoint string, value string) Option
- func WithGenesisTime(t0 time.Time) Option
- func WithGenesisValidatorsRoot(root [32]byte) Option
- func WithNoAttesterDuties() Option
- func WithNoProposerDuties() Option
- func WithNoSyncCommitteeDuties() Option
- func WithSlotDuration(duration time.Duration) Option
- func WithSlotsPerEpoch(slotsPerEpoch int) Option
- func WithSyncCommitteeSize(size int) Option
- func WithSyncCommitteeSubnetCount(count int) Option
- func WithValidatorSet(set ValidatorSet) Option
- type ValidatorSet
- func (s ValidatorSet) ByPublicKey(pubkey eth2p0.BLSPubKey) (*eth2v1.Validator, bool)
- func (s ValidatorSet) Clone() (ValidatorSet, error)
- func (s ValidatorSet) CorePubKeys() ([]core.PubKey, error)
- func (s ValidatorSet) PublicKeys() []eth2p0.BLSPubKey
- func (s ValidatorSet) Validators() []*eth2v1.Validator
Constants ¶
This section is empty.
Variables ¶
var ValidatorSetA = ValidatorSet{ 1: { Index: 1, Balance: 1, Status: eth2v1.ValidatorStateActiveOngoing, Validator: ð2p0.Validator{ PublicKey: mustPKFromHex("0x914cff835a769156ba43ad50b931083c2dadd94e8359ce394bc7a3e06424d0214922ddf15f81640530b9c25c0bc0d490"), EffectiveBalance: 1, ActivationEligibilityEpoch: 1, ActivationEpoch: 2, WithdrawalCredentials: []byte("12345678901234567890123456789012"), }, }, 2: { Index: 2, Balance: 2, Status: eth2v1.ValidatorStateActiveOngoing, Validator: ð2p0.Validator{ PublicKey: mustPKFromHex("0x8dae41352b69f2b3a1c0b05330c1bf65f03730c520273028864b11fcb94d8ce8f26d64f979a0ee3025467f45fd2241ea"), EffectiveBalance: 2, ActivationEligibilityEpoch: 2, ActivationEpoch: 3, WithdrawalCredentials: []byte("12345678901234567890123456789012"), }, }, 3: { Index: 3, Balance: 3, Status: eth2v1.ValidatorStateActiveOngoing, Validator: ð2p0.Validator{ PublicKey: mustPKFromHex("0x8ee91545183c8c2db86633626f5074fd8ef93c4c9b7a2879ad1768f600c5b5906c3af20d47de42c3b032956fa8db1a76"), EffectiveBalance: 3, ActivationEligibilityEpoch: 3, ActivationEpoch: 4, WithdrawalCredentials: []byte("12345678901234567890123456789012"), }, }, }
ValidatorSetA defines a set of 3 validators.
Functions ¶
This section is empty.
Types ¶
type HTTPMock ¶
type HTTPMock interface { eth2client.BeaconBlockRootProvider eth2client.DepositContractProvider eth2client.DomainProvider eth2client.EventsProvider eth2client.ForkProvider eth2client.ForkScheduleProvider eth2client.GenesisProvider eth2client.GenesisTimeProvider eth2client.NodeSyncingProvider eth2client.NodeVersionProvider eth2client.SlotDurationProvider eth2client.SlotsPerEpochProvider eth2client.SpecProvider eth2client.SyncCommitteeSubscriptionsSubmitter }
HTTPMock defines the endpoints served by the beacon API mock http server. It serves all proxied endpoints not handled by charon's validatorapi. Endpoints include static endpoints defined in static.json and a few stubbed paths.
type Mock ¶
type Mock struct { HTTPMock AttestationDataFunc func(context.Context, eth2p0.Slot, eth2p0.CommitteeIndex) (*eth2p0.AttestationData, error) AttesterDutiesFunc func(context.Context, eth2p0.Epoch, []eth2p0.ValidatorIndex) ([]*eth2v1.AttesterDuty, error) BlockAttestationsFunc func(ctx context.Context, stateID string) ([]*eth2p0.Attestation, error) BlindedBeaconBlockProposalFunc func(ctx context.Context, slot eth2p0.Slot, randaoReveal eth2p0.BLSSignature, graffiti []byte) (*eth2api.VersionedBlindedBeaconBlock, error) BeaconCommitteesFunc func(ctx context.Context, stateID string) ([]*eth2v1.BeaconCommittee, error) BeaconBlockProposalFunc func(ctx context.Context, slot eth2p0.Slot, randaoReveal eth2p0.BLSSignature, graffiti []byte) (*spec.VersionedBeaconBlock, error) BeaconBlockRootFunc func(ctx context.Context, blockID string) (*eth2p0.Root, error) SignedBeaconBlockFunc func(ctx context.Context, blockID string) (*spec.VersionedSignedBeaconBlock, error) ProposerDutiesFunc func(context.Context, eth2p0.Epoch, []eth2p0.ValidatorIndex) ([]*eth2v1.ProposerDuty, error) SubmitAttestationsFunc func(context.Context, []*eth2p0.Attestation) error SubmitBeaconBlockFunc func(context.Context, *spec.VersionedSignedBeaconBlock) error SubmitBlindedBeaconBlockFunc func(context.Context, *eth2api.VersionedSignedBlindedBeaconBlock) error SubmitVoluntaryExitFunc func(context.Context, *eth2p0.SignedVoluntaryExit) error ValidatorsByPubKeyFunc func(context.Context, string, []eth2p0.BLSPubKey) (map[eth2p0.ValidatorIndex]*eth2v1.Validator, error) ValidatorsFunc func(context.Context, string, []eth2p0.ValidatorIndex) (map[eth2p0.ValidatorIndex]*eth2v1.Validator, error) GenesisTimeFunc func(context.Context) (time.Time, error) NodeSyncingFunc func(context.Context) (*eth2v1.SyncState, error) EventsFunc func(context.Context, []string, eth2client.EventHandlerFunc) error SubmitValidatorRegistrationsFunc func(context.Context, []*eth2api.VersionedSignedValidatorRegistration) error SlotsPerEpochFunc func(context.Context) (uint64, error) AggregateBeaconCommitteeSelectionsFunc func(context.Context, []*eth2exp.BeaconCommitteeSelection) ([]*eth2exp.BeaconCommitteeSelection, error) AggregateSyncCommitteeSelectionsFunc func(context.Context, []*eth2exp.SyncCommitteeSelection) ([]*eth2exp.SyncCommitteeSelection, error) SubmitBeaconCommitteeSubscriptionsFunc func(ctx context.Context, subscriptions []*eth2v1.BeaconCommitteeSubscription) error AggregateAttestationFunc func(ctx context.Context, slot eth2p0.Slot, attestationDataRoot eth2p0.Root) (*eth2p0.Attestation, error) SubmitAggregateAttestationsFunc func(ctx context.Context, aggregateAndProofs []*eth2p0.SignedAggregateAndProof) error SyncCommitteeDutiesFunc func(ctx context.Context, epoch eth2p0.Epoch, validatorIndices []eth2p0.ValidatorIndex) ([]*eth2v1.SyncCommitteeDuty, error) SubmitSyncCommitteeMessagesFunc func(ctx context.Context, messages []*altair.SyncCommitteeMessage) error SubmitSyncCommitteeContributionsFunc func(ctx context.Context, contributionAndProofs []*altair.SignedContributionAndProof) error SyncCommitteeContributionFunc func(ctx context.Context, slot eth2p0.Slot, subcommitteeIndex uint64, beaconBlockRoot eth2p0.Root) (*altair.SyncCommitteeContribution, error) SubmitSyncCommitteeSubscriptionsFunc func(ctx context.Context, subscriptions []*eth2v1.SyncCommitteeSubscription) error SubmitProposalPreparationsFunc func(ctx context.Context, preparations []*eth2v1.ProposalPreparation) error // contains filtered or unexported fields }
Mock provides a mock beacon client and implements eth2wrap.Client. Create a new instance with default behaviour via New and then override any function.
func (Mock) AggregateAttestation ¶ added in v0.10.1
func (Mock) AggregateBeaconCommitteeSelections ¶ added in v0.11.0
func (m Mock) AggregateBeaconCommitteeSelections(ctx context.Context, selections []*eth2exp.BeaconCommitteeSelection) ([]*eth2exp.BeaconCommitteeSelection, error)
func (Mock) AggregateSyncCommitteeSelections ¶ added in v0.12.0
func (m Mock) AggregateSyncCommitteeSelections(ctx context.Context, selections []*eth2exp.SyncCommitteeSelection) ([]*eth2exp.SyncCommitteeSelection, error)
func (Mock) AttestationData ¶
func (m Mock) AttestationData(ctx context.Context, slot eth2p0.Slot, committeeIndex eth2p0.CommitteeIndex) (*eth2p0.AttestationData, error)
func (Mock) AttesterDuties ¶
func (m Mock) AttesterDuties(ctx context.Context, epoch eth2p0.Epoch, validatorIndices []eth2p0.ValidatorIndex) ([]*eth2v1.AttesterDuty, error)
func (Mock) BeaconBlockProposal ¶
func (Mock) BeaconBlockRoot ¶ added in v0.11.0
func (Mock) BeaconCommittees ¶ added in v0.10.1
func (Mock) BlindedBeaconBlockProposal ¶ added in v0.9.0
func (Mock) BlockAttestations ¶ added in v0.12.0
func (Mock) Events ¶ added in v0.8.0
func (m Mock) Events(ctx context.Context, topics []string, handler eth2client.EventHandlerFunc) error
func (Mock) ProposerDuties ¶
func (m Mock) ProposerDuties(ctx context.Context, epoch eth2p0.Epoch, validatorIndices []eth2p0.ValidatorIndex) ([]*eth2v1.ProposerDuty, error)
func (Mock) SignedBeaconBlock ¶ added in v0.13.0
func (Mock) SlotsPerEpoch ¶ added in v0.10.0
func (Mock) SubmitAggregateAttestations ¶ added in v0.10.1
func (Mock) SubmitAttestations ¶
func (Mock) SubmitBeaconBlock ¶ added in v0.3.0
func (Mock) SubmitBeaconCommitteeSubscriptions ¶ added in v0.10.1
func (Mock) SubmitBlindedBeaconBlock ¶ added in v0.9.0
func (Mock) SubmitProposalPreparations ¶ added in v0.11.0
func (Mock) SubmitSyncCommitteeContributions ¶ added in v0.10.1
func (Mock) SubmitSyncCommitteeMessages ¶ added in v0.10.1
func (Mock) SubmitSyncCommitteeSubscriptions ¶ added in v0.10.1
func (Mock) SubmitValidatorRegistrations ¶ added in v0.10.0
func (Mock) SubmitVoluntaryExit ¶ added in v0.6.0
func (Mock) SyncCommitteeContribution ¶ added in v0.10.1
func (Mock) SyncCommitteeDuties ¶ added in v0.10.1
func (m Mock) SyncCommitteeDuties(ctx context.Context, epoch eth2p0.Epoch, validatorIndices []eth2p0.ValidatorIndex) ([]*eth2v1.SyncCommitteeDuty, error)
func (Mock) TekuProposerConfig ¶ added in v0.12.0
func (Mock) TekuProposerConfig(context.Context) (validatorapi.TekuProposerConfigResponse, error)
func (Mock) Validators ¶
type Option ¶
type Option func(*Mock)
Option defines a functional option to configure the mock beacon client.
func WithDeterministicAttesterDuties ¶ added in v0.4.0
WithDeterministicAttesterDuties configures the mock to provide deterministic duties based on provided arguments and config. Note it depends on ValidatorsFunc being populated, e.g. via WithValidatorSet.
func WithDeterministicProposerDuties ¶ added in v0.4.0
WithDeterministicProposerDuties configures the mock to provide deterministic duties based on provided arguments and config. Note it depends on ValidatorsFunc being populated, e.g. via WithValidatorSet.
func WithDeterministicSyncCommDuties ¶ added in v0.12.0
WithDeterministicSyncCommDuties configures the mock to override SyncCommitteeDutiesFunc to return sync committee duties for all validators for first N epochs in every K epochs. N is also used as EPOCHS_PER_SYNC_COMMITTEE_PERIOD.
func WithEndpoint ¶
WithEndpoint configures the http mock with the endpoint override.
func WithGenesisTime ¶
WithGenesisTime configures the http mock with the provided genesis time.
func WithGenesisValidatorsRoot ¶
WithGenesisValidatorsRoot configures the http mock with the provided genesis validators root.
func WithNoAttesterDuties ¶ added in v0.4.0
func WithNoAttesterDuties() Option
WithNoAttesterDuties configures the mock to override AttesterDutiesFunc to return nothing.
func WithNoProposerDuties ¶
func WithNoProposerDuties() Option
WithNoProposerDuties configures the mock to override ProposerDutiesFunc to return nothing.
func WithNoSyncCommitteeDuties ¶ added in v0.11.0
func WithNoSyncCommitteeDuties() Option
WithNoSyncCommitteeDuties configures the mock to override SyncCommitteeDutiesFunc to return nothing.
func WithSlotDuration ¶
WithSlotDuration configures the http mock with the provided slots duration.
func WithSlotsPerEpoch ¶
WithSlotsPerEpoch configures the http mock with the provided slots per epoch.
func WithSyncCommitteeSize ¶ added in v0.13.0
WithSyncCommitteeSize configures the http mock with the provided sync committee size.
func WithSyncCommitteeSubnetCount ¶ added in v0.13.0
WithSyncCommitteeSubnetCount configures the http mock with the provided sync committee subnet count.
func WithValidatorSet ¶
func WithValidatorSet(set ValidatorSet) Option
WithValidatorSet configures the mock with the provided validator set.
type ValidatorSet ¶
type ValidatorSet map[eth2p0.ValidatorIndex]*eth2v1.Validator
func (ValidatorSet) ByPublicKey ¶
ByPublicKey is a convenience function to return a validator by its public key.
func (ValidatorSet) Clone ¶ added in v0.12.0
func (s ValidatorSet) Clone() (ValidatorSet, error)
Clone returns a copy of this validator set.
func (ValidatorSet) CorePubKeys ¶
func (s ValidatorSet) CorePubKeys() ([]core.PubKey, error)
CorePubKeys is a convenience function to extract the core workflow public keys from the validators.
func (ValidatorSet) PublicKeys ¶
func (s ValidatorSet) PublicKeys() []eth2p0.BLSPubKey
PublicKeys is a convenience function to extract the eth2 client bls public keys from the validators.
func (ValidatorSet) Validators ¶ added in v0.12.0
func (s ValidatorSet) Validators() []*eth2v1.Validator
Validators is a convenience function to return the validators as a slice.