Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/deployment #2076

Merged
merged 8 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,13 @@ func start(cliCtx *cli.Context) error {
log.Fatal(err)
}
// Read Fork ID FROM POE SC
forkIDIntervals, err := etherman.GetForks(cliCtx.Context)
if err != nil || len(forkIDIntervals) == 0 {
log.Fatal("error getting forks: ", err)
forkIDIntervals, err := etherman.GetForks(cliCtx.Context, c.NetworkConfig.Genesis.GenesisBlockNum)
if err != nil {
log.Fatal("error getting forks. Please check the configuration. Error: ", err)
} else if len(forkIDIntervals) == 0 {
log.Fatal("error: no forkID received. It should receive at least one, please check the configuration...")
}

currentForkID := forkIDIntervals[len(forkIDIntervals)-1].ForkId

c.Aggregator.ChainID = l2ChainID
Expand Down
2 changes: 1 addition & 1 deletion config/environments/local/local.genesis.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"polygonZkEVMGlobalExitRootAddress": "0x2279B7A0a67DB372996a5FaB50D91eAA73d2eBe6"
},
"root": "0xd88680f1b151dd67518f9aca85161424c0cac61df2f5424a3ddc04ea25adecc7",
"genesisBlockNumber": 74,
"genesisBlockNumber": 65,
"genesis": [
{
"contractName": "PolygonZkEVMDeployer",
Expand Down
1 change: 1 addition & 0 deletions db/scripts/init_prover_db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ CREATE TABLE state.program (hash BYTEA PRIMARY KEY, data BYTEA NOT NULL);

CREATE USER prover_user with password 'prover_pass';
GRANT CONNECT ON DATABASE prover_db TO prover_user;
ALTER USER prover_user SET SEARCH_PATH=state;
GRANT ALL PRIVILEGES ON SCHEMA state TO prover_user;
GRANT ALL PRIVILEGES ON TABLE state.nodes TO prover_user;
GRANT ALL PRIVILEGES ON TABLE state.program TO prover_user;
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ services:
restart: unless-stopped
image: postgres
healthcheck:
test: [ "CMD-SHELL", "pg_isready" ]
test: ["CMD-SHELL", "pg_isready -d $${POSTGRES_DB} -U $${POSTGRES_USER}"]
interval: 10s
timeout: 5s
retries: 5
Expand All @@ -85,7 +85,7 @@ services:
restart: unless-stopped
image: postgres
healthcheck:
test: [ "CMD-SHELL", "pg_isready" ]
test: ["CMD-SHELL", "pg_isready -d $${POSTGRES_DB} -U $${POSTGRES_USER}"]
interval: 10s
timeout: 5s
retries: 5
Expand Down
2 changes: 1 addition & 1 deletion docs/production-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ If everything has gone as expected you should be able to run queries to the JSON
## Stop

```bash
sudo docker compose --env-file $ZKEVM_CONFIG_DIR/.env -f $ZKEVM_DIR/$ZKEVM_NET/docker-compose.yml down
docker compose --env-file $ZKEVM_CONFIG_DIR/.env -f $ZKEVM_DIR/$ZKEVM_NET/docker-compose.yml down
```

## Updating
Expand Down
38 changes: 19 additions & 19 deletions etherman/etherman.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package etherman

import (
"context"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -192,38 +191,39 @@ func NewClient(cfg Config, l1Config L1Config) (*Client, error) {

// VerifyGenBlockNumber verifies if the genesis Block Number is valid
func (etherMan *Client) VerifyGenBlockNumber(ctx context.Context, genBlockNumber uint64) (bool, error) {
genBlock := big.NewInt(0).SetUint64(genBlockNumber)
response, err := etherMan.EthClient.CodeAt(ctx, etherMan.l1Cfg.ZkEVMAddr, genBlock)
log.Info("Verifying genesis blockNumber: ", genBlockNumber)
// Filter query
genBlock := new(big.Int).SetUint64(genBlockNumber)
query := ethereum.FilterQuery{
FromBlock: genBlock,
ToBlock: genBlock,
Addresses: etherMan.SCAddresses,
Topics: [][]common.Hash{{updateZkEVMVersionSignatureHash}},
}
logs, err := etherMan.EthClient.FilterLogs(ctx, query)
if err != nil {
log.Error("error getting smc code for gen block number. Error: ", err)
return false, err
}
responseString := hex.EncodeToString(response)
if responseString == "" {
return false, nil
if len(logs) == 0 {
return false, fmt.Errorf("the specified genBlockNumber in config file does not contain any forkID event. Please use the proper blockNumber.")
}
responsePrev, err := etherMan.EthClient.CodeAt(ctx, etherMan.l1Cfg.ZkEVMAddr, genBlock.Sub(genBlock, big.NewInt(1)))
zkevmVersion, err := etherMan.ZkEVM.ParseUpdateZkEVMVersion(logs[0])
if err != nil {
if parsedErr, ok := tryParseError(err); ok {
if errors.Is(parsedErr, ErrMissingTrieNode) {
return true, nil
}
}
log.Error("error getting smc code for gen block number. Error: ", err)
log.Error("error parsing the forkID event")
return false, err
}
responsePrevString := hex.EncodeToString(responsePrev)
if responsePrevString != "" {
return false, nil
if zkevmVersion.NumBatch != 0 {
return false, fmt.Errorf("the specified genBlockNumber in config file does not contain the initial forkID event (BatchNum: %d). Please use the proper blockNumber.", zkevmVersion.NumBatch)
}
return true, nil
}

// GetForks returns fork information
func (etherMan *Client) GetForks(ctx context.Context) ([]state.ForkIDInterval, error) {
func (etherMan *Client) GetForks(ctx context.Context, genBlockNumber uint64) ([]state.ForkIDInterval, error) {
log.Debug("Getting forkIDs from blockNumber: ", genBlockNumber)
// Filter query
query := ethereum.FilterQuery{
FromBlock: new(big.Int).SetUint64(1),
FromBlock: new(big.Int).SetUint64(genBlockNumber),
Addresses: etherMan.SCAddresses,
Topics: [][]common.Hash{{updateZkEVMVersionSignatureHash}},
}
Expand Down
2 changes: 1 addition & 1 deletion etherman/etherman_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ func TestGetForks(t *testing.T) {
// Set up testing environment
etherman, _, _, _, _ := newTestingEnv()
ctx := context.Background()
forks, err := etherman.GetForks(ctx)
forks, err := etherman.GetForks(ctx, 0)
require.NoError(t, err)
assert.Equal(t, 1, len(forks))
assert.Equal(t, uint64(1), forks[0].ForkId)
Expand Down
2 changes: 1 addition & 1 deletion synchronizer/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type ethermanInterface interface {
GetLatestBatchNumber() (uint64, error)
GetTrustedSequencerURL() (string, error)
VerifyGenBlockNumber(ctx context.Context, genBlockNumber uint64) (bool, error)
GetForks(ctx context.Context) ([]state.ForkIDInterval, error)
GetForks(ctx context.Context, genBlockNumber uint64) ([]state.ForkIDInterval, error)
GetLatestVerifiedBatchNum() (uint64, error)
}

Expand Down
18 changes: 9 additions & 9 deletions synchronizer/mock_etherman.go

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

4 changes: 2 additions & 2 deletions synchronizer/synchronizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ func (s *ClientSynchronizer) processForkID(forkID etherman.ForkID, blockNumber u
}
if latestBatchNumber < forkID.BatchNumber { //If the forkID will start in a future batch
// Read Fork ID FROM POE SC
forkIDIntervals, err := s.etherMan.GetForks(s.ctx)
forkIDIntervals, err := s.etherMan.GetForks(s.ctx, s.genesis.GenesisBlockNum)
if err != nil || len(forkIDIntervals) == 0 {
log.Error("error getting all forkIDs: ", err)
rollbackErr := dbTx.Rollback(s.ctx)
Expand Down Expand Up @@ -664,7 +664,7 @@ func (s *ClientSynchronizer) processForkID(forkID etherman.ForkID, blockNumber u
}

// Read Fork ID FROM POE SC
forkIDIntervals, err := s.etherMan.GetForks(s.ctx)
forkIDIntervals, err := s.etherMan.GetForks(s.ctx, s.genesis.GenesisBlockNum)
if err != nil || len(forkIDIntervals) == 0 {
log.Error("error getting all forkIDs: ", err)
rollbackErr := dbTx.Rollback(s.ctx)
Expand Down
2 changes: 1 addition & 1 deletion test/config/test.genesis.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"polygonZkEVMGlobalExitRootAddress": "0x2279B7A0a67DB372996a5FaB50D91eAA73d2eBe6"
},
"root": "0xd88680f1b151dd67518f9aca85161424c0cac61df2f5424a3ddc04ea25adecc7",
"genesisBlockNumber": 74,
"genesisBlockNumber": 65,
"genesis": [
{
"contractName": "PolygonZkEVMDeployer",
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/sendForcedBatch/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func sendForcedBatches(cliCtx *cli.Context) error {
log.Debug("currentBlock.Time(): ", currentBlock.Time())

// Get tip
tip, err := poe.BatchFee(&bind.CallOpts{Pending: false})
tip, err := poe.GetForcedBatchFee(&bind.CallOpts{Pending: false})
if err != nil {
log.Error("error getting tip. Error: ", err)
return err
Expand Down