Avoid crash on nil beacon block.

Situation reported where a node returns nil for a beacon block when
scoring attestation data.  Although this should not happen (the provider
told us about the block via the attestation, it should know it) this
patch covers the situation where the returned block is empty or
malformed.

Fixes #9
This commit is contained in:
Jim McDonald 2020-12-14 09:29:34 +00:00
parent 57fcf15be1
commit 3a8098981c
No known key found for this signature in database
GPG Key ID: 89CEB61B2AD2A5E7
1 changed files with 10 additions and 2 deletions

View File

@ -36,14 +36,22 @@ func (s *Service) scoreAttestationData(ctx context.Context,
if headerProvider, isProvider := provider.(eth2client.BeaconBlockHeadersProvider); isProvider {
block, err := headerProvider.BeaconBlockHeader(ctx, fmt.Sprintf("%#x", attestationData.BeaconBlockRoot))
if err != nil {
log.Error().Err(err).Msg("failed to obtain block header")
log.Error().Err(err).Msg("Failed to obtain block header")
return float64(attestationData.Source.Epoch + attestationData.Target.Epoch)
}
slot = block.Header.Message.Slot
} else if blockProvider, isProvider := provider.(eth2client.SignedBeaconBlockProvider); isProvider {
block, err := blockProvider.SignedBeaconBlock(ctx, fmt.Sprintf("%#x", attestationData.BeaconBlockRoot))
if err != nil {
log.Error().Err(err).Msg("failed to obtain block")
log.Error().Err(err).Msg("Failed to obtain block")
return float64(attestationData.Source.Epoch + attestationData.Target.Epoch)
}
if block == nil {
log.Warn().Str("block_root", fmt.Sprintf("%#x", attestationData.BeaconBlockRoot)).Msg("No block returned by provider")
return float64(attestationData.Source.Epoch + attestationData.Target.Epoch)
}
if block.Message == nil {
log.Warn().Str("block_root", fmt.Sprintf("%#x", attestationData.BeaconBlockRoot)).Msg("Empty block returned by provider")
return float64(attestationData.Source.Epoch + attestationData.Target.Epoch)
}
slot = block.Message.Slot