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

Increase max attestation inclusion slot (p2p changes) #7305

Conversation

StefanBratanov
Copy link
Contributor

@StefanBratanov StefanBratanov commented Jun 26, 2023

PR Description

  • Created AttestationUtilDeneb to deal with slot inclusion gossip validation changes for attestations in Deneb. Moved the previous slot inclusion validations in AttestationUtilPhase0
  • Split AttestationValidatorTest into Deneb and Phase0 one
  • Other small nits/refactors

p2p-interface.md changes

Fixed Issue(s)

fixes #7299

Documentation

  • I thought about documentation and added the doc-change-required label to this PR if updates are required.

Changelog

  • I thought about adding a changelog entry, and added one if I deemed necessary.

@StefanBratanov StefanBratanov force-pushed the increase_max_attestation_inclusion_slot branch 3 times, most recently from baeadd1 to abd3bbd Compare June 27, 2023 12:22
@StefanBratanov StefanBratanov force-pushed the increase_max_attestation_inclusion_slot branch 2 times, most recently from bc36366 to e6e8917 Compare June 28, 2023 11:37
@StefanBratanov StefanBratanov marked this pull request as ready for review June 28, 2023 11:38
@StefanBratanov StefanBratanov force-pushed the increase_max_attestation_inclusion_slot branch 2 times, most recently from f7dafef to 23f2ffd Compare June 28, 2023 16:11
@StefanBratanov StefanBratanov changed the title Increase max attestation inclusion slot Increase max attestation inclusion slot (p2p changes) Jun 29, 2023
@StefanBratanov StefanBratanov marked this pull request as draft June 29, 2023 11:12
@StefanBratanov StefanBratanov force-pushed the increase_max_attestation_inclusion_slot branch from ec62ffa to 9c87726 Compare July 3, 2023 08:31
@StefanBratanov StefanBratanov marked this pull request as ready for review July 3, 2023 09:01
@StefanBratanov StefanBratanov force-pushed the increase_max_attestation_inclusion_slot branch from 4972cb3 to dceb04a Compare July 3, 2023 10:13
Comment on lines 137 to 138
slotInclusionGossipValidationWithStateResult =
attestationUtil.performSlotInclusionGossipValidation(attestation, state);
Copy link
Contributor

Choose a reason for hiding this comment

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

If we were going to do this, we'd be needing to pass the head state, not just any state chosen for gossip topic inclusion. Head state is also sketchy (eg. future slot errors where we haven't completed epoch transitions).

Because it's using the state to compute the current epoch and previous epoch, if we end up using something like a fork state from previous epoch as the best state, then we'd actually be using current-1, current-2, and that'd be bad...
My suggestion if they're only using state to check against epoch is we compute the epoch against wall time inside that function, and then even if the state machine is behind we're accepting gossip correctly...

Then performSlotInclusionGossipValidation would only take the attestation... unless we need a state because of test cases or something...

If we did we could probably just have a wrapper interface that takes attestation and state and computes the epoch of the state then calls a private function that takes attestation, headEpoch, and the default public interface could derive headEpoch from wallTime...

Anyway, that's a couple of ideas. happy to talk further.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did change implementation to use the wall time instead.

@StefanBratanov StefanBratanov force-pushed the increase_max_attestation_inclusion_slot branch 3 times, most recently from 92f4980 to d420eb7 Compare July 5, 2023 14:56
@StefanBratanov StefanBratanov force-pushed the increase_max_attestation_inclusion_slot branch from 0a7c832 to 3cf4f85 Compare July 6, 2023 13:40
Copy link
Contributor

@tbenr tbenr left a comment

Choose a reason for hiding this comment

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

we discussed a couple of things in a call. This is one of them

return computeStartTimeAtSlot(genesisTime, epochStartSlot);
}

public UInt64 computeStartTimeAtSlot(final UInt64 genesisTime, final UInt64 slot) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't be just another version of computeTimeAtSlot, otherwise it should be computeSlotStartTime (same for epoch). According to my hears.

@StefanBratanov StefanBratanov force-pushed the increase_max_attestation_inclusion_slot branch 2 times, most recently from f8ef5b9 to 79d2ba7 Compare July 10, 2023 08:12
Comment on lines 82 to 94
return attestationForkChoiceEligibleTimeMillis.isGreaterThan(discardAttestationsAfterMillis);
}

private boolean isCurrentTimeBeforeMinimumAttestationBroadcastTime(
final UInt64 attestationSlot, final UInt64 genesisTime, final UInt64 currentTimeMillis) {
final UInt64 minimumBroadcastTimeMillis =
minimumBroadcastTimeMillis(attestationSlot, genesisTime);
return currentTimeMillis.isLessThan(minimumBroadcastTimeMillis);
}

private boolean isCurrentTimeAfterAttestationPropagationSlotRange(
final UInt64 attestationSlot, final UInt64 genesisTime, final UInt64 currentTimeMillis) {
return maximumBroadcastTimeMillis(attestationSlot, genesisTime).isLessThan(currentTimeMillis);
Copy link
Contributor

Choose a reason for hiding this comment

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

can we check code coverage, and if its not immaculate, then we should consider making tests for these - they could easily be package private static, and we could feed in values to validate with great coverage..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I will extend current tests for Phase0. I didn't touch them but good idea to see we are covering all methods.

Comment on lines 66 to 94
private boolean isAttestationSlotAfterCurrentTime(
final UInt64 attestationSlotTimeMillis, final UInt64 currentTimeMillis) {
return attestationSlotTimeMillis.isGreaterThan(
currentTimeMillis.plus(specConfig.getMaximumGossipClockDisparity()));
}

private boolean isAttestationSlotInCurrentOrPreviousEpoch(
final UInt64 attestationSlot, final UInt64 genesisTime, final UInt64 currentTimeMillis) {
final UInt64 currentSlot =
miscHelpers.computeSlotAtTime(genesisTime, millisToSeconds(currentTimeMillis));
final UInt64 currentEpoch = miscHelpers.computeEpochAtSlot(currentSlot);
final UInt64 previousEpoch = currentEpoch.minusMinZero(1);
final int slotDisparity = calculateMaximumGossipClockDisparityInSlots();
// min and max slot for the given attestation slot based on previous and current epoch with
// MAXIMUM_GOSSIP_CLOCK_DISPARITY
final UInt64 minSlot =
miscHelpers.computeStartSlotAtEpoch(previousEpoch).minusMinZero(slotDisparity);
final UInt64 maxSlot = miscHelpers.computeEndSlotAtEpoch(currentEpoch).plus(slotDisparity);

return attestationSlot.isGreaterThanOrEqualTo(minSlot)
&& attestationSlot.isLessThanOrEqualTo(maxSlot);
}

private int calculateMaximumGossipClockDisparityInSlots() {
return (specConfig.getMaximumGossipClockDisparity() / specConfig.getMillisPerSlot()) + 1;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

likewise here, could definitely do some unit testing if we need to check any of this... it would show us our business logic is correct for isAttestationSlotInCurrentOrPreviousEpoch for example, and we could easily boundary test etc...

Comment on lines 125 to 133
public UInt64 computeEndSlotAtEpoch(final UInt64 epoch) {
return computeStartSlotAtEpoch(epoch).plus(specConfig.getSlotsPerEpoch() - 1);
}

public UInt64 computeSlotAtTime(final UInt64 genesisTime, final UInt64 currentTime) {
return currentTime.minusMinZero(genesisTime).dividedBy(specConfig.getSecondsPerSlot());
}

public UInt64 computeTimeAtSlot(final UInt64 genesisTime, final UInt64 slot) {
return genesisTime.plus(slot.times(specConfig.getSecondsPerSlot()));
}

public UInt64 computeTimeAtSlot(final BeaconState state, final UInt64 slot) {
Copy link
Contributor

Choose a reason for hiding this comment

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

test... they're simple in this case but we really do need basic tests so that when we refactor we can find issues.

import tech.pegasys.teku.spec.datastructures.operations.Attestation;
import tech.pegasys.teku.spec.util.DataStructureUtil;

class AttestationUtilPhase0Test {

Check notice

Code scanning / CodeQL

Unused classes and interfaces

Unused class: AttestationUtilPhase0Test is not referenced within this codebase. If not used as an external API it should be removed.
@StefanBratanov StefanBratanov force-pushed the increase_max_attestation_inclusion_slot branch from 6f4f6bd to b669fde Compare July 10, 2023 19:33
@StefanBratanov StefanBratanov force-pushed the increase_max_attestation_inclusion_slot branch from 9d5c4a9 to d629e9c Compare July 12, 2023 09:28
@StefanBratanov StefanBratanov enabled auto-merge (squash) July 12, 2023 09:28
@StefanBratanov StefanBratanov merged commit 12a6c96 into Consensys:master Jul 12, 2023
@tbenr tbenr mentioned this pull request Mar 19, 2024
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Increase max attestation inclusion slot
3 participants