arnaucube
arnaucube/hermez-nodePublic Self-hosted repository
Merge pull request #587 from hermeznetwork/feature/legacy-sync2

Update synchronizer.Sync2 to Sync from legacy impl
Eduard S eduard@iden3.io
Thu, 25 Feb 2021 17:02:15 +0100
commit

0adcf1a2bc82ea7e6a75a5fb671aa12e911b6786

parent

527cd9a2ccc82111c805202eb86ff581f417fff0

M coordinator/coordinator_test.go → coordinator/coordinator_test.go

@@ -517,7 +517,7 @@ // Synchronizer loop

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
M coordinator/pipeline_test.go → coordinator/pipeline_test.go

@@ -148,7 +148,7 @@ require.NoError(t, err)

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 {
M node/node.go → node/node.go

@@ -558,7 +558,7 @@

// 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
M synchronizer/synchronizer.go → synchronizer/synchronizer.go

@@ -503,13 +503,13 @@ s.resetStateFailed = false

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 {
M synchronizer/synchronizer_test.go → synchronizer/synchronizer_test.go

@@ -359,7 +359,7 @@ stats := s.Stats()

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 @@ assert.Equal(t, 2, len(dbBlocks))

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 @@ //

// 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 @@ checkSyncBlock(t, s, 2, &blocks[0], syncBlock)

// 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 @@ _, err = client.RollupWithdrawMerkleProof(tc.Users["C"].BJJ.Public().Compress(), 1, 3, 258, big.NewInt(50), []*big.Int{}, false)

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 @@ 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)

@@ -656,7 +656,7 @@ err = client.CtlAddBlocks(blocks)

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 @@ assertEqualAccountsHistoryDBStateDB(t, dbAccounts, sdbAccounts)

// 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 @@ // }

// 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 @@ // Add block data to the smart contracts

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 {