Skip to content

Commit

Permalink
sync set genesis (0xPolygonHermez#888)
Browse files Browse the repository at this point in the history
* add set genesis to synchronization process

* remove zkprover init from make run

* fix makefile, config and batch state root

* Update zkprover image

Co-authored-by: Arnau <[email protected]>
  • Loading branch information
tclemos and arnaubennassar authored Jul 13, 2022
1 parent dc6bde8 commit 5f0fae4
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 11 deletions.
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -194,6 +199,8 @@ run: compile-scs ## Runs all the services
$(RUNEXPLORERDB)
$(RUNL1NETWORK)
sleep 5
$(RUNZKPROVER)
sleep 5
$(RUNPROVER)
sleep 2
$(RUNSEQUENCER)
Expand Down
8 changes: 7 additions & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions config/config.local.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand Down
2 changes: 1 addition & 1 deletion synchronizer/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions synchronizer/synchronizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type ClientSynchronizer struct {
ctx context.Context
cancelCtx context.CancelFunc
genBlockNumber uint64
genesis state.Genesis
reorgBlockNumChan chan struct{}
cfg Config
}
Expand All @@ -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
Expand All @@ -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{
Expand Down

0 comments on commit 5f0fae4

Please sign in to comment.