common

package
v0.0.0-...-a4e836c Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2023 License: AGPL-3.0 Imports: 37 Imported by: 0

Documentation

Overview

Package common provides things used by various other components

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrServerAlreadyRunning = errors.New("server already running")

	SlotsPerEpoch    = uint64(32)
	DurationPerSlot  = time.Second * 12
	DurationPerEpoch = DurationPerSlot * time.Duration(SlotsPerEpoch)
)
View Source
var (
	EthNetworkKiln    = "kiln"
	EthNetworkRopsten = "ropsten"
	EthNetworkSepolia = "sepolia"
	EthNetworkGoerli  = "goerli"
	EthNetworkMainnet = "mainnet"

	GenesisValidatorsRootGoerli = "0x043db0d9a83813551ee2f33450d23797757d430911a9320530ad8a0eabc43efb"
	GenesisForkVersionGoerli    = "0x00001020"
	BellatrixForkVersionGoerli  = "0x02001020"

	GenesisValidatorsRootGoerliShadowFork6 = "0x6985063fa80a61a958ceeac5cf6125991ac297348e42542c85affbe9fb1c7328"
	GenesisForkVersionGoerliShadowFork6    = "0x13001035"
	BellatrixForkVersionGoerliShadowFork6  = "0x22001035"

	// https://github.com/eth-clients/eth2-networks/blob/f3ccbe0cf5798d5cd23e4e6e7119aefa043c0935/shared/mainnet/config.yaml
	GenesisValidatorsRootMainnet = "0x4b363db94e286120d76eb905340fdd4e54bfe9f06bf33ff6cf5ad27f511bfe95"
	GenesisForkVersionMainnet    = "0x00000000"
	BellatrixForkVersionMainnet  = "0x02000000"
)
View Source
var (
	ErrEmptyPayload    = errors.New("empty payload")
	EthNetworkZhejiang = "zhejiang"
	EthNetworkCustom   = "custom"

	CapellaForkVersionRopsten = "0x03001020"
	CapellaForkVersionSepolia = "0x90000072"
	CapellaForkVersionGoerli  = "0x03001020"
	CapellaForkVersionMainnet = "0x03000000"

	// Zhejiang details
	GenesisForkVersionZhejiang    = "0x00000069"
	GenesisValidatorsRootZhejiang = "0x53a92d8f2bb1d85f62d16a156e6ebcd1bcaba652d0900b2c2f387826f3481f6f"
	BellatrixForkVersionZhejiang  = "0x00000071"
	CapellaForkVersionZhejiang    = "0x00000072"
)
View Source
var (
	ErrMissingRequest     = errors.New("req is nil")
	ErrMissingSecretKey   = errors.New("secret key is nil")
	ErrInvalidTransaction = errors.New("invalid transaction")
)
View Source
var (
	ErrInvalidForkVersion = errors.New("invalid fork version")
	ErrHTTPErrorResponse  = errors.New("got an HTTP error response")
	ErrIncorrectLength    = errors.New("incorrect length")
)
View Source
var ErrUnknownNetwork = errors.New("unknown network")
View Source
var NilResponse = struct{}{}
View Source
var TestLog = logrus.WithField("testing", true)

TestLog is used to log information in the test methods

View Source
var ValidPayloadRegisterValidator = types.SignedValidatorRegistration{
	Message: &types.RegisterValidatorRequestMessage{
		FeeRecipient: _HexToAddress("0xdb65fEd33dc262Fe09D9a2Ba8F80b329BA25f941"),
		Timestamp:    1234356,
		GasLimit:     278234191203,
		Pubkey: _HexToPubkey(
			"0x8a1d7b8dd64e0aafe7ea7b6c95065c9364cf99d38470c12ee807d55f7de1529ad29ce2c422e0b65e3d5a05c02caca249"),
	},

	Signature: _HexToSignature(
		"0x8209b5391cd69f392b1f02dbc03bab61f574bb6bb54bf87b59e2a85bdc0756f7db6a71ce1b41b727a1f46ccc77b213bf0df1426177b5b29926b39956114421eaa36ec4602969f6f6370a44de44a6bce6dae2136e5fb594cce2a476354264d1ea"),
}
View Source
var VersionBellatrix boostTypes.VersionString = "bellatrix"
View Source
var ZeroU256 = boostTypes.IntToU256(0)

Functions

func BoostBidToBidTrace

func BoostBidToBidTrace(bidTrace *types.BidTrace) *apiv1.BidTrace

func BuilderSubmitBlockRequestToSignedBuilderBid

func BuilderSubmitBlockRequestToSignedBuilderBid(req *capella.SubmitBlockRequest, sk *bls.SecretKey, pubkey *phase0.BLSPubKey, domain boostTypes.Domain) (*capella.SignedBuilderBid, error)

func ComputeDomain

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

ComputeDomain computes the signing domain

func CreateKeyPair

func CreateKeyPair(certificatesPath string) (tls.Certificate, error)

func CreateTestBlockSubmission

func CreateTestBlockSubmission(t *testing.T, builderPubkey string, value *big.Int, opts *CreateTestBlockSubmissionOpts) (payload *BuilderSubmitBlockRequest, getPayloadResponse *GetPayloadResponse, getHeaderResponse *GetHeaderResponse)

func DecodeExtraData

func DecodeExtraData(extraData types.ExtraData) string

DecodeExtraData returns a decoded string from block ExtraData

func GenerateRandomEthHash

func GenerateRandomEthHash() common.Hash

GenerateRandomEthHash returns a random 32-byte SHA-256 hash (block hash, tx hash, etc.)

func GenerateRandomPublicKey

func GenerateRandomPublicKey() types.PublicKey

GenerateRandomPublicKey returns a random 48-byte public key

func GetEnv

func GetEnv(key, defaultValue string) string

func GetEnvStrSlice

func GetEnvStrSlice(key string, defaultValue []string) []string

GetEnvStrSlice returns a slice of strings from a comma-separated env var

func GetIPXForwardedFor

func GetIPXForwardedFor(r *http.Request) string

func GetMevBoostVersionFromUserAgent

func GetMevBoostVersionFromUserAgent(ua string) string

GetMevBoostVersionFromUserAgent returns the mev-boost version from an user agent string Example ua: "mev-boost/1.0.1 go-http-client" -> returns "1.0.1". If no version is found, returns "-"

func GetSliceEnv

func GetSliceEnv(key string, defaultValue []string) []string

func LogSetup

func LogSetup(json bool, logLevel string)

func MakeRequest

func MakeRequest(ctx context.Context, client http.Client, method, url string, payload any) (*http.Response, error)

func NewCapellaBuilderSubmitBlockRequest

func NewCapellaBuilderSubmitBlockRequest(builderPubKey types.PublicKey, blockHash common.Hash, bidValue *big.Int, receiveTime time.Time) *capellaapi.SubmitBlockRequest

NewCapellaBuilderSubmitBlockRequest returns a Capella submit block request based on a provided builder pub key, block hash, and value

func SlotPos

func SlotPos(slot uint64) uint64

SlotPos returns the slot's position in the epoch (1-based, i.e. 1..32)

func StrToPhase0Hash

func StrToPhase0Hash(s string) (ret phase0.Hash32, err error)

func StrToPhase0Pubkey

func StrToPhase0Pubkey(s string) (ret phase0.BLSPubKey, err error)

func U256StrToUint256

func U256StrToUint256(s types.U256Str) *uint256.Int

func WeiToEth

func WeiToEth(valueString string) string

func WeiToEthRounded

func WeiToEthRounded(value string) string

Types

type BeaconBlock

type BeaconBlock struct {
	ExecutionPayload types.ExecutionPayload `json:"execution_payload"`
	RandaoReveal     string                 `json:"randao_reveal"`
}

type BeaconBlockData

type BeaconBlockData struct {
	Message BeaconBlockMessage `json:"message"`
}

type BeaconBlockMessage

type BeaconBlockMessage struct {
	Body          BeaconBlock `json:"body"`
	Slot          string      `json:"slot"`
	ProposerIndex string      `json:"proposer_index"`
}

type BeaconBlockResponse

type BeaconBlockResponse struct {
	Data BeaconBlockData `json:"data"`
}

type BellatrixBuilderSubmitBlockRequest

type BellatrixBuilderSubmitBlockRequest struct {
	Signature        types.Signature         `json:"signature" ssz-size:"96"`
	Message          *types.BidTrace         `json:"message"`
	ExecutionPayload *types.ExecutionPayload `json:"execution_payload"`
}

BellatrixBuilderSubmitBlockRequest supports bellatrix block submissions

type BidTraceV2

type BidTraceV2 struct {
	apiv1.BidTrace
	BlockNumber uint64 `json:"block_number,string" db:"block_number"`
	NumTx       uint64 `json:"num_tx,string" db:"num_tx"`
}

func (BidTraceV2) MarshalJSON

func (b BidTraceV2) MarshalJSON() ([]byte, error)

func (*BidTraceV2) UnmarshalJSON

func (b *BidTraceV2) UnmarshalJSON(data []byte) error

type BidTraceV2JSON

type BidTraceV2JSON struct {
	Slot                 uint64 `json:"slot,string"`
	ParentHash           string `json:"parent_hash"`
	BlockHash            string `json:"block_hash"`
	BuilderPubkey        string `json:"builder_pubkey"`
	ProposerPubkey       string `json:"proposer_pubkey"`
	ProposerFeeRecipient string `json:"proposer_fee_recipient"`
	GasLimit             uint64 `json:"gas_limit,string"`
	GasUsed              uint64 `json:"gas_used,string"`
	Value                string `json:"value"`
	NumTx                uint64 `json:"num_tx,string"`
	BlockNumber          uint64 `json:"block_number,string"`
}

func (*BidTraceV2JSON) CSVHeader

func (b *BidTraceV2JSON) CSVHeader() []string

func (*BidTraceV2JSON) ToCSVRecord

func (b *BidTraceV2JSON) ToCSVRecord() []string

type BidTraceV2WithTimestampJSON

type BidTraceV2WithTimestampJSON struct {
	BidTraceV2JSON
	Timestamp   int64 `json:"timestamp,string,omitempty"`
	TimestampMs int64 `json:"timestamp_ms,string,omitempty"`
}

func (*BidTraceV2WithTimestampJSON) CSVHeader

func (b *BidTraceV2WithTimestampJSON) CSVHeader() []string

func (*BidTraceV2WithTimestampJSON) ToCSVRecord

func (b *BidTraceV2WithTimestampJSON) ToCSVRecord() []string

type BuilderBlockValidationRequest

type BuilderBlockValidationRequest struct {
	BuilderSubmitBlockRequest
	RegisteredGasLimit uint64 `json:"registered_gas_limit,string"`
}

func (*BuilderBlockValidationRequest) MarshalJSON

func (r *BuilderBlockValidationRequest) MarshalJSON() ([]byte, error)

type BuilderBlockValidationRequestV2

type BuilderBlockValidationRequestV2 struct {
	capella.SubmitBlockRequest
	RegisteredGasLimit uint64         `json:"registered_gas_limit,string"`
	WithdrawalsRoot    ethcommon.Hash `json:"withdrawals_root"`
}

type BuilderEntry

type BuilderEntry struct {
	Address string
	Pubkey  hexutil.Bytes
	URL     *url.URL
}

BuilderEntry represents a builder that is allowed to send blocks Address will be schema://hostname:port

func NewBuilderEntry

func NewBuilderEntry(builderURL string) (entry *BuilderEntry, err error)

NewBuilderEntry creates a new instance based on an input string builderURL can be IP@PORT, PUBKEY@IP:PORT, https://IP, etc.

type BuilderGetValidatorsResponseEntry

type BuilderGetValidatorsResponseEntry struct {
	Slot           uint64                             `json:"slot,string"`
	ValidatorIndex uint64                             `json:"validator_index,string"`
	Entry          *types.SignedValidatorRegistration `json:"entry"`
}

type BuilderSubmitBlockRequest

type BuilderSubmitBlockRequest struct {
	Bellatrix *types.BuilderSubmitBlockRequest
	Capella   *capella.SubmitBlockRequest
}

func (*BuilderSubmitBlockRequest) BlockHash

func (b *BuilderSubmitBlockRequest) BlockHash() string

func (*BuilderSubmitBlockRequest) BlockNumber

func (b *BuilderSubmitBlockRequest) BlockNumber() uint64

func (*BuilderSubmitBlockRequest) BuilderPubkey

func (b *BuilderSubmitBlockRequest) BuilderPubkey() phase0.BLSPubKey

func (*BuilderSubmitBlockRequest) ExecutionPayloadBlockHash

func (b *BuilderSubmitBlockRequest) ExecutionPayloadBlockHash() string

func (*BuilderSubmitBlockRequest) ExecutionPayloadParentHash

func (b *BuilderSubmitBlockRequest) ExecutionPayloadParentHash() string

func (*BuilderSubmitBlockRequest) ExecutionPayloadResponse

func (b *BuilderSubmitBlockRequest) ExecutionPayloadResponse() (*GetPayloadResponse, error)

func (*BuilderSubmitBlockRequest) GasLimit

func (b *BuilderSubmitBlockRequest) GasLimit() uint64

func (*BuilderSubmitBlockRequest) GasUsed

func (b *BuilderSubmitBlockRequest) GasUsed() uint64

func (*BuilderSubmitBlockRequest) HasExecutionPayload

func (b *BuilderSubmitBlockRequest) HasExecutionPayload() bool

func (*BuilderSubmitBlockRequest) MarshalJSON

func (b *BuilderSubmitBlockRequest) MarshalJSON() ([]byte, error)

func (*BuilderSubmitBlockRequest) Message

func (*BuilderSubmitBlockRequest) NumTx

func (b *BuilderSubmitBlockRequest) NumTx() int

func (*BuilderSubmitBlockRequest) ParentHash

func (b *BuilderSubmitBlockRequest) ParentHash() string

func (*BuilderSubmitBlockRequest) ProposerFeeRecipient

func (b *BuilderSubmitBlockRequest) ProposerFeeRecipient() string

func (*BuilderSubmitBlockRequest) ProposerPubkey

func (b *BuilderSubmitBlockRequest) ProposerPubkey() string

func (*BuilderSubmitBlockRequest) Random

func (b *BuilderSubmitBlockRequest) Random() string

func (*BuilderSubmitBlockRequest) Signature

func (*BuilderSubmitBlockRequest) Slot

func (*BuilderSubmitBlockRequest) Timestamp

func (b *BuilderSubmitBlockRequest) Timestamp() uint64

func (*BuilderSubmitBlockRequest) UnmarshalJSON

func (b *BuilderSubmitBlockRequest) UnmarshalJSON(data []byte) error

func (*BuilderSubmitBlockRequest) Value

func (b *BuilderSubmitBlockRequest) Value() *big.Int

func (*BuilderSubmitBlockRequest) Withdrawals

type CapellaBuilderSubmitBlockRequest

type CapellaBuilderSubmitBlockRequest capella.SubmitBlockRequest

CapellaBuilderSubmitBlockRequest supports capella block submissions

func (*CapellaBuilderSubmitBlockRequest) MarshalBinary

func (cpsbr *CapellaBuilderSubmitBlockRequest) MarshalBinary() ([]byte, error)

type CreateTestBlockSubmissionOpts

type CreateTestBlockSubmissionOpts struct {
	Slot           uint64
	ParentHash     string
	ProposerPubkey string
	// contains filtered or unexported fields
}

type EpochSummary

type EpochSummary struct {
	Epoch uint64 `json:"epoch"      db:"epoch"`

	// first and last slots are just derived from the epoch
	SlotFirst uint64 `json:"slot_first" db:"slot_first"`
	SlotLast  uint64 `json:"slot_last"  db:"slot_last"`

	// registered are those that were actually used by the relay (some might be skipped if only one relay and it started in the middle of the epoch)
	SlotFirstProcessed uint64 `json:"slot_first_processed" db:"slot_first_processed"`
	SlotLastProcessed  uint64 `json:"slot_last_processed"  db:"slot_last_processed"`

	// Validator stats
	ValidatorsKnownTotal                     uint64 `json:"validators_known_total"                      db:"validators_known_total"`
	ValidatorRegistrationsTotal              uint64 `json:"validator_registrations_total"               db:"validator_registrations_total"`
	ValidatorRegistrationsSaved              uint64 `json:"validator_registrations_saved"               db:"validator_registrations_saved"`
	ValidatorRegistrationsReceivedUnverified uint64 `json:"validator_registrations_received_unverified" db:"validator_registrations_received_unverified"`

	// The number of requests are the count of all requests to a specific path, even invalid ones
	NumRegisterValidatorRequests uint64 `json:"num_register_validator_requests" db:"num_register_validator_requests"`
	NumGetHeaderRequests         uint64 `json:"num_get_header_requests"         db:"num_get_header_requests"`
	NumGetPayloadRequests        uint64 `json:"num_get_payload_requests"        db:"num_get_payload_requests"`

	// Responses to successful queries
	NumHeaderSentOk       uint64 `json:"num_header_sent_ok"       db:"num_header_sent_ok"`
	NumHeaderSent204      uint64 `json:"num_header_sent_204"      db:"num_header_sent_204"`
	NumPayloadSent        uint64 `json:"num_payload_sent"         db:"num_payload_sent"`
	NumBuilderBidReceived uint64 `json:"num_builder_bid_received" db:"num_builder_bid_received"`

	// Whether all slots were seen
	IsComplete bool `json:"is_complete" db:"is_complete"`
}

type EthNetworkDetails

type EthNetworkDetails struct {
	Name                     string
	GenesisForkVersionHex    string
	GenesisValidatorsRootHex string
	BellatrixForkVersionHex  string
	CapellaForkVersionHex    string

	DomainBuilder                 types.Domain
	DomainBeaconProposerBellatrix types.Domain
	DomainBeaconProposerCapella   types.Domain
}

func NewEthNetworkDetails

func NewEthNetworkDetails(networkName string) (ret *EthNetworkDetails, err error)

func (*EthNetworkDetails) String

func (e *EthNetworkDetails) String() string

type GetHeaderResponse

type GetHeaderResponse struct {
	Bellatrix *types.GetHeaderResponse
	Capella   *spec.VersionedSignedBuilderBid
}

func BuildGetHeaderResponse

func BuildGetHeaderResponse(payload *BuilderSubmitBlockRequest, sk *bls.SecretKey, pubkey *boostTypes.PublicKey, domain boostTypes.Domain) (*GetHeaderResponse, error)

func (*GetHeaderResponse) BlockHash

func (p *GetHeaderResponse) BlockHash() phase0.Hash32

func (*GetHeaderResponse) Empty

func (p *GetHeaderResponse) Empty() bool

func (*GetHeaderResponse) MarshalJSON

func (p *GetHeaderResponse) MarshalJSON() ([]byte, error)

func (*GetHeaderResponse) UnmarshalJSON

func (p *GetHeaderResponse) UnmarshalJSON(data []byte) error

func (*GetHeaderResponse) Value

func (p *GetHeaderResponse) Value() *big.Int

type GetPayloadResponse

type GetPayloadResponse struct {
	Bellatrix *types.GetPayloadResponse
	Capella   *api.VersionedExecutionPayload
}

func BuildGetPayloadResponse

func BuildGetPayloadResponse(payload *BuilderSubmitBlockRequest) (*GetPayloadResponse, error)

func (*GetPayloadResponse) MarshalJSON

func (p *GetPayloadResponse) MarshalJSON() ([]byte, error)

func (*GetPayloadResponse) UnmarshalJSON

func (p *GetPayloadResponse) UnmarshalJSON(data []byte) error

type HTTPErrorResp

type HTTPErrorResp struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

type HTTPServerTimeouts

type HTTPServerTimeouts struct {
	Read       time.Duration // Timeout for body reads. None if 0.
	ReadHeader time.Duration // Timeout for header reads. None if 0.
	Write      time.Duration // Timeout for writes. None if 0.
	Idle       time.Duration // Timeout to disconnect idle client connections. None if 0.
}

HTTPServerTimeouts are various timeouts for requests to the mev-boost HTTP server

type SignedBeaconBlock

type SignedBeaconBlock struct {
	Bellatrix *types.SignedBeaconBlock
	Capella   *consensuscapella.SignedBeaconBlock
}

func (*SignedBeaconBlock) BlockHash

func (s *SignedBeaconBlock) BlockHash() string

func (*SignedBeaconBlock) MarshalJSON

func (s *SignedBeaconBlock) MarshalJSON() ([]byte, error)

func (*SignedBeaconBlock) Slot

func (s *SignedBeaconBlock) Slot() uint64

type SignedBlindedBeaconBlock

type SignedBlindedBeaconBlock struct {
	Bellatrix *types.SignedBlindedBeaconBlock
	Capella   *apiv1capella.SignedBlindedBeaconBlock
}

func (*SignedBlindedBeaconBlock) BlockHash

func (s *SignedBlindedBeaconBlock) BlockHash() string

func (*SignedBlindedBeaconBlock) BlockNumber

func (s *SignedBlindedBeaconBlock) BlockNumber() uint64

func (*SignedBlindedBeaconBlock) MarshalJSON

func (s *SignedBlindedBeaconBlock) MarshalJSON() ([]byte, error)

func (*SignedBlindedBeaconBlock) Message

func (*SignedBlindedBeaconBlock) ProposerIndex

func (s *SignedBlindedBeaconBlock) ProposerIndex() uint64

func (*SignedBlindedBeaconBlock) Signature

func (s *SignedBlindedBeaconBlock) Signature() []byte

func (*SignedBlindedBeaconBlock) Slot

func (s *SignedBlindedBeaconBlock) Slot() uint64

type SlotSummary

type SlotSummary struct {
	Slot   uint64 `json:"slot"   db:"slot"`
	Epoch  uint64 `json:"epoch"  db:"epoch"`
	Missed bool   `json:"missed" db:"missed"`

	// General validator stats
	ValidatorsKnownTotal        uint64 `json:"validators_known_total"                      db:"validators_known_total"`
	ValidatorRegistrationsTotal uint64 `json:"validator_registrations_total"               db:"validator_registrations_total"`

	// Slot proposer details
	ProposerPubkey       string `json:"proposer_pubkey"        db:"proposer_pubkey"`
	ProposerIsRegistered bool   `json:"proposer_is_registered" db:"proposer_is_registered"`

	// The number of requests are the count of all requests to a specific path, even invalid ones
	NumGetHeaderRequests  uint64 `json:"num_get_header_requests"         db:"num_get_header_requests"`
	NumGetPayloadRequests uint64 `json:"num_get_payload_requests"        db:"num_get_payload_requests"`

	// Responses to successful queries
	NumHeaderSentOk       uint64 `json:"num_header_sent_ok"       db:"num_header_sent_ok"`
	NumHeaderSent204      uint64 `json:"num_header_sent_204"      db:"num_header_sent_204"`
	NumPayloadSent        uint64 `json:"num_payload_sent"         db:"num_payload_sent"`
	NumBuilderBidReceived uint64 `json:"num_builder_bid_received" db:"num_builder_bid_received"`
}

type VersionedExecutionPayload

type VersionedExecutionPayload struct {
	Bellatrix *types.GetPayloadResponse
	Capella   *api.VersionedExecutionPayload
}

func (*VersionedExecutionPayload) MarshalJSON

func (e *VersionedExecutionPayload) MarshalJSON() ([]byte, error)

func (*VersionedExecutionPayload) NumTx

func (e *VersionedExecutionPayload) NumTx() int

func (*VersionedExecutionPayload) UnmarshalJSON

func (e *VersionedExecutionPayload) UnmarshalJSON(data []byte) error

type WrappedCapellaBuilderSubmitBlockRequest

type WrappedCapellaBuilderSubmitBlockRequest struct {
	Payload     *capella.SubmitBlockRequest
	ReceiveTime time.Time
}

WrappedCapellaBuilderSubmitBlockRequest supports capella block submissions

Jump to

Keyboard shortcuts

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