Skip to content

Commit

Permalink
Make findEpochRoot work with missing blocks at the end of an epoch (#…
Browse files Browse the repository at this point in the history
…12061)

This is for example used in attestations rewards calculation, which was
failing with the error message "no block found for this epoch".

In reality only the last block was not found in the epoch, and that
already triggered the error.

With this change, we find the last non-missed block in this case.
  • Loading branch information
errge committed Sep 22, 2024
1 parent 4c4d443 commit 5d43b25
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions cl/beacon/handler/lighthouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,24 @@ type LighthouseValidatorInclusionGlobal struct {
PreviousEpochHeadAttestingGwei uint64 `json:"previous_epoch_head_attesting_gwei"`
}

// the block root hash of the highest numbered slot that actually exists
func (a *ApiHandler) findEpochRoot(tx kv.Tx, epoch uint64) (common.Hash, error) {
var currentBlockRoot common.Hash
var validBlockRoot common.Hash
var err error
for i := epoch * a.beaconChainCfg.SlotsPerEpoch; i < (epoch+1)*a.beaconChainCfg.SlotsPerEpoch; i++ {
// read the block root
currentBlockRoot, err = beacon_indicies.ReadCanonicalBlockRoot(tx, i)
if err != nil {
return common.Hash{}, err
}
if currentBlockRoot != (common.Hash{}) {
// only accept a block root, if it was not missed
validBlockRoot = currentBlockRoot
}
}
return currentBlockRoot, nil

// return the last valid block root that was not missed and we found
return validBlockRoot, nil
}

func (a *ApiHandler) GetLighthouseValidatorInclusionGlobal(w http.ResponseWriter, r *http.Request) (*beaconhttp.BeaconResponse, error) {
Expand Down

0 comments on commit 5d43b25

Please sign in to comment.