Include source and target epochs when scoring attestation data.

Fixes #8
This commit is contained in:
Jim McDonald 2020-11-29 10:21:51 +00:00
parent b22c451636
commit 6a28a2ce86
No known key found for this signature in database
GPG Key ID: 89CEB61B2AD2A5E7
4 changed files with 12 additions and 6 deletions

View File

@ -1,3 +1,6 @@
Development:
- include source and target epochs when scoring attestation data
1.0.0:
- mainnet-ready
- introduce attestation data strategy, allowing selection of best or first attestation from a set

View File

@ -74,7 +74,7 @@ import (
)
// ReleaseVersion is the release version for the code.
var ReleaseVersion = "1.0.0"
var ReleaseVersion = "1.0.1-prerelease"
func main() {
os.Exit(main2())

View File

@ -75,6 +75,7 @@ func (s *Service) AttestationData(ctx context.Context, slot spec.Slot, committee
responded++
if bestAttestationData == nil || resp.score > bestScore {
bestAttestationData = resp.attestationData
bestScore = resp.score
}
}
}
@ -83,6 +84,7 @@ func (s *Service) AttestationData(ctx context.Context, slot spec.Slot, committee
if bestAttestationData == nil {
return nil, errors.New("no attestations received")
}
log.Trace().Stringer("attestation_data", bestAttestationData).Float64("score", bestScore).Msg("Selected best attestation")
return bestAttestationData, nil
}

View File

@ -37,27 +37,28 @@ func (s *Service) scoreAttestationData(ctx context.Context,
block, err := headerProvider.BeaconBlockHeader(ctx, fmt.Sprintf("%#x", attestationData.BeaconBlockRoot))
if err != nil {
log.Error().Err(err).Msg("failed to obtain block header")
return float64(1) / float64(32)
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")
return float64(1) / float64(32)
return float64(attestationData.Source.Epoch + attestationData.Target.Epoch)
}
slot = block.Message.Slot
} else {
log.Warn().Msg("Cannot score attestation")
// Give minimal score.
slot = attestationData.Slot - 32
return float64(attestationData.Source.Epoch + attestationData.Target.Epoch)
}
score := float64(1) / float64(1+attestationData.Slot-slot)
score := float64(attestationData.Source.Epoch+attestationData.Target.Epoch) + float64(1)/float64(1+attestationData.Slot-slot)
log.Trace().
Str("provider", name).
Uint64("attestation_slot", uint64(attestationData.Slot)).
Uint64("head_slot", uint64(slot)).
Uint64("source_epoch", uint64(attestationData.Source.Epoch)).
Uint64("target_epoch", uint64(attestationData.Target.Epoch)).
Float64("score", score).
Msg("Scored attestation data")
return score