-
Notifications
You must be signed in to change notification settings - Fork 307
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
Increase max attestation inclusion slot (p2p changes) #7305
Conversation
baeadd1
to
abd3bbd
Compare
bc36366
to
e6e8917
Compare
f7dafef
to
23f2ffd
Compare
ec62ffa
to
9c87726
Compare
4972cb3
to
dceb04a
Compare
slotInclusionGossipValidationWithStateResult = | ||
attestationUtil.performSlotInclusionGossipValidation(attestation, state); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
92f4980
to
d420eb7
Compare
...pec/src/main/java/tech/pegasys/teku/spec/logic/versions/deneb/util/AttestationUtilDeneb.java
Show resolved
Hide resolved
0a7c832
to
3cf4f85
Compare
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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.
f8ef5b9
to
79d2ba7
Compare
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); |
There was a problem hiding this comment.
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..
There was a problem hiding this comment.
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.
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; | ||
} |
There was a problem hiding this comment.
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...
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) { |
There was a problem hiding this comment.
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
6f4f6bd
to
b669fde
Compare
...eum/spec/src/main/java/tech/pegasys/teku/spec/datastructures/operations/AttestationData.java
Outdated
Show resolved
Hide resolved
ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/helpers/MiscHelpers.java
Outdated
Show resolved
Hide resolved
9d5c4a9
to
d629e9c
Compare
PR Description
AttestationUtilDeneb
to deal with slot inclusion gossip validation changes for attestations in Deneb. Moved the previous slot inclusion validations inAttestationUtilPhase0
AttestationValidatorTest
into Deneb and Phase0 onep2p-interface.md changes
Fixed Issue(s)
fixes #7299
Documentation
doc-change-required
label to this PR if updates are required.Changelog