Skip to content

Commit

Permalink
synchronizer adopt GetLastL2BlockByBatchNumber to check elderberry ts…
Browse files Browse the repository at this point in the history
…tamp baches (#3340) (#3342)

* synchronizer adopt GetLastL2BlockByBatchNumber to check elderberry bacthes tstamp
  • Loading branch information
joanestebanr authored Feb 26, 2024
1 parent 81ba29f commit f04da66
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 81 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type PreviousProcessor interface {
// StateL1SequenceBatchesElderberry state interface
type StateL1SequenceBatchesElderberry interface {
GetLastVirtualBatchNum(ctx context.Context, dbTx pgx.Tx) (uint64, error)
GetL2BlocksByBatchNumber(ctx context.Context, batchNumber uint64, dbTx pgx.Tx) ([]state.L2Block, error)
GetLastL2BlockByBatchNumber(ctx context.Context, batchNumber uint64, dbTx pgx.Tx) (*state.L2Block, error)
}

// ProcessorL1SequenceBatchesElderberry is the processor for SequenceBatches for Elderberry
Expand Down Expand Up @@ -100,16 +100,15 @@ func (g *ProcessorL1SequenceBatchesElderberry) sanityCheckTstampLastL2Block(time
log.Errorf("Error getting last virtual batch number: %s", err)
return err
}
l2blocks, err := g.state.GetL2BlocksByBatchNumber(context.Background(), lastVirtualBatchNum, dbTx)
lastL2Block, err := g.state.GetLastL2BlockByBatchNumber(context.Background(), lastVirtualBatchNum, dbTx)
if err != nil {
log.Errorf("Error getting last virtual batch number: %s", err)
return err
}
if len(l2blocks) == 0 {
if lastL2Block == nil {
//TODO: find the previous batch until we find a L2 block to check the timestamp
return nil
}
lastL2Block := l2blocks[len(l2blocks)-1]
if uint64(lastL2Block.ReceivedAt.Unix()) > timeLimit {
log.Errorf("The last L2 block timestamp can't be greater than timeLimit. Expected: %d (L1 event), got: %d (last L2Block)", timeLimit, lastL2Block.ReceivedAt.Unix())
return fmt.Errorf("wrong timestamp of last L2 block timestamp with L1 event timestamp")
Expand Down
120 changes: 60 additions & 60 deletions synchronizer/common/syncinterfaces/mocks/state_full_interface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion synchronizer/common/syncinterfaces/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,5 @@ type StateFullInterface interface {
GetL1InfoTreeDataFromBatchL2Data(ctx context.Context, batchL2Data []byte, dbTx pgx.Tx) (map[uint32]state.L1DataV2, common.Hash, common.Hash, error)
GetExitRootByGlobalExitRoot(ctx context.Context, ger common.Hash, dbTx pgx.Tx) (*state.GlobalExitRoot, error)
GetForkIDInMemory(forkId uint64) *state.ForkIDInterval
GetL2BlocksByBatchNumber(ctx context.Context, batchNumber uint64, dbTx pgx.Tx) ([]state.L2Block, error)
GetLastL2BlockByBatchNumber(ctx context.Context, batchNumber uint64, dbTx pgx.Tx) (*state.L2Block, error)
}
2 changes: 1 addition & 1 deletion test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ test-full-non-e2e: stop ## Runs non-e2e tests checking race conditions
sleep 15
docker ps -a
docker logs $(DOCKERCOMPOSEZKPROVER)
trap '$(STOP)' EXIT; MallocNanoZone=0 go test -count=1 -short -race -p 1 -covermode=atomic -coverprofile=../coverage.out -timeout 70s ../...
trap '$(STOP)' EXIT; MallocNanoZone=0 go test -count=1 -short -race -p 1 -covermode=atomic -coverprofile=../coverage.out -coverpkg ./... -timeout 70s ../...

.PHONY: test-e2e-group-1
test-e2e-group-1: stop ## Runs group 1 e2e tests checking race conditions
Expand Down

0 comments on commit f04da66

Please sign in to comment.