From 15fd3945ddbb98ac2417ee73e71cdd6106dcfbf5 Mon Sep 17 00:00:00 2001 From: arnaucube Date: Thu, 25 Feb 2021 16:52:07 +0100 Subject: [PATCH] Update synchronizer.Sync2 to Sync from legacy impl --- coordinator/coordinator_test.go | 2 +- coordinator/pipeline_test.go | 2 +- node/node.go | 2 +- synchronizer/synchronizer.go | 4 ++-- synchronizer/synchronizer_test.go | 20 ++++++++++---------- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/coordinator/coordinator_test.go b/coordinator/coordinator_test.go index c5d4e9c..eb68e94 100644 --- a/coordinator/coordinator_test.go +++ b/coordinator/coordinator_test.go @@ -517,7 +517,7 @@ func TestCoordinatorStress(t *testing.T) { wg.Add(1) go func() { for { - blockData, _, err := syn.Sync2(ctx, nil) + blockData, _, err := syn.Sync(ctx, nil) if ctx.Err() != nil { wg.Done() return diff --git a/coordinator/pipeline_test.go b/coordinator/pipeline_test.go index 454c446..8bb228b 100644 --- a/coordinator/pipeline_test.go +++ b/coordinator/pipeline_test.go @@ -148,7 +148,7 @@ func preloadSync(t *testing.T, ethClient *test.Client, sync *synchronizer.Synchr ctx := context.Background() for { - syncBlock, discards, err := sync.Sync2(ctx, nil) + syncBlock, discards, err := sync.Sync(ctx, nil) require.NoError(t, err) require.Nil(t, discards) if syncBlock == nil { diff --git a/node/node.go b/node/node.go index cc9069e..664649d 100644 --- a/node/node.go +++ b/node/node.go @@ -552,7 +552,7 @@ func (n *Node) handleReorg(ctx context.Context, stats *synchronizer.Stats, vars // TODO(Edu): Consider keeping the `lastBlock` inside synchronizer so that we // don't have to pass it around. func (n *Node) syncLoopFn(ctx context.Context, lastBlock *common.Block) (*common.Block, time.Duration, error) { - blockData, discarded, err := n.sync.Sync2(ctx, lastBlock) + blockData, discarded, err := n.sync.Sync(ctx, lastBlock) stats := n.sync.Stats() if err != nil { // case: error diff --git a/synchronizer/synchronizer.go b/synchronizer/synchronizer.go index 4dc872c..514a5ec 100644 --- a/synchronizer/synchronizer.go +++ b/synchronizer/synchronizer.go @@ -503,13 +503,13 @@ func (s *Synchronizer) resetIntermediateState() error { return nil } -// Sync2 attems to synchronize an ethereum block starting from lastSavedBlock. +// Sync attems to synchronize an ethereum block starting from lastSavedBlock. // If lastSavedBlock is nil, the lastSavedBlock value is obtained from de DB. // If a block is synched, it will be returned and also stored in the DB. If a // reorg is detected, the number of discarded blocks will be returned and no // synchronization will be made. // TODO: Be smart about locking: only lock during the read/write operations -func (s *Synchronizer) Sync2(ctx context.Context, +func (s *Synchronizer) Sync(ctx context.Context, lastSavedBlock *common.Block) (blockData *common.BlockData, discarded *int64, err error) { if s.resetStateFailed { if err := s.resetIntermediateState(); err != nil { diff --git a/synchronizer/synchronizer_test.go b/synchronizer/synchronizer_test.go index aa1dcb4..ed8ce7b 100644 --- a/synchronizer/synchronizer_test.go +++ b/synchronizer/synchronizer_test.go @@ -359,7 +359,7 @@ func TestSyncGeneral(t *testing.T) { assert.Equal(t, false, stats.Synced()) // Test Sync for rollup genesis block - syncBlock, discards, err := s.Sync2(ctx, nil) + syncBlock, discards, err := s.Sync(ctx, nil) require.NoError(t, err) require.Nil(t, discards) require.NotNil(t, syncBlock) @@ -382,7 +382,7 @@ func TestSyncGeneral(t *testing.T) { assert.Equal(t, int64(1), dbBlocks[1].Num) // Sync again and expect no new blocks - syncBlock, discards, err = s.Sync2(ctx, nil) + syncBlock, discards, err = s.Sync(ctx, nil) require.NoError(t, err) require.Nil(t, discards) require.Nil(t, syncBlock) @@ -479,7 +479,7 @@ func TestSyncGeneral(t *testing.T) { // Block 2 - syncBlock, discards, err = s.Sync2(ctx, nil) + syncBlock, discards, err = s.Sync(ctx, nil) require.NoError(t, err) require.Nil(t, discards) require.NotNil(t, syncBlock) @@ -496,7 +496,7 @@ func TestSyncGeneral(t *testing.T) { // Block 3 - syncBlock, discards, err = s.Sync2(ctx, nil) + syncBlock, discards, err = s.Sync(ctx, nil) assert.NoError(t, err) require.NoError(t, err) require.Nil(t, discards) @@ -520,7 +520,7 @@ func TestSyncGeneral(t *testing.T) { require.NoError(t, err) client.CtlMineBlock() - syncBlock, discards, err = s.Sync2(ctx, nil) + syncBlock, discards, err = s.Sync(ctx, nil) require.NoError(t, err) require.Nil(t, discards) require.NotNil(t, syncBlock) @@ -571,7 +571,7 @@ func TestSyncGeneral(t *testing.T) { client.CtlMineBlock() - syncBlock, discards, err = s.Sync2(ctx, nil) + syncBlock, discards, err = s.Sync(ctx, nil) require.NoError(t, err) require.Nil(t, discards) require.NotNil(t, syncBlock) @@ -656,7 +656,7 @@ func TestSyncGeneral(t *testing.T) { require.NoError(t, err) // First sync detects the reorg and discards 4 blocks - syncBlock, discards, err = s.Sync2(ctx, nil) + syncBlock, discards, err = s.Sync(ctx, nil) require.NoError(t, err) expetedDiscards := int64(4) require.Equal(t, &expetedDiscards, discards) @@ -684,7 +684,7 @@ func TestSyncGeneral(t *testing.T) { // Sync blocks 2-6 for i := 0; i < 5; i++ { - syncBlock, discards, err = s.Sync2(ctx, nil) + syncBlock, discards, err = s.Sync(ctx, nil) require.NoError(t, err) require.Nil(t, discards) require.NotNil(t, syncBlock) @@ -807,7 +807,7 @@ func TestSyncForgerCommitment(t *testing.T) { // be in sync for { - syncBlock, discards, err := s.Sync2(ctx, nil) + syncBlock, discards, err := s.Sync(ctx, nil) require.NoError(t, err) require.Nil(t, discards) if syncBlock == nil { @@ -826,7 +826,7 @@ func TestSyncForgerCommitment(t *testing.T) { err = client.CtlAddBlocks([]common.BlockData{block}) require.NoError(t, err) - syncBlock, discards, err := s.Sync2(ctx, nil) + syncBlock, discards, err := s.Sync(ctx, nil) require.NoError(t, err) require.Nil(t, discards) if syncBlock == nil {