Skip to content

Commit

Permalink
Allow fork epochs to be 0 (#520)
Browse files Browse the repository at this point in the history
  • Loading branch information
avalonche authored Sep 7, 2023
1 parent 4e78ec8 commit cec4116
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
15 changes: 10 additions & 5 deletions services/api/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,23 +408,28 @@ func (api *RelayAPI) StartServer() (err error) {
if err != nil {
return err
}
var foundCapellaEpoch, foundDenebEpoch bool
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
case api.opts.EthNetDetails.DenebForkVersionHex:
foundDenebEpoch = true
api.denebEpoch = fork.Epoch
}
}

if !foundCapellaEpoch || !foundDenebEpoch {
return ErrMissingForkVersions
}

// Print fork version information
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) {
if hasReachedFork(currentSlot, api.denebEpoch) {
log.Infof("deneb fork detected (currentEpoch: %d / denebEpoch: %d)", common.SlotToEpoch(currentSlot), api.denebEpoch)
} else {
return ErrMismatchedForkVersions
} else if hasReachedFork(currentSlot, api.capellaEpoch) {
log.Infof("capella fork detected (currentEpoch: %d / capellaEpoch: %d)", common.SlotToEpoch(currentSlot), api.capellaEpoch)
}

// start proposer API specific things
Expand Down
4 changes: 2 additions & 2 deletions services/api/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,8 @@ func TestBuilderSubmitBlock(t *testing.T) {

// Setup the test relay backend
backend.relay.headSlot.Store(headSlot)
backend.relay.capellaEpoch = 1
backend.relay.capellaEpoch = 0
backend.relay.denebEpoch = 1
backend.relay.proposerDutiesMap = make(map[uint64]*common.BuilderGetValidatorsResponseEntry)
backend.relay.proposerDutiesMap[headSlot+1] = &common.BuilderGetValidatorsResponseEntry{
Slot: headSlot,
Expand Down Expand Up @@ -719,7 +720,6 @@ func TestCheckSubmissionPayloadAttrs(t *testing.T) {
backend.relay.payloadAttributesLock.RLock()
backend.relay.payloadAttributes[testParentHash] = tc.attrs
backend.relay.payloadAttributesLock.RUnlock()
backend.relay.capellaEpoch = 1

w := httptest.NewRecorder()
logger := logrus.New()
Expand Down
3 changes: 0 additions & 3 deletions services/api/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,6 @@ func checkBLSPublicKeyHex(pkHex string) error {
}

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

0 comments on commit cec4116

Please sign in to comment.