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

Replace validator wait for activation stream with polling #14514

Merged
merged 22 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f0850bc
wip, waitForNextEpoch Broken
james-prysm Oct 4, 2024
0e031d4
fixing wait for activation and timings
james-prysm Oct 4, 2024
e2396be
updating tests wip
james-prysm Oct 4, 2024
d877fe5
fixing tests
james-prysm Oct 7, 2024
4f51abd
deprecating wait for activation stream
james-prysm Oct 7, 2024
1dbc751
Merge branch 'develop' into remove-validator-wait-activation
james-prysm Oct 7, 2024
1312a8e
removing duplicate test
james-prysm Oct 7, 2024
85bac27
Update validator/client/wait_for_activation.go
james-prysm Oct 7, 2024
efb99f0
Update CHANGELOG.md
james-prysm Oct 7, 2024
2356639
Update CHANGELOG.md
james-prysm Oct 8, 2024
645e79f
Update validator/client/wait_for_activation.go
james-prysm Oct 8, 2024
2a2df19
Merge branch 'develop' into remove-validator-wait-activation
james-prysm Oct 8, 2024
5f6e9f5
moving seconds until next epoch start to slottime and adding unit test
james-prysm Oct 8, 2024
e513b87
removing seconds into slot buffer, will need to test
james-prysm Oct 8, 2024
6819a82
Merge branch 'develop' into remove-validator-wait-activation
james-prysm Oct 9, 2024
bca707e
fixing waittime bug
james-prysm Oct 9, 2024
6732cc4
adding pr to changelog
james-prysm Oct 9, 2024
9aa2121
Update validator/client/wait_for_activation.go
james-prysm Oct 10, 2024
cbb4713
Update validator/client/wait_for_activation.go
james-prysm Oct 10, 2024
a678545
fixing incorect log
james-prysm Oct 10, 2024
17e89c3
refactoring based on feedback
james-prysm Oct 10, 2024
d23faec
Merge branch 'develop' into remove-validator-wait-activation
james-prysm Oct 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ The format is based on Keep a Changelog, and this project adheres to Semantic Ve
### Deprecated
- `--disable-grpc-gateway` flag is deprecated due to grpc gateway removal.
- `--enable-experimental-state` flag is deprecated. This feature is now on by default. Opt-out with `--disable-experimental-state`.
- `/eth/v1alpha1/validator/activation/stream` grpc wait for activation stream is deprecated. [pr](https://github.com/prysmaticlabs/prysm/pull/14514)

### Removed

Expand Down
1 change: 1 addition & 0 deletions beacon-chain/rpc/prysm/v1alpha1/validator/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ type Server struct {
// WaitForActivation checks if a validator public key exists in the active validator registry of the current
// beacon state, if not, then it creates a stream which listens for canonical states which contain
// the validator with the public key as an active validator record.
// Deprecated: do not use, just poll validator status every epoch.
func (vs *Server) WaitForActivation(req *ethpb.ValidatorActivationRequest, stream ethpb.BeaconNodeValidator_WaitForActivationServer) error {
activeValidatorExists, validatorStatuses, err := vs.activationStatus(stream.Context(), req.PublicKeys)
if err != nil {
Expand Down
567 changes: 285 additions & 282 deletions proto/prysm/v1alpha1/validator.pb.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions proto/prysm/v1alpha1/validator.proto
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ service BeaconNodeValidator {
option (google.api.http) = {
get: "/eth/v1alpha1/validator/activation/stream"
};
option deprecated = true;
}

// ValidatorIndex retrieves a validator's index location in the beacon state's
Expand Down
123 changes: 0 additions & 123 deletions testing/mock/beacon_validator_client_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions time/slots/slottime.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
mathutil "github.com/prysmaticlabs/prysm/v5/math"
prysmTime "github.com/prysmaticlabs/prysm/v5/time"
"github.com/sirupsen/logrus"
)

// MaxSlotBuffer specifies the max buffer given to slots from
Expand Down Expand Up @@ -286,3 +287,27 @@ func WithinVotingWindow(genesisTime uint64, slot primitives.Slot) bool {
func MaxSafeEpoch() primitives.Epoch {
return primitives.Epoch(math.MaxUint64 / uint64(params.BeaconConfig().SlotsPerEpoch))
}

// SecondsUntilNextEpochStart returns how many seconds until the next Epoch start from the current time and slot
func SecondsUntilNextEpochStart(genesisTimeSec uint64) (uint64, error) {
currentSlot := CurrentSlot(genesisTimeSec)
firstSlotOfNextEpoch, err := EpochStart(ToEpoch(currentSlot) + 1)
if err != nil {
return 0, err
}
nextEpochStartTime, err := ToTime(genesisTimeSec, firstSlotOfNextEpoch)
if err != nil {
return 0, err
}
es := nextEpochStartTime.Unix()
n := time.Now().Unix()
waitTime := uint64(es - n)
log.WithFields(logrus.Fields{
"current_slot": currentSlot,
"next_epoch_start_slot": firstSlotOfNextEpoch,
"slots_until_next_start": firstSlotOfNextEpoch - currentSlot,
"total_wait_time": waitTime,
"is_epoch_start": IsEpochStart(currentSlot),
Copy link
Contributor

Choose a reason for hiding this comment

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

Our convention is to use camelCase for log fields

}).Warn("Waiting until next epoch before re-checking validator statuses...")
Copy link
Contributor

Choose a reason for hiding this comment

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

This log does not belong here

return waitTime, nil
}
25 changes: 25 additions & 0 deletions time/slots/slottime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,3 +607,28 @@ func TestWithinVotingWindow(t *testing.T) {
genesisTime = uint64(time.Now().Add(-40 * time.Second).Unix())
require.Equal(t, false, WithinVotingWindow(genesisTime, 3))
}

func TestSecondsUntilNextEpochStart(t *testing.T) {
secondsInEpoch := uint64(params.BeaconConfig().SlotsPerEpoch) * params.BeaconConfig().SecondsPerSlot
// try slot 3
genesisTime := uint64(time.Now().Add(-39 * time.Second).Unix())
waitTime, err := SecondsUntilNextEpochStart(genesisTime)
require.NoError(t, err)
require.Equal(t, secondsInEpoch-(params.BeaconConfig().SecondsPerSlot*3)-3, waitTime)
// try slot 34
genesisTime = uint64(time.Now().Add(time.Duration(-1*int(secondsInEpoch)-int(params.BeaconConfig().SecondsPerSlot*2)-5) * time.Second).Unix())
waitTime, err = SecondsUntilNextEpochStart(genesisTime)
require.NoError(t, err)
require.Equal(t, secondsInEpoch-(params.BeaconConfig().SecondsPerSlot*2)-5, waitTime)

// check if waitTime is correctly EpochStart
n := time.Now().Add(-39 * time.Second)
genesisTime = uint64(n.Unix())
waitTime, err = SecondsUntilNextEpochStart(genesisTime)
require.NoError(t, err)
require.Equal(t, secondsInEpoch-39, waitTime)
newGenesisTime := uint64(n.Add(time.Duration(-1*int(waitTime)) * time.Second).Unix())
currentSlot := CurrentSlot(newGenesisTime)
require.Equal(t, true, IsEpochStart(currentSlot))

}
2 changes: 0 additions & 2 deletions validator/client/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ go_test(
"//runtime:go_default_library",
"//runtime/version:go_default_library",
"//testing/assert:go_default_library",
"//testing/mock:go_default_library",
"//testing/require:go_default_library",
"//testing/util:go_default_library",
"//testing/validator-mock:go_default_library",
Expand All @@ -169,7 +168,6 @@ go_test(
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
"@com_github_sirupsen_logrus//hooks/test:go_default_library",
"@com_github_stretchr_testify//mock:go_default_library",
"@com_github_tyler_smith_go_bip39//:go_default_library",
"@com_github_urfave_cli_v2//:go_default_library",
"@com_github_wealdtech_go_eth2_util//:go_default_library",
Expand Down
2 changes: 0 additions & 2 deletions validator/client/beacon-api/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ load("@prysm//tools/go:def.bzl", "go_library", "go_test")
go_library(
name = "go_default_library",
srcs = [
"activation.go",
"attestation_data.go",
"beacon_api_beacon_chain_client.go",
"beacon_api_helpers.go",
Expand Down Expand Up @@ -75,7 +74,6 @@ go_test(
name = "go_default_test",
size = "small",
srcs = [
"activation_test.go",
"attestation_data_test.go",
"beacon_api_beacon_chain_client_test.go",
"beacon_api_helpers_test.go",
Expand Down
121 changes: 0 additions & 121 deletions validator/client/beacon-api/activation.go

This file was deleted.

Loading
Loading