From 5833d504c9c0e4655a7bb7e7e15bed8740a4ef8c Mon Sep 17 00:00:00 2001 From: agnusmor Date: Tue, 6 Feb 2024 13:24:17 +0100 Subject: [PATCH 1/2] set l2 block gas limit to 2**50 (1125899906842624) --- config/config_test.go | 2 +- config/default.go | 2 +- config/environments/cardona/node.config.toml | 2 +- config/environments/local/local.node.config.toml | 2 +- config/environments/mainnet/node.config.toml | 2 +- config/environments/testnet/node.config.toml | 2 +- docs/config-file/node-config-doc.html | 2 +- docs/config-file/node-config-doc.md | 6 +++--- docs/config-file/node-config-schema.json | 2 +- state/transaction.go | 4 ++-- test/benchmarks/sequencer/common/setup/setup.go | 3 +-- test/config/test.node.config.toml | 2 +- 12 files changed, 15 insertions(+), 16 deletions(-) diff --git a/config/config_test.go b/config/config_test.go index 27aeab2602..a031f88a68 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -487,7 +487,7 @@ func Test_Defaults(t *testing.T) { }, { path: "State.Batch.Constraints.MaxCumulativeGasUsed", - expectedValue: uint64(9223372036854775807), + expectedValue: uint64(1125899906842624), }, { path: "State.Batch.Constraints.MaxKeccakHashes", diff --git a/config/default.go b/config/default.go index 2ef97a2c85..a18586be4e 100644 --- a/config/default.go +++ b/config/default.go @@ -24,7 +24,7 @@ Outputs = ["stderr"] [State.Batch.Constraints] MaxTxsPerBatch = 300 MaxBatchBytesSize = 120000 - MaxCumulativeGasUsed = 9223372036854775807 + MaxCumulativeGasUsed = 1125899906842624 MaxKeccakHashes = 2145 MaxPoseidonHashes = 252357 MaxPoseidonPaddings = 135191 diff --git a/config/environments/cardona/node.config.toml b/config/environments/cardona/node.config.toml index ff2afcbe40..1ec17081b2 100644 --- a/config/environments/cardona/node.config.toml +++ b/config/environments/cardona/node.config.toml @@ -16,7 +16,7 @@ Outputs = ["stderr"] [State.Batch.Constraints] MaxTxsPerBatch = 300 MaxBatchBytesSize = 120000 - MaxCumulativeGasUsed = 9223372036854775807 + MaxCumulativeGasUsed = 1125899906842624 MaxKeccakHashes = 2145 MaxPoseidonHashes = 252357 MaxPoseidonPaddings = 135191 diff --git a/config/environments/local/local.node.config.toml b/config/environments/local/local.node.config.toml index f3ffeb3685..ebf5b2544d 100644 --- a/config/environments/local/local.node.config.toml +++ b/config/environments/local/local.node.config.toml @@ -19,7 +19,7 @@ Outputs = ["stderr"] [State.Batch.Constraints] MaxTxsPerBatch = 300 MaxBatchBytesSize = 120000 - MaxCumulativeGasUsed = 9223372036854775807 + MaxCumulativeGasUsed = 1125899906842624 MaxKeccakHashes = 2145 MaxPoseidonHashes = 252357 MaxPoseidonPaddings = 135191 diff --git a/config/environments/mainnet/node.config.toml b/config/environments/mainnet/node.config.toml index 8a3b2dec3d..f46e972802 100644 --- a/config/environments/mainnet/node.config.toml +++ b/config/environments/mainnet/node.config.toml @@ -16,7 +16,7 @@ Outputs = ["stderr"] [State.Batch.Constraints] MaxTxsPerBatch = 300 MaxBatchBytesSize = 120000 - MaxCumulativeGasUsed = 9223372036854775807 + MaxCumulativeGasUsed = 1125899906842624 MaxKeccakHashes = 2145 MaxPoseidonHashes = 252357 MaxPoseidonPaddings = 135191 diff --git a/config/environments/testnet/node.config.toml b/config/environments/testnet/node.config.toml index 596a9048c3..da12f0d1bc 100644 --- a/config/environments/testnet/node.config.toml +++ b/config/environments/testnet/node.config.toml @@ -16,7 +16,7 @@ Outputs = ["stderr"] [State.Batch.Constraints] MaxTxsPerBatch = 300 MaxBatchBytesSize = 120000 - MaxCumulativeGasUsed = 9223372036854775807 + MaxCumulativeGasUsed = 1125899906842624 MaxKeccakHashes = 2145 MaxPoseidonHashes = 252357 MaxPoseidonPaddings = 135191 diff --git a/docs/config-file/node-config-doc.html b/docs/config-file/node-config-doc.html index 111fb8018b..8f9e04279a 100644 --- a/docs/config-file/node-config-doc.html +++ b/docs/config-file/node-config-doc.html @@ -76,4 +76,4 @@
"300ms"
 

Default: 100000000Type: integer

Configuration of the merkle tree client service. Not use in the node, only for testing
Default: "zkevm-prover:50061"Type: string

URI is the server URI.


Configuration of the metrics service, basically is where is going to publish the metrics
Default: "0.0.0.0"Type: string

Host is the address to bind the metrics server


Default: 9091Type: integer

Port is the port to bind the metrics server


Default: falseType: boolean

Enabled is the flag to enable/disable the metrics server


Default: ""Type: string

ProfilingHost is the address to bind the profiling server


Default: 0Type: integer

ProfilingPort is the port to bind the profiling server


Default: falseType: boolean

ProfilingEnabled is the flag to enable/disable the profiling server


Configuration of the event database connection

DB is the database configuration
Default: ""Type: string

Database name


Default: ""Type: string

Database User name


Default: ""Type: string

Database Password of the user


Default: ""Type: string

Host address of database


Default: ""Type: string

Port Number of database


Default: falseType: boolean

EnableLog


Default: 0Type: integer

MaxConns is the maximum number of connections in the pool.


Configuration of the hash database connection
Default: "prover_db"Type: string

Database name


Default: "prover_user"Type: string

Database User name


Default: "prover_pass"Type: string

Database Password of the user


Default: "zkevm-state-db"Type: string

Host address of database


Default: "5432"Type: string

Port Number of database


Default: falseType: boolean

EnableLog


Default: 200Type: integer

MaxConns is the maximum number of connections in the pool.


State service configuration
Default: 0Type: integer

MaxCumulativeGasUsed is the max gas allowed per batch


Default: 0Type: integer

ChainID is the L2 ChainID provided by the Network Config


Type: array of object

ForkIdIntervals is the list of fork id intervals

Each item of this array must be:


Default: 0Type: integer

MaxResourceExhaustedAttempts is the max number of attempts to make a transaction succeed because of resource exhaustion


Default: "0s"Type: string

WaitOnResourceExhaustion is the time to wait before retrying a transaction because of resource exhaustion


Examples:

"1m"
 
"300ms"
-

Default: 0Type: integer

Batch number from which there is a forkid change (fork upgrade)


Default: 0Type: integer

New fork id to be used for batches greaters than ForkUpgradeBatchNumber (fork upgrade)


DB is the database configuration
Default: "state_db"Type: string

Database name


Default: "state_user"Type: string

Database User name


Default: "state_password"Type: string

Database Password of the user


Default: "zkevm-state-db"Type: string

Host address of database


Default: "5432"Type: string

Port Number of database


Default: falseType: boolean

EnableLog


Default: 200Type: integer

MaxConns is the maximum number of connections in the pool.


Configuration for the batch constraints
Default: 300Type: integer

Default: 120000Type: integer

Default: 9223372036854775807Type: integer

Default: 2145Type: integer

Default: 252357Type: integer

Default: 135191Type: integer

Default: 236585Type: integer

Default: 236585Type: integer

Default: 473170Type: integer

Default: 7570538Type: integer

Default: 1596Type: integer

Default: 0Type: integer

MaxLogsCount is a configuration to set the max number of logs that can be returned
in a single call to the state, if zero it means no limit


Default: 0Type: integer

MaxLogsBlockRange is a configuration to set the max range for block number when querying TXs
logs in a single call to the state, if zero it means no limit


Default: 0Type: integer

MaxNativeBlockHashBlockRange is a configuration to set the max range for block number when querying
native block hashes in a single call to the state, if zero it means no limit


Default: falseType: boolean

AvoidForkIDInMemory is a configuration that forces the ForkID information to be loaded
from the DB every time it's needed


\ No newline at end of file +
Default: 0Type: integer

Batch number from which there is a forkid change (fork upgrade)


Default: 0Type: integer

New fork id to be used for batches greaters than ForkUpgradeBatchNumber (fork upgrade)


DB is the database configuration
Default: "state_db"Type: string

Database name


Default: "state_user"Type: string

Database User name


Default: "state_password"Type: string

Database Password of the user


Default: "zkevm-state-db"Type: string

Host address of database


Default: "5432"Type: string

Port Number of database


Default: falseType: boolean

EnableLog


Default: 200Type: integer

MaxConns is the maximum number of connections in the pool.


Configuration for the batch constraints
Default: 300Type: integer

Default: 120000Type: integer

Default: 1125899906842624Type: integer

Default: 2145Type: integer

Default: 252357Type: integer

Default: 135191Type: integer

Default: 236585Type: integer

Default: 236585Type: integer

Default: 473170Type: integer

Default: 7570538Type: integer

Default: 1596Type: integer

Default: 0Type: integer

MaxLogsCount is a configuration to set the max number of logs that can be returned
in a single call to the state, if zero it means no limit


Default: 0Type: integer

MaxLogsBlockRange is a configuration to set the max range for block number when querying TXs
logs in a single call to the state, if zero it means no limit


Default: 0Type: integer

MaxNativeBlockHashBlockRange is a configuration to set the max range for block number when querying
native block hashes in a single call to the state, if zero it means no limit


Default: falseType: boolean

AvoidForkIDInMemory is a configuration that forces the ForkID information to be loaded
from the DB every time it's needed


\ No newline at end of file diff --git a/docs/config-file/node-config-doc.md b/docs/config-file/node-config-doc.md index e6a97716a9..37a3d6563a 100644 --- a/docs/config-file/node-config-doc.md +++ b/docs/config-file/node-config-doc.md @@ -3736,12 +3736,12 @@ MaxBatchBytesSize=120000 **Type:** : `integer` -**Default:** `9223372036854775807` +**Default:** `1125899906842624` -**Example setting the default value** (9223372036854775807): +**Example setting the default value** (1125899906842624): ``` [State.Batch.Constraints] -MaxCumulativeGasUsed=9223372036854775807 +MaxCumulativeGasUsed=1125899906842624 ``` ##### 20.9.1.4. `State.Batch.Constraints.MaxKeccakHashes` diff --git a/docs/config-file/node-config-schema.json b/docs/config-file/node-config-schema.json index 9c1f305445..b28e8ea462 100644 --- a/docs/config-file/node-config-schema.json +++ b/docs/config-file/node-config-schema.json @@ -1484,7 +1484,7 @@ }, "MaxCumulativeGasUsed": { "type": "integer", - "default": 9223372036854775807 + "default": 1125899906842624 }, "MaxKeccakHashes": { "type": "integer", diff --git a/state/transaction.go b/state/transaction.go index 1cd0ab7791..1a5acb00c1 100644 --- a/state/transaction.go +++ b/state/transaction.go @@ -160,7 +160,7 @@ func (s *State) StoreTransactions(ctx context.Context, batchNumber uint64, proce Coinbase: processingContext.Coinbase, Root: processedTx.StateRoot, GasUsed: processedTx.GasUsed, - GasLimit: processedBlock.GasLimit, + GasLimit: s.cfg.MaxCumulativeGasUsed, Time: uint64(processingContext.Timestamp.Unix()), }) header.GlobalExitRoot = processedBlock.GlobalExitRoot @@ -215,7 +215,7 @@ func (s *State) StoreL2Block(ctx context.Context, batchNumber uint64, l2Block *P Coinbase: l2Block.Coinbase, Root: l2Block.BlockHash, //BlockHash returned by the executor is the StateRoot in Etrog GasUsed: l2Block.GasUsed, - GasLimit: l2Block.GasLimit, + GasLimit: s.cfg.MaxCumulativeGasUsed, Time: l2Block.Timestamp, } diff --git a/test/benchmarks/sequencer/common/setup/setup.go b/test/benchmarks/sequencer/common/setup/setup.go index 4a633bcc8b..5c38786ae4 100644 --- a/test/benchmarks/sequencer/common/setup/setup.go +++ b/test/benchmarks/sequencer/common/setup/setup.go @@ -3,7 +3,6 @@ package setup import ( "context" "fmt" - "math" "math/big" "testing" "time" @@ -32,7 +31,7 @@ var ( bc = state.BatchConstraintsCfg{ MaxTxsPerBatch: 300, MaxBatchBytesSize: 120000, - MaxCumulativeGasUsed: uint64(math.MaxInt64), + MaxCumulativeGasUsed: uint64(1125899906842624), MaxKeccakHashes: 2145, MaxPoseidonHashes: 252357, MaxPoseidonPaddings: 135191, diff --git a/test/config/test.node.config.toml b/test/config/test.node.config.toml index 471f905baa..76c6e53aee 100644 --- a/test/config/test.node.config.toml +++ b/test/config/test.node.config.toml @@ -18,7 +18,7 @@ Outputs = ["stderr"] [State.Batch.Constraints] MaxTxsPerBatch = 300 MaxBatchBytesSize = 120000 - MaxCumulativeGasUsed = 9223372036854775807 + MaxCumulativeGasUsed = 1125899906842624 MaxKeccakHashes = 2145 MaxPoseidonHashes = 252357 MaxPoseidonPaddings = 135191 From 0ef4f0d8d9acb41d7624359a750164f39c1a2281 Mon Sep 17 00:00:00 2001 From: agnusmor Date: Tue, 6 Feb 2024 14:27:08 +0100 Subject: [PATCH 2/2] limit L2 block gasLimit in StoreL2Block function --- state/convertersV2.go | 5 +++++ state/transaction.go | 11 ++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/state/convertersV2.go b/state/convertersV2.go index b841417ad0..fde56858bd 100644 --- a/state/convertersV2.go +++ b/state/convertersV2.go @@ -19,6 +19,11 @@ import ( "github.com/ethereum/go-ethereum/core/types" ) +const ( + // MaxL2BlockGasLimit is the gas limit allowed per L2 block in a batch + MaxL2BlockGasLimit = uint64(1125899906842624) +) + var ( errL2BlockInvalid = errors.New("A L2 block fails, that invalidate totally the batch") ) diff --git a/state/transaction.go b/state/transaction.go index 1a5acb00c1..c2011c8e30 100644 --- a/state/transaction.go +++ b/state/transaction.go @@ -160,7 +160,7 @@ func (s *State) StoreTransactions(ctx context.Context, batchNumber uint64, proce Coinbase: processingContext.Coinbase, Root: processedTx.StateRoot, GasUsed: processedTx.GasUsed, - GasLimit: s.cfg.MaxCumulativeGasUsed, + GasLimit: processedBlock.GasLimit, Time: uint64(processingContext.Timestamp.Unix()), }) header.GlobalExitRoot = processedBlock.GlobalExitRoot @@ -209,13 +209,18 @@ func (s *State) StoreL2Block(ctx context.Context, batchNumber uint64, l2Block *P return err } + gasLimit := l2Block.GasLimit + if gasLimit > MaxL2BlockGasLimit { + gasLimit = MaxL2BlockGasLimit + } + header := &types.Header{ Number: new(big.Int).SetUint64(l2Block.BlockNumber), ParentHash: prevL2BlockHash, Coinbase: l2Block.Coinbase, Root: l2Block.BlockHash, //BlockHash returned by the executor is the StateRoot in Etrog GasUsed: l2Block.GasUsed, - GasLimit: s.cfg.MaxCumulativeGasUsed, + GasLimit: gasLimit, Time: l2Block.Timestamp, } @@ -630,7 +635,7 @@ func (s *State) StoreTransaction(ctx context.Context, batchNumber uint64, proces Coinbase: coinbase, Root: processedTx.StateRoot, GasUsed: processedTx.GasUsed, - GasLimit: s.cfg.MaxCumulativeGasUsed, + GasLimit: MaxTxGasLimit, Time: timestamp, }) header.GlobalExitRoot = globalExitRoot