Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EIP-7549: p2p and sync #14085

Merged
merged 12 commits into from
Jun 24, 2024
Merged

EIP-7549: p2p and sync #14085

merged 12 commits into from
Jun 24, 2024

Conversation

rkapka
Copy link
Contributor

@rkapka rkapka commented Jun 6, 2024

What type of PR is this?

Feature

What does this PR do? Why is it needed?

  • Support for Electra objects in p2p/sync
  • Create a generic extractDataType function instead of a separate function for each object type (blocks, metadata, attestations etc)

@rkapka rkapka requested a review from a team as a code owner June 6, 2024 13:51
@rkapka rkapka added Electra electra hardfork Networking P2P related items labels Jun 6, 2024
@rkapka rkapka added the Ready For Review A pull request ready for code review label Jun 6, 2024
}

// Reset our attestation map.
AttestationMap = map[[4]byte]func() (ethpb.Att, error){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doing this for all topics this way is pretty ugly, not strictly against your PR but if we are going to do this for multiple types, it might be better to have a cleaner way to set this up. Rather than manually transcribing it for each fork. Something to do as a follow up

@@ -46,6 +46,12 @@ func TestInitializeDataMaps(t *testing.T) {
tt.action()
_, ok := BlockMap[bytesutil.ToBytes4(params.BeaconConfig().GenesisForkVersion)]
assert.Equal(t, tt.exists, ok)
_, ok = MetaDataMap[bytesutil.ToBytes4(params.BeaconConfig().GenesisForkVersion)]
assert.Equal(t, tt.exists, ok)
_, ok = AttestationMap[bytesutil.ToBytes4(params.BeaconConfig().GenesisForkVersion)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets also test that they return the correct types

@@ -51,7 +57,19 @@ func (s *Service) decodePubsubMessage(msg *pubsub.Message) (ssz.Unmarshaler, err
}
// Handle different message types across forks.
if topic == p2p.BlockSubnetTopicFormat {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using a switch here is cleaner

}
}
if topic == p2p.AttestationSubnetTopicFormat {
m, err = extractDataType(types.AttestationMap, fDigest[:], s.cfg.clock)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of passing a map for each type, we could just pass the topic and the method does the rest.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but then the function would no longer be generic and the same code would have to be duplicated for each map

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You infer the type from the topic

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ex: an attestation topic will always use the attestation map and never anything else. This switching is done in the extractDataType method itself


func Test_attsAreEqual_committee(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a more proper test signature ?

if !ok {
err := errors.New("attestation has wrong type")
tracing.AnnotateError(span, err)
return pubsub.ValidationReject, err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be an ignore, it would point there to being an error in our pipeline

if !ok {
err := errors.New("attestation has wrong type")
tracing.AnnotateError(span, err)
return pubsub.ValidationReject, err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

a, ok := att.(*eth.AttestationElectra)
// This will never fail in practice because we asserted the version
if !ok {
return pubsub.ValidationReject, fmt.Errorf("attestation has wrong type (expected %T, got %T)", &eth.AttestationElectra{}, att)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, please change it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change this to ignore

if err != nil {
return nil, err
}
dt, err := extractDataTypeFromTopic(topic, fDigest[:], s.cfg.clock)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should change its name to be more accurate as it does not apply for all types.
extractValidDataTypeFromTopic or something to that effect

@@ -33,6 +35,8 @@ import (
// - attestation.data.slot is within the last ATTESTATION_PROPAGATION_SLOT_RANGE slots (attestation.data.slot + ATTESTATION_PROPAGATION_SLOT_RANGE >= current_slot >= attestation.data.slot).
// - The signature of attestation is valid.
func (s *Service) validateCommitteeIndexBeaconAttestation(ctx context.Context, pid peer.ID, msg *pubsub.Message) (pubsub.ValidationResult, error) {
var validationRes pubsub.ValidationResult
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move validationRes lower to where its used

a, ok := att.(*eth.AttestationElectra)
// This will never fail in practice because we asserted the version
if !ok {
return pubsub.ValidationReject, fmt.Errorf("attestation has wrong type (expected %T, got %T)", &eth.AttestationElectra{}, att)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change this to ignore

@rkapka rkapka added this pull request to the merge queue Jun 24, 2024
Merged via the queue into develop with commit adc875b Jun 24, 2024
16 of 17 checks passed
@rkapka rkapka deleted the eip-7549-sync branch June 24, 2024 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Electra electra hardfork Networking P2P related items Ready For Review A pull request ready for code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants