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 forkID #1729

Merged
merged 3 commits into from
Mar 3, 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
1 change: 0 additions & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ func newState(ctx context.Context, c *config.Config, l2ChainID uint64, currentFo
stateCfg := state.Config{
MaxCumulativeGasUsed: c.Sequencer.MaxCumulativeGasUsed,
ChainID: l2ChainID,
CurrentForkID: currentForkID,
ForkIDIntervals: forkIDIntervals,
}

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ services:

zkevm-prover:
container_name: zkevm-prover
image: hermeznetwork/zkevm-prover:ab739f6
image: hermeznetwork/zkevm-prover:798d9e0
ports:
- 50061:50061 # MT
- 50071:50071 # Executor
Expand Down
7 changes: 6 additions & 1 deletion pool/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,12 @@ func newState(sqlDB *pgxpool.Pool) *state.State {
executorClient, _, _ := executor.NewExecutorClient(ctx, executorServerConfig)
stateDBClient, _, _ := merkletree.NewMTDBServiceClient(ctx, mtDBServerConfig)
stateTree := merkletree.NewStateTree(stateDBClient)
st := state.NewState(state.Config{MaxCumulativeGasUsed: 800000, ChainID: chainID.Uint64(), CurrentForkID: 1}, stateDb, executorClient, stateTree)
st := state.NewState(state.Config{MaxCumulativeGasUsed: 800000, ChainID: chainID.Uint64(), ForkIDIntervals: []state.ForkIDInterval{{
FromBatchNumber: 0,
ToBatchNumber: math.MaxUint64,
ForkId: 0,
Version: "",
}}}, stateDb, executorClient, stateTree)
return st
}

Expand Down
3 changes: 0 additions & 3 deletions state/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ type Config struct {
// ChainID is the L2 ChainID provided by the Network Config
ChainID uint64

// Current ForkId is the current fork id used by the network
CurrentForkID uint64

// ForkIdIntervals is the list of fork id intervals
ForkIDIntervals []ForkIDInterval
}
12 changes: 8 additions & 4 deletions state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ func (s *State) EstimateGas(transaction *types.Transaction, senderAddress common
return false, false, gasUsed, err
}

forkID := GetForkIDByBatchNumber(s.cfg.ForkIDIntervals, lastBatch.BatchNumber)
// Create a batch to be sent to the executor
processBatchRequest := &pb.ProcessBatchRequest{
OldBatchNum: lastBatch.BatchNumber,
Expand All @@ -278,7 +279,7 @@ func (s *State) EstimateGas(transaction *types.Transaction, senderAddress common
Coinbase: lastBatch.Coinbase.String(),
UpdateMerkleTree: cFalse,
ChainId: s.cfg.ChainID,
ForkId: s.cfg.CurrentForkID,
ForkId: forkID,
}

log.Debugf("EstimateGas[processBatchRequest.OldBatchNum]: %v", processBatchRequest.OldBatchNum)
Expand Down Expand Up @@ -473,6 +474,7 @@ func (s *State) ProcessBatch(ctx context.Context, request ProcessRequest, update
updateMT = cTrue
}

forkID := GetForkIDByBatchNumber(s.cfg.ForkIDIntervals, request.BatchNumber)
// Create Batch
processBatchRequest := &pb.ProcessBatchRequest{
OldBatchNum: request.BatchNumber - 1,
Expand All @@ -484,7 +486,7 @@ func (s *State) ProcessBatch(ctx context.Context, request ProcessRequest, update
EthTimestamp: request.Timestamp,
UpdateMerkleTree: updateMT,
ChainId: s.cfg.ChainID,
ForkId: s.cfg.CurrentForkID,
ForkId: forkID,
}
res, err := s.sendBatchRequestToExecutor(ctx, processBatchRequest, request.Caller)
if err != nil {
Expand Down Expand Up @@ -603,6 +605,7 @@ func (s *State) processBatch(
if lastBatch.BatchNumber != batchNumber {
return nil, ErrInvalidBatchNumber
}
forkID := GetForkIDByBatchNumber(s.cfg.ForkIDIntervals, lastBatch.BatchNumber)
// Create Batch
processBatchRequest := &pb.ProcessBatchRequest{
OldBatchNum: lastBatch.BatchNumber - 1,
Expand All @@ -614,7 +617,7 @@ func (s *State) processBatch(
EthTimestamp: uint64(lastBatch.Timestamp.Unix()),
UpdateMerkleTree: cTrue,
ChainId: s.cfg.ChainID,
ForkId: s.cfg.CurrentForkID,
ForkId: forkID,
}

res, err := s.sendBatchRequestToExecutor(ctx, processBatchRequest, caller)
Expand Down Expand Up @@ -1227,6 +1230,7 @@ func (s *State) internalProcessUnsignedTransaction(ctx context.Context, tx *type
return nil, err
}

forkID := GetForkIDByBatchNumber(s.cfg.ForkIDIntervals, lastBatch.BatchNumber)
// Create Batch
processBatchRequest := &pb.ProcessBatchRequest{
OldBatchNum: lastBatch.BatchNumber,
Expand All @@ -1239,7 +1243,7 @@ func (s *State) internalProcessUnsignedTransaction(ctx context.Context, tx *type
Coinbase: lastBatch.Coinbase.String(),
UpdateMerkleTree: cFalse,
ChainId: s.cfg.ChainID,
ForkId: s.cfg.CurrentForkID,
ForkId: forkID,
}

if noZKEVMCounters {
Expand Down
43 changes: 25 additions & 18 deletions state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"math"
"math/big"
"os"
"path/filepath"
Expand Down Expand Up @@ -51,8 +52,14 @@ var (
stateCfg = state.Config{
MaxCumulativeGasUsed: 800000,
ChainID: 1000,
CurrentForkID: 1,
}
ForkIDIntervals: []state.ForkIDInterval{{
FromBatchNumber: 0,
ToBatchNumber: math.MaxUint64,
ForkId: 0,
Version: "",
}},
}
forkID uint64 = 2
executorClient executorclientpb.ExecutorServiceClient
mtDBServiceClient mtDBclientpb.StateDBServiceClient
executorClientConn, mtDBClientConn *grpc.ClientConn
Expand Down Expand Up @@ -491,7 +498,7 @@ func TestExecuteTransaction(t *testing.T) {
EthTimestamp: uint64(time.Now().Unix()),
UpdateMerkleTree: 1,
ChainId: stateCfg.ChainID,
ForkId: stateCfg.CurrentForkID,
ForkId: forkID,
}

log.Debugf("%v", processBatchRequest)
Expand Down Expand Up @@ -878,7 +885,7 @@ func TestExecutor(t *testing.T) {
UpdateMerkleTree: 0,
Db: db,
ChainId: stateCfg.ChainID,
ForkId: stateCfg.CurrentForkID,
ForkId: forkID,
}

processBatchResponse, err := executorClient.ProcessBatch(ctx, processBatchRequest)
Expand Down Expand Up @@ -958,7 +965,7 @@ func TestExecutorRevert(t *testing.T) {
EthTimestamp: uint64(time.Now().Unix()),
UpdateMerkleTree: 0,
ChainId: stateCfg.ChainID,
ForkId: stateCfg.CurrentForkID,
ForkId: forkID,
}

processBatchResponse, err := executorClient.ProcessBatch(ctx, processBatchRequest)
Expand Down Expand Up @@ -1080,7 +1087,7 @@ func TestExecutorLogs(t *testing.T) {
UpdateMerkleTree: 0,
Db: genesisDB,
ChainId: stateCfg.ChainID,
ForkId: stateCfg.CurrentForkID,
ForkId: forkID,
}

processBatchResponse, err := executorClient.ProcessBatch(ctx, processBatchRequest)
Expand Down Expand Up @@ -1159,7 +1166,7 @@ func TestExecutorTransfer(t *testing.T) {
EthTimestamp: uint64(0),
UpdateMerkleTree: 1,
ChainId: stateCfg.ChainID,
ForkId: stateCfg.CurrentForkID,
ForkId: forkID,
}

// Read Sender Balance before execution
Expand Down Expand Up @@ -1306,7 +1313,7 @@ func TestExecutorTxHashAndRLP(t *testing.T) {
EthTimestamp: uint64(0),
UpdateMerkleTree: 1,
ChainId: stateCfg.ChainID,
ForkId: stateCfg.CurrentForkID,
ForkId: forkID,
}

// Process batch
Expand Down Expand Up @@ -1415,7 +1422,7 @@ func TestExecutorInvalidNonce(t *testing.T) {
EthTimestamp: uint64(0),
UpdateMerkleTree: 1,
ChainId: stateCfg.ChainID,
ForkId: stateCfg.CurrentForkID,
ForkId: forkID,
}

// Process batch
Expand Down Expand Up @@ -2014,7 +2021,7 @@ func TestExecutorUniswapOutOfCounters(t *testing.T) {
EthTimestamp: uint64(0),
UpdateMerkleTree: 1,
ChainId: stateCfg.ChainID,
ForkId: stateCfg.CurrentForkID,
ForkId: forkID,
}

// Process batch
Expand Down Expand Up @@ -2151,7 +2158,7 @@ func TestExecutorEstimateGas(t *testing.T) {
EthTimestamp: uint64(time.Now().Unix()),
UpdateMerkleTree: 0,
ChainId: stateCfg.ChainID,
ForkId: stateCfg.CurrentForkID,
ForkId: forkID,
}

processBatchResponse, err := executorClient.ProcessBatch(ctx, processBatchRequest)
Expand Down Expand Up @@ -2298,7 +2305,7 @@ func TestExecutorGasRefund(t *testing.T) {
EthTimestamp: uint64(time.Now().Unix()),
UpdateMerkleTree: 1,
ChainId: stateCfg.ChainID,
ForkId: stateCfg.CurrentForkID,
ForkId: forkID,
}

processBatchResponse, err := executorClient.ProcessBatch(ctx, processBatchRequest)
Expand Down Expand Up @@ -2364,7 +2371,7 @@ func TestExecutorGasRefund(t *testing.T) {
EthTimestamp: uint64(time.Now().Unix()),
UpdateMerkleTree: 1,
ChainId: stateCfg.ChainID,
ForkId: stateCfg.CurrentForkID,
ForkId: forkID,
}

processBatchResponse, err = executorClient.ProcessBatch(ctx, processBatchRequest)
Expand Down Expand Up @@ -2499,7 +2506,7 @@ func TestExecutorGasEstimationMultisig(t *testing.T) {
EthTimestamp: uint64(time.Now().Unix()),
UpdateMerkleTree: 1,
ChainId: stateCfg.ChainID,
ForkId: stateCfg.CurrentForkID,
ForkId: forkID,
}

processBatchResponse, err := executorClient.ProcessBatch(ctx, processBatchRequest)
Expand Down Expand Up @@ -2583,7 +2590,7 @@ func TestExecutorGasEstimationMultisig(t *testing.T) {
EthTimestamp: uint64(time.Now().Unix()),
UpdateMerkleTree: 1,
ChainId: stateCfg.ChainID,
ForkId: stateCfg.CurrentForkID,
ForkId: forkID,
}

processBatchResponse, err = executorClient.ProcessBatch(ctx, processBatchRequest)
Expand Down Expand Up @@ -2724,7 +2731,7 @@ func TestStoreDebugInfo(t *testing.T) {
UpdateMerkleTree: 0,
Db: db,
ChainId: stateCfg.ChainID,
ForkId: stateCfg.CurrentForkID,
ForkId: forkID,
}

_, err := executorClient.ProcessBatch(ctx, processBatchRequest)
Expand Down Expand Up @@ -2791,7 +2798,7 @@ func TestExecuteWithoutUpdatingMT(t *testing.T) {
EthTimestamp: uint64(time.Now().Unix()),
UpdateMerkleTree: 0,
ChainId: stateCfg.ChainID,
ForkId: stateCfg.CurrentForkID,
ForkId: forkID,
}

processBatchResponse, err := executorClient.ProcessBatch(ctx, processBatchRequest)
Expand Down Expand Up @@ -2850,7 +2857,7 @@ func TestExecuteWithoutUpdatingMT(t *testing.T) {
EthTimestamp: uint64(time.Now().Unix()),
UpdateMerkleTree: 0,
ChainId: stateCfg.ChainID,
ForkId: stateCfg.CurrentForkID,
ForkId: forkID,
}

processBatchResponse, err = executorClient.ProcessBatch(ctx, processBatchRequest)
Expand Down
5 changes: 4 additions & 1 deletion test/config/test.prover.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@
"databaseURL": "postgresql://prover_user:prover_pass@zkevm-state-db:5432/prover_db",
"dbNodesTableName": "state.nodes",
"dbProgramTableName": "state.program",
"dbAsyncWrite": false,
"dbMultiWrite": true,
"dbFlushInParallel": false,
"dbMTCacheSize": 1024,
"dbProgramCacheSize": 1024,
"cleanerPollingPeriod": 600,
"requestsPersistence": 3600,
"maxExecutorThreads": 20,
Expand Down
2 changes: 1 addition & 1 deletion test/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ services:

zkevm-prover:
container_name: zkevm-prover
image: hermeznetwork/zkevm-prover:fix-aggr-client
image: hermeznetwork/zkevm-prover:798d9e0
ports:
# - 50051:50051 # Prover
- 50052:50052 # Mock prover
Expand Down