relay

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2022 License: AGPL-3.0 Imports: 27 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.1.0"
)

Variables

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

	ErrOldSlot = errors.New("old slot")
)
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")
	UnregisteredValidatorMsg = "unregistered validator"
)
View Source
var ErrHTTPErrorResponse = errors.New("got an HTTP error response")
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 DeliveredKey

func DeliveredKey(key ds.Key) 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 HeaderPubkeyKey

func HeaderPubkeyKey(pk types.PublicKey) ds.Key

func PayloadKey

func PayloadKey(h types.Hash) 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 received when querying the active validators

type BeaconClient

type BeaconClient interface {
	SubscribeToHeadEvents(context.Context) <-chan HeadEvent
	GetProposerDuties(Epoch) (*RegisteredProposersResponse, error)
	SyncStatus() (*SyncStatusPayloadData, error)
	UpdateProposerDuties(context.Context, Slot, Datastore) error
	ProcessNewSlot(context.Context, Slot, Datastore) error
	GetProposerByIndex(uint64) (types.PubkeyHex, error)
	GetValidatorsMap() BuilderGetValidatorsResponseEntrySlice
	IsValidator(PubKey) bool
	HeadSlot() Slot
}

func NewBeaconClient

func NewBeaconClient(config Config) (BeaconClient, error)

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
	BeaconEndpoint      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 {
	Storage TTLStorage
}

func (DefaultDatastore) GetHeader

func (s DefaultDatastore) GetHeader(ctx context.Context, slot Slot, delivered bool) (HeaderAndTrace, error)

func (DefaultDatastore) GetHeaderBatch

func (s DefaultDatastore) GetHeaderBatch(ctx context.Context, slots []Slot, delivered bool) ([]HeaderAndTrace, error)

func (DefaultDatastore) GetHeaderByBlockHash

func (s DefaultDatastore) GetHeaderByBlockHash(ctx context.Context, bh types.Hash, delivered bool) (HeaderAndTrace, error)

func (DefaultDatastore) GetHeaderByBlockNum

func (s DefaultDatastore) GetHeaderByBlockNum(ctx context.Context, bn uint64, delivered bool) (HeaderAndTrace, error)

func (DefaultDatastore) GetHeaderByPubkey

func (s DefaultDatastore) GetHeaderByPubkey(ctx context.Context, pk types.PublicKey, delivered bool) (HeaderAndTrace, error)

func (DefaultDatastore) GetPayload

func (s DefaultDatastore) GetPayload(ctx context.Context, h types.Hash) (*BlockBidAndTrace, error)

func (DefaultDatastore) GetRegistration

func (DefaultDatastore) PutDelivered

func (s DefaultDatastore) PutDelivered(ctx context.Context, slot Slot, 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, h types.Hash, 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, slot Slot) ([]BidTraceWithTimestamp, error)

func (*DefaultService) GetBlockReceivedByHash

func (s *DefaultService) GetBlockReceivedByHash(ctx context.Context, bh types.Hash) ([]BidTraceWithTimestamp, error)

func (*DefaultService) GetBlockReceivedByNum

func (s *DefaultService) GetBlockReceivedByNum(ctx context.Context, bn uint64) ([]BidTraceWithTimestamp, error)

func (*DefaultService) GetDelivered

func (s *DefaultService) GetDelivered(ctx context.Context, slot Slot) ([]types.BidTrace, error)

func (*DefaultService) GetDeliveredByHash

func (s *DefaultService) GetDeliveredByHash(ctx context.Context, bh types.Hash) ([]types.BidTrace, error)

func (*DefaultService) GetDeliveredByNum

func (s *DefaultService) GetDeliveredByNum(ctx context.Context, bn uint64) ([]types.BidTrace, error)

func (*DefaultService) GetDeliveredByPubKey

func (s *DefaultService) GetDeliveredByPubKey(ctx context.Context, pk types.PublicKey) ([]types.BidTrace, error)

func (*DefaultService) GetHeader

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

func (*DefaultService) GetPayload

func (*DefaultService) GetTailBlockReceived

func (s *DefaultService) GetTailBlockReceived(ctx context.Context, limit uint64) ([]BidTraceWithTimestamp, error)

func (*DefaultService) GetTailDelivered

func (s *DefaultService) GetTailDelivered(ctx context.Context, limit uint64) ([]types.BidTrace, error)

func (*DefaultService) GetTailDeliveredCursor

func (s *DefaultService) GetTailDeliveredCursor(ctx context.Context, limit, cursor uint64) ([]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 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 on new slots in beacon client

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 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 RegisteredProposersResponse

type RegisteredProposersResponse struct {
	Data []RegisteredProposersResponseData
}

RegisteredProposersResponse is received when 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() BeaconClient
}

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 UserAgent

type UserAgent string

type ValidatorData

type ValidatorData struct {
	PubKey       PubKey
	FeeRecipient types.Address `json:"feeRecipient"`
	GasLimit     uint64        `json:"gasLimit"`
	Timestamp    uint64        `json:"timestamp"`
}

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