diff --git a/Makefile b/Makefile index cd8870c243..1978eafb90 100644 --- a/Makefile +++ b/Makefile @@ -74,18 +74,23 @@ build-docker-nc: ## Builds a docker image with the node binary - but without bui .PHONY: test test: compile-scs ## Runs only short tests without checking race conditions $(STOPDB) + $(STOPZKPROVER) $(RUNDB); sleep 5 - trap '$(STOPDB)' EXIT; go test -short -race -p 1 ./... + $(RUNZKPROVER); sleep 5 + trap '$(STOPDB) && $(STOPZKPROVER)' EXIT; go test -short -race -p 1 ./... .PHONY: test-full test-full: build-docker compile-scs ## Runs all tests checking race conditions $(STOPDB) + $(STOPZKPROVER) $(RUNDB); sleep 7 - trap '$(STOPDB)' EXIT; MallocNanoZone=0 go test -race -p 1 -timeout 1200s `go list ./... | grep -v \/ci\/e2e-group` + $(RUNZKPROVER); sleep 5 + trap '$(STOPDB) && $(STOPZKPROVER)' EXIT; MallocNanoZone=0 go test -race -p 1 -timeout 1200s `go list ./... | grep -v \/ci\/e2e-group` .PHONY: test-full-non-e2e test-full-non-e2e: build-docker compile-scs ## Runs non-e2e tests checking race conditions $(STOPDB) + $(STOPZKPROVER) $(RUNDB); sleep 7 $(RUNZKPROVER) sleep 5 @@ -194,6 +199,8 @@ run: compile-scs ## Runs all the services $(RUNEXPLORERDB) $(RUNL1NETWORK) sleep 5 + $(RUNZKPROVER) + sleep 5 $(RUNPROVER) sleep 2 $(RUNSEQUENCER) diff --git a/cmd/run.go b/cmd/run.go index 53973afbd2..b49e8b03f2 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -136,7 +136,13 @@ func newEtherman(c config.Config) (*etherman.Client, error) { } func runSynchronizer(networkConfig config.NetworkConfig, etherman *etherman.Client, st *state.State, cfg synchronizer.Config, reorgBlockNumChan chan struct{}) { - sy, err := synchronizer.NewSynchronizer(etherman, st, networkConfig.GenBlockNumber, reorgBlockNumChan, cfg) + genesis := state.Genesis{ + Balances: networkConfig.Genesis.Balances, + SmartContracts: networkConfig.Genesis.SmartContracts, + Storage: networkConfig.Genesis.Storage, + Nonces: networkConfig.Genesis.Nonces, + } + sy, err := synchronizer.NewSynchronizer(etherman, st, networkConfig.GenBlockNumber, genesis, reorgBlockNumChan, cfg) if err != nil { log.Fatal(err) } diff --git a/config/config.local.toml b/config/config.local.toml index 6a9421378b..199b10bb9a 100644 --- a/config/config.local.toml +++ b/config/config.local.toml @@ -54,10 +54,10 @@ Port = 50060 StoreBackend = "PostgreSQL" [MTClient] -URI = "127.0.0.1:50060" +URI = "zkevm-prover:50061" [Executor] -URI = "127.0.0.1:50071" +URI = "zkevm-prover:50071" [BroadcastServer] Host = "0.0.0.0" diff --git a/docker-compose.yml b/docker-compose.yml index 114f2d7ce1..58179a40ec 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -177,7 +177,7 @@ services: zkevm-prover: container_name: zkevm-prover - image: hermeznetwork/zkprover-local@sha256:e9d6696c3a8e0a3f0950930dd8d6111473e9cd22769346a70110d70ec37eb783 + image: hermeznetwork/zkprover-local@sha256:99a2d26fe83e23cc26d7f5bab49852e5e4eb6b5dce2abbcbb8e0f55d4ddb77a4 ports: # - 50051:50051 # Uncoment once the prover integration is ready, and enable the mock in the config file (and remove the zkevm-mock-prover) - 50061:50061 diff --git a/state/state.go b/state/state.go index ca87f2ea82..2849baeb50 100644 --- a/state/state.go +++ b/state/state.go @@ -644,7 +644,7 @@ func (s *State) SetGenesis(ctx context.Context, genesis Genesis, dbTx pgx.Tx) er BatchNumber: 0, Coinbase: ZeroAddress, BatchL2Data: nil, - StateRoot: ZeroHash, + StateRoot: root, LocalExitRoot: ZeroHash, Timestamp: receivedAt, Transactions: []types.Transaction{}, diff --git a/synchronizer/interfaces.go b/synchronizer/interfaces.go index 2482d4a205..db1560b6bb 100644 --- a/synchronizer/interfaces.go +++ b/synchronizer/interfaces.go @@ -35,8 +35,8 @@ type stateInterface interface { GetNextForcedBatches(ctx context.Context, nextForcedBatches int, dbTx pgx.Tx) ([]state.ForcedBatch, error) AddBatchNumberInForcedBatch(ctx context.Context, forceBatchNumber, batchNumber uint64, dbTx pgx.Tx) error AddVerifiedBatch(ctx context.Context, verifiedBatch *state.VerifiedBatch, dbTx pgx.Tx) error - ProcessAndStoreClosedBatch(ctx context.Context, processingCtx state.ProcessingContext, encodedTxs []byte, dbTx pgx.Tx) error + SetGenesis(ctx context.Context, genesis state.Genesis, dbTx pgx.Tx) error BeginStateTransaction(ctx context.Context) (pgx.Tx, error) RollbackStateTransaction(ctx context.Context, dbTx pgx.Tx) error diff --git a/synchronizer/synchronizer.go b/synchronizer/synchronizer.go index 950268c0f5..93d4febf07 100644 --- a/synchronizer/synchronizer.go +++ b/synchronizer/synchronizer.go @@ -28,6 +28,7 @@ type ClientSynchronizer struct { ctx context.Context cancelCtx context.CancelFunc genBlockNumber uint64 + genesis state.Genesis reorgBlockNumChan chan struct{} cfg Config } @@ -37,15 +38,18 @@ func NewSynchronizer( ethMan ethermanInterface, st stateInterface, genBlockNumber uint64, + genesis state.Genesis, reorgBlockNumChan chan struct{}, cfg Config) (Synchronizer, error) { ctx, cancel := context.WithCancel(context.Background()) + return &ClientSynchronizer{ state: st, etherMan: ethMan, ctx: ctx, cancelCtx: cancel, genBlockNumber: genBlockNumber, + genesis: genesis, reorgBlockNumChan: reorgBlockNumChan, cfg: cfg, }, nil @@ -66,13 +70,16 @@ func (s *ClientSynchronizer) Sync() error { lastEthBlockSynced, err := s.state.GetLastBlock(s.ctx, dbTx) if err != nil { if err == state.ErrStateNotSynchronized { - log.Warn("error getting the latest ethereum block. No data stored. Setting genesis block. Error: ", err) + log.Info("State is empty, setting genesis block") lastEthBlockSynced = &state.Block{ BlockNumber: s.genBlockNumber, } - // TODO Set Genesis if needed + err := s.state.SetGenesis(s.ctx, s.genesis, dbTx) + if err != nil { + log.Fatal("error setting genesis: ", err) + } } else { - log.Fatal("unexpected error getting the latest ethereum block. Setting genesis block. Error: ", err) + log.Fatal("unexpected error getting the latest ethereum block. Error: ", err) } } else if lastEthBlockSynced.BlockNumber == 0 { lastEthBlockSynced = &state.Block{