Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
countvonzero committed Aug 5, 2023
1 parent 4d8dd30 commit 7ce710c
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 22 deletions.
4 changes: 2 additions & 2 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -863,8 +863,8 @@ func (app *App) initServices(ctx context.Context) error {
fetch.ValidatorFunc(pubsub.DropPeerOnValidationReject(malfeasanceHandler.HandleSyncedMalfeasanceProof, app.host, lg)),
)

syncHandler := func(_ context.Context, _ p2p.Peer, _ []byte) error {
if newSyncer.ListenToGossip() {
syncHandler := func(ctx context.Context, _ p2p.Peer, _ []byte) error {
if newSyncer.IsSynced(ctx) {
return nil
}
return errors.New("not synced for gossip")
Expand Down
6 changes: 0 additions & 6 deletions syncer/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,6 @@ func (s *Syncer) RegisterForATXSynced() chan struct{} {
return s.awaitATXSyncedCh
}

// ListenToGossip returns true if the node is listening to gossip for blocks/TXs data.
func (s *Syncer) ListenToGossip() bool {
return s.getSyncState() == synced
}

// ListenToATXGossip returns true if the node is listening to gossip for ATXs data.
func (s *Syncer) ListenToATXGossip() bool {
return s.getATXSyncState() == synced
Expand Down Expand Up @@ -307,7 +302,6 @@ func (s *Syncer) setSyncerIdle() {
s.isBusy.Store(0)
}

// syncedLayer is used to signal at which layer we can set this node to synced state.
func (s *Syncer) setLayerTurnedSynced(lid types.LayerID) {
s.layerTurnedSynced.Store(lid)
}
Expand Down
15 changes: 1 addition & 14 deletions syncer/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,14 @@ func TestStartAndShutdown(t *testing.T) {

require.False(t, ts.syncer.IsSynced(ctx))
require.False(t, ts.syncer.ListenToATXGossip())
require.False(t, ts.syncer.ListenToGossip())

// the node is synced when current layer is <= 1
ts.syncer.Start()

ts.mForkFinder.EXPECT().Purge(false).AnyTimes()
ts.mDataFetcher.EXPECT().PollLayerOpinions(gomock.Any(), gomock.Any()).AnyTimes()
require.Eventually(t, func() bool {
return ts.syncer.ListenToATXGossip() && ts.syncer.ListenToGossip() && ts.syncer.IsSynced(ctx)
return ts.syncer.ListenToATXGossip() && ts.syncer.IsSynced(ctx)
}, time.Second, 10*time.Millisecond)

cancel()
Expand Down Expand Up @@ -206,7 +205,6 @@ func TestSynchronize_AllGood(t *testing.T) {
require.Equal(t, current.GetEpoch(), ts.syncer.lastAtxEpoch())
require.True(t, ts.syncer.dataSynced())
require.True(t, ts.syncer.ListenToATXGossip())
require.True(t, ts.syncer.ListenToGossip())
require.True(t, ts.syncer.IsSynced(context.Background()))

wg.Add(1)
Expand Down Expand Up @@ -238,7 +236,6 @@ func TestSynchronize_FetchLayerDataFailed(t *testing.T) {
require.Equal(t, current.GetEpoch(), ts.syncer.lastAtxEpoch())
require.False(t, ts.syncer.dataSynced())
require.True(t, ts.syncer.ListenToATXGossip())
require.False(t, ts.syncer.ListenToGossip())
require.False(t, ts.syncer.IsSynced(context.Background()))
}

Expand Down Expand Up @@ -283,7 +280,6 @@ func TestSynchronize_FailedInitialATXsSync(t *testing.T) {
require.Equal(t, failedEpoch-1, ts.syncer.lastAtxEpoch())
require.False(t, ts.syncer.dataSynced())
require.False(t, ts.syncer.ListenToATXGossip())
require.False(t, ts.syncer.ListenToGossip())
require.False(t, ts.syncer.IsSynced(context.Background()))

wg.Add(1)
Expand All @@ -307,7 +303,6 @@ func startWithSyncedState(t *testing.T, ts *testSyncer) types.LayerID {
ts.mDataFetcher.EXPECT().GetEpochATXs(gomock.Any(), gLayer.GetEpoch())
require.True(t, ts.syncer.synchronize(context.Background()))
require.True(t, ts.syncer.ListenToATXGossip())
require.True(t, ts.syncer.ListenToGossip())
require.True(t, ts.syncer.IsSynced(context.Background()))

current := gLayer.Add(2)
Expand All @@ -317,7 +312,6 @@ func startWithSyncedState(t *testing.T, ts *testSyncer) types.LayerID {

require.True(t, ts.syncer.synchronize(context.Background()))
require.True(t, ts.syncer.ListenToATXGossip())
require.True(t, ts.syncer.ListenToGossip())
require.True(t, ts.syncer.IsSynced(context.Background()))
return current
}
Expand Down Expand Up @@ -406,7 +400,6 @@ func TestSynchronize_StaySyncedUponFailure(t *testing.T) {
require.False(t, ts.syncer.synchronize(context.Background()))
require.False(t, ts.syncer.dataSynced())
require.True(t, ts.syncer.ListenToATXGossip())
require.True(t, ts.syncer.ListenToGossip())
require.True(t, ts.syncer.IsSynced(context.Background()))
}

Expand All @@ -420,7 +413,6 @@ func TestSynchronize_BecomeNotSyncedUponFailureIfNoGossip(t *testing.T) {
require.False(t, ts.syncer.synchronize(context.Background()))
require.False(t, ts.syncer.dataSynced())
require.True(t, ts.syncer.ListenToATXGossip())
require.False(t, ts.syncer.ListenToGossip())
require.False(t, ts.syncer.IsSynced(context.Background()))
}

Expand All @@ -437,7 +429,6 @@ func TestFromNotSyncedToSynced(t *testing.T) {
require.False(t, ts.syncer.synchronize(context.Background()))
require.False(t, ts.syncer.dataSynced())
require.True(t, ts.syncer.ListenToATXGossip())
require.False(t, ts.syncer.ListenToGossip())
require.False(t, ts.syncer.IsSynced(context.Background()))

for lid := lyr; lid <= current; lid++ {
Expand All @@ -446,7 +437,6 @@ func TestFromNotSyncedToSynced(t *testing.T) {
require.True(t, ts.syncer.synchronize(context.Background()))
require.True(t, ts.syncer.dataSynced())
require.True(t, ts.syncer.ListenToATXGossip())
require.True(t, ts.syncer.ListenToGossip())
require.True(t, ts.syncer.IsSynced(context.Background()))
}

Expand All @@ -462,7 +452,6 @@ func TestNetworkHasNoData(t *testing.T) {
require.True(t, ts.syncer.synchronize(context.Background()))
require.True(t, ts.syncer.dataSynced())
require.True(t, ts.syncer.ListenToATXGossip())
require.True(t, ts.syncer.ListenToGossip())
require.True(t, ts.syncer.IsSynced(context.Background()))
}
// the network hasn't received any data
Expand All @@ -488,7 +477,6 @@ func TestFromSyncedToNotSynced(t *testing.T) {
require.False(t, ts.syncer.synchronize(context.Background()))
require.False(t, ts.syncer.dataSynced())
require.True(t, ts.syncer.ListenToATXGossip())
require.False(t, ts.syncer.ListenToGossip())
require.False(t, ts.syncer.IsSynced(context.Background()))

for lid := lyr; lid <= current; lid++ {
Expand All @@ -497,7 +485,6 @@ func TestFromSyncedToNotSynced(t *testing.T) {
require.True(t, ts.syncer.synchronize(context.Background()))
require.True(t, ts.syncer.dataSynced())
require.True(t, ts.syncer.ListenToATXGossip())
require.True(t, ts.syncer.ListenToGossip())
require.True(t, ts.syncer.IsSynced(context.Background()))
}

Expand Down

0 comments on commit 7ce710c

Please sign in to comment.