Skip to content

Commit

Permalink
Remove WaitForSynced (#7835)
Browse files Browse the repository at this point in the history
* Remove waitforsynced

* Remove WaitForsynced entirely

* Fix bazel

* tidy
  • Loading branch information
0xKiwi committed Nov 17, 2020
1 parent 7449eba commit 5889670
Show file tree
Hide file tree
Showing 17 changed files with 24 additions and 599 deletions.
2 changes: 1 addition & 1 deletion beacon-chain/rpc/beaconv1/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (bs *Server) ListValidators(ctx context.Context, req *ethpb.StateValidators
}

// ListValidatorBalances returns a filterable list of validator balances.
func (bs *Server) ListValidatorBalances(ctx context.Context, req *ethpb.StateValidatorsRequest) (*ethpb.ValidatorBalancesResponse, error) {
func (bs *Server) ListValidatorBalances(ctx context.Context, req *ethpb.ValidatorBalancesRequest) (*ethpb.ValidatorBalancesResponse, error) {
return nil, errors.New("unimplemented")
}

Expand Down
42 changes: 0 additions & 42 deletions beacon-chain/rpc/validator/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,45 +209,3 @@ func (vs *Server) WaitForChainStart(_ *ptypes.Empty, stream ethpb.BeaconNodeVali
}
}
}

// WaitForSynced subscribes to the state channel and ends the stream when the state channel
// indicates the beacon node has been initialized and is ready
func (vs *Server) WaitForSynced(_ *ptypes.Empty, stream ethpb.BeaconNodeValidator_WaitForSyncedServer) error {
head, err := vs.HeadFetcher.HeadState(stream.Context())
if err != nil {
return status.Errorf(codes.Internal, "Could not retrieve head state: %v", err)
}
if head != nil && !vs.SyncChecker.Syncing() {
res := &ethpb.SyncedResponse{
Synced: true,
GenesisTime: head.GenesisTime(),
}
return stream.Send(res)
}

stateChannel := make(chan *feed.Event, 1)
stateSub := vs.StateNotifier.StateFeed().Subscribe(stateChannel)
defer stateSub.Unsubscribe()
for {
select {
case event := <-stateChannel:
if event.Type == statefeed.Synced {
data, ok := event.Data.(*statefeed.SyncedData)
if !ok {
return errors.New("event data is not type *statefeed.SyncedData")
}
log.WithField("starttime", data.StartTime).Debug("Received sync completed event")
log.Debug("Sending genesis time notification to connected validator clients")
res := &ethpb.SyncedResponse{
Synced: true,
GenesisTime: uint64(data.StartTime.Unix()),
}
return stream.Send(res)
}
case <-stateSub.Err():
return status.Error(codes.Aborted, "Subscriber closed, exiting goroutine")
case <-vs.Ctx.Done():
return status.Error(codes.Canceled, "Context canceled")
}
}
}
106 changes: 0 additions & 106 deletions beacon-chain/rpc/validator/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
dbutil "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
mockPOW "github.com/prysmaticlabs/prysm/beacon-chain/powchain/testing"
stateTrie "github.com/prysmaticlabs/prysm/beacon-chain/state"
mockSync "github.com/prysmaticlabs/prysm/beacon-chain/sync/initial-sync/testing"
pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/bls"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
Expand Down Expand Up @@ -427,108 +426,3 @@ func TestWaitForChainStart_NotStartedThenLogFired(t *testing.T) {
exitRoutine <- true
require.LogsContain(t, hook, "Sending genesis time")
}

func TestWaitForSynced_ContextClosed(t *testing.T) {
db, _ := dbutil.SetupDB(t)
ctx, cancel := context.WithCancel(context.Background())
chainService := &mockChain.ChainService{}
Server := &Server{
Ctx: ctx,
ChainStartFetcher: &mockPOW.FaultyMockPOWChain{
ChainFeed: new(event.Feed),
},
StateNotifier: chainService.StateNotifier(),
BeaconDB: db,
HeadFetcher: chainService,
}

exitRoutine := make(chan bool)
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockStream := mock.NewMockBeaconNodeValidator_WaitForSyncedServer(ctrl)
mockStream.EXPECT().Context().Return(context.Background())
go func(tt *testing.T) {
err := Server.WaitForSynced(&ptypes.Empty{}, mockStream)
assert.ErrorContains(tt, "Context canceled", err)
<-exitRoutine
}(t)
cancel()
exitRoutine <- true
}

func TestWaitForSynced_AlreadySynced(t *testing.T) {
db, _ := dbutil.SetupDB(t)
ctx := context.Background()
headBlockRoot := [32]byte{0x01, 0x02}
trie := testutil.NewBeaconState()
require.NoError(t, trie.SetSlot(3))
require.NoError(t, db.SaveState(ctx, trie, headBlockRoot))
require.NoError(t, db.SaveHeadBlockRoot(ctx, headBlockRoot))

chainService := &mockChain.ChainService{State: trie}
Server := &Server{
Ctx: context.Background(),
ChainStartFetcher: &mockPOW.POWChain{
ChainFeed: new(event.Feed),
},
BeaconDB: db,
StateNotifier: chainService.StateNotifier(),
HeadFetcher: chainService,
SyncChecker: &mockSync.Sync{IsSyncing: false},
}
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockStream := mock.NewMockBeaconNodeValidator_WaitForSyncedServer(ctrl)
mockStream.EXPECT().Send(
&ethpb.SyncedResponse{
Synced: true,
GenesisTime: uint64(time.Unix(0, 0).Unix()),
},
).Return(nil)
mockStream.EXPECT().Context().Return(context.Background())
assert.NoError(t, Server.WaitForSynced(&ptypes.Empty{}, mockStream), "Could not call RPC method")
}

func TestWaitForSynced_NotStartedThenLogFired(t *testing.T) {
db, _ := dbutil.SetupDB(t)

hook := logTest.NewGlobal()
chainService := &mockChain.ChainService{}
Server := &Server{
Ctx: context.Background(),
ChainStartFetcher: &mockPOW.FaultyMockPOWChain{
ChainFeed: new(event.Feed),
},
BeaconDB: db,
StateNotifier: chainService.StateNotifier(),
HeadFetcher: chainService,
}
exitRoutine := make(chan bool)
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockStream := mock.NewMockBeaconNodeValidator_WaitForSyncedServer(ctrl)
mockStream.EXPECT().Send(
&ethpb.SyncedResponse{
Synced: true,
GenesisTime: uint64(time.Unix(0, 0).Unix()),
},
).Return(nil)
mockStream.EXPECT().Context().Return(context.Background())
go func(tt *testing.T) {
assert.NoError(tt, Server.WaitForSynced(&ptypes.Empty{}, mockStream), "Could not call RPC method")
<-exitRoutine
}(t)

// Send in a loop to ensure it is delivered (busy wait for the service to subscribe to the state feed).
for sent := 0; sent == 0; {
sent = Server.StateNotifier.StateFeed().Send(&feed.Event{
Type: statefeed.Synced,
Data: &statefeed.SyncedData{
StartTime: time.Unix(0, 0),
},
})
}

exitRoutine <- true
require.LogsContain(t, hook, "Sending genesis time")
}
4 changes: 2 additions & 2 deletions deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2190,8 +2190,8 @@ def prysm_deps():
name = "com_github_prysmaticlabs_ethereumapis",
build_file_generation = "off",
importpath = "github.com/prysmaticlabs/ethereumapis",
sum = "h1:dGeuKeaXxCepTbwsz7kYSfP1yazw1uRMn58CqNCcPP4=",
version = "v0.0.0-20201003171600-a72e5f77d233",
sum = "h1:bvsgNf1mHXFN5M+BYXqnWvceQkibz28Qo/x/jOs6wGc=",
version = "v0.0.0-20201116210408-3e6658264073",
)
go_repository(
name = "com_github_prysmaticlabs_go_bitfield",
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ require (
github.com/prometheus/client_golang v1.7.1
github.com/prometheus/tsdb v0.10.0 // indirect
github.com/protolambda/zssz v0.1.5
github.com/prysmaticlabs/ethereumapis v0.0.0-20201003171600-a72e5f77d233
github.com/prysmaticlabs/ethereumapis v0.0.0-20201116210408-3e6658264073
github.com/prysmaticlabs/go-bitfield v0.0.0-20200618145306-2ae0807bef65
github.com/prysmaticlabs/go-ssz v0.0.0-20200612203617-6d5c9aa213ae
github.com/prysmaticlabs/prombbolt v0.0.0-20200324184628-09789ef63796
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -967,8 +967,8 @@ github.com/protolambda/zssz v0.1.5 h1:7fjJjissZIIaa2QcvmhS/pZISMX21zVITt49sW1oue
github.com/protolambda/zssz v0.1.5/go.mod h1:a4iwOX5FE7/JkKA+J/PH0Mjo9oXftN6P8NZyL28gpag=
github.com/prysmaticlabs/bazel-go-ethereum v0.0.0-20201116135122-233538bfc3d8 h1:Fc6JMvJBFAAdI07o//gNgT5MiCCScpe1u/KM1A6MDGo=
github.com/prysmaticlabs/bazel-go-ethereum v0.0.0-20201116135122-233538bfc3d8/go.mod h1:JIfVb6esrqALTExdz9hRYvrP0xBDf6wCncIu1hNwHpM=
github.com/prysmaticlabs/ethereumapis v0.0.0-20201003171600-a72e5f77d233 h1:dGeuKeaXxCepTbwsz7kYSfP1yazw1uRMn58CqNCcPP4=
github.com/prysmaticlabs/ethereumapis v0.0.0-20201003171600-a72e5f77d233/go.mod h1:k7b2dxy6RppCG6kmOJkNOXzRpEoTdsPygc2aQhsUsZk=
github.com/prysmaticlabs/ethereumapis v0.0.0-20201116210408-3e6658264073 h1:bvsgNf1mHXFN5M+BYXqnWvceQkibz28Qo/x/jOs6wGc=
github.com/prysmaticlabs/ethereumapis v0.0.0-20201116210408-3e6658264073/go.mod h1:k7b2dxy6RppCG6kmOJkNOXzRpEoTdsPygc2aQhsUsZk=
github.com/prysmaticlabs/go-bitfield v0.0.0-20200322041314-62c2aee71669 h1:cX6YRZnZ9sgMqM5U14llxUiXVNJ3u07Res1IIjTOgtI=
github.com/prysmaticlabs/go-bitfield v0.0.0-20200322041314-62c2aee71669/go.mod h1:hCwmef+4qXWjv0jLDbQdWnL0Ol7cS7/lCSS26WR+u6s=
github.com/prysmaticlabs/go-bitfield v0.0.0-20200618145306-2ae0807bef65 h1:hJfAWrlxx7SKpn4S/h2JGl2HHwA1a2wSS3HAzzZ0F+U=
Expand Down
4 changes: 2 additions & 2 deletions scripts/update-mockgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ mock_path="shared/mock"
mocks=(
"$mock_path/beacon_service_mock.go BeaconChainClient,BeaconChain_StreamChainHeadClient,BeaconChain_StreamAttestationsClient,BeaconChain_StreamBlocksClient,BeaconChain_StreamValidatorsInfoClient,BeaconChain_StreamIndexedAttestationsClient"
"$mock_path/beacon_chain_service_mock.go BeaconChain_StreamChainHeadServer,BeaconChain_StreamAttestationsServer,BeaconChain_StreamBlocksServer,BeaconChain_StreamValidatorsInfoServer,BeaconChain_StreamIndexedAttestationsServer"
"$mock_path/beacon_validator_server_mock.go BeaconNodeValidatorServer,BeaconNodeValidator_WaitForSyncedServer,BeaconNodeValidator_WaitForActivationServer,BeaconNodeValidator_WaitForChainStartServer,BeaconNodeValidator_StreamDutiesServer"
"$mock_path/beacon_validator_client_mock.go BeaconNodeValidatorClient,BeaconNodeValidator_WaitForSyncedClient,BeaconNodeValidator_WaitForChainStartClient,BeaconNodeValidator_WaitForActivationClient,BeaconNodeValidator_StreamDutiesClient"
"$mock_path/beacon_validator_server_mock.go BeaconNodeValidatorServer,BeaconNodeValidator_WaitForActivationServer,BeaconNodeValidator_WaitForChainStartServer,BeaconNodeValidator_StreamDutiesServer"
"$mock_path/beacon_validator_client_mock.go BeaconNodeValidatorClient,BeaconNodeValidator_WaitForChainStartClient,BeaconNodeValidator_WaitForActivationClient,BeaconNodeValidator_StreamDutiesClient"
"$mock_path/node_service_mock.go NodeClient"
"$mock_path/keymanager_mock.go RemoteSignerClient"
)
Expand Down
1 change: 0 additions & 1 deletion shared/featureconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ type Flags struct {
EnableSnappyDBCompression bool // EnableSnappyDBCompression in the database.
SlasherProtection bool // SlasherProtection protects validator fron sending over a slashable offense over the network using external slasher.
EnableNoise bool // EnableNoise enables the beacon node to use NOISE instead of SECIO when performing a handshake with another peer.
WaitForSynced bool // WaitForSynced uses WaitForSynced in validator startup to ensure it can communicate with the beacon node as soon as possible.
EnableEth1DataMajorityVote bool // EnableEth1DataMajorityVote uses the Voting With The Majority algorithm to vote for eth1data.
EnablePeerScorer bool // EnablePeerScorer enables experimental peer scoring in p2p.
EnablePruningDepositProofs bool // EnablePruningDepositProofs enables pruning deposit proofs which significantly reduces the size of a deposit
Expand Down
6 changes: 6 additions & 0 deletions shared/featureconfig/deprecated_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,17 @@ var (
Usage: deprecatedUsage,
Hidden: true,
}
deprecatedWaitForSyncedFlag = &cli.BoolFlag{
Name: "wait-for-synced",
Usage: deprecatedUsage,
Hidden: true,
}
)

var deprecatedFlags = []cli.Flag{
exampleDeprecatedFeatureFlag,
deprecatedEnablePruningDepositProofs,
deprecatedEnableEth1DataMajorityVote,
deprecatedEnableBlst,
deprecatedWaitForSyncedFlag,
}
10 changes: 1 addition & 9 deletions shared/featureconfig/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ var (
Usage: "Enables the validator to connect to external slasher to prevent it from " +
"transmitting a slashable offence over the network.",
}
waitForSyncedFlag = &cli.BoolFlag{
Name: "wait-for-synced",
Usage: "Uses WaitForSynced for validator startup, to ensure a validator is able to communicate with the beacon node as quick as possible",
}
disableLookbackFlag = &cli.BoolFlag{
Name: "disable-lookback",
Usage: "Disables use of the lookback feature and updates attestation history for validators from head to epoch 0",
Expand Down Expand Up @@ -94,7 +90,6 @@ var devModeFlags = []cli.Flag{
// ValidatorFlags contains a list of all the feature flags that apply to the validator client.
var ValidatorFlags = append(deprecatedFlags, []cli.Flag{
enableExternalSlasherProtectionFlag,
waitForSyncedFlag,
ToledoTestnet,
PyrmontTestnet,
Mainnet,
Expand All @@ -111,16 +106,13 @@ var SlasherFlags = append(deprecatedFlags, []cli.Flag{
}...)

// E2EValidatorFlags contains a list of the validator feature flags to be tested in E2E.
var E2EValidatorFlags = []string{
"--wait-for-synced",
}
var E2EValidatorFlags = []string{}

// BeaconChainFlags contains a list of all the feature flags that apply to the beacon-chain client.
var BeaconChainFlags = append(deprecatedFlags, []cli.Flag{
devModeFlag,
writeSSZStateTransitionsFlag,
kafkaBootstrapServersFlag,
waitForSyncedFlag,
disableGRPCConnectionLogging,
attestationAggregationStrategy,
ToledoTestnet,
Expand Down

0 comments on commit 5889670

Please sign in to comment.