-
Notifications
You must be signed in to change notification settings - Fork 1.2k
add delay before broadcasting lc objects #15776
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
Conversation
98c7809
to
504ea55
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.
There is also code in /beacon-chain/sync/validate_light_client.go
that deals with timing. It's based on the old spec (
prysm/beacon-chain/sync/validate_light_client.go
Lines 50 to 65 in cc2565a
// [IGNORE] The optimistic_update is received after the block at signature_slot was given enough time | |
// to propagate through the network -- i.e. validate that one-third of optimistic_update.signature_slot | |
// has transpired (SECONDS_PER_SLOT / INTERVALS_PER_SLOT seconds after the start of the slot, | |
// with a MAXIMUM_GOSSIP_CLOCK_DISPARITY allowance) | |
slotStart, err := slots.StartTime(s.cfg.clock.GenesisTime(), newUpdate.SignatureSlot()) | |
if err != nil { | |
log.WithError(err).Debug("Peer sent a slot that would overflow slot start time") | |
return pubsub.ValidationReject, nil | |
} | |
earliestValidTime := slotStart. | |
Add(time.Second * time.Duration(params.BeaconConfig().SecondsPerSlot/params.BeaconConfig().IntervalsPerSlot)). | |
Add(-params.BeaconConfig().MaximumGossipClockDisparityDuration()) | |
if s.cfg.clock.Now().Before(earliestValidTime) { | |
log.Debug("Newly received light client optimistic update ignored. not enough time passed for block to propagate") | |
return pubsub.ValidationIgnore, nil | |
} |
prysm/beacon-chain/sync/validate_light_client.go
Lines 117 to 132 in cc2565a
// [IGNORE] The optimistic_update is received after the block at signature_slot was given enough time | |
// to propagate through the network -- i.e. validate that one-third of optimistic_update.signature_slot | |
// has transpired (SECONDS_PER_SLOT / INTERVALS_PER_SLOT seconds after the start of the slot, | |
// with a MAXIMUM_GOSSIP_CLOCK_DISPARITY allowance) | |
slotStart, err := slots.StartTime(s.cfg.clock.GenesisTime(), newUpdate.SignatureSlot()) | |
if err != nil { | |
log.WithError(err).Debug("Peer sent a slot that would overflow slot start time") | |
return pubsub.ValidationReject, nil | |
} | |
earliestValidTime := slotStart. | |
Add(time.Second * time.Duration(params.BeaconConfig().SecondsPerSlot/params.BeaconConfig().IntervalsPerSlot)). | |
Add(-params.BeaconConfig().MaximumGossipClockDisparityDuration()) | |
if s.cfg.clock.Now().Before(earliestValidTime) { | |
log.Debug("Newly received light client finality update ignored. not enough time passed for block to propagate") | |
return pubsub.ValidationIgnore, nil | |
} |
BP
construct too?
beacon-chain/p2p/broadcaster_test.go
Outdated
func TestService_BroadcastLightClientOptimisticUpdate(t *testing.T) { | ||
params.SetupTestConfigCleanup(t) | ||
config := params.BeaconConfig().Copy() | ||
config.SyncMessageDueBPS = 833 // ~1 second |
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.
What if we changed this to 1
? Will the test still pass?
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.
yes the test will pass. but we want to be able to test that enough time has passed. if you make it 1, you might as well make it zero.
c44bc02
to
fa77961
Compare
What type of PR is this?
Bug fix
What does this PR do? Why is it needed?
As per spec, light client p2p messages should be broadcasted with a delay of ~4 seconds after the slot start time. This PR adds that necessary delay.
It also adds the
BASIS_POINTS
values and logic to calculate component durations based on basis points.