mirror of https://github.com/certusone/vouch.git
Include source and target epochs when scoring attestation data.
Fixes #8
This commit is contained in:
parent
b22c451636
commit
6a28a2ce86
|
@ -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
|
||||
|
|
2
main.go
2
main.go
|
@ -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())
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue