Browse Source

Update synchronizer.Sync2 to Sync from legacy impl

feature/serveapicli
arnaucube 3 years ago
parent
commit
15fd3945dd
5 changed files with 15 additions and 15 deletions
  1. +1
    -1
      coordinator/coordinator_test.go
  2. +1
    -1
      coordinator/pipeline_test.go
  3. +1
    -1
      node/node.go
  4. +2
    -2
      synchronizer/synchronizer.go
  5. +10
    -10
      synchronizer/synchronizer_test.go

+ 1
- 1
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

+ 1
- 1
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 {

+ 1
- 1
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

+ 2
- 2
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 {

+ 10
- 10
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 {

Loading…
Cancel
Save