relay

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2022 License: AGPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// proposer endpoints
	PathStatus            = "/eth/v1/builder/status"
	PathRegisterValidator = "/eth/v1/builder/validators"
	PathGetHeader         = "/eth/v1/builder/header/{slot:[0-9]+}/{parent_hash:0x[a-fA-F0-9]+}/{pubkey:0x[a-fA-F0-9]+}"
	PathGetPayload        = "/eth/v1/builder/blinded_blocks"

	// builder endpoints
	PathGetValidators = "/relay/v1/builder/validators"
	PathSubmitBlock   = "/relay/v1/builder/blocks"

	// data api
	PathBuilderBlocksReceived     = "/relay/v1/data/bidtraces/builder_blocks_received"
	PathProposerPayloadsDelivered = "/relay/v1/data/bidtraces/proposer_payload_delivered"
	PathSpecificRegistration      = "/relay/v1/data/validator_registration"

	// tracing
	PathPprofIndex   = "/debug/pprof/"
	PathPprofCmdline = "/debug/pprof/cmdline"
	PathPprofSymbol  = "/debug/pprof/symbol"
	PathPprofTrace   = "/debug/pprof/trace"
	PathPprofProfile = "/debug/pprof/profile"
)

Router paths

View Source
const (
	GenesisForkVersionMainnet = "0x00000000"
	GenesisForkVersionKiln    = "0x70000069" // https://github.com/eth-clients/merge-testnets/blob/main/kiln/config.yaml#L10
	GenesisForkVersionRopsten = "0x80000069"
	GenesisForkVersionSepolia = "0x90000069"
	GenesisForkVersionGoerli  = "0x00001020" // https://github.com/eth-clients/merge-testnets/blob/main/goerli-shadow-fork-5/config.yaml#L11

	GenesisValidatorsRootMainnet = "0x4b363db94e286120d76eb905340fdd4e54bfe9f06bf33ff6cf5ad27f511bfe95"
	GenesisValidatorsRootKiln    = "0x99b09fcd43e5905236c370f184056bec6e6638cfc31a323b304fc4aa789cb4ad"
	GenesisValidatorsRootRopsten = "0x44f1e56283ca88b35c789f7f449e52339bc1fefe3a45913a43a6d16edcd33cf1"
	GenesisValidatorsRootSepolia = "0xd8ea171f3c94aea21ebc42a1ed61052acf3f9209c00e4efbaaddac09ed9b8078"
	GenesisValidatorsRootGoerli  = "0x043db0d9a83813551ee2f33450d23797757d430911a9320530ad8a0eabc43efb"

	BellatrixForkVersionMainnet = "0x02000000"
	BellatrixForkVersionKiln    = "0x70000071"
	BellatrixForkVersionRopsten = "0x80000071"
	BellatrixForkVersionSepolia = "0x90000071"
	BellatrixForkVersionGoerli  = "0x02001020"
)
View Source
const (
	Version = "0.2.0"
)

Variables

View Source
var (
	SlotsPerEpoch    Slot = 32
	DurationPerSlot       = time.Second * 12
	DurationPerEpoch      = DurationPerSlot * time.Duration(SlotsPerEpoch)

	ErrHTTPErrorResponse = errors.New("got an HTTP error response")
	ErrNodesUnavailable  = errors.New("beacon nodes are unavailable")
)
View Source
var (
	ErrNoPayloadFound        = errors.New("no payload found")
	ErrBeaconNodeSyncing     = errors.New("beacon node is syncing")
	ErrMissingRequest        = errors.New("req is nil")
	ErrMissingSecretKey      = errors.New("secret key is nil")
	ErrUnknownValue          = errors.New("value is unknown")
	UnregisteredValidatorMsg = "unregistered validator"
)
View Source
var (
	ErrParamNotFound = errors.New("not found")
)

Functions

func ComputeDomain

func ComputeDomain(domainType types.DomainType, forkVersionHex string, genesisValidatorsRootHex string) (domain types.Domain, err error)

ComputeDomain computes the signing domain

func DeliveredHashKey added in v0.1.3

func DeliveredHashKey(bh types.Hash) ds.Key

func DeliveredKey

func DeliveredKey(slot Slot) ds.Key

func DeliveredNumKey added in v0.1.3

func DeliveredNumKey(bn uint64) ds.Key

func DeliveredPubkeyKey added in v0.1.3

func DeliveredPubkeyKey(pk types.PublicKey) ds.Key

func HeaderHashKey

func HeaderHashKey(bh types.Hash) ds.Key

func HeaderKey

func HeaderKey(slot Slot) ds.Key

func HeaderNumKey

func HeaderNumKey(bn uint64) ds.Key

func Max added in v0.1.5

func Max[T constraints.Ordered](args ...T) T

func NewBeaconClient

func NewBeaconClient(endpoint string, config Config) (*beaconClient, error)

func PayloadKeyKey added in v0.1.2

func PayloadKeyKey(key PayloadKey) ds.Key

func RegistrationKey

func RegistrationKey(pk PubKey) ds.Key

func SubmitBlockRequestToSignedBuilderBid

func SubmitBlockRequestToSignedBuilderBid(req *types.BuilderSubmitBlockRequest, sk *bls.SecretKey, pubkey *types.PublicKey, domain types.Domain) (*types.SignedBuilderBid, error)

SubmitBlockRequestToSignedBuilderBid converts a builders block submission to a bid compatible with mev-boost

func ValidatorKey

func ValidatorKey(pk PubKey) ds.Key

Types

type API

type API struct {
	Service       RelayService
	Log           log.Logger
	EnableProfile bool
	// contains filtered or unexported fields
}

func (*API) ServeHTTP

func (a *API) ServeHTTP(w http.ResponseWriter, r *http.Request)

type AllValidatorsResponse

type AllValidatorsResponse struct {
	Data []ValidatorResponseEntry
}

AllValidatorsResponse is the response for querying active validators

type BeaconClient

type BeaconClient interface {
	SubscribeToHeadEvents(ctx context.Context, slotC chan HeadEvent)
	GetProposerDuties(Epoch) (*RegisteredProposersResponse, error)
	SyncStatus() (*SyncStatusPayloadData, error)
	KnownValidators(Slot) (AllValidatorsResponse, error)
	Endpoint() string
}

func NewMultiBeaconClient added in v0.1.2

func NewMultiBeaconClient(l log.Logger, clients []BeaconClient) BeaconClient

type BeaconState added in v0.1.2

type BeaconState interface {
	KnownValidatorByIndex(uint64) (types.PubkeyHex, error)
	IsKnownValidator(types.PubkeyHex) (bool, error)
	HeadSlot() Slot
	ValidatorsMap() BuilderGetValidatorsResponseEntrySlice
}

type BidTraceWithTimestamp

type BidTraceWithTimestamp struct {
	types.BidTrace
	Timestamp uint64 `json:"timestamp,string"`
}

type BlockBidAndTrace

type BlockBidAndTrace struct {
	Trace   *types.SignedBidTrace
	Bid     *types.GetHeaderResponse
	Payload *types.GetPayloadResponse
}

func SubmitBlockRequestToBlockBidAndTrace

func SubmitBlockRequestToBlockBidAndTrace(signedBuilderBid *types.SignedBuilderBid, submitBlockRequest *types.BuilderSubmitBlockRequest) BlockBidAndTrace

type BuilderGetValidatorsResponseEntrySlice

type BuilderGetValidatorsResponseEntrySlice []types.BuilderGetValidatorsResponseEntry

func (BuilderGetValidatorsResponseEntrySlice) Loggable

type Config

type Config struct {
	Log                 log.Logger
	BuilderURLs         []string
	Network             string
	RelayRequestTimeout time.Duration
	BuilderCheck        bool
	BeaconEndpoints     []string
	PubKey              types.PublicKey
	SecretKey           *bls.SecretKey
	Datadir             string
	TTL                 time.Duration
	CheckKnownValidator bool
	// contains filtered or unexported fields
}

Config provides all available options for the default BeaconClient and Relay

type DefaultDatastore

type DefaultDatastore struct {
	TTLStorage
	// contains filtered or unexported fields
}

func (*DefaultDatastore) GetDelivered added in v0.1.3

func (s *DefaultDatastore) GetDelivered(ctx context.Context, query Query) (BidTraceWithTimestamp, error)

func (*DefaultDatastore) GetDeliveredBatch added in v0.1.3

func (s *DefaultDatastore) GetDeliveredBatch(ctx context.Context, queries []Query) ([]BidTraceWithTimestamp, error)

func (*DefaultDatastore) GetHeaderBatch

func (s *DefaultDatastore) GetHeaderBatch(ctx context.Context, queries []Query) ([]HeaderAndTrace, error)

func (*DefaultDatastore) GetHeaders added in v0.1.5

func (s *DefaultDatastore) GetHeaders(ctx context.Context, query Query) ([]HeaderAndTrace, error)

func (*DefaultDatastore) GetPayload

func (s *DefaultDatastore) GetPayload(ctx context.Context, key PayloadKey) (*BlockBidAndTrace, error)

func (*DefaultDatastore) GetRegistration

func (*DefaultDatastore) PutDelivered

func (s *DefaultDatastore) PutDelivered(ctx context.Context, slot Slot, trace DeliveredTrace, ttl time.Duration) error

func (*DefaultDatastore) PutHeader

func (s *DefaultDatastore) PutHeader(ctx context.Context, slot Slot, header HeaderAndTrace, ttl time.Duration) error

func (*DefaultDatastore) PutPayload

func (s *DefaultDatastore) PutPayload(ctx context.Context, key PayloadKey, payload *BlockBidAndTrace, ttl time.Duration) error

func (*DefaultDatastore) PutRegistration

func (s *DefaultDatastore) PutRegistration(ctx context.Context, pk PubKey, registration types.SignedValidatorRegistration, ttl time.Duration) error

type DefaultRelay

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

func NewRelay

func NewRelay(config Config) (*DefaultRelay, error)

NewRelay relay service

func (*DefaultRelay) GetHeader

func (rs *DefaultRelay) GetHeader(ctx context.Context, request HeaderRequest, state State) (*types.GetHeaderResponse, error)

GetHeader is called by a block proposer communicating through mev-boost and returns a bid along with an execution payload header

func (*DefaultRelay) GetPayload

func (rs *DefaultRelay) GetPayload(ctx context.Context, payloadRequest *types.SignedBlindedBeaconBlock, state State) (*types.GetPayloadResponse, error)

GetPayload is called by a block proposer communicating through mev-boost and reveals execution payload of given signed beacon block if stored

func (*DefaultRelay) GetValidators

GetValidators returns a list of registered block proposers in current and next epoch

func (*DefaultRelay) Log

func (rs *DefaultRelay) Log() log.Logger

func (*DefaultRelay) RegisterValidator

func (rs *DefaultRelay) RegisterValidator(ctx context.Context, payload []types.SignedValidatorRegistration, state State) error

RegisterValidator is called is called by validators communicating through mev-boost who would like to receive a block from us when their slot is scheduled

func (*DefaultRelay) SubmitBlock

func (rs *DefaultRelay) SubmitBlock(ctx context.Context, submitBlockRequest *types.BuilderSubmitBlockRequest, state State) error

SubmitBlock Accepts block from trusted builder and stores

type DefaultService

type DefaultService struct {
	Log             log.Logger
	Config          Config
	Relay           Relay
	Storage         TTLStorage
	Datastore       Datastore
	NewBeaconClient func() (BeaconClient, error)
	// contains filtered or unexported fields
}

func (*DefaultService) GetBlockReceived

func (s *DefaultService) GetBlockReceived(ctx context.Context, query TraceQuery) ([]BidTraceWithTimestamp, error)

func (*DefaultService) GetHeader

func (s *DefaultService) GetHeader(ctx context.Context, request HeaderRequest) (*types.GetHeaderResponse, error)

func (*DefaultService) GetPayload

func (*DefaultService) GetPayloadDelivered added in v0.1.5

func (s *DefaultService) GetPayloadDelivered(ctx context.Context, query TraceQuery) ([]types.BidTrace, error)

func (*DefaultService) GetValidators

func (*DefaultService) Ready

func (s *DefaultService) Ready() <-chan struct{}

func (*DefaultService) RegisterValidator

func (s *DefaultService) RegisterValidator(ctx context.Context, payload []types.SignedValidatorRegistration) error

func (*DefaultService) Registration

func (*DefaultService) Run

func (s *DefaultService) Run(ctx context.Context) (err error)

Run creates a relay, datastore and starts the beacon client event loop

func (*DefaultService) SubmitBlock

func (s *DefaultService) SubmitBlock(ctx context.Context, submitBlockRequest *types.BuilderSubmitBlockRequest) error

type DeliveredTrace added in v0.1.3

type DeliveredTrace struct {
	Trace       BidTraceWithTimestamp
	BlockNumber uint64
}

type Epoch

type Epoch uint64

func (Epoch) Loggable

func (e Epoch) Loggable() map[string]any

type ErrBadProposer

type ErrBadProposer struct {
	Want, Got PubKey
}

func (ErrBadProposer) Error

func (ErrBadProposer) Error() string

type GetValidatorRelayResponse

type GetValidatorRelayResponse []struct {
	Slot  uint64 `json:"slot,string"`
	Entry struct {
		Message struct {
			FeeRecipient string `json:"fee_recipient"`
			GasLimit     uint64 `json:"gas_limit,string"`
			Timestamp    uint64 `json:"timestamp,string"`
			PubKey       string `json:"pubkey"`
		} `json:"message"`
		Signature string `json:"signature"`
	} `json:"entry"`
}

type HeadEvent

type HeadEvent struct {
	Slot  uint64 `json:"slot,string"`
	Block string `json:"block"`
	State string `json:"state"`
}

HeadEvent is emitted when subscribing to head events

func (HeadEvent) Loggable

func (h HeadEvent) Loggable() map[string]any

type HeaderAndTrace

type HeaderAndTrace struct {
	Header *types.ExecutionPayloadHeader
	Trace  *BidTraceWithTimestamp
}

type HeaderRequest

type HeaderRequest map[string]string

func ParseHeaderRequest

func ParseHeaderRequest(r *http.Request) HeaderRequest

func (HeaderRequest) Slot

func (hr HeaderRequest) Slot() (Slot, error)

type MultiBeaconClient added in v0.1.2

type MultiBeaconClient struct {
	Log     log.Logger
	Clients []BeaconClient
	// contains filtered or unexported fields
}

func (*MultiBeaconClient) Endpoint added in v0.1.2

func (b *MultiBeaconClient) Endpoint() string

func (*MultiBeaconClient) GetProposerDuties added in v0.1.2

func (b *MultiBeaconClient) GetProposerDuties(epoch Epoch) (*RegisteredProposersResponse, error)

func (*MultiBeaconClient) KnownValidators added in v0.1.2

func (b *MultiBeaconClient) KnownValidators(headSlot Slot) (AllValidatorsResponse, error)

func (*MultiBeaconClient) SubscribeToHeadEvents added in v0.1.2

func (b *MultiBeaconClient) SubscribeToHeadEvents(ctx context.Context, slotC chan HeadEvent)

func (*MultiBeaconClient) SyncStatus added in v0.1.2

func (b *MultiBeaconClient) SyncStatus() (*SyncStatusPayloadData, error)

type PayloadKey

type PayloadKey struct {
	BlockHash types.Hash
	Proposer  types.PublicKey
	Slot      Slot
}

func SubmissionToKey added in v0.1.2

func SubmissionToKey(submission *types.BuilderSubmitBlockRequest) PayloadKey

type PubKey

type PubKey struct{ types.PublicKey }

func (PubKey) Bytes

func (pk PubKey) Bytes() []byte

func (PubKey) Loggable

func (pk PubKey) Loggable() map[string]any

func (PubKey) RegistrationKey

func (pk PubKey) RegistrationKey() ds.Key

func (PubKey) ValidatorKey

func (pk PubKey) ValidatorKey() ds.Key

type Query added in v0.1.5

type Query struct {
	Slot      Slot
	BlockHash types.Hash
	BlockNum  uint64
	PubKey    types.PublicKey
}

type RegisteredProposersResponse

type RegisteredProposersResponse struct {
	Data []RegisteredProposersResponseData
}

RegisteredProposersResponse is the response for querying proposer duties

type RegisteredProposersResponseData

type RegisteredProposersResponseData struct {
	PubKey PubKey `json:"pubkey"`
	Slot   uint64 `json:"slot,string"`
}

type Slot

type Slot uint64

func (Slot) Epoch

func (s Slot) Epoch() Epoch

func (Slot) HeaderKey

func (s Slot) HeaderKey() ds.Key

func (Slot) Loggable

func (s Slot) Loggable() map[string]any

func (Slot) PayloadKey

func (s Slot) PayloadKey() ds.Key

type State

type State interface {
	Datastore() Datastore
	Beacon() BeaconState
}

type SyncStatusPayload

type SyncStatusPayload struct {
	Data SyncStatusPayloadData
}

SyncStatusPayload is the response payload for /eth/v1/node/syncing

type SyncStatusPayloadData

type SyncStatusPayloadData struct {
	HeadSlot  uint64 `json:"head_slot,string"`
	IsSyncing bool   `json:"is_syncing"`
}

type TTLDatastoreBatcher

type TTLDatastoreBatcher struct {
	ds.TTLDatastore
}

func (*TTLDatastoreBatcher) GetBatch

func (bb *TTLDatastoreBatcher) GetBatch(ctx context.Context, keys []ds.Key) (batch [][]byte, err error)

type TTLStorage

type TTLStorage interface {
	PutWithTTL(context.Context, ds.Key, []byte, time.Duration) error
	Get(context.Context, ds.Key) ([]byte, error)
	GetBatch(ctx context.Context, keys []ds.Key) (batch [][]byte, err error)
	Close() error
}

type TraceQuery added in v0.1.5

type TraceQuery struct {
	Slot          Slot
	BlockHash     types.Hash
	BlockNum      uint64
	Pubkey        types.PublicKey
	Cursor, Limit uint64
}

func (TraceQuery) HasBlockHash added in v0.1.5

func (q TraceQuery) HasBlockHash() bool

func (TraceQuery) HasBlockNum added in v0.1.5

func (q TraceQuery) HasBlockNum() bool

func (TraceQuery) HasCursor added in v0.1.5

func (q TraceQuery) HasCursor() bool

func (TraceQuery) HasLimit added in v0.1.5

func (q TraceQuery) HasLimit() bool

func (TraceQuery) HasPubkey added in v0.1.5

func (q TraceQuery) HasPubkey() bool

func (TraceQuery) HasSlot added in v0.1.5

func (q TraceQuery) HasSlot() bool

type UserAgent

type UserAgent string

type ValidatorResponseEntry

type ValidatorResponseEntry struct {
	Index     uint64                         `json:"index,string"` // Index of validator in validator registry.
	Balance   string                         `json:"balance"`      // Current validator balance in gwei.
	Status    string                         `json:"status"`
	Validator ValidatorResponseValidatorData `json:"validator"`
}

type ValidatorResponseValidatorData

type ValidatorResponseValidatorData struct {
	Pubkey string `json:"pubkey"`
}

Jump to

Keyboard shortcuts

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