Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up deprecated forks and add deneb support #486

Merged
merged 2 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 46 additions & 25 deletions common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,18 @@ var (
ErrUnknownNetwork = errors.New("unknown network")
ErrEmptyPayload = errors.New("empty payload")

EthNetworkRopsten = "ropsten"
EthNetworkSepolia = "sepolia"
EthNetworkGoerli = "goerli"
EthNetworkMainnet = "mainnet"
EthNetworkZhejiang = "zhejiang"
EthNetworkCustom = "custom"

CapellaForkVersionRopsten = "0x03001020"
EthNetworkSepolia = "sepolia"
EthNetworkGoerli = "goerli"
EthNetworkMainnet = "mainnet"
EthNetworkCustom = "custom"

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

// Zhejiang details
GenesisForkVersionZhejiang = "0x00000069"
GenesisValidatorsRootZhejiang = "0x53a92d8f2bb1d85f62d16a156e6ebcd1bcaba652d0900b2c2f387826f3481f6f"
BellatrixForkVersionZhejiang = "0x00000071"
CapellaForkVersionZhejiang = "0x00000072"
DenebForkVersionSepolia = "0x90000073"
DenebForkVersionGoerli = "0x04001020"
DenebForkVersionMainnet = "0x04000000"

ForkVersionStringBellatrix = "bellatrix"
ForkVersionStringCapella = "capella"
Expand All @@ -52,52 +47,50 @@ type EthNetworkDetails struct {
GenesisValidatorsRootHex string
BellatrixForkVersionHex string
CapellaForkVersionHex string
DenebForkVersionHex string

DomainBuilder boostTypes.Domain
DomainBeaconProposerBellatrix boostTypes.Domain
DomainBeaconProposerCapella boostTypes.Domain
DomainBeaconProposerDeneb boostTypes.Domain
}

func NewEthNetworkDetails(networkName string) (ret *EthNetworkDetails, err error) {
var genesisForkVersion string
var genesisValidatorsRoot string
var bellatrixForkVersion string
var capellaForkVersion string
var denebForkVersion string
var domainBuilder boostTypes.Domain
var domainBeaconProposerBellatrix boostTypes.Domain
var domainBeaconProposerCapella boostTypes.Domain
var domainBeaconProposerDeneb boostTypes.Domain

switch networkName {
case EthNetworkRopsten:
genesisForkVersion = boostTypes.GenesisForkVersionRopsten
genesisValidatorsRoot = boostTypes.GenesisValidatorsRootRopsten
bellatrixForkVersion = boostTypes.BellatrixForkVersionRopsten
capellaForkVersion = CapellaForkVersionRopsten
case EthNetworkSepolia:
genesisForkVersion = boostTypes.GenesisForkVersionSepolia
genesisValidatorsRoot = boostTypes.GenesisValidatorsRootSepolia
bellatrixForkVersion = boostTypes.BellatrixForkVersionSepolia
capellaForkVersion = CapellaForkVersionSepolia
denebForkVersion = DenebForkVersionSepolia
case EthNetworkGoerli:
genesisForkVersion = boostTypes.GenesisForkVersionGoerli
genesisValidatorsRoot = boostTypes.GenesisValidatorsRootGoerli
bellatrixForkVersion = boostTypes.BellatrixForkVersionGoerli
capellaForkVersion = CapellaForkVersionGoerli
denebForkVersion = DenebForkVersionGoerli
case EthNetworkMainnet:
genesisForkVersion = boostTypes.GenesisForkVersionMainnet
genesisValidatorsRoot = boostTypes.GenesisValidatorsRootMainnet
bellatrixForkVersion = boostTypes.BellatrixForkVersionMainnet
capellaForkVersion = CapellaForkVersionMainnet
case EthNetworkZhejiang:
genesisForkVersion = GenesisForkVersionZhejiang
genesisValidatorsRoot = GenesisValidatorsRootZhejiang
bellatrixForkVersion = BellatrixForkVersionZhejiang
capellaForkVersion = CapellaForkVersionZhejiang
denebForkVersion = DenebForkVersionMainnet
case EthNetworkCustom:
genesisForkVersion = os.Getenv("GENESIS_FORK_VERSION")
genesisValidatorsRoot = os.Getenv("GENESIS_VALIDATORS_ROOT")
bellatrixForkVersion = os.Getenv("BELLATRIX_FORK_VERSION")
capellaForkVersion = os.Getenv("CAPELLA_FORK_VERSION")
denebForkVersion = os.Getenv("DENEB_FORK_VERSION")
default:
return nil, fmt.Errorf("%w: %s", ErrUnknownNetwork, networkName)
}
Expand All @@ -117,21 +110,49 @@ func NewEthNetworkDetails(networkName string) (ret *EthNetworkDetails, err error
return nil, err
}

domainBeaconProposerDeneb, err = ComputeDomain(boostTypes.DomainTypeBeaconProposer, denebForkVersion, genesisValidatorsRoot)
if err != nil {
return nil, err
}

return &EthNetworkDetails{
Name: networkName,
GenesisForkVersionHex: genesisForkVersion,
GenesisValidatorsRootHex: genesisValidatorsRoot,
BellatrixForkVersionHex: bellatrixForkVersion,
CapellaForkVersionHex: capellaForkVersion,
DenebForkVersionHex: denebForkVersion,
DomainBuilder: domainBuilder,
DomainBeaconProposerBellatrix: domainBeaconProposerBellatrix,
DomainBeaconProposerCapella: domainBeaconProposerCapella,
DomainBeaconProposerDeneb: domainBeaconProposerDeneb,
}, nil
}

func (e *EthNetworkDetails) String() string {
return fmt.Sprintf("EthNetworkDetails{Name: %s, GenesisForkVersionHex: %s, GenesisValidatorsRootHex: %s, BellatrixForkVersionHex: %s, CapellaForkVersionHex: %s, DomainBuilder: %x, DomainBeaconProposerBellatrix: %x, DomainBeaconProposerCapella: %x}",
e.Name, e.GenesisForkVersionHex, e.GenesisValidatorsRootHex, e.BellatrixForkVersionHex, e.CapellaForkVersionHex, e.DomainBuilder, e.DomainBeaconProposerBellatrix, e.DomainBeaconProposerCapella)
return fmt.Sprintf(
`EthNetworkDetails{
Name: %s,
GenesisForkVersionHex: %s,
GenesisValidatorsRootHex: %s,
BellatrixForkVersionHex: %s,
CapellaForkVersionHex: %s,
DenebForkVersionHex: %s,
DomainBuilder: %x,
DomainBeaconProposerBellatrix: %x,
DomainBeaconProposerCapella: %x,
DomainBeaconProposerDeneb: %x
}`,
e.Name,
e.GenesisForkVersionHex,
e.GenesisValidatorsRootHex,
e.BellatrixForkVersionHex,
e.CapellaForkVersionHex,
e.DenebForkVersionHex,
e.DomainBuilder,
e.DomainBeaconProposerBellatrix,
e.DomainBeaconProposerCapella,
e.DomainBeaconProposerDeneb)
}

type BuilderGetValidatorsResponseEntry struct {
Expand Down
21 changes: 8 additions & 13 deletions services/api/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ type RelayAPI struct {
headSlot uberatomic.Uint64
genesisInfo *beaconclient.GetGenesisResponse
capellaEpoch uint64
denebEpoch uint64

proposerDutiesLock sync.RWMutex
proposerDutiesResponse *[]byte // raw http response
Expand Down Expand Up @@ -375,14 +376,6 @@ func (api *RelayAPI) getRouter() http.Handler {
return withGz
}

func (api *RelayAPI) isCapella(slot uint64) bool {
if api.capellaEpoch == 0 { // CL didn't yet have it
return false
}
epoch := slot / common.SlotsPerEpoch
return epoch >= api.capellaEpoch
}

// StartServer starts up this API instance and HTTP server
// - First it initializes the cache and updates local information
// - Once that is done, the HTTP server is started
Expand Down Expand Up @@ -420,14 +413,16 @@ func (api *RelayAPI) StartServer() (err error) {
switch fork.CurrentVersion {
case api.opts.EthNetDetails.CapellaForkVersionHex:
api.capellaEpoch = fork.Epoch
// TODO: add deneb support.
case api.opts.EthNetDetails.DenebForkVersionHex:
api.denebEpoch = fork.Epoch
}
}

// Print fork version information
// TODO: add deneb support.
if api.isCapella(currentSlot) {
if hasReachedFork(currentSlot, api.capellaEpoch) {
log.Infof("capella fork detected (currentEpoch: %d / capellaEpoch: %d)", common.SlotToEpoch(currentSlot), api.capellaEpoch)
} else if hasReachedFork(currentSlot, api.denebEpoch) {
log.Infof("deneb fork detected (currentEpoch: %d / denebEpoch: %d)", common.SlotToEpoch(currentSlot), api.denebEpoch)
} else {
return ErrMismatchedForkVersions
}
Expand Down Expand Up @@ -667,7 +662,7 @@ func (api *RelayAPI) processPayloadAttributes(payloadAttributes beaconclient.Pay

var withdrawalsRoot phase0.Root
var err error
if api.isCapella(payloadAttrSlot) {
if hasReachedFork(payloadAttrSlot, api.capellaEpoch) {
withdrawalsRoot, err = ComputeWithdrawalsRoot(payloadAttributes.Data.PayloadAttributes.Withdrawals)
log = log.WithField("withdrawalsRoot", withdrawalsRoot.String())
if err != nil {
Expand Down Expand Up @@ -1699,7 +1694,7 @@ func (api *RelayAPI) handleSubmitNewBlock(w http.ResponseWriter, req *http.Reque
return
}

if api.isCapella(payload.Slot()) { // Capella requires correct withdrawals
if hasReachedFork(payload.Slot(), api.capellaEpoch) { // Capella requires correct withdrawals
withdrawalsRoot, err := ComputeWithdrawalsRoot(payload.Withdrawals())
if err != nil {
log.WithError(err).Warn("could not compute withdrawals root from payload")
Expand Down
18 changes: 13 additions & 5 deletions services/api/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ func SanityCheckBuilderBlockSubmission(payload *common.BuilderSubmitBlockRequest
return nil
}

func checkBLSPublicKeyHex(pkHex string) error {
var proposerPubkey boostTypes.PublicKey
return proposerPubkey.UnmarshalText([]byte(pkHex))
}

func ComputeWithdrawalsRoot(w []*capella.Withdrawal) (phase0.Root, error) {
if w == nil {
return phase0.Root{}, ErrNoWithdrawals
Expand Down Expand Up @@ -102,3 +97,16 @@ func EqExecutionPayloadToHeader(bb *common.SignedBlindedBeaconBlock, payload *co

return ErrNoPayloads
}

func checkBLSPublicKeyHex(pkHex string) error {
var proposerPubkey boostTypes.PublicKey
return proposerPubkey.UnmarshalText([]byte(pkHex))
}

func hasReachedFork(slot, forkEpoch uint64) bool {
if forkEpoch == 0 {
return false
}
currentEpoch := slot / common.SlotsPerEpoch
return currentEpoch >= forkEpoch
}
Loading