Skip to content

Commit

Permalink
Handle no deneb fork schedule from beacon client (#572)
Browse files Browse the repository at this point in the history
* backwards compatibility if no deneb schedule

* Update services/api/service.go

Co-authored-by: Chris Hager <chris@linuxuser.at>

---------

Co-authored-by: Chris Hager <chris@linuxuser.at>
  • Loading branch information
avalonche and metachris authored Jan 25, 2024
1 parent d2237f8 commit 0346f6f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
23 changes: 14 additions & 9 deletions services/api/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ type RelayAPI struct {

headSlot uberatomic.Uint64
genesisInfo *beaconclient.GetGenesisResponse
capellaEpoch uint64
denebEpoch uint64
capellaEpoch int64
denebEpoch int64

proposerDutiesLock sync.RWMutex
proposerDutiesResponse *[]byte // raw http response
Expand Down Expand Up @@ -411,23 +411,28 @@ func (api *RelayAPI) StartServer() (err error) {
if err != nil {
return err
}
var foundCapellaEpoch, foundDenebEpoch bool

api.denebEpoch = -1
api.capellaEpoch = -1
for _, fork := range forkSchedule.Data {
log.Infof("forkSchedule: version=%s / epoch=%d", fork.CurrentVersion, fork.Epoch)
switch fork.CurrentVersion {
case api.opts.EthNetDetails.CapellaForkVersionHex:
foundCapellaEpoch = true
api.capellaEpoch = fork.Epoch
api.capellaEpoch = int64(fork.Epoch)
case api.opts.EthNetDetails.DenebForkVersionHex:
foundDenebEpoch = true
api.denebEpoch = fork.Epoch
api.denebEpoch = int64(fork.Epoch)
}
}

if api.denebEpoch == -1 {
// log warning that deneb epoch was not found in CL fork schedule, suggest CL upgrade
log.Info("Deneb epoch not found in fork schedule")
}

// Print fork version information
if foundDenebEpoch && hasReachedFork(currentSlot, api.denebEpoch) {
if hasReachedFork(currentSlot, api.denebEpoch) {
log.Infof("deneb fork detected (currentEpoch: %d / denebEpoch: %d)", common.SlotToEpoch(currentSlot), api.denebEpoch)
} else if foundCapellaEpoch && hasReachedFork(currentSlot, api.capellaEpoch) {
} else if hasReachedFork(currentSlot, api.capellaEpoch) {
log.Infof("capella fork detected (currentEpoch: %d / capellaEpoch: %d)", common.SlotToEpoch(currentSlot), api.capellaEpoch)
}

Expand Down
7 changes: 5 additions & 2 deletions services/api/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,12 @@ func checkBLSPublicKeyHex(pkHex string) error {
return err
}

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

func verifyBlockSignature(block *common.VersionedSignedBlindedBeaconBlock, domain phase0.Domain, pubKey []byte) (bool, error) {
Expand Down

0 comments on commit 0346f6f

Please sign in to comment.