diff --git a/common/types.go b/common/types.go index 2e54782f..70af7ca4 100644 --- a/common/types.go +++ b/common/types.go @@ -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" @@ -52,10 +47,12 @@ 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) { @@ -63,41 +60,37 @@ func NewEthNetworkDetails(networkName string) (ret *EthNetworkDetails, err error 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) } @@ -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 { diff --git a/services/api/service.go b/services/api/service.go index e47c40b3..2f7a2dca 100644 --- a/services/api/service.go +++ b/services/api/service.go @@ -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 @@ -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 @@ -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 } @@ -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 { @@ -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") diff --git a/services/api/utils.go b/services/api/utils.go index 7bb8571b..ca562704 100644 --- a/services/api/utils.go +++ b/services/api/utils.go @@ -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 @@ -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 +}