From 806d147ce848a45ed4c5b3a40a34757c920e61df Mon Sep 17 00:00:00 2001 From: Nikolay Nedkov Date: Wed, 12 Jul 2023 17:37:14 +0300 Subject: [PATCH 1/6] improve: Add IP and ZKCounter Validation, Refactor Batch Configs Signed-off-by: Nikolay Nedkov --- cmd/run.go | 20 +- config/config.go | 2 + config/config_test.go | 153 +++++++------- config/default.go | 42 ++-- .../environments/local/local.node.config.toml | 42 ++-- pool/config.go | 58 ++++++ pool/config_test.go | 63 ++++++ pool/errors.go | 9 + pool/pool.go | 25 ++- pool/pool_test.go | 189 +++++++++++++----- pool/validation.go | 8 + pool/validation_test.go | 27 +++ sequencer/addrqueue.go | 3 +- sequencer/closingsignalsmanager_test.go | 3 +- sequencer/config.go | 58 ------ sequencer/dbmanager.go | 6 +- sequencer/dbmanager_test.go | 3 +- sequencer/efficiencylist.go | 2 +- sequencer/finalizer.go | 6 +- sequencer/finalizer_test.go | 2 +- sequencer/sequencer.go | 66 +----- sequencer/txtracker.go | 9 +- sequencer/txtracker_test.go | 43 ++-- sequencer/worker.go | 49 +++-- sequencer/worker_test.go | 132 +++++++----- .../sequencer/common/params/constants.go | 2 +- .../sequencer/common/setup/setup.go | 17 +- .../sequencer/eth-transfers/tx_sender.go | 4 +- test/config/debug.node.config.toml | 42 ++-- test/config/test.node.config.toml | 42 ++-- test/e2e/uniswap_test.go | 2 +- 31 files changed, 680 insertions(+), 449 deletions(-) create mode 100644 pool/config_test.go create mode 100644 pool/validation.go create mode 100644 pool/validation_test.go diff --git a/cmd/run.go b/cmd/run.go index f85f3c1f52..f09dc41663 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -170,7 +170,7 @@ func start(cliCtx *cli.Context) error { log.Fatal(err) } if poolInstance == nil { - poolInstance = createPool(c.Pool, l2ChainID, st, eventLog) + poolInstance = createPool(c.Pool, c.Batch.Constraints, l2ChainID, st, eventLog) } seq := createSequencer(*c, poolInstance, ethTxManagerStorage, st, eventLog) go seq.Start(ctx) @@ -182,7 +182,7 @@ func start(cliCtx *cli.Context) error { log.Fatal(err) } if poolInstance == nil { - poolInstance = createPool(c.Pool, l2ChainID, st, eventLog) + poolInstance = createPool(c.Pool, c.Batch.Constraints, l2ChainID, st, eventLog) } seqSender := createSequenceSender(*c, poolInstance, ethTxManagerStorage, st, eventLog) go seqSender.Start(ctx) @@ -194,7 +194,7 @@ func start(cliCtx *cli.Context) error { log.Fatal(err) } if poolInstance == nil { - poolInstance = createPool(c.Pool, l2ChainID, st, eventLog) + poolInstance = createPool(c.Pool, c.Batch.Constraints, l2ChainID, st, eventLog) } if c.RPC.EnableL2SuggestedGasPricePolling { // Needed for rejecting transactions with too low gas price @@ -213,7 +213,7 @@ func start(cliCtx *cli.Context) error { log.Fatal(err) } if poolInstance == nil { - poolInstance = createPool(c.Pool, l2ChainID, st, eventLog) + poolInstance = createPool(c.Pool, c.Batch.Constraints, l2ChainID, st, eventLog) } go runSynchronizer(*c, etherman, etm, st, poolInstance, eventLog) case ETHTXMANAGER: @@ -233,7 +233,7 @@ func start(cliCtx *cli.Context) error { log.Fatal(err) } if poolInstance == nil { - poolInstance = createPool(c.Pool, l2ChainID, st, eventLog) + poolInstance = createPool(c.Pool, c.Batch.Constraints, l2ChainID, st, eventLog) } go runL2GasPriceSuggester(c.L2GasPriceSuggester, st, poolInstance, etherman) } @@ -315,7 +315,7 @@ func runSynchronizer(cfg config.Config, etherman *etherman.Client, ethTxManager func runJSONRPCServer(c config.Config, etherman *etherman.Client, chainID uint64, pool *pool.Pool, st *state.State, apis map[string]bool) { var err error storage := jsonrpc.NewStorage() - c.RPC.MaxCumulativeGasUsed = c.Sequencer.MaxCumulativeGasUsed + c.RPC.MaxCumulativeGasUsed = c.Batch.Constraints.MaxCumulativeGasUsed if !c.IsTrustedSequencer { if c.RPC.SequencerNodeURI == "" { log.Debug("getting trusted sequencer URL from smc") @@ -383,7 +383,7 @@ func createSequencer(cfg config.Config, pool *pool.Pool, etmStorage *ethtxmanage ethTxManager := ethtxmanager.New(cfg.EthTxManager, etherman, etmStorage, st) - seq, err := sequencer.New(cfg.Sequencer, pool, st, etherman, ethTxManager, eventLog) + seq, err := sequencer.New(cfg.Sequencer, cfg.Batch, pool, st, etherman, ethTxManager, eventLog) if err != nil { log.Fatal(err) } @@ -467,7 +467,7 @@ func newState(ctx context.Context, c *config.Config, l2ChainID uint64, forkIDInt } stateCfg := state.Config{ - MaxCumulativeGasUsed: c.Sequencer.MaxCumulativeGasUsed, + MaxCumulativeGasUsed: c.Batch.Constraints.MaxCumulativeGasUsed, ChainID: l2ChainID, ForkIDIntervals: forkIDIntervals, MaxResourceExhaustedAttempts: c.Executor.MaxResourceExhaustedAttempts, @@ -480,13 +480,13 @@ func newState(ctx context.Context, c *config.Config, l2ChainID uint64, forkIDInt return st } -func createPool(cfgPool pool.Config, l2ChainID uint64, st *state.State, eventLog *event.EventLog) *pool.Pool { +func createPool(cfgPool pool.Config, constraintsCfg pool.BatchConstraintsCfg, l2ChainID uint64, st *state.State, eventLog *event.EventLog) *pool.Pool { runPoolMigrations(cfgPool.DB) poolStorage, err := pgpoolstorage.NewPostgresPoolStorage(cfgPool.DB) if err != nil { log.Fatal(err) } - poolInstance := pool.NewPool(cfgPool, poolStorage, st, l2ChainID, eventLog) + poolInstance := pool.NewPool(cfgPool, constraintsCfg, poolStorage, st, l2ChainID, eventLog) return poolInstance } diff --git a/config/config.go b/config/config.go index 98f28fc48d..b83cfd6d20 100644 --- a/config/config.go +++ b/config/config.go @@ -116,6 +116,8 @@ type Config struct { EventLog event.Config // Configuration of the hash database connection HashDB db.Config + // Configuration of the batch service + Batch pool.BatchConfig } // Default parses the default configuration values. diff --git a/config/config_test.go b/config/config_test.go index 269a2e19ba..ed580d22e7 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -44,14 +44,6 @@ func Test_Defaults(t *testing.T) { path: "Sequencer.WaitPeriodPoolIsEmpty", expectedValue: types.NewDuration(1 * time.Second), }, - { - path: "Sequencer.MaxTxsPerBatch", - expectedValue: uint64(300), - }, - { - path: "Sequencer.MaxBatchBytesSize", - expectedValue: uint64(120000), - }, { path: "Sequencer.BlocksAmountForTxsToBeDeleted", expectedValue: uint64(100), @@ -60,38 +52,6 @@ func Test_Defaults(t *testing.T) { path: "Sequencer.FrequencyToCheckTxsForDelete", expectedValue: types.NewDuration(12 * time.Hour), }, - { - path: "Sequencer.MaxCumulativeGasUsed", - expectedValue: uint64(30000000), - }, - { - path: "Sequencer.MaxKeccakHashes", - expectedValue: uint32(2145), - }, - { - path: "Sequencer.MaxPoseidonHashes", - expectedValue: uint32(252357), - }, - { - path: "Sequencer.MaxPoseidonPaddings", - expectedValue: uint32(135191), - }, - { - path: "Sequencer.MaxMemAligns", - expectedValue: uint32(236585), - }, - { - path: "Sequencer.MaxArithmetics", - expectedValue: uint32(236585), - }, - { - path: "Sequencer.MaxBinaries", - expectedValue: uint32(473170), - }, - { - path: "Sequencer.MaxSteps", - expectedValue: uint32(7570538), - }, { path: "Sequencer.TxLifetimeCheckTimeout", expectedValue: types.NewDuration(10 * time.Minute), @@ -100,42 +60,6 @@ func Test_Defaults(t *testing.T) { path: "Sequencer.MaxTxLifetime", expectedValue: types.NewDuration(3 * time.Hour), }, - { - path: "Sequencer.WeightBatchBytesSize", - expectedValue: 1, - }, - { - path: "Sequencer.WeightCumulativeGasUsed", - expectedValue: 1, - }, - { - path: "Sequencer.WeightKeccakHashes", - expectedValue: 1, - }, - { - path: "Sequencer.WeightPoseidonHashes", - expectedValue: 1, - }, - { - path: "Sequencer.WeightPoseidonPaddings", - expectedValue: 1, - }, - { - path: "Sequencer.WeightMemAligns", - expectedValue: 1, - }, - { - path: "Sequencer.WeightArithmetics", - expectedValue: 1, - }, - { - path: "Sequencer.WeightBinaries", - expectedValue: 1, - }, - { - path: "Sequencer.WeightSteps", - expectedValue: 1, - }, { path: "Sequencer.Finalizer.GERDeadlineTimeout", expectedValue: types.NewDuration(5 * time.Second), @@ -469,6 +393,83 @@ func Test_Defaults(t *testing.T) { path: "Aggregator.GeneratingProofCleanupThreshold", expectedValue: "10m", }, + + { + path: "Batch.Constraints.MaxTxsPerBatch", + expectedValue: uint64(300), + }, + { + path: "Batch.Constraints.MaxBatchBytesSize", + expectedValue: uint64(120000), + }, + { + path: "Batch.Constraints.MaxCumulativeGasUsed", + expectedValue: uint64(30000000), + }, + { + path: "Batch.Constraints.MaxKeccakHashes", + expectedValue: uint32(2145), + }, + { + path: "Batch.Constraints.MaxPoseidonHashes", + expectedValue: uint32(252357), + }, + { + path: "Batch.Constraints.MaxPoseidonPaddings", + expectedValue: uint32(135191), + }, + { + path: "Batch.Constraints.MaxMemAligns", + expectedValue: uint32(236585), + }, + { + path: "Batch.Constraints.MaxArithmetics", + expectedValue: uint32(236585), + }, + { + path: "Batch.Constraints.MaxBinaries", + expectedValue: uint32(473170), + }, + { + path: "Batch.Constraints.MaxSteps", + expectedValue: uint32(7570538), + }, + { + path: "Batch.ResourceWeights.WeightBatchBytesSize", + expectedValue: 1, + }, + { + path: "Batch.ResourceWeights.WeightCumulativeGasUsed", + expectedValue: 1, + }, + { + path: "Batch.ResourceWeights.WeightKeccakHashes", + expectedValue: 1, + }, + { + path: "Batch.ResourceWeights.WeightPoseidonHashes", + expectedValue: 1, + }, + { + path: "Batch.ResourceWeights.WeightPoseidonPaddings", + expectedValue: 1, + }, + { + path: "Batch.ResourceWeights.WeightMemAligns", + expectedValue: 1, + }, + { + path: "Batch.ResourceWeights.WeightArithmetics", + expectedValue: 1, + }, + { + path: "Batch.ResourceWeights.WeightBinaries", + expectedValue: 1, + }, + { + path: "Batch.ResourceWeights.WeightSteps", + expectedValue: 1, + }, } file, err := os.CreateTemp("", "genesisConfig") require.NoError(t, err) diff --git a/config/default.go b/config/default.go index 8d44065ab8..30d4961181 100644 --- a/config/default.go +++ b/config/default.go @@ -73,25 +73,6 @@ TrustedSequencerURL = "" # If it is empty or not specified, then the value is re WaitPeriodPoolIsEmpty = "1s" BlocksAmountForTxsToBeDeleted = 100 FrequencyToCheckTxsForDelete = "12h" -MaxTxsPerBatch = 300 -MaxBatchBytesSize = 120000 -MaxCumulativeGasUsed = 30000000 -MaxKeccakHashes = 2145 -MaxPoseidonHashes = 252357 -MaxPoseidonPaddings = 135191 -MaxMemAligns = 236585 -MaxArithmetics = 236585 -MaxBinaries = 473170 -MaxSteps = 7570538 -WeightBatchBytesSize = 1 -WeightCumulativeGasUsed = 1 -WeightKeccakHashes = 1 -WeightPoseidonHashes = 1 -WeightPoseidonPaddings = 1 -WeightMemAligns = 1 -WeightArithmetics = 1 -WeightBinaries = 1 -WeightSteps = 1 TxLifetimeCheckTimeout = "10m" MaxTxLifetime = "3h" [Sequencer.Finalizer] @@ -167,4 +148,27 @@ Host = "zkevm-state-db" Port = "5432" EnableLog = false MaxConns = 200 + +[Batch] + [Batch.Constraints] + MaxTxsPerBatch = 300 + MaxBatchBytesSize = 120000 + MaxCumulativeGasUsed = 30000000 + MaxKeccakHashes = 2145 + MaxPoseidonHashes = 252357 + MaxPoseidonPaddings = 135191 + MaxMemAligns = 236585 + MaxArithmetics = 236585 + MaxBinaries = 473170 + MaxSteps = 7570538 + [Batch.ResourceWeights] + WeightBatchBytesSize = 1 + WeightCumulativeGasUsed = 1 + WeightKeccakHashes = 1 + WeightPoseidonHashes = 1 + WeightPoseidonPaddings = 1 + WeightMemAligns = 1 + WeightArithmetics = 1 + WeightBinaries = 1 + WeightSteps = 1 ` diff --git a/config/environments/local/local.node.config.toml b/config/environments/local/local.node.config.toml index cc03b03701..b133637a0b 100644 --- a/config/environments/local/local.node.config.toml +++ b/config/environments/local/local.node.config.toml @@ -59,25 +59,6 @@ TrustedSequencerURL = "" # If it is empty or not specified, then the value is re WaitPeriodPoolIsEmpty = "1s" BlocksAmountForTxsToBeDeleted = 100 FrequencyToCheckTxsForDelete = "12h" -MaxTxsPerBatch = 300 -MaxBatchBytesSize = 120000 -MaxCumulativeGasUsed = 30000000 -MaxKeccakHashes = 2145 -MaxPoseidonHashes = 252357 -MaxPoseidonPaddings = 135191 -MaxMemAligns = 236585 -MaxArithmetics = 236585 -MaxBinaries = 473170 -MaxSteps = 7570538 -WeightBatchBytesSize = 1 -WeightCumulativeGasUsed = 1 -WeightKeccakHashes = 1 -WeightPoseidonHashes = 1 -WeightPoseidonPaddings = 1 -WeightMemAligns = 1 -WeightArithmetics = 1 -WeightBinaries = 1 -WeightSteps = 1 TxLifetimeCheckTimeout = "10m" MaxTxLifetime = "3h" [Sequencer.Finalizer] @@ -160,3 +141,26 @@ Host = "zkevm-state-db" Port = "5432" EnableLog = false MaxConns = 200 + +[Batch] + [Batch.Constraints] + MaxTxsPerBatch = 300 + MaxBatchBytesSize = 120000 + MaxCumulativeGasUsed = 30000000 + MaxKeccakHashes = 2145 + MaxPoseidonHashes = 252357 + MaxPoseidonPaddings = 135191 + MaxMemAligns = 236585 + MaxArithmetics = 236585 + MaxBinaries = 473170 + MaxSteps = 7570538 + [Batch.ResourceWeights] + WeightBatchBytesSize = 1 + WeightCumulativeGasUsed = 1 + WeightKeccakHashes = 1 + WeightPoseidonHashes = 1 + WeightPoseidonPaddings = 1 + WeightMemAligns = 1 + WeightArithmetics = 1 + WeightBinaries = 1 + WeightSteps = 1 diff --git a/pool/config.go b/pool/config.go index c744fd6c82..d7fc598c45 100644 --- a/pool/config.go +++ b/pool/config.go @@ -3,6 +3,7 @@ package pool import ( "github.com/0xPolygonHermez/zkevm-node/config/types" "github.com/0xPolygonHermez/zkevm-node/db" + "github.com/0xPolygonHermez/zkevm-node/state" ) // Config is the pool configuration @@ -38,3 +39,60 @@ type Config struct { // GlobalQueue represents the maximum number of non-executable transaction slots for all accounts GlobalQueue uint64 `mapstructure:"GlobalQueue"` } + +// EffectiveGasPrice has parameters for the effective gas price calculation. +type EffectiveGasPrice struct { + // L1GasPriceFactor is the percentage of the L1 gas price that will be used as the L2 min gas price + L1GasPriceFactor float64 `mapstructure:"L1GasPriceFactor"` + + // ByteGasCost is the gas cost per byte + ByteGasCost uint64 `mapstructure:"ByteGasCost"` + + // MarginFactor is the margin factor percentage to be added to the L2 min gas price + MarginFactor float64 `mapstructure:"MarginFactor"` +} + +// BatchConfig represents the configuration of the batch constraints +type BatchConfig struct { + Constraints BatchConstraintsCfg `mapstructure:"Constraints"` + ResourceWeights BatchResourceWeights `mapstructure:"ResourceWeights"` +} + +// BatchConstraintsCfg represents the configuration of the batch constraints +type BatchConstraintsCfg struct { + MaxTxsPerBatch uint64 `mapstructure:"MaxTxsPerBatch"` + MaxBatchBytesSize uint64 `mapstructure:"MaxBatchBytesSize"` + MaxCumulativeGasUsed uint64 `mapstructure:"MaxCumulativeGasUsed"` + MaxKeccakHashes uint32 `mapstructure:"MaxKeccakHashes"` + MaxPoseidonHashes uint32 `mapstructure:"MaxPoseidonHashes"` + MaxPoseidonPaddings uint32 `mapstructure:"MaxPoseidonPaddings"` + MaxMemAligns uint32 `mapstructure:"MaxMemAligns"` + MaxArithmetics uint32 `mapstructure:"MaxArithmetics"` + MaxBinaries uint32 `mapstructure:"MaxBinaries"` + MaxSteps uint32 `mapstructure:"MaxSteps"` +} + +// IsWithinConstraints checks if the counters are within the batch constraints +func (c BatchConstraintsCfg) IsWithinConstraints(counters state.ZKCounters) bool { + return counters.CumulativeGasUsed <= c.MaxCumulativeGasUsed && + counters.UsedKeccakHashes <= c.MaxKeccakHashes && + counters.UsedPoseidonHashes <= c.MaxPoseidonHashes && + counters.UsedPoseidonPaddings <= c.MaxPoseidonPaddings && + counters.UsedMemAligns <= c.MaxMemAligns && + counters.UsedArithmetics <= c.MaxArithmetics && + counters.UsedBinaries <= c.MaxBinaries && + counters.UsedSteps <= c.MaxSteps +} + +// BatchResourceWeights represents the configuration of the batch resource weights +type BatchResourceWeights struct { + WeightBatchBytesSize int `mapstructure:"WeightBatchBytesSize"` + WeightCumulativeGasUsed int `mapstructure:"WeightCumulativeGasUsed"` + WeightKeccakHashes int `mapstructure:"WeightKeccakHashes"` + WeightPoseidonHashes int `mapstructure:"WeightPoseidonHashes"` + WeightPoseidonPaddings int `mapstructure:"WeightPoseidonPaddings"` + WeightMemAligns int `mapstructure:"WeightMemAligns"` + WeightArithmetics int `mapstructure:"WeightArithmetics"` + WeightBinaries int `mapstructure:"WeightBinaries"` + WeightSteps int `mapstructure:"WeightSteps"` +} diff --git a/pool/config_test.go b/pool/config_test.go new file mode 100644 index 0000000000..d73d694328 --- /dev/null +++ b/pool/config_test.go @@ -0,0 +1,63 @@ +package pool + +import ( + "testing" + + "github.com/0xPolygonHermez/zkevm-node/state" +) + +func TestIsWithinConstraints(t *testing.T) { + cfg := BatchConstraintsCfg{ + MaxCumulativeGasUsed: 500, + MaxKeccakHashes: 100, + MaxPoseidonHashes: 200, + MaxPoseidonPaddings: 150, + MaxMemAligns: 1000, + MaxArithmetics: 2000, + MaxBinaries: 3000, + MaxSteps: 4000, + } + + testCases := []struct { + desc string + counters state.ZKCounters + expected bool + }{ + { + desc: "All constraints within limits", + counters: state.ZKCounters{ + CumulativeGasUsed: 300, + UsedKeccakHashes: 50, + UsedPoseidonHashes: 100, + UsedPoseidonPaddings: 75, + UsedMemAligns: 500, + UsedArithmetics: 1000, + UsedBinaries: 2000, + UsedSteps: 2000, + }, + expected: true, + }, + { + desc: "All constraints exceed limits", + counters: state.ZKCounters{ + CumulativeGasUsed: 600, + UsedKeccakHashes: 150, + UsedPoseidonHashes: 300, + UsedPoseidonPaddings: 200, + UsedMemAligns: 2000, + UsedArithmetics: 3000, + UsedBinaries: 4000, + UsedSteps: 5000, + }, + expected: false, + }, + } + + for _, tC := range testCases { + t.Run(tC.desc, func(t *testing.T) { + if got := cfg.IsWithinConstraints(tC.counters); got != tC.expected { + t.Errorf("Expected %v, got %v", tC.expected, got) + } + }) + } +} diff --git a/pool/errors.go b/pool/errors.go index 14bcb8b08e..3b90864470 100644 --- a/pool/errors.go +++ b/pool/errors.go @@ -64,4 +64,13 @@ var ( // ErrGasPrice is returned if the transaction has specified lower gas price than the minimum allowed. ErrGasPrice = errors.New("gas price too low") + + // ErrReceivedZeroL1GasPrice is returned if the L1 gas price is 0. + ErrReceivedZeroL1GasPrice = errors.New("received L1 gas price 0") + + // ErrInvalidIP is returned if the IP address is invalid. + ErrInvalidIP = errors.New("invalid IP address") + + // ErrOutOfCounters is returned if the pool is out of counters. + ErrOutOfCounters = errors.New("out of counters") ) diff --git a/pool/pool.go b/pool/pool.go index 7a0ca6a1f1..b8718b9ade 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -38,6 +38,7 @@ type Pool struct { state stateInterface chainID uint64 cfg Config + batchConstraintsCfg BatchConstraintsCfg blockedAddresses sync.Map minSuggestedGasPrice *big.Int minSuggestedGasPriceMux *sync.RWMutex @@ -63,10 +64,11 @@ type GasPrices struct { } // NewPool creates and initializes an instance of Pool -func NewPool(cfg Config, s storage, st stateInterface, chainID uint64, eventLog *event.EventLog) *Pool { +func NewPool(cfg Config, batchConstraintsCfg BatchConstraintsCfg, s storage, st stateInterface, chainID uint64, eventLog *event.EventLog) *Pool { startTimestamp := time.Now() p := &Pool{ cfg: cfg, + batchConstraintsCfg: batchConstraintsCfg, startTimestamp: startTimestamp, storage: s, state: st, @@ -194,7 +196,7 @@ func (p *Pool) StoreTx(ctx context.Context, tx types.Transaction, ip string, isW log.Errorf("error adding event: %v", err) } // Do not add tx to the pool - return fmt.Errorf("out of counters") + return ErrOutOfCounters } else if preExecutionResponse.isOOG { event := &event.Event{ ReceivedAt: time.Now(), @@ -230,10 +232,18 @@ func (p *Pool) preExecuteTx(ctx context.Context, tx types.Transaction) (preExecu if processBatchResponse.Responses != nil && len(processBatchResponse.Responses) > 0 { errorToCheck := processBatchResponse.Responses[0].RomError - response.isReverted = errors.Is(errorToCheck, runtime.ErrExecutionReverted) response.isExecutorLevelError = processBatchResponse.IsExecutorLevelError - response.isOOC = executor.IsROMOutOfCountersError(executor.RomErrorCode(errorToCheck)) - response.isOOG = errors.Is(errorToCheck, runtime.ErrOutOfGas) + if errorToCheck != nil { + response.isReverted = errors.Is(errorToCheck, runtime.ErrExecutionReverted) + response.isOOC = executor.IsROMOutOfCountersError(executor.RomErrorCode(errorToCheck)) + response.isOOG = errors.Is(errorToCheck, runtime.ErrOutOfGas) + } else { + if !p.batchConstraintsCfg.IsWithinConstraints(processBatchResponse.UsedZkCounters) { + response.isOOC = true + log.Errorf("OutOfCounters Error (Node level) for tx: %s", tx.Hash().String()) + } + } + response.usedZkCounters = processBatchResponse.UsedZkCounters response.txResponse = processBatchResponse.Responses[0] } @@ -302,6 +312,11 @@ func (p *Pool) IsTxPending(ctx context.Context, hash common.Hash) (bool, error) } func (p *Pool) validateTx(ctx context.Context, poolTx Transaction) error { + // Make sure the IP is valid. + if poolTx.IP != "" && !IsValidIP(poolTx.IP) { + return ErrInvalidIP + } + // Make sure the transaction is signed properly. if err := state.CheckSignature(poolTx.Transaction); err != nil { return ErrInvalidSender diff --git a/pool/pool_test.go b/pool/pool_test.go index 39751375ef..7eadbed00d 100644 --- a/pool/pool_test.go +++ b/pool/pool_test.go @@ -70,6 +70,19 @@ var ( l1GasPrice = big.NewInt(1000000000000) gasLimit = uint64(21000) chainID = big.NewInt(1337) + bc = pool.BatchConstraintsCfg{ + MaxTxsPerBatch: 300, + MaxBatchBytesSize: 120000, + MaxCumulativeGasUsed: 30000000, + MaxKeccakHashes: 2145, + MaxPoseidonHashes: 252357, + MaxPoseidonPaddings: 135191, + MaxMemAligns: 236585, + MaxArithmetics: 236585, + MaxBinaries: 473170, + MaxSteps: 7570538, + } + ip = "101.1.50.20" ) func TestMain(m *testing.M) { @@ -119,7 +132,7 @@ func Test_AddTx(t *testing.T) { require.NoError(t, err) const chainID = 2576980377 - p := setupPool(t, cfg, s, st, chainID, ctx, eventLog) + p := setupPool(t, cfg, bc, s, st, chainID, ctx, eventLog) tx := new(ethTypes.Transaction) expectedTxEncoded := "0xf86880843b9aca008252089400000000000000000000000000000000000000008080850133333355a03ee24709870c8dbc67884c9c8acb864c1aceaaa7332b9a3db0d7a5d7c68eb8e4a0302980b070f5e3ffca3dc27b07daf69d66ab27d4df648e0b3ed059cf23aa168d" @@ -127,7 +140,7 @@ func Test_AddTx(t *testing.T) { require.NoError(t, err) tx.UnmarshalBinary(b) //nolint:gosec,errcheck - err = p.AddTx(ctx, *tx, "") + err = p.AddTx(ctx, *tx, ip) require.NoError(t, err) rows, err := poolSqlDB.Query(ctx, "SELECT hash, encoded, decoded, status, used_steps FROM pool.transaction") @@ -200,7 +213,7 @@ func Test_AddTx_OversizedData(t *testing.T) { require.NoError(t, err) const chainID = 2576980377 - p := pool.NewPool(cfg, s, st, chainID, eventLog) + p := pool.NewPool(cfg, bc, s, st, chainID, eventLog) b := make([]byte, cfg.MaxTxBytesSize+1) to := common.HexToAddress(operations.DefaultSequencerAddress) @@ -212,7 +225,7 @@ func Test_AddTx_OversizedData(t *testing.T) { signedTx, err := auth.Signer(auth.From, tx) require.NoError(t, err) - err = p.AddTx(ctx, *signedTx, "") + err = p.AddTx(ctx, *signedTx, ip) require.EqualError(t, err, pool.ErrOversizedData.Error()) } @@ -266,7 +279,7 @@ func Test_AddPreEIP155Tx(t *testing.T) { require.NoError(t, err) const chainID = 2576980377 - p := setupPool(t, cfg, s, st, chainID, ctx, eventLog) + p := setupPool(t, cfg, bc, s, st, chainID, ctx, eventLog) batchL2Data := "0xe580843b9aca00830186a0941275fbb540c8efc58b812ba83b0d0b8b9917ae98808464fbb77c6b39bdc5f8e458aba689f2a1ff8c543a94e4817bda40f3fe34080c4ab26c1e3c2fc2cda93bc32f0a79940501fd505dcf48d94abfde932ebf1417f502cb0d9de81bff" b, err := hex.DecodeHex(batchL2Data) @@ -276,7 +289,7 @@ func Test_AddPreEIP155Tx(t *testing.T) { tx := txs[0] - err = p.AddTx(ctx, tx, "") + err = p.AddTx(ctx, tx, ip) require.NoError(t, err) rows, err := poolSqlDB.Query(ctx, "SELECT hash, encoded, decoded, status FROM pool.transaction") @@ -335,7 +348,7 @@ func Test_GetPendingTxs(t *testing.T) { s, err := pgpoolstorage.NewPostgresPoolStorage(poolDBCfg) require.NoError(t, err) - p := setupPool(t, cfg, s, st, chainID.Uint64(), ctx, eventLog) + p := setupPool(t, cfg, bc, s, st, chainID.Uint64(), ctx, eventLog) const txsCount = 10 const limit = 5 @@ -351,7 +364,7 @@ func Test_GetPendingTxs(t *testing.T) { tx := ethTypes.NewTransaction(uint64(i), common.Address{}, big.NewInt(10), gasLimit, gasPrice, []byte{}) signedTx, err := auth.Signer(auth.From, tx) require.NoError(t, err) - err = p.AddTx(ctx, *signedTx, "") + err = p.AddTx(ctx, *signedTx, ip) require.NoError(t, err) } @@ -395,7 +408,7 @@ func Test_GetPendingTxsZeroPassed(t *testing.T) { s, err := pgpoolstorage.NewPostgresPoolStorage(poolDBCfg) require.NoError(t, err) - p := setupPool(t, cfg, s, st, chainID.Uint64(), ctx, eventLog) + p := setupPool(t, cfg, bc, s, st, chainID.Uint64(), ctx, eventLog) const txsCount = 10 const limit = 0 @@ -411,7 +424,7 @@ func Test_GetPendingTxsZeroPassed(t *testing.T) { tx := ethTypes.NewTransaction(uint64(i), common.Address{}, big.NewInt(10), gasLimit, gasPrice, []byte{}) signedTx, err := auth.Signer(auth.From, tx) require.NoError(t, err) - err = p.AddTx(ctx, *signedTx, "") + err = p.AddTx(ctx, *signedTx, ip) require.NoError(t, err) } @@ -455,7 +468,7 @@ func Test_GetTopPendingTxByProfitabilityAndZkCounters(t *testing.T) { s, err := pgpoolstorage.NewPostgresPoolStorage(poolDBCfg) require.NoError(t, err) - p := setupPool(t, cfg, s, st, chainID.Uint64(), ctx, eventLog) + p := setupPool(t, cfg, bc, s, st, chainID.Uint64(), ctx, eventLog) const txsCount = 10 @@ -470,7 +483,7 @@ func Test_GetTopPendingTxByProfitabilityAndZkCounters(t *testing.T) { tx := ethTypes.NewTransaction(uint64(i), common.Address{}, big.NewInt(10), gasLimit, big.NewInt(gasPrice.Int64()+int64(i)), []byte{}) signedTx, err := auth.Signer(auth.From, tx) require.NoError(t, err) - err = p.AddTx(ctx, *signedTx, "") + err = p.AddTx(ctx, *signedTx, ip) require.NoError(t, err) } @@ -515,7 +528,7 @@ func Test_UpdateTxsStatus(t *testing.T) { s, err := pgpoolstorage.NewPostgresPoolStorage(poolDBCfg) require.NoError(t, err) - p := setupPool(t, cfg, s, st, chainID.Uint64(), ctx, eventLog) + p := setupPool(t, cfg, bc, s, st, chainID.Uint64(), ctx, eventLog) privateKey, err := crypto.HexToECDSA(strings.TrimPrefix(senderPrivateKey, "0x")) require.NoError(t, err) @@ -526,13 +539,13 @@ func Test_UpdateTxsStatus(t *testing.T) { tx1 := ethTypes.NewTransaction(uint64(0), common.Address{}, big.NewInt(10), gasLimit, gasPrice, []byte{}) signedTx1, err := auth.Signer(auth.From, tx1) require.NoError(t, err) - err = p.AddTx(ctx, *signedTx1, "") + err = p.AddTx(ctx, *signedTx1, ip) require.NoError(t, err) tx2 := ethTypes.NewTransaction(uint64(1), common.Address{}, big.NewInt(10), gasLimit, gasPrice, []byte{}) signedTx2, err := auth.Signer(auth.From, tx2) require.NoError(t, err) - err = p.AddTx(ctx, *signedTx2, "") + err = p.AddTx(ctx, *signedTx2, ip) require.NoError(t, err) expectedFailedReason := "failed" @@ -606,7 +619,7 @@ func Test_UpdateTxStatus(t *testing.T) { s, err := pgpoolstorage.NewPostgresPoolStorage(poolDBCfg) require.NoError(t, err) - p := setupPool(t, cfg, s, st, chainID.Uint64(), ctx, eventLog) + p := setupPool(t, cfg, bc, s, st, chainID.Uint64(), ctx, eventLog) privateKey, err := crypto.HexToECDSA(strings.TrimPrefix(senderPrivateKey, "0x")) require.NoError(t, err) @@ -616,7 +629,7 @@ func Test_UpdateTxStatus(t *testing.T) { tx := ethTypes.NewTransaction(uint64(0), common.Address{}, big.NewInt(10), gasLimit, gasPrice, []byte{}) signedTx, err := auth.Signer(auth.From, tx) require.NoError(t, err) - if err := p.AddTx(ctx, *signedTx, ""); err != nil { + if err := p.AddTx(ctx, *signedTx, ip); err != nil { t.Error(err) } expectedFailedReason := "failed" @@ -649,7 +662,7 @@ func Test_SetAndGetGasPrice(t *testing.T) { require.NoError(t, err) eventLog := event.NewEventLog(event.Config{}, eventStorage) - p := pool.NewPool(cfg, s, nil, chainID.Uint64(), eventLog) + p := pool.NewPool(cfg, bc, s, nil, chainID.Uint64(), eventLog) nBig, err := rand.Int(rand.Reader, big.NewInt(0).SetUint64(math.MaxUint64)) require.NoError(t, err) @@ -674,7 +687,7 @@ func TestDeleteGasPricesHistoryOlderThan(t *testing.T) { require.NoError(t, err) eventLog := event.NewEventLog(event.Config{}, eventStorage) - p := pool.NewPool(cfg, s, nil, chainID.Uint64(), eventLog) + p := pool.NewPool(cfg, bc, s, nil, chainID.Uint64(), eventLog) ctx := context.Background() @@ -743,7 +756,7 @@ func TestGetPendingTxSince(t *testing.T) { s, err := pgpoolstorage.NewPostgresPoolStorage(poolDBCfg) require.NoError(t, err) - p := setupPool(t, cfg, s, st, chainID.Uint64(), ctx, eventLog) + p := setupPool(t, cfg, bc, s, st, chainID.Uint64(), ctx, eventLog) const txsCount = 10 @@ -763,7 +776,7 @@ func TestGetPendingTxSince(t *testing.T) { signedTx, err := auth.Signer(auth.From, tx) require.NoError(t, err) txsAddedTime = append(txsAddedTime, time.Now()) - err = p.AddTx(ctx, *signedTx, "") + err = p.AddTx(ctx, *signedTx, ip) require.NoError(t, err) txsAddedHashes = append(txsAddedHashes, signedTx.Hash()) time.Sleep(1 * time.Second) @@ -835,7 +848,7 @@ func Test_DeleteTransactionsByHashes(t *testing.T) { s, err := pgpoolstorage.NewPostgresPoolStorage(poolDBCfg) require.NoError(t, err) - p := setupPool(t, cfg, s, st, chainID.Uint64(), ctx, eventLog) + p := setupPool(t, cfg, bc, s, st, chainID.Uint64(), ctx, eventLog) privateKey, err := crypto.HexToECDSA(strings.TrimPrefix(senderPrivateKey, "0x")) require.NoError(t, err) @@ -846,13 +859,13 @@ func Test_DeleteTransactionsByHashes(t *testing.T) { tx1 := ethTypes.NewTransaction(uint64(0), common.Address{}, big.NewInt(10), gasLimit, gasPrice, []byte{}) signedTx1, err := auth.Signer(auth.From, tx1) require.NoError(t, err) - err = p.AddTx(ctx, *signedTx1, "") + err = p.AddTx(ctx, *signedTx1, ip) require.NoError(t, err) tx2 := ethTypes.NewTransaction(uint64(1), common.Address{}, big.NewInt(10), gasLimit, gasPrice, []byte{}) signedTx2, err := auth.Signer(auth.From, tx2) require.NoError(t, err) - err = p.AddTx(ctx, *signedTx2, "") + err = p.AddTx(ctx, *signedTx2, ip) require.NoError(t, err) err = p.DeleteTransactionsByHashes(ctx, []common.Hash{signedTx1.Hash(), signedTx2.Hash()}) @@ -985,8 +998,8 @@ func Test_TryAddIncompatibleTxs(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.name, func(t *testing.T) { incompatibleTx := testCase.createIncompatibleTx() - p := setupPool(t, cfg, s, st, incompatibleTx.ChainId().Uint64(), ctx, eventLog) - err = p.AddTx(ctx, incompatibleTx, "") + p := setupPool(t, cfg, bc, s, st, incompatibleTx.ChainId().Uint64(), ctx, eventLog) + err = p.AddTx(ctx, incompatibleTx, ip) assert.Equal(t, testCase.expectedError, err) }) } @@ -1050,7 +1063,7 @@ func Test_AddTxWithIntrinsicGasTooLow(t *testing.T) { s, err := pgpoolstorage.NewPostgresPoolStorage(poolDBCfg) require.NoError(t, err) - p := setupPool(t, cfg, s, st, chainID.Uint64(), ctx, eventLog) + p := setupPool(t, cfg, bc, s, st, chainID.Uint64(), ctx, eventLog) privateKey, err := crypto.HexToECDSA(strings.TrimPrefix(senderPrivateKey, "0x")) require.NoError(t, err) @@ -1069,7 +1082,7 @@ func Test_AddTxWithIntrinsicGasTooLow(t *testing.T) { }) signedTx, err := auth.Signer(auth.From, tx) require.NoError(t, err) - err = p.AddTx(ctx, *signedTx, "") + err = p.AddTx(ctx, *signedTx, ip) require.Error(t, err) assert.Equal(t, err.Error(), pool.ErrIntrinsicGas.Error()) @@ -1083,7 +1096,7 @@ func Test_AddTxWithIntrinsicGasTooLow(t *testing.T) { }) signedTx, err = auth.Signer(auth.From, tx) require.NoError(t, err) - err = p.AddTx(ctx, *signedTx, "") + err = p.AddTx(ctx, *signedTx, ip) require.Error(t, err) assert.Equal(t, err.Error(), pool.ErrIntrinsicGas.Error()) @@ -1097,7 +1110,7 @@ func Test_AddTxWithIntrinsicGasTooLow(t *testing.T) { }) signedTx, err = auth.Signer(auth.From, tx) require.NoError(t, err) - err = p.AddTx(ctx, *signedTx, "") + err = p.AddTx(ctx, *signedTx, ip) require.NoError(t, err) tx = ethTypes.NewTx(ðTypes.LegacyTx{ @@ -1110,7 +1123,7 @@ func Test_AddTxWithIntrinsicGasTooLow(t *testing.T) { }) signedTx, err = auth.Signer(auth.From, tx) require.NoError(t, err) - err = p.AddTx(ctx, *signedTx, "") + err = p.AddTx(ctx, *signedTx, ip) require.Error(t, err) assert.Equal(t, err.Error(), pool.ErrIntrinsicGas.Error()) @@ -1124,7 +1137,7 @@ func Test_AddTxWithIntrinsicGasTooLow(t *testing.T) { }) signedTx, err = auth.Signer(auth.From, tx) require.NoError(t, err) - err = p.AddTx(ctx, *signedTx, "") + err = p.AddTx(ctx, *signedTx, ip) require.Error(t, err) assert.Equal(t, err.Error(), pool.ErrIntrinsicGas.Error()) @@ -1138,7 +1151,7 @@ func Test_AddTxWithIntrinsicGasTooLow(t *testing.T) { }) signedTx, err = auth.Signer(auth.From, tx) require.NoError(t, err) - err = p.AddTx(ctx, *signedTx, "") + err = p.AddTx(ctx, *signedTx, ip) require.NoError(t, err) txs, err := p.GetPendingTxs(ctx, 0) @@ -1230,7 +1243,7 @@ func Test_AddTx_GasPriceErr(t *testing.T) { s, err := pgpoolstorage.NewPostgresPoolStorage(poolDBCfg) require.NoError(t, err) - p := setupPool(t, cfg, s, st, chainID.Uint64(), ctx, eventLog) + p := setupPool(t, cfg, bc, s, st, chainID.Uint64(), ctx, eventLog) tx := ethTypes.NewTx(ðTypes.LegacyTx{ Nonce: tc.nonce, To: tc.to, @@ -1248,7 +1261,7 @@ func Test_AddTx_GasPriceErr(t *testing.T) { signedTx, err := auth.Signer(auth.From, tx) require.NoError(t, err) - err = p.AddTx(ctx, *signedTx, "") + err = p.AddTx(ctx, *signedTx, ip) if tc.expectedError != nil { require.ErrorIs(t, err, tc.expectedError) } else { @@ -1287,9 +1300,9 @@ func Test_AddRevertedTx(t *testing.T) { require.NoError(t, dbTx.Commit(ctx)) s, err := pgpoolstorage.NewPostgresPoolStorage(poolDBCfg) - require.NoError(t, err) - p := setupPool(t, cfg, s, st, chainID.Uint64(), ctx, eventLog) + + p := setupPool(t, cfg, bc, s, st, chainID.Uint64(), ctx, eventLog) privateKey, err := crypto.HexToECDSA(strings.TrimPrefix(senderPrivateKey, "0x")) require.NoError(t, err) @@ -1309,7 +1322,7 @@ func Test_AddRevertedTx(t *testing.T) { signedTx, err := auth.Signer(auth.From, tx) require.NoError(t, err) - err = p.AddTx(ctx, *signedTx, "") + err = p.AddTx(ctx, *signedTx, ip) require.NoError(t, err) txs, err := p.GetPendingTxs(ctx, 0) @@ -1382,7 +1395,7 @@ func Test_BlockedAddress(t *testing.T) { GlobalQueue: 1024, } - p := setupPool(t, cfg, s, st, chainID.Uint64(), ctx, eventLog) + p := setupPool(t, cfg, bc, s, st, chainID.Uint64(), ctx, eventLog) gasPrices, err := p.GetGasPrices(ctx) require.NoError(t, err) @@ -1398,7 +1411,7 @@ func Test_BlockedAddress(t *testing.T) { signedTx, err := auth.Signer(auth.From, tx) require.NoError(t, err) - err = p.AddTx(ctx, *signedTx, "") + err = p.AddTx(ctx, *signedTx, ip) require.NoError(t, err) // block address @@ -1419,7 +1432,7 @@ func Test_BlockedAddress(t *testing.T) { signedTx, err = auth.Signer(auth.From, tx) require.NoError(t, err) - err = p.AddTx(ctx, *signedTx, "") + err = p.AddTx(ctx, *signedTx, ip) require.Equal(t, pool.ErrBlockedSender, err) // remove block @@ -1430,7 +1443,7 @@ func Test_BlockedAddress(t *testing.T) { time.Sleep(cfg.IntervalToRefreshBlockedAddresses.Duration) // allowed to add tx again - err = p.AddTx(ctx, *signedTx, "") + err = p.AddTx(ctx, *signedTx, ip) require.NoError(t, err) } @@ -1504,7 +1517,7 @@ func Test_AddTx_GasOverBatchLimit(t *testing.T) { s, err := pgpoolstorage.NewPostgresPoolStorage(poolDBCfg) require.NoError(t, err) - p := setupPool(t, cfg, s, st, chainID.Uint64(), ctx, eventLog) + p := setupPool(t, cfg, bc, s, st, chainID.Uint64(), ctx, eventLog) tx := ethTypes.NewTx(ðTypes.LegacyTx{ Nonce: tc.nonce, To: tc.to, @@ -1522,7 +1535,7 @@ func Test_AddTx_GasOverBatchLimit(t *testing.T) { signedTx, err := auth.Signer(auth.From, tx) require.NoError(t, err) - err = p.AddTx(ctx, *signedTx, "") + err = p.AddTx(ctx, *signedTx, ip) if tc.expectedError != nil { require.ErrorIs(t, err, tc.expectedError) } else { @@ -1578,7 +1591,7 @@ func Test_AddTx_AccountQueueLimit(t *testing.T) { s, err := pgpoolstorage.NewPostgresPoolStorage(poolDBCfg) require.NoError(t, err) - p := setupPool(t, cfg, s, st, chainID.Uint64(), ctx, eventLog) + p := setupPool(t, cfg, bc, s, st, chainID.Uint64(), ctx, eventLog) privateKey, err := crypto.HexToECDSA(strings.TrimPrefix(senderPrivateKey, "0x")) require.NoError(t, err) @@ -1598,7 +1611,7 @@ func Test_AddTx_AccountQueueLimit(t *testing.T) { signedTx, err := auth.Signer(auth.From, tx) require.NoError(t, err) - err = p.AddTx(ctx, *signedTx, "") + err = p.AddTx(ctx, *signedTx, ip) require.NoError(t, err) nonce++ } @@ -1613,7 +1626,7 @@ func Test_AddTx_AccountQueueLimit(t *testing.T) { signedTx, err := auth.Signer(auth.From, tx) require.NoError(t, err) - err = p.AddTx(ctx, *signedTx, "") + err = p.AddTx(ctx, *signedTx, ip) require.Error(t, err, pool.ErrNonceTooHigh) } @@ -1679,7 +1692,7 @@ func Test_AddTx_GlobalQueueLimit(t *testing.T) { s, err := pgpoolstorage.NewPostgresPoolStorage(poolDBCfg) require.NoError(t, err) - p := setupPool(t, cfg, s, st, chainID.Uint64(), ctx, eventLog) + p := setupPool(t, cfg, bc, s, st, chainID.Uint64(), ctx, eventLog) for _, privateKey := range accounts { auth, err := bind.NewKeyedTransactorWithChainID(privateKey, chainID) @@ -1694,7 +1707,7 @@ func Test_AddTx_GlobalQueueLimit(t *testing.T) { signedTx, err := auth.Signer(auth.From, tx) require.NoError(t, err) - err = p.AddTx(ctx, *signedTx, "") + err = p.AddTx(ctx, *signedTx, ip) require.NoError(t, err) } @@ -1714,7 +1727,7 @@ func Test_AddTx_GlobalQueueLimit(t *testing.T) { signedTx, err := auth.Signer(auth.From, tx) require.NoError(t, err) - err = p.AddTx(ctx, *signedTx, "") + err = p.AddTx(ctx, *signedTx, ip) require.Error(t, err, pool.ErrTxPoolOverflow) } @@ -1765,7 +1778,7 @@ func Test_AddTx_NonceTooHigh(t *testing.T) { s, err := pgpoolstorage.NewPostgresPoolStorage(poolDBCfg) require.NoError(t, err) - p := setupPool(t, cfg, s, st, chainID.Uint64(), ctx, eventLog) + p := setupPool(t, cfg, bc, s, st, chainID.Uint64(), ctx, eventLog) tx := ethTypes.NewTx(ðTypes.LegacyTx{ Nonce: cfg.AccountQueue, @@ -1783,12 +1796,80 @@ func Test_AddTx_NonceTooHigh(t *testing.T) { signedTx, err := auth.Signer(auth.From, tx) require.NoError(t, err) - err = p.AddTx(ctx, *signedTx, "") + err = p.AddTx(ctx, *signedTx, ip) require.Error(t, err, pool.ErrNonceTooHigh) } -func setupPool(t *testing.T, cfg pool.Config, s *pgpoolstorage.PostgresPoolStorage, st *state.State, chainID uint64, ctx context.Context, eventLog *event.EventLog) *pool.Pool { - p := pool.NewPool(cfg, s, st, chainID, eventLog) +func Test_AddTx_IPValidation(t *testing.T) { + var tests = []struct { + name string + ip string + expected error + }{ + {"Valid IPv4", "127.0.0.1", nil}, + {"Valid IPv6", "2001:db8:0:1:1:1:1:1", nil}, + {"Invalid IP", "300.0.0.1", pool.ErrInvalidIP}, + } + + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + initOrResetDB(t) + + stateSqlDB, err := db.NewSQLDB(stateDBCfg) + require.NoError(t, err) + defer stateSqlDB.Close() //nolint:gosec,errcheck + + poolSqlDB, err := db.NewSQLDB(poolDBCfg) + require.NoError(t, err) + + defer poolSqlDB.Close() //nolint:gosec,errcheck + + eventStorage, err := nileventstorage.NewNilEventStorage() + if err != nil { + log.Fatal(err) + } + eventLog := event.NewEventLog(event.Config{}, eventStorage) + + st := newState(stateSqlDB, eventLog) + + genesisBlock := state.Block{ + BlockNumber: 0, + BlockHash: state.ZeroHash, + ParentHash: state.ZeroHash, + ReceivedAt: time.Now(), + } + ctx := context.Background() + dbTx, err := st.BeginStateTransaction(ctx) + require.NoError(t, err) + _, err = st.SetGenesis(ctx, genesisBlock, genesis, dbTx) + require.NoError(t, err) + require.NoError(t, dbTx.Commit(ctx)) + + s, err := pgpoolstorage.NewPostgresPoolStorage(poolDBCfg) + require.NoError(t, err) + + const chainID = 2576980377 + p := setupPool(t, cfg, bc, s, st, chainID, ctx, eventLog) + + tx := new(ethTypes.Transaction) + expectedTxEncoded := "0xf86880843b9aca008252089400000000000000000000000000000000000000008080850133333355a03ee24709870c8dbc67884c9c8acb864c1aceaaa7332b9a3db0d7a5d7c68eb8e4a0302980b070f5e3ffca3dc27b07daf69d66ab27d4df648e0b3ed059cf23aa168d" + b, err := hex.DecodeHex(expectedTxEncoded) + require.NoError(t, err) + tx.UnmarshalBinary(b) //nolint:gosec,errcheck + + err = p.AddTx(context.Background(), *tx, tc.ip) + + if tc.expected != nil { + assert.ErrorIs(t, err, tc.expected) + } else { + assert.NoError(t, err) + } + }) + } +} + +func setupPool(t *testing.T, cfg pool.Config, constraintsCfg pool.BatchConstraintsCfg, s *pgpoolstorage.PostgresPoolStorage, st *state.State, chainID uint64, ctx context.Context, eventLog *event.EventLog) *pool.Pool { + p := pool.NewPool(cfg, constraintsCfg, s, st, chainID, eventLog) err := p.SetGasPrices(ctx, gasPrice.Uint64(), l1GasPrice.Uint64()) require.NoError(t, err) diff --git a/pool/validation.go b/pool/validation.go new file mode 100644 index 0000000000..daf1460115 --- /dev/null +++ b/pool/validation.go @@ -0,0 +1,8 @@ +package pool + +import "net" + +// IsValidIP returns true if the given string is a valid IP address +func IsValidIP(ip string) bool { + return ip != "" && net.ParseIP(ip) != nil +} diff --git a/pool/validation_test.go b/pool/validation_test.go new file mode 100644 index 0000000000..d03ee86fc1 --- /dev/null +++ b/pool/validation_test.go @@ -0,0 +1,27 @@ +package pool + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func Test_IsValidIP(t *testing.T) { + var tests = []struct { + name string + ip string + expected bool + }{ + {"Valid IPv4", "127.0.0.1", true}, + {"Valid IPv6", "2001:db8:0:1:1:1:1:1", true}, + {"Invalid IP", "300.0.0.1", false}, + {"Empty IP", "", false}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + result := IsValidIP(tt.ip) + assert.Equal(t, tt.expected, result) + }) + } +} diff --git a/sequencer/addrqueue.go b/sequencer/addrqueue.go index 684a060aed..c5a97c128c 100644 --- a/sequencer/addrqueue.go +++ b/sequencer/addrqueue.go @@ -5,6 +5,7 @@ import ( "time" "github.com/0xPolygonHermez/zkevm-node/log" + "github.com/0xPolygonHermez/zkevm-node/pool" "github.com/0xPolygonHermez/zkevm-node/state" "github.com/0xPolygonHermez/zkevm-node/state/runtime" "github.com/ethereum/go-ethereum/common" @@ -186,7 +187,7 @@ func (a *addrQueue) updateCurrentNonceBalance(nonce *uint64, balance *big.Int) ( // UpdateTxZKCounters updates the ZKCounters for the given tx (txHash) // If the updated tx is the readyTx it returns a copy of the previous readyTx, nil otherwise -func (a *addrQueue) UpdateTxZKCounters(txHash common.Hash, counters state.ZKCounters, constraints batchConstraintsFloat64, weights batchResourceWeights) (newReadyTx, prevReadyTx *TxTracker) { +func (a *addrQueue) UpdateTxZKCounters(txHash common.Hash, counters state.ZKCounters, constraints batchConstraintsFloat64, weights pool.BatchResourceWeights) (newReadyTx, prevReadyTx *TxTracker) { txHashStr := txHash.String() if (a.readyTx != nil) && (a.readyTx.HashStr == txHashStr) { diff --git a/sequencer/closingsignalsmanager_test.go b/sequencer/closingsignalsmanager_test.go index cb09f40e34..8f805c292a 100644 --- a/sequencer/closingsignalsmanager_test.go +++ b/sequencer/closingsignalsmanager_test.go @@ -12,6 +12,7 @@ import ( "github.com/0xPolygonHermez/zkevm-node/log" "github.com/0xPolygonHermez/zkevm-node/merkletree" mtDBclientpb "github.com/0xPolygonHermez/zkevm-node/merkletree/pb" + "github.com/0xPolygonHermez/zkevm-node/pool" "github.com/0xPolygonHermez/zkevm-node/state" "github.com/0xPolygonHermez/zkevm-node/state/runtime/executor" "github.com/0xPolygonHermez/zkevm-node/test/dbutils" @@ -74,7 +75,7 @@ func setupTest(t *testing.T) { localStateTree := merkletree.NewStateTree(localMtDBServiceClient) localState = state.NewState(stateCfg, state.NewPostgresStorage(localStateDb), localExecutorClient, localStateTree, eventLog) - batchConstraints := batchConstraints{ + batchConstraints := pool.BatchConstraintsCfg{ MaxTxsPerBatch: 300, MaxBatchBytesSize: 120000, MaxCumulativeGasUsed: 30000000, diff --git a/sequencer/config.go b/sequencer/config.go index 9b99af333b..bb8a77e8f2 100644 --- a/sequencer/config.go +++ b/sequencer/config.go @@ -16,64 +16,6 @@ type Config struct { // FrequencyToCheckTxsForDelete is frequency with which txs will be checked for deleting FrequencyToCheckTxsForDelete types.Duration `mapstructure:"FrequencyToCheckTxsForDelete"` - // MaxTxsPerBatch is the maximum amount of transactions in the batch - MaxTxsPerBatch uint64 `mapstructure:"MaxTxsPerBatch"` - - // MaxBatchBytesSize is the maximum batch size in bytes - // (subtracted bits of all types.Sequence fields excluding BatchL2Data from MaxTxSizeForL1) - MaxBatchBytesSize uint64 `mapstructure:"MaxBatchBytesSize"` - - // MaxCumulativeGasUsed is max gas amount used by batch - MaxCumulativeGasUsed uint64 `mapstructure:"MaxCumulativeGasUsed"` - - // MaxKeccakHashes is max keccak hashes used by batch - MaxKeccakHashes uint32 `mapstructure:"MaxKeccakHashes"` - - // MaxPoseidonHashes is max poseidon hashes batch can handle - MaxPoseidonHashes uint32 `mapstructure:"MaxPoseidonHashes"` - - // MaxPoseidonPaddings is max poseidon paddings batch can handle - MaxPoseidonPaddings uint32 `mapstructure:"MaxPoseidonPaddings"` - - // MaxMemAligns is max mem aligns batch can handle - MaxMemAligns uint32 `mapstructure:"MaxMemAligns"` - - // MaxArithmetics is max arithmetics batch can handle - MaxArithmetics uint32 `mapstructure:"MaxArithmetics"` - - // MaxBinaries is max binaries batch can handle - MaxBinaries uint32 `mapstructure:"MaxBinaries"` - - // MaxSteps is max steps batch can handle - MaxSteps uint32 `mapstructure:"MaxSteps"` - - // WeightBatchBytesSize is the cost weight for the BatchBytesSize batch resource - WeightBatchBytesSize int `mapstructure:"WeightBatchBytesSize"` - - // WeightCumulativeGasUsed is the cost weight for the CumulativeGasUsed batch resource - WeightCumulativeGasUsed int `mapstructure:"WeightCumulativeGasUsed"` - - // WeightKeccakHashes is the cost weight for the KeccakHashes batch resource - WeightKeccakHashes int `mapstructure:"WeightKeccakHashes"` - - // WeightPoseidonHashes is the cost weight for the PoseidonHashes batch resource - WeightPoseidonHashes int `mapstructure:"WeightPoseidonHashes"` - - // WeightPoseidonPaddings is the cost weight for the PoseidonPaddings batch resource - WeightPoseidonPaddings int `mapstructure:"WeightPoseidonPaddings"` - - // WeightMemAligns is the cost weight for the MemAligns batch resource - WeightMemAligns int `mapstructure:"WeightMemAligns"` - - // WeightArithmetics is the cost weight for the Arithmetics batch resource - WeightArithmetics int `mapstructure:"WeightArithmetics"` - - // WeightBinaries is the cost weight for the Binaries batch resource - WeightBinaries int `mapstructure:"WeightBinaries"` - - // WeightSteps is the cost weight for the Steps batch resource - WeightSteps int `mapstructure:"WeightSteps"` - // TxLifetimeCheckTimeout is the time the sequencer waits to check txs lifetime TxLifetimeCheckTimeout types.Duration `mapstructure:"TxLifetimeCheckTimeout"` diff --git a/sequencer/dbmanager.go b/sequencer/dbmanager.go index b47de338ef..815f5a4892 100644 --- a/sequencer/dbmanager.go +++ b/sequencer/dbmanager.go @@ -21,7 +21,7 @@ type dbManager struct { worker workerInterface l2ReorgCh chan L2ReorgEvent ctx context.Context - batchConstraints batchConstraints + batchConstraints pool.BatchConstraintsCfg numberOfReorgs uint64 } @@ -41,7 +41,7 @@ type ClosingBatchParameters struct { EffectivePercentages []uint8 } -func newDBManager(ctx context.Context, config DBManagerCfg, txPool txPool, state stateInterface, worker *Worker, closingSignalCh ClosingSignalCh, batchConstraints batchConstraints) *dbManager { +func newDBManager(ctx context.Context, config DBManagerCfg, txPool txPool, state stateInterface, worker *Worker, closingSignalCh ClosingSignalCh, batchConstraints pool.BatchConstraintsCfg) *dbManager { numberOfReorgs, err := state.CountReorgs(ctx, nil) if err != nil { log.Error("failed to get number of reorgs: %v", err) @@ -270,7 +270,7 @@ func (d *dbManager) GetWIPBatch(ctx context.Context) (*WipBatch, error) { // Init counters to MAX values var totalBytes uint64 = d.batchConstraints.MaxBatchBytesSize - var batchZkCounters state.ZKCounters = state.ZKCounters{ + var batchZkCounters = state.ZKCounters{ CumulativeGasUsed: d.batchConstraints.MaxCumulativeGasUsed, UsedKeccakHashes: d.batchConstraints.MaxKeccakHashes, UsedPoseidonHashes: d.batchConstraints.MaxPoseidonHashes, diff --git a/sequencer/dbmanager_test.go b/sequencer/dbmanager_test.go index 647a134dbf..2b4b66558d 100644 --- a/sequencer/dbmanager_test.go +++ b/sequencer/dbmanager_test.go @@ -13,6 +13,7 @@ import ( "github.com/0xPolygonHermez/zkevm-node/log" "github.com/0xPolygonHermez/zkevm-node/merkletree" mtDBclientpb "github.com/0xPolygonHermez/zkevm-node/merkletree/pb" + "github.com/0xPolygonHermez/zkevm-node/pool" "github.com/0xPolygonHermez/zkevm-node/state" "github.com/0xPolygonHermez/zkevm-node/state/runtime/executor" "github.com/0xPolygonHermez/zkevm-node/test/dbutils" @@ -73,7 +74,7 @@ func setupDBManager() { GERCh: make(chan common.Hash), L2ReorgCh: make(chan L2ReorgEvent), } - batchConstraints := batchConstraints{ + batchConstraints := pool.BatchConstraintsCfg{ MaxTxsPerBatch: 300, MaxBatchBytesSize: 120000, MaxCumulativeGasUsed: 30000000, diff --git a/sequencer/efficiencylist.go b/sequencer/efficiencylist.go index 0508046b8d..588b1e2dbb 100644 --- a/sequencer/efficiencylist.go +++ b/sequencer/efficiencylist.go @@ -103,7 +103,7 @@ func (e *efficiencyList) addSort(tx *TxTracker) { e.sorted = append(e.sorted, nil) copy(e.sorted[i+1:], e.sorted[i:]) e.sorted[i] = tx - log.Infof("Added tx(%s) to efficiencyList. With efficiency(%f) at index(%d) from total(%d)", tx.HashStr, tx.Efficiency, i, len(e.sorted)) + //log.Infof("Added tx(%s) to efficiencyList. With efficiency(%f) at index(%d) from total(%d)", tx.HashStr, tx.Efficiency, i, len(e.sorted)) } // isGreaterThan returns true if the tx1 has best efficiency than tx2 diff --git a/sequencer/finalizer.go b/sequencer/finalizer.go index 52311e3bf5..d6df7226bb 100644 --- a/sequencer/finalizer.go +++ b/sequencer/finalizer.go @@ -42,7 +42,7 @@ type finalizer struct { dbManager dbManagerInterface executor stateInterface batch *WipBatch - batchConstraints batchConstraints + batchConstraints pool.BatchConstraintsCfg processRequest state.ProcessRequest sharedResourcesMux *sync.RWMutex lastGERHash common.Hash @@ -111,7 +111,7 @@ func newFinalizer( sequencerAddr common.Address, isSynced func(ctx context.Context) bool, closingSignalCh ClosingSignalCh, - batchConstraints batchConstraints, + batchConstraints pool.BatchConstraintsCfg, eventLog *event.EventLog, ) *finalizer { return &finalizer{ @@ -1246,7 +1246,7 @@ func (f *finalizer) getConstraintThresholdUint32(input uint32) uint32 { } // getUsedBatchResources returns the used resources in the batch -func getUsedBatchResources(constraints batchConstraints, remainingResources state.BatchResources) state.BatchResources { +func getUsedBatchResources(constraints pool.BatchConstraintsCfg, remainingResources state.BatchResources) state.BatchResources { return state.BatchResources{ ZKCounters: state.ZKCounters{ CumulativeGasUsed: constraints.MaxCumulativeGasUsed - remainingResources.ZKCounters.CumulativeGasUsed, diff --git a/sequencer/finalizer_test.go b/sequencer/finalizer_test.go index 74751f453c..dd2dcce454 100644 --- a/sequencer/finalizer_test.go +++ b/sequencer/finalizer_test.go @@ -33,7 +33,7 @@ var ( executorMock = new(StateMock) workerMock = new(WorkerMock) dbTxMock = new(DbTxMock) - bc = batchConstraints{ + bc = pool.BatchConstraintsCfg{ MaxTxsPerBatch: 300, MaxBatchBytesSize: 120000, MaxCumulativeGasUsed: 30000000, diff --git a/sequencer/sequencer.go b/sequencer/sequencer.go index ef41799b03..20ed62045a 100644 --- a/sequencer/sequencer.go +++ b/sequencer/sequencer.go @@ -17,7 +17,8 @@ import ( // Sequencer represents a sequencer type Sequencer struct { - cfg Config + cfg Config + batchCfg pool.BatchConfig pool txPool state stateInterface @@ -28,33 +29,6 @@ type Sequencer struct { address common.Address } -// batchConstraints represents the constraints for a batch -type batchConstraints struct { - MaxTxsPerBatch uint64 - MaxBatchBytesSize uint64 - MaxCumulativeGasUsed uint64 - MaxKeccakHashes uint32 - MaxPoseidonHashes uint32 - MaxPoseidonPaddings uint32 - MaxMemAligns uint32 - MaxArithmetics uint32 - MaxBinaries uint32 - MaxSteps uint32 -} - -// TODO: Add tests to config_test.go -type batchResourceWeights struct { - WeightBatchBytesSize int - WeightCumulativeGasUsed int - WeightKeccakHashes int - WeightPoseidonHashes int - WeightPoseidonPaddings int - WeightMemAligns int - WeightArithmetics int - WeightBinaries int - WeightSteps int -} - // L2ReorgEvent is the event that is triggered when a reorg happens in the L2 type L2ReorgEvent struct { TxHashes []common.Hash @@ -68,7 +42,7 @@ type ClosingSignalCh struct { } // New init sequencer -func New(cfg Config, txPool txPool, state stateInterface, etherman etherman, manager ethTxManager, eventLog *event.EventLog) (*Sequencer, error) { +func New(cfg Config, batchCfg pool.BatchConfig, txPool txPool, state stateInterface, etherman etherman, manager ethTxManager, eventLog *event.EventLog) (*Sequencer, error) { addr, err := etherman.TrustedSequencer() if err != nil { return nil, fmt.Errorf("failed to get trusted sequencer address, err: %v", err) @@ -76,6 +50,7 @@ func New(cfg Config, txPool txPool, state stateInterface, etherman etherman, man return &Sequencer{ cfg: cfg, + batchCfg: batchCfg, pool: txPool, state: state, etherman: etherman, @@ -98,41 +73,16 @@ func (s *Sequencer) Start(ctx context.Context) { GERCh: make(chan common.Hash), L2ReorgCh: make(chan L2ReorgEvent), } - - batchConstraints := batchConstraints{ - MaxTxsPerBatch: s.cfg.MaxTxsPerBatch, - MaxBatchBytesSize: s.cfg.MaxBatchBytesSize, - MaxCumulativeGasUsed: s.cfg.MaxCumulativeGasUsed, - MaxKeccakHashes: s.cfg.MaxKeccakHashes, - MaxPoseidonHashes: s.cfg.MaxPoseidonHashes, - MaxPoseidonPaddings: s.cfg.MaxPoseidonPaddings, - MaxMemAligns: s.cfg.MaxMemAligns, - MaxArithmetics: s.cfg.MaxArithmetics, - MaxBinaries: s.cfg.MaxBinaries, - MaxSteps: s.cfg.MaxSteps, - } - batchResourceWeights := batchResourceWeights{ - WeightBatchBytesSize: s.cfg.WeightBatchBytesSize, - WeightCumulativeGasUsed: s.cfg.WeightCumulativeGasUsed, - WeightKeccakHashes: s.cfg.WeightKeccakHashes, - WeightPoseidonHashes: s.cfg.WeightPoseidonHashes, - WeightPoseidonPaddings: s.cfg.WeightPoseidonPaddings, - WeightMemAligns: s.cfg.WeightMemAligns, - WeightArithmetics: s.cfg.WeightArithmetics, - WeightBinaries: s.cfg.WeightBinaries, - WeightSteps: s.cfg.WeightSteps, - } - err := s.pool.MarkWIPTxsAsPending(ctx) if err != nil { log.Fatalf("failed to mark WIP txs as pending, err: %v", err) } - worker := NewWorker(s.cfg.Worker, s.state, batchConstraints, batchResourceWeights) - dbManager := newDBManager(ctx, s.cfg.DBManager, s.pool, s.state, worker, closingSignalCh, batchConstraints) + worker := NewWorker(s.cfg.Worker, s.state, s.batchCfg.Constraints, s.batchCfg.ResourceWeights) + dbManager := newDBManager(ctx, s.cfg.DBManager, s.pool, s.state, worker, closingSignalCh, s.batchCfg.Constraints) go dbManager.Start() - finalizer := newFinalizer(s.cfg.Finalizer, s.cfg.EffectiveGasPrice, worker, dbManager, s.state, s.address, s.isSynced, closingSignalCh, batchConstraints, s.eventLog) + finalizer := newFinalizer(s.cfg.Finalizer, s.cfg.EffectiveGasPrice, worker, dbManager, s.state, s.address, s.isSynced, closingSignalCh, s.batchCfg.Constraints, s.eventLog) currBatch, processingReq := s.bootstrap(ctx, dbManager, finalizer) go finalizer.Start(ctx, currBatch, processingReq) @@ -274,7 +224,7 @@ func (s *Sequencer) isSynced(ctx context.Context) bool { return true } -func getMaxRemainingResources(constraints batchConstraints) state.BatchResources { +func getMaxRemainingResources(constraints pool.BatchConstraintsCfg) state.BatchResources { return state.BatchResources{ ZKCounters: state.ZKCounters{ CumulativeGasUsed: constraints.MaxCumulativeGasUsed, diff --git a/sequencer/txtracker.go b/sequencer/txtracker.go index bfc67f5b7b..4870c3e8f3 100644 --- a/sequencer/txtracker.go +++ b/sequencer/txtracker.go @@ -5,6 +5,7 @@ import ( "time" "github.com/0xPolygonHermez/zkevm-node/log" + "github.com/0xPolygonHermez/zkevm-node/pool" "github.com/0xPolygonHermez/zkevm-node/state" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" @@ -66,7 +67,7 @@ type batchConstraintsFloat64 struct { } // newTxTracker creates and inti a TxTracker -func newTxTracker(tx types.Transaction, counters state.ZKCounters, constraints batchConstraintsFloat64, weights batchResourceWeights, resourceCostMultiplier float64, ip string) (*TxTracker, error) { +func newTxTracker(tx types.Transaction, counters state.ZKCounters, constraints batchConstraintsFloat64, weights pool.BatchResourceWeights, resourceCostMultiplier float64, ip string) (*TxTracker, error) { addr, err := state.GetSender(tx) if err != nil { return nil, err @@ -112,13 +113,13 @@ func newTxTracker(tx types.Transaction, counters state.ZKCounters, constraints b // updateZKCounters updates the counters of the tx and recalculates the tx efficiency -func (tx *TxTracker) updateZKCounters(counters state.ZKCounters, constraints batchConstraintsFloat64, weights batchResourceWeights) { +func (tx *TxTracker) updateZKCounters(counters state.ZKCounters, constraints batchConstraintsFloat64, weights pool.BatchResourceWeights) { tx.BatchResources.ZKCounters = counters tx.calculateEfficiency(constraints, weights) } // calculateEfficiency calculates the tx efficiency -func (tx *TxTracker) calculateEfficiency(constraints batchConstraintsFloat64, weights batchResourceWeights) { +func (tx *TxTracker) calculateEfficiency(constraints batchConstraintsFloat64, weights pool.BatchResourceWeights) { totalWeight := float64(weights.WeightArithmetics + weights.WeightBatchBytesSize + weights.WeightBinaries + weights.WeightCumulativeGasUsed + weights.WeightKeccakHashes + weights.WeightMemAligns + weights.WeightPoseidonHashes + weights.WeightPoseidonPaddings + weights.WeightSteps) @@ -151,7 +152,7 @@ func (tx *TxTracker) calculateEfficiency(constraints batchConstraintsFloat64, we } // calculateWeightMultipliers calculates the weight multipliers for each resource -func calculateWeightMultipliers(weights batchResourceWeights, totalWeight float64) batchResourceWeightMultipliers { +func calculateWeightMultipliers(weights pool.BatchResourceWeights, totalWeight float64) batchResourceWeightMultipliers { return batchResourceWeightMultipliers{ cumulativeGasUsed: float64(weights.WeightCumulativeGasUsed) / totalWeight, arithmetics: float64(weights.WeightArithmetics) / totalWeight, diff --git a/sequencer/txtracker_test.go b/sequencer/txtracker_test.go index e5663f78b2..313a26ef74 100644 --- a/sequencer/txtracker_test.go +++ b/sequencer/txtracker_test.go @@ -5,6 +5,7 @@ import ( "math/big" "testing" + "github.com/0xPolygonHermez/zkevm-node/pool" "github.com/0xPolygonHermez/zkevm-node/state" "github.com/stretchr/testify/assert" ) @@ -19,28 +20,30 @@ type efficiencyCalcTestCase struct { func TestTxTrackerEfficiencyCalculation(t *testing.T) { // Init ZKEVM resourceCostWeight values - rcWeigth := batchResourceWeights{} - rcWeigth.WeightCumulativeGasUsed = 1 - rcWeigth.WeightArithmetics = 1 - rcWeigth.WeightBinaries = 1 - rcWeigth.WeightKeccakHashes = 1 - rcWeigth.WeightMemAligns = 1 - rcWeigth.WeightPoseidonHashes = 1 - rcWeigth.WeightPoseidonPaddings = 1 - rcWeigth.WeightSteps = 1 - rcWeigth.WeightBatchBytesSize = 2 + rcWeigth := pool.BatchResourceWeights{ + WeightBatchBytesSize: 2, + WeightCumulativeGasUsed: 1, + WeightArithmetics: 1, + WeightBinaries: 1, + WeightKeccakHashes: 1, + WeightMemAligns: 1, + WeightPoseidonHashes: 1, + WeightPoseidonPaddings: 1, + WeightSteps: 1, + } // Init ZKEVM resourceCostMax values - rcMax := batchConstraintsFloat64{} - rcMax.maxCumulativeGasUsed = 10 - rcMax.maxArithmetics = 10 - rcMax.maxBinaries = 10 - rcMax.maxKeccakHashes = 10 - rcMax.maxMemAligns = 10 - rcMax.maxPoseidonHashes = 10 - rcMax.maxPoseidonPaddings = 10 - rcMax.maxSteps = 10 - rcMax.maxBatchBytesSize = 10 + rcMax := batchConstraintsFloat64{ + maxCumulativeGasUsed: 10, + maxArithmetics: 10, + maxBinaries: 10, + maxKeccakHashes: 10, + maxMemAligns: 10, + maxPoseidonHashes: 10, + maxPoseidonPaddings: 10, + maxSteps: 10, + maxBatchBytesSize: 10, + } totalWeight := float64(rcWeigth.WeightArithmetics + rcWeigth.WeightBatchBytesSize + rcWeigth.WeightBinaries + rcWeigth.WeightCumulativeGasUsed + rcWeigth.WeightKeccakHashes + rcWeigth.WeightMemAligns + rcWeigth.WeightPoseidonHashes + rcWeigth.WeightPoseidonPaddings + rcWeigth.WeightSteps) diff --git a/sequencer/worker.go b/sequencer/worker.go index cba6938f7c..a8ddce001d 100644 --- a/sequencer/worker.go +++ b/sequencer/worker.go @@ -9,6 +9,7 @@ import ( "time" "github.com/0xPolygonHermez/zkevm-node/log" + "github.com/0xPolygonHermez/zkevm-node/pool" "github.com/0xPolygonHermez/zkevm-node/state" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" @@ -16,24 +17,26 @@ import ( // Worker represents the worker component of the sequencer type Worker struct { - cfg WorkerCfg - pool map[string]*addrQueue - efficiencyList *efficiencyList - workerMutex sync.Mutex - state stateInterface - batchConstraints batchConstraintsFloat64 - batchResourceWeights batchResourceWeights + cfg WorkerCfg + pool map[string]*addrQueue + efficiencyList *efficiencyList + workerMutex sync.Mutex + state stateInterface + batchConstraints pool.BatchConstraintsCfg + batchConstraintsFloat64 batchConstraintsFloat64 + batchResourceWeights pool.BatchResourceWeights } // NewWorker creates an init a worker -func NewWorker(cfg WorkerCfg, state stateInterface, constraints batchConstraints, weights batchResourceWeights) *Worker { +func NewWorker(cfg WorkerCfg, state stateInterface, constraints pool.BatchConstraintsCfg, weights pool.BatchResourceWeights) *Worker { w := Worker{ - cfg: cfg, - pool: make(map[string]*addrQueue), - efficiencyList: newEfficiencyList(), - state: state, - batchConstraints: convertBatchConstraintsToFloat64(constraints), - batchResourceWeights: weights, + cfg: cfg, + pool: make(map[string]*addrQueue), + efficiencyList: newEfficiencyList(), + state: state, + batchConstraints: constraints, + batchConstraintsFloat64: convertBatchConstraintsToFloat64(constraints), + batchResourceWeights: weights, } return &w @@ -41,7 +44,7 @@ func NewWorker(cfg WorkerCfg, state stateInterface, constraints batchConstraints // NewTxTracker creates and inits a TxTracker func (w *Worker) NewTxTracker(tx types.Transaction, counters state.ZKCounters, ip string) (*TxTracker, error) { - return newTxTracker(tx, counters, w.batchConstraints, w.batchResourceWeights, w.cfg.ResourceCostMultiplier, ip) + return newTxTracker(tx, counters, w.batchConstraintsFloat64, w.batchResourceWeights, w.cfg.ResourceCostMultiplier, ip) } // AddTxTracker adds a new Tx to the Worker @@ -49,8 +52,18 @@ func (w *Worker) AddTxTracker(ctx context.Context, tx *TxTracker) (replacedTx *T w.workerMutex.Lock() defer w.workerMutex.Unlock() - addr, found := w.pool[tx.FromStr] + // Make sure the IP is valid. + if tx.IP != "" && !pool.IsValidIP(tx.IP) { + return pool.ErrInvalidIP, false + } + // Make sure the transaction's batch resources are within the constraints. + if !w.batchConstraints.IsWithinConstraints(tx.BatchResources.ZKCounters) { + log.Errorf("OutOfCounters Error (Node level) for tx: %s", tx.Hash.String()) + return pool.ErrOutOfCounters, false + } + + addr, found := w.pool[tx.FromStr] if !found { // Unlock the worker to let execute other worker functions while creating the new AddrQueue w.workerMutex.Unlock() @@ -212,7 +225,7 @@ func (w *Worker) UpdateTx(txHash common.Hash, addr common.Address, counters stat addrQueue, found := w.pool[addr.String()] if found { - newReadyTx, prevReadyTx := addrQueue.UpdateTxZKCounters(txHash, counters, w.batchConstraints, w.batchResourceWeights) + newReadyTx, prevReadyTx := addrQueue.UpdateTxZKCounters(txHash, counters, w.batchConstraintsFloat64, w.batchResourceWeights) // Resort the newReadyTx in efficiencyList if prevReadyTx != nil { @@ -321,7 +334,7 @@ func (w *Worker) HandleL2Reorg(txHashes []common.Hash) { } // convertBatchConstraintsToFloat64 converts the batch Constraints to float64 -func convertBatchConstraintsToFloat64(constraints batchConstraints) batchConstraintsFloat64 { +func convertBatchConstraintsToFloat64(constraints pool.BatchConstraintsCfg) batchConstraintsFloat64 { return batchConstraintsFloat64{ maxTxsPerBatch: float64(constraints.MaxTxsPerBatch), maxBatchBytesSize: float64(constraints.MaxBatchBytesSize), diff --git a/sequencer/worker_test.go b/sequencer/worker_test.go index 51787f188c..b81b136f40 100644 --- a/sequencer/worker_test.go +++ b/sequencer/worker_test.go @@ -6,15 +6,45 @@ import ( "math/big" "testing" + "github.com/0xPolygonHermez/zkevm-node/pool" "github.com/0xPolygonHermez/zkevm-node/state" "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/assert" ) +const ( + validIP = "10.23.100.1" +) + var ( workerCfg = WorkerCfg{ ResourceCostMultiplier: 1000, } + // Init ZKEVM resourceCostWeight values + rcWeight = pool.BatchResourceWeights{ + WeightBatchBytesSize: 2, + WeightCumulativeGasUsed: 1, + WeightArithmetics: 1, + WeightBinaries: 1, + WeightKeccakHashes: 1, + WeightMemAligns: 1, + WeightPoseidonHashes: 1, + WeightPoseidonPaddings: 1, + WeightSteps: 1, + } + + // Init ZKEVM resourceCostMax values + rcMax = pool.BatchConstraintsCfg{ + MaxCumulativeGasUsed: 10, + MaxArithmetics: 10, + MaxBinaries: 10, + MaxKeccakHashes: 10, + MaxMemAligns: 10, + MaxPoseidonHashes: 10, + MaxPoseidonPaddings: 10, + MaxSteps: 10, + MaxBatchBytesSize: 10, + } ) type workerAddTxTestCase struct { @@ -28,6 +58,8 @@ type workerAddTxTestCase struct { counters state.ZKCounters usedBytes uint64 expectedEfficiencyList []common.Hash + ip string + expectedErr error } type workerAddrQueueInfo struct { @@ -48,7 +80,7 @@ func processWorkerAddTxTestCases(t *testing.T, worker *Worker, testCases []worke tx := TxTracker{} tx.WeightMultipliers = calculateWeightMultipliers(worker.batchResourceWeights, totalWeight) - tx.Constraints = worker.batchConstraints + tx.Constraints = worker.batchConstraintsFloat64 tx.ResourceCostMultiplier = worker.cfg.ResourceCostMultiplier tx.Hash = testCase.txHash tx.HashStr = testCase.txHash.String() @@ -58,11 +90,18 @@ func processWorkerAddTxTestCases(t *testing.T, worker *Worker, testCases []worke tx.Benefit = new(big.Int).SetInt64(testCase.benefit) tx.Cost = testCase.cost tx.BatchResources.Bytes = testCase.usedBytes - tx.updateZKCounters(testCase.counters, worker.batchConstraints, worker.batchResourceWeights) + // A random valid IP Address + if testCase.ip == "" { + tx.IP = validIP + } else { + tx.IP = testCase.ip + } + tx.updateZKCounters(testCase.counters, worker.batchConstraintsFloat64, worker.batchResourceWeights) t.Logf("%s=%s", testCase.name, fmt.Sprintf("%.2f", tx.Efficiency)) _, err := worker.AddTxTracker(ctx, &tx) - if err != nil { + if err != nil && testCase.expectedErr != nil { + assert.ErrorIs(t, err, testCase.expectedErr) return } @@ -82,34 +121,10 @@ func processWorkerAddTxTestCases(t *testing.T, worker *Worker, testCases []worke func TestWorkerAddTx(t *testing.T) { var nilErr error - // Init ZKEVM resourceCostWeight values - rcWeigth := batchResourceWeights{} - rcWeigth.WeightCumulativeGasUsed = 1 - rcWeigth.WeightArithmetics = 1 - rcWeigth.WeightBinaries = 1 - rcWeigth.WeightKeccakHashes = 1 - rcWeigth.WeightMemAligns = 1 - rcWeigth.WeightPoseidonHashes = 1 - rcWeigth.WeightPoseidonPaddings = 1 - rcWeigth.WeightSteps = 1 - rcWeigth.WeightBatchBytesSize = 2 - - // Init ZKEVM resourceCostMax values - rcMax := batchConstraints{} - rcMax.MaxCumulativeGasUsed = 10 - rcMax.MaxArithmetics = 10 - rcMax.MaxBinaries = 10 - rcMax.MaxKeccakHashes = 10 - rcMax.MaxMemAligns = 10 - rcMax.MaxPoseidonHashes = 10 - rcMax.MaxPoseidonPaddings = 10 - rcMax.MaxSteps = 10 - rcMax.MaxBatchBytesSize = 10 - stateMock := NewStateMock(t) - worker := initWorker(stateMock, rcMax, rcWeigth) + worker := initWorker(stateMock, rcMax, rcWeight) - ctx := context.Background() + ctx = context.Background() stateMock.On("GetLastStateRoot", ctx, nil).Return(common.Hash{0}, nilErr) @@ -162,6 +177,39 @@ func TestWorkerAddTx(t *testing.T) { {3}, {1}, {2}, }, }, + { + name: "Invalid IP address", from: common.Address{5}, txHash: common.Hash{5}, nonce: 1, + benefit: 3000, cost: new(big.Int).SetInt64(5), + counters: state.ZKCounters{CumulativeGasUsed: 1, UsedKeccakHashes: 1, UsedPoseidonHashes: 1, UsedPoseidonPaddings: 1, UsedMemAligns: 1, UsedArithmetics: 1, UsedBinaries: 1, UsedSteps: 1}, + usedBytes: 1, + ip: "invalid IP", + expectedEfficiencyList: []common.Hash{ + {3}, {1}, {2}, + }, + expectedErr: pool.ErrInvalidIP, + }, + { + name: "Out Of Counters Err", + from: common.Address{5}, txHash: common.Hash{5}, nonce: 1, + benefit: 5000, + cost: new(big.Int).SetInt64(5), + // Here, we intentionally set the counters such that they violate the constraints + counters: state.ZKCounters{ + CumulativeGasUsed: worker.batchConstraints.MaxCumulativeGasUsed + 1, + UsedKeccakHashes: worker.batchConstraints.MaxKeccakHashes + 1, + UsedPoseidonHashes: worker.batchConstraints.MaxPoseidonHashes + 1, + UsedPoseidonPaddings: worker.batchConstraints.MaxPoseidonPaddings + 1, + UsedMemAligns: worker.batchConstraints.MaxMemAligns + 1, + UsedArithmetics: worker.batchConstraints.MaxArithmetics + 1, + UsedBinaries: worker.batchConstraints.MaxBinaries + 1, + UsedSteps: worker.batchConstraints.MaxSteps + 1, + }, + expectedEfficiencyList: []common.Hash{ + {3}, {1}, {2}, + }, + usedBytes: 1, + expectedErr: pool.ErrOutOfCounters, + }, } processWorkerAddTxTestCases(t, worker, addTxsTC) @@ -188,30 +236,6 @@ func TestWorkerAddTx(t *testing.T) { func TestWorkerGetBestTx(t *testing.T) { var nilErr error - // Init ZKEVM resourceCostWeight values - rcWeight := batchResourceWeights{} - rcWeight.WeightCumulativeGasUsed = 1 - rcWeight.WeightArithmetics = 1 - rcWeight.WeightBinaries = 1 - rcWeight.WeightKeccakHashes = 1 - rcWeight.WeightMemAligns = 1 - rcWeight.WeightPoseidonHashes = 1 - rcWeight.WeightPoseidonPaddings = 1 - rcWeight.WeightSteps = 1 - rcWeight.WeightBatchBytesSize = 2 - - // Init ZKEVM resourceCostMax values - rcMax := batchConstraints{} - rcMax.MaxCumulativeGasUsed = 10 - rcMax.MaxArithmetics = 10 - rcMax.MaxBinaries = 10 - rcMax.MaxKeccakHashes = 10 - rcMax.MaxMemAligns = 10 - rcMax.MaxPoseidonHashes = 10 - rcMax.MaxPoseidonPaddings = 10 - rcMax.MaxSteps = 10 - rcMax.MaxBatchBytesSize = 10 - rc := state.BatchResources{ ZKCounters: state.ZKCounters{CumulativeGasUsed: 10, UsedKeccakHashes: 10, UsedPoseidonHashes: 10, UsedPoseidonPaddings: 10, UsedMemAligns: 10, UsedArithmetics: 10, UsedBinaries: 10, UsedSteps: 10}, Bytes: 10, @@ -306,7 +330,7 @@ func TestWorkerGetBestTx(t *testing.T) { } } -func initWorker(stateMock *StateMock, rcMax batchConstraints, rcWeigth batchResourceWeights) *Worker { +func initWorker(stateMock *StateMock, rcMax pool.BatchConstraintsCfg, rcWeigth pool.BatchResourceWeights) *Worker { worker := NewWorker(workerCfg, stateMock, rcMax, rcWeigth) return worker } diff --git a/test/benchmarks/sequencer/common/params/constants.go b/test/benchmarks/sequencer/common/params/constants.go index 735fd9788f..2965f6779c 100644 --- a/test/benchmarks/sequencer/common/params/constants.go +++ b/test/benchmarks/sequencer/common/params/constants.go @@ -12,5 +12,5 @@ const ( // PrometheusPort is the port where prometheus is running PrometheusPort = 9092 // NumberOfTxs is the number of transactions to send - NumberOfTxs = 1000 + NumberOfTxs = 200 ) diff --git a/test/benchmarks/sequencer/common/setup/setup.go b/test/benchmarks/sequencer/common/setup/setup.go index 066514996b..28bcb96201 100644 --- a/test/benchmarks/sequencer/common/setup/setup.go +++ b/test/benchmarks/sequencer/common/setup/setup.go @@ -26,6 +26,21 @@ const ( defaultGasPrice = 1000000000 ) +var ( + bc = pool.BatchConstraintsCfg{ + MaxTxsPerBatch: 300, + MaxBatchBytesSize: 120000, + MaxCumulativeGasUsed: 30000000, + MaxKeccakHashes: 2145, + MaxPoseidonHashes: 252357, + MaxPoseidonPaddings: 135191, + MaxMemAligns: 236585, + MaxArithmetics: 236585, + MaxBinaries: 473170, + MaxSteps: 7570538, + } +) + // Environment sets up the environment for the benchmark func Environment(ctx context.Context, b *testing.B) (*operations.Manager, *ethclient.Client, *pool.Pool, *bind.TransactOpts) { if testing.Short() { @@ -64,7 +79,7 @@ func Environment(ctx context.Context, b *testing.B) (*operations.Manager, *ethcl require.NoError(b, err) eventLog := event.NewEventLog(event.Config{}, eventStorage) - pl := pool.NewPool(config, s, st, params.ChainID, eventLog) + pl := pool.NewPool(config, bc, s, st, params.ChainID, eventLog) // Print Info before send senderBalance, err := client.BalanceAt(ctx, auth.From, nil) diff --git a/test/benchmarks/sequencer/eth-transfers/tx_sender.go b/test/benchmarks/sequencer/eth-transfers/tx_sender.go index 02ac3f6c8b..8b0f2c6799 100644 --- a/test/benchmarks/sequencer/eth-transfers/tx_sender.go +++ b/test/benchmarks/sequencer/eth-transfers/tx_sender.go @@ -32,8 +32,8 @@ func TxSender(l2Client *ethclient.Client, gasPrice *big.Int, nonce uint64, auth } err = l2Client.SendTransaction(params.Ctx, signedTx) - if errors.Is(err, state.ErrStateNotSynchronized) { - for errors.Is(err, state.ErrStateNotSynchronized) { + if errors.Is(err, state.ErrStateNotSynchronized) || errors.Is(err, state.ErrInsufficientFunds) { + for errors.Is(err, state.ErrStateNotSynchronized) || errors.Is(err, state.ErrInsufficientFunds) { time.Sleep(sleepTime) err = l2Client.SendTransaction(params.Ctx, signedTx) } diff --git a/test/config/debug.node.config.toml b/test/config/debug.node.config.toml index 1fb57cb65b..09a6dd37f8 100644 --- a/test/config/debug.node.config.toml +++ b/test/config/debug.node.config.toml @@ -59,25 +59,6 @@ TrustedSequencerURL = "" WaitPeriodPoolIsEmpty = "1s" BlocksAmountForTxsToBeDeleted = 100 FrequencyToCheckTxsForDelete = "12h" -MaxTxsPerBatch = 300 -MaxBatchBytesSize = 120000 -MaxCumulativeGasUsed = 30000000 -MaxKeccakHashes = 2145 -MaxPoseidonHashes = 252357 -MaxPoseidonPaddings = 135191 -MaxMemAligns = 236585 -MaxArithmetics = 236585 -MaxBinaries = 473170 -MaxSteps = 7570538 -WeightBatchBytesSize = 1 -WeightCumulativeGasUsed = 1 -WeightKeccakHashes = 1 -WeightPoseidonHashes = 1 -WeightPoseidonPaddings = 1 -WeightMemAligns = 1 -WeightArithmetics = 1 -WeightBinaries = 1 -WeightSteps = 1 TxLifetimeCheckTimeout = "10m" MaxTxLifetime = "3h" [Sequencer.Finalizer] @@ -159,3 +140,26 @@ ProfilingEnabled = false Port = "5435" EnableLog = false MaxConns = 200 + +[Batch] + [Batch.Constraints] + MaxTxsPerBatch = 300 + MaxBatchBytesSize = 120000 + MaxCumulativeGasUsed = 30000000 + MaxKeccakHashes = 2145 + MaxPoseidonHashes = 252357 + MaxPoseidonPaddings = 135191 + MaxMemAligns = 236585 + MaxArithmetics = 236585 + MaxBinaries = 473170 + MaxSteps = 7570538 + [Batch.ResourceWeights] + WeightBatchBytesSize = 1 + WeightCumulativeGasUsed = 1 + WeightKeccakHashes = 1 + WeightPoseidonHashes = 1 + WeightPoseidonPaddings = 1 + WeightMemAligns = 1 + WeightArithmetics = 1 + WeightBinaries = 1 + WeightSteps = 1 diff --git a/test/config/test.node.config.toml b/test/config/test.node.config.toml index d5133f7b47..d485fa76ac 100644 --- a/test/config/test.node.config.toml +++ b/test/config/test.node.config.toml @@ -60,25 +60,6 @@ WaitPeriodPoolIsEmpty = "1s" LastBatchVirtualizationTimeMaxWaitPeriod = "10s" BlocksAmountForTxsToBeDeleted = 100 FrequencyToCheckTxsForDelete = "12h" -MaxTxsPerBatch = 300 -MaxBatchBytesSize = 120000 -MaxCumulativeGasUsed = 30000000 -MaxKeccakHashes = 2145 -MaxPoseidonHashes = 252357 -MaxPoseidonPaddings = 135191 -MaxMemAligns = 236585 -MaxArithmetics = 236585 -MaxBinaries = 473170 -MaxSteps = 7570538 -WeightBatchBytesSize = 1 -WeightCumulativeGasUsed = 1 -WeightKeccakHashes = 1 -WeightPoseidonHashes = 1 -WeightPoseidonPaddings = 1 -WeightMemAligns = 1 -WeightArithmetics = 1 -WeightBinaries = 1 -WeightSteps = 1 TxLifetimeCheckTimeout = "10m" MaxTxLifetime = "3h" [Sequencer.Finalizer] @@ -171,3 +152,26 @@ Host = "zkevm-state-db" Port = "5432" EnableLog = false MaxConns = 200 + +[Batch] + [Batch.Constraints] + MaxTxsPerBatch = 300 + MaxBatchBytesSize = 120000 + MaxCumulativeGasUsed = 30000000 + MaxKeccakHashes = 2145 + MaxPoseidonHashes = 252357 + MaxPoseidonPaddings = 135191 + MaxMemAligns = 236585 + MaxArithmetics = 236585 + MaxBinaries = 473170 + MaxSteps = 7570538 + [Batch.ResourceWeights] + WeightBatchBytesSize = 1 + WeightCumulativeGasUsed = 1 + WeightKeccakHashes = 1 + WeightPoseidonHashes = 1 + WeightPoseidonPaddings = 1 + WeightMemAligns = 1 + WeightArithmetics = 1 + WeightBinaries = 1 + WeightSteps = 1 diff --git a/test/e2e/uniswap_test.go b/test/e2e/uniswap_test.go index 73e69c4b6c..9ea1980b00 100644 --- a/test/e2e/uniswap_test.go +++ b/test/e2e/uniswap_test.go @@ -36,7 +36,7 @@ func TestUniswap(t *testing.T) { opsCfg := &operations.Config{ State: &state.Config{ - MaxCumulativeGasUsed: cfg.Sequencer.MaxCumulativeGasUsed, + MaxCumulativeGasUsed: cfg.Batch.Constraints.MaxCumulativeGasUsed, }, SequenceSender: &operations.SequenceSenderConfig{ SenderAddress: "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", From df000681c3bfa90e1b30bd1e82855b534c97d99e Mon Sep 17 00:00:00 2001 From: Nikolay Nedkov Date: Thu, 27 Jul 2023 15:03:27 +0300 Subject: [PATCH 2/6] fixing comments Signed-off-by: Nikolay Nedkov --- .../environments/local/local.node.config.toml | 25 +------------------ sequencer/efficiencylist.go | 2 +- test/config/debug.node.config.toml | 25 +------------------ test/config/test.node.config.toml | 23 ----------------- 4 files changed, 3 insertions(+), 72 deletions(-) diff --git a/config/environments/local/local.node.config.toml b/config/environments/local/local.node.config.toml index b133637a0b..6092455beb 100644 --- a/config/environments/local/local.node.config.toml +++ b/config/environments/local/local.node.config.toml @@ -140,27 +140,4 @@ Name = "prover_db" Host = "zkevm-state-db" Port = "5432" EnableLog = false -MaxConns = 200 - -[Batch] - [Batch.Constraints] - MaxTxsPerBatch = 300 - MaxBatchBytesSize = 120000 - MaxCumulativeGasUsed = 30000000 - MaxKeccakHashes = 2145 - MaxPoseidonHashes = 252357 - MaxPoseidonPaddings = 135191 - MaxMemAligns = 236585 - MaxArithmetics = 236585 - MaxBinaries = 473170 - MaxSteps = 7570538 - [Batch.ResourceWeights] - WeightBatchBytesSize = 1 - WeightCumulativeGasUsed = 1 - WeightKeccakHashes = 1 - WeightPoseidonHashes = 1 - WeightPoseidonPaddings = 1 - WeightMemAligns = 1 - WeightArithmetics = 1 - WeightBinaries = 1 - WeightSteps = 1 +MaxConns = 200 \ No newline at end of file diff --git a/sequencer/efficiencylist.go b/sequencer/efficiencylist.go index 588b1e2dbb..0508046b8d 100644 --- a/sequencer/efficiencylist.go +++ b/sequencer/efficiencylist.go @@ -103,7 +103,7 @@ func (e *efficiencyList) addSort(tx *TxTracker) { e.sorted = append(e.sorted, nil) copy(e.sorted[i+1:], e.sorted[i:]) e.sorted[i] = tx - //log.Infof("Added tx(%s) to efficiencyList. With efficiency(%f) at index(%d) from total(%d)", tx.HashStr, tx.Efficiency, i, len(e.sorted)) + log.Infof("Added tx(%s) to efficiencyList. With efficiency(%f) at index(%d) from total(%d)", tx.HashStr, tx.Efficiency, i, len(e.sorted)) } // isGreaterThan returns true if the tx1 has best efficiency than tx2 diff --git a/test/config/debug.node.config.toml b/test/config/debug.node.config.toml index 09a6dd37f8..ab71c2740f 100644 --- a/test/config/debug.node.config.toml +++ b/test/config/debug.node.config.toml @@ -139,27 +139,4 @@ ProfilingEnabled = false Host = "localhost" Port = "5435" EnableLog = false - MaxConns = 200 - -[Batch] - [Batch.Constraints] - MaxTxsPerBatch = 300 - MaxBatchBytesSize = 120000 - MaxCumulativeGasUsed = 30000000 - MaxKeccakHashes = 2145 - MaxPoseidonHashes = 252357 - MaxPoseidonPaddings = 135191 - MaxMemAligns = 236585 - MaxArithmetics = 236585 - MaxBinaries = 473170 - MaxSteps = 7570538 - [Batch.ResourceWeights] - WeightBatchBytesSize = 1 - WeightCumulativeGasUsed = 1 - WeightKeccakHashes = 1 - WeightPoseidonHashes = 1 - WeightPoseidonPaddings = 1 - WeightMemAligns = 1 - WeightArithmetics = 1 - WeightBinaries = 1 - WeightSteps = 1 + MaxConns = 200 \ No newline at end of file diff --git a/test/config/test.node.config.toml b/test/config/test.node.config.toml index d485fa76ac..3db4f5d84f 100644 --- a/test/config/test.node.config.toml +++ b/test/config/test.node.config.toml @@ -152,26 +152,3 @@ Host = "zkevm-state-db" Port = "5432" EnableLog = false MaxConns = 200 - -[Batch] - [Batch.Constraints] - MaxTxsPerBatch = 300 - MaxBatchBytesSize = 120000 - MaxCumulativeGasUsed = 30000000 - MaxKeccakHashes = 2145 - MaxPoseidonHashes = 252357 - MaxPoseidonPaddings = 135191 - MaxMemAligns = 236585 - MaxArithmetics = 236585 - MaxBinaries = 473170 - MaxSteps = 7570538 - [Batch.ResourceWeights] - WeightBatchBytesSize = 1 - WeightCumulativeGasUsed = 1 - WeightKeccakHashes = 1 - WeightPoseidonHashes = 1 - WeightPoseidonPaddings = 1 - WeightMemAligns = 1 - WeightArithmetics = 1 - WeightBinaries = 1 - WeightSteps = 1 From 53eefdd2f2f556f20a369b202d6a86fcbc963728 Mon Sep 17 00:00:00 2001 From: Nikolay Nedkov Date: Thu, 27 Jul 2023 15:21:03 +0300 Subject: [PATCH 3/6] fixing rebase errors Signed-off-by: Nikolay Nedkov --- docs/config-file/node-config-doc.html | 4 +- docs/config-file/node-config-doc.md | 632 +++++++++++------------ docs/config-file/node-config-schema.json | 190 +++---- sequencer/worker.go | 4 +- 4 files changed, 408 insertions(+), 422 deletions(-) diff --git a/docs/config-file/node-config-doc.html b/docs/config-file/node-config-doc.html index 04f2a688b7..022afdbe81 100644 --- a/docs/config-file/node-config-doc.html +++ b/docs/config-file/node-config-doc.html @@ -20,7 +20,7 @@
"300ms"
 

Default: 100Type: integer

BlocksAmountForTxsToBeDeleted is blocks amount after which txs will be deleted from the pool


Default: "12h0m0s"Type: string

FrequencyToCheckTxsForDelete is frequency with which txs will be checked for deleting


Examples:

"1m"
 
"300ms"
-

Default: 300Type: integer

MaxTxsPerBatch is the maximum amount of transactions in the batch


Default: 120000Type: integer

MaxBatchBytesSize is the maximum batch size in bytes
(subtracted bits of all types.Sequence fields excluding BatchL2Data from MaxTxSizeForL1)


Default: 30000000Type: integer

MaxCumulativeGasUsed is max gas amount used by batch


Default: 2145Type: integer

MaxKeccakHashes is max keccak hashes used by batch


Default: 252357Type: integer

MaxPoseidonHashes is max poseidon hashes batch can handle


Default: 135191Type: integer

MaxPoseidonPaddings is max poseidon paddings batch can handle


Default: 236585Type: integer

MaxMemAligns is max mem aligns batch can handle


Default: 236585Type: integer

MaxArithmetics is max arithmetics batch can handle


Default: 473170Type: integer

MaxBinaries is max binaries batch can handle


Default: 7570538Type: integer

MaxSteps is max steps batch can handle


Default: 1Type: integer

WeightBatchBytesSize is the cost weight for the BatchBytesSize batch resource


Default: 1Type: integer

WeightCumulativeGasUsed is the cost weight for the CumulativeGasUsed batch resource


Default: 1Type: integer

WeightKeccakHashes is the cost weight for the KeccakHashes batch resource


Default: 1Type: integer

WeightPoseidonHashes is the cost weight for the PoseidonHashes batch resource


Default: 1Type: integer

WeightPoseidonPaddings is the cost weight for the PoseidonPaddings batch resource


Default: 1Type: integer

WeightMemAligns is the cost weight for the MemAligns batch resource


Default: 1Type: integer

WeightArithmetics is the cost weight for the Arithmetics batch resource


Default: 1Type: integer

WeightBinaries is the cost weight for the Binaries batch resource


Default: 1Type: integer

WeightSteps is the cost weight for the Steps batch resource


Default: "10m0s"Type: string

TxLifetimeCheckTimeout is the time the sequencer waits to check txs lifetime


Examples:

"1m"
+

Default: "10m0s"Type: string

TxLifetimeCheckTimeout is the time the sequencer waits to check txs lifetime


Examples:

"1m"
 
"300ms"
 

Default: "3h0m0s"Type: string

MaxTxLifetime is the time a tx can be in the sequencer memory


Examples:

"1m"
 
"300ms"
@@ -64,4 +64,4 @@
 
"300ms"
 

Default: 0.15Type: number

Configuration of the executor service
Default: "zkevm-prover:50071"Type: string

Default: 3Type: integer

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


Default: "1s"Type: string

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


Examples:

"1m"
 
"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 state database connection
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 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.


\ No newline at end of file +
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 state database connection
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 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.


Configuration of the batch service
Default: 300Type: integer

Default: 120000Type: integer

Default: 30000000Type: integer

Default: 2145Type: integer

Default: 252357Type: integer

Default: 135191Type: integer

Default: 236585Type: integer

Default: 236585Type: integer

Default: 473170Type: integer

Default: 7570538Type: integer

\ 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 69c8f8bb43..00135944fb 100644 --- a/docs/config-file/node-config-doc.md +++ b/docs/config-file/node-config-doc.md @@ -27,6 +27,7 @@ | - [Metrics](#Metrics ) | No | object | No | - | Configuration of the metrics service, basically is where is going to publish the metrics | | - [EventLog](#EventLog ) | No | object | No | - | Configuration of the event database connection | | - [HashDB](#HashDB ) | No | object | No | - | Configuration of the hash database connection | +| - [Batch](#Batch ) | No | object | No | - | Configuration of the batch service | ## 1. `IsTrustedSequencer` @@ -938,36 +939,17 @@ TrustedSequencerURL="" **Type:** : `object` **Description:** Configuration of the sequencer service -| Property | Pattern | Type | Deprecated | Definition | Title/Description | -| ---------------------------------------------------------------------------- | ------- | ------- | ---------- | ---------- | -------------------------------------------------------------------------------------------------------------------------------------------------- | -| - [WaitPeriodPoolIsEmpty](#Sequencer_WaitPeriodPoolIsEmpty ) | No | string | No | - | Duration | -| - [BlocksAmountForTxsToBeDeleted](#Sequencer_BlocksAmountForTxsToBeDeleted ) | No | integer | No | - | BlocksAmountForTxsToBeDeleted is blocks amount after which txs will be deleted from the pool | -| - [FrequencyToCheckTxsForDelete](#Sequencer_FrequencyToCheckTxsForDelete ) | No | string | No | - | Duration | -| - [MaxTxsPerBatch](#Sequencer_MaxTxsPerBatch ) | No | integer | No | - | MaxTxsPerBatch is the maximum amount of transactions in the batch | -| - [MaxBatchBytesSize](#Sequencer_MaxBatchBytesSize ) | No | integer | No | - | MaxBatchBytesSize is the maximum batch size in bytes
(subtracted bits of all types.Sequence fields excluding BatchL2Data from MaxTxSizeForL1) | -| - [MaxCumulativeGasUsed](#Sequencer_MaxCumulativeGasUsed ) | No | integer | No | - | MaxCumulativeGasUsed is max gas amount used by batch | -| - [MaxKeccakHashes](#Sequencer_MaxKeccakHashes ) | No | integer | No | - | MaxKeccakHashes is max keccak hashes used by batch | -| - [MaxPoseidonHashes](#Sequencer_MaxPoseidonHashes ) | No | integer | No | - | MaxPoseidonHashes is max poseidon hashes batch can handle | -| - [MaxPoseidonPaddings](#Sequencer_MaxPoseidonPaddings ) | No | integer | No | - | MaxPoseidonPaddings is max poseidon paddings batch can handle | -| - [MaxMemAligns](#Sequencer_MaxMemAligns ) | No | integer | No | - | MaxMemAligns is max mem aligns batch can handle | -| - [MaxArithmetics](#Sequencer_MaxArithmetics ) | No | integer | No | - | MaxArithmetics is max arithmetics batch can handle | -| - [MaxBinaries](#Sequencer_MaxBinaries ) | No | integer | No | - | MaxBinaries is max binaries batch can handle | -| - [MaxSteps](#Sequencer_MaxSteps ) | No | integer | No | - | MaxSteps is max steps batch can handle | -| - [WeightBatchBytesSize](#Sequencer_WeightBatchBytesSize ) | No | integer | No | - | WeightBatchBytesSize is the cost weight for the BatchBytesSize batch resource | -| - [WeightCumulativeGasUsed](#Sequencer_WeightCumulativeGasUsed ) | No | integer | No | - | WeightCumulativeGasUsed is the cost weight for the CumulativeGasUsed batch resource | -| - [WeightKeccakHashes](#Sequencer_WeightKeccakHashes ) | No | integer | No | - | WeightKeccakHashes is the cost weight for the KeccakHashes batch resource | -| - [WeightPoseidonHashes](#Sequencer_WeightPoseidonHashes ) | No | integer | No | - | WeightPoseidonHashes is the cost weight for the PoseidonHashes batch resource | -| - [WeightPoseidonPaddings](#Sequencer_WeightPoseidonPaddings ) | No | integer | No | - | WeightPoseidonPaddings is the cost weight for the PoseidonPaddings batch resource | -| - [WeightMemAligns](#Sequencer_WeightMemAligns ) | No | integer | No | - | WeightMemAligns is the cost weight for the MemAligns batch resource | -| - [WeightArithmetics](#Sequencer_WeightArithmetics ) | No | integer | No | - | WeightArithmetics is the cost weight for the Arithmetics batch resource | -| - [WeightBinaries](#Sequencer_WeightBinaries ) | No | integer | No | - | WeightBinaries is the cost weight for the Binaries batch resource | -| - [WeightSteps](#Sequencer_WeightSteps ) | No | integer | No | - | WeightSteps is the cost weight for the Steps batch resource | -| - [TxLifetimeCheckTimeout](#Sequencer_TxLifetimeCheckTimeout ) | No | string | No | - | Duration | -| - [MaxTxLifetime](#Sequencer_MaxTxLifetime ) | No | string | No | - | Duration | -| - [Finalizer](#Sequencer_Finalizer ) | No | object | No | - | Finalizer's specific config properties | -| - [DBManager](#Sequencer_DBManager ) | No | object | No | - | DBManager's specific config properties | -| - [Worker](#Sequencer_Worker ) | No | object | No | - | Worker's specific config properties | -| - [EffectiveGasPrice](#Sequencer_EffectiveGasPrice ) | No | object | No | - | EffectiveGasPrice is the config for the gas price | +| Property | Pattern | Type | Deprecated | Definition | Title/Description | +| ---------------------------------------------------------------------------- | ------- | ------- | ---------- | ---------- | -------------------------------------------------------------------------------------------- | +| - [WaitPeriodPoolIsEmpty](#Sequencer_WaitPeriodPoolIsEmpty ) | No | string | No | - | Duration | +| - [BlocksAmountForTxsToBeDeleted](#Sequencer_BlocksAmountForTxsToBeDeleted ) | No | integer | No | - | BlocksAmountForTxsToBeDeleted is blocks amount after which txs will be deleted from the pool | +| - [FrequencyToCheckTxsForDelete](#Sequencer_FrequencyToCheckTxsForDelete ) | No | string | No | - | Duration | +| - [TxLifetimeCheckTimeout](#Sequencer_TxLifetimeCheckTimeout ) | No | string | No | - | Duration | +| - [MaxTxLifetime](#Sequencer_MaxTxLifetime ) | No | string | No | - | Duration | +| - [Finalizer](#Sequencer_Finalizer ) | No | object | No | - | Finalizer's specific config properties | +| - [DBManager](#Sequencer_DBManager ) | No | object | No | - | DBManager's specific config properties | +| - [Worker](#Sequencer_Worker ) | No | object | No | - | Worker's specific config properties | +| - [EffectiveGasPrice](#Sequencer_EffectiveGasPrice ) | No | object | No | - | EffectiveGasPrice is the config for the gas price | ### 10.1. `Sequencer.WaitPeriodPoolIsEmpty` @@ -1036,274 +1018,7 @@ BlocksAmountForTxsToBeDeleted=100 FrequencyToCheckTxsForDelete="12h0m0s" ``` -### 10.4. `Sequencer.MaxTxsPerBatch` - -**Type:** : `integer` - -**Default:** `300` - -**Description:** MaxTxsPerBatch is the maximum amount of transactions in the batch - -**Example setting the default value** (300): -``` -[Sequencer] -MaxTxsPerBatch=300 -``` - -### 10.5. `Sequencer.MaxBatchBytesSize` - -**Type:** : `integer` - -**Default:** `120000` - -**Description:** MaxBatchBytesSize is the maximum batch size in bytes -(subtracted bits of all types.Sequence fields excluding BatchL2Data from MaxTxSizeForL1) - -**Example setting the default value** (120000): -``` -[Sequencer] -MaxBatchBytesSize=120000 -``` - -### 10.6. `Sequencer.MaxCumulativeGasUsed` - -**Type:** : `integer` - -**Default:** `30000000` - -**Description:** MaxCumulativeGasUsed is max gas amount used by batch - -**Example setting the default value** (30000000): -``` -[Sequencer] -MaxCumulativeGasUsed=30000000 -``` - -### 10.7. `Sequencer.MaxKeccakHashes` - -**Type:** : `integer` - -**Default:** `2145` - -**Description:** MaxKeccakHashes is max keccak hashes used by batch - -**Example setting the default value** (2145): -``` -[Sequencer] -MaxKeccakHashes=2145 -``` - -### 10.8. `Sequencer.MaxPoseidonHashes` - -**Type:** : `integer` - -**Default:** `252357` - -**Description:** MaxPoseidonHashes is max poseidon hashes batch can handle - -**Example setting the default value** (252357): -``` -[Sequencer] -MaxPoseidonHashes=252357 -``` - -### 10.9. `Sequencer.MaxPoseidonPaddings` - -**Type:** : `integer` - -**Default:** `135191` - -**Description:** MaxPoseidonPaddings is max poseidon paddings batch can handle - -**Example setting the default value** (135191): -``` -[Sequencer] -MaxPoseidonPaddings=135191 -``` - -### 10.10. `Sequencer.MaxMemAligns` - -**Type:** : `integer` - -**Default:** `236585` - -**Description:** MaxMemAligns is max mem aligns batch can handle - -**Example setting the default value** (236585): -``` -[Sequencer] -MaxMemAligns=236585 -``` - -### 10.11. `Sequencer.MaxArithmetics` - -**Type:** : `integer` - -**Default:** `236585` - -**Description:** MaxArithmetics is max arithmetics batch can handle - -**Example setting the default value** (236585): -``` -[Sequencer] -MaxArithmetics=236585 -``` - -### 10.12. `Sequencer.MaxBinaries` - -**Type:** : `integer` - -**Default:** `473170` - -**Description:** MaxBinaries is max binaries batch can handle - -**Example setting the default value** (473170): -``` -[Sequencer] -MaxBinaries=473170 -``` - -### 10.13. `Sequencer.MaxSteps` - -**Type:** : `integer` - -**Default:** `7570538` - -**Description:** MaxSteps is max steps batch can handle - -**Example setting the default value** (7570538): -``` -[Sequencer] -MaxSteps=7570538 -``` - -### 10.14. `Sequencer.WeightBatchBytesSize` - -**Type:** : `integer` - -**Default:** `1` - -**Description:** WeightBatchBytesSize is the cost weight for the BatchBytesSize batch resource - -**Example setting the default value** (1): -``` -[Sequencer] -WeightBatchBytesSize=1 -``` - -### 10.15. `Sequencer.WeightCumulativeGasUsed` - -**Type:** : `integer` - -**Default:** `1` - -**Description:** WeightCumulativeGasUsed is the cost weight for the CumulativeGasUsed batch resource - -**Example setting the default value** (1): -``` -[Sequencer] -WeightCumulativeGasUsed=1 -``` - -### 10.16. `Sequencer.WeightKeccakHashes` - -**Type:** : `integer` - -**Default:** `1` - -**Description:** WeightKeccakHashes is the cost weight for the KeccakHashes batch resource - -**Example setting the default value** (1): -``` -[Sequencer] -WeightKeccakHashes=1 -``` - -### 10.17. `Sequencer.WeightPoseidonHashes` - -**Type:** : `integer` - -**Default:** `1` - -**Description:** WeightPoseidonHashes is the cost weight for the PoseidonHashes batch resource - -**Example setting the default value** (1): -``` -[Sequencer] -WeightPoseidonHashes=1 -``` - -### 10.18. `Sequencer.WeightPoseidonPaddings` - -**Type:** : `integer` - -**Default:** `1` - -**Description:** WeightPoseidonPaddings is the cost weight for the PoseidonPaddings batch resource - -**Example setting the default value** (1): -``` -[Sequencer] -WeightPoseidonPaddings=1 -``` - -### 10.19. `Sequencer.WeightMemAligns` - -**Type:** : `integer` - -**Default:** `1` - -**Description:** WeightMemAligns is the cost weight for the MemAligns batch resource - -**Example setting the default value** (1): -``` -[Sequencer] -WeightMemAligns=1 -``` - -### 10.20. `Sequencer.WeightArithmetics` - -**Type:** : `integer` - -**Default:** `1` - -**Description:** WeightArithmetics is the cost weight for the Arithmetics batch resource - -**Example setting the default value** (1): -``` -[Sequencer] -WeightArithmetics=1 -``` - -### 10.21. `Sequencer.WeightBinaries` - -**Type:** : `integer` - -**Default:** `1` - -**Description:** WeightBinaries is the cost weight for the Binaries batch resource - -**Example setting the default value** (1): -``` -[Sequencer] -WeightBinaries=1 -``` - -### 10.22. `Sequencer.WeightSteps` - -**Type:** : `integer` - -**Default:** `1` - -**Description:** WeightSteps is the cost weight for the Steps batch resource - -**Example setting the default value** (1): -``` -[Sequencer] -WeightSteps=1 -``` - -### 10.23. `Sequencer.TxLifetimeCheckTimeout` +### 10.4. `Sequencer.TxLifetimeCheckTimeout` **Title:** Duration @@ -1329,7 +1044,7 @@ WeightSteps=1 TxLifetimeCheckTimeout="10m0s" ``` -### 10.24. `Sequencer.MaxTxLifetime` +### 10.5. `Sequencer.MaxTxLifetime` **Title:** Duration @@ -1355,7 +1070,7 @@ TxLifetimeCheckTimeout="10m0s" MaxTxLifetime="3h0m0s" ``` -### 10.25. `[Sequencer.Finalizer]` +### 10.6. `[Sequencer.Finalizer]` **Type:** : `object` **Description:** Finalizer's specific config properties @@ -1374,7 +1089,7 @@ MaxTxLifetime="3h0m0s" | - [TimestampResolution](#Sequencer_Finalizer_TimestampResolution ) | No | string | No | - | Duration | | - [StopSequencerOnBatchNum](#Sequencer_Finalizer_StopSequencerOnBatchNum ) | No | integer | No | - | StopSequencerOnBatchNum specifies the batch number where the Sequencer will stop to process more transactions and generate new batches. The Sequencer will halt after it closes the batch equal to this number | -#### 10.25.1. `Sequencer.Finalizer.GERDeadlineTimeout` +#### 10.6.1. `Sequencer.Finalizer.GERDeadlineTimeout` **Title:** Duration @@ -1400,7 +1115,7 @@ MaxTxLifetime="3h0m0s" GERDeadlineTimeout="5s" ``` -#### 10.25.2. `Sequencer.Finalizer.ForcedBatchDeadlineTimeout` +#### 10.6.2. `Sequencer.Finalizer.ForcedBatchDeadlineTimeout` **Title:** Duration @@ -1426,7 +1141,7 @@ GERDeadlineTimeout="5s" ForcedBatchDeadlineTimeout="1m0s" ``` -#### 10.25.3. `Sequencer.Finalizer.SleepDuration` +#### 10.6.3. `Sequencer.Finalizer.SleepDuration` **Title:** Duration @@ -1452,7 +1167,7 @@ ForcedBatchDeadlineTimeout="1m0s" SleepDuration="100ms" ``` -#### 10.25.4. `Sequencer.Finalizer.ResourcePercentageToCloseBatch` +#### 10.6.4. `Sequencer.Finalizer.ResourcePercentageToCloseBatch` **Type:** : `integer` @@ -1466,7 +1181,7 @@ SleepDuration="100ms" ResourcePercentageToCloseBatch=10 ``` -#### 10.25.5. `Sequencer.Finalizer.GERFinalityNumberOfBlocks` +#### 10.6.5. `Sequencer.Finalizer.GERFinalityNumberOfBlocks` **Type:** : `integer` @@ -1480,7 +1195,7 @@ ResourcePercentageToCloseBatch=10 GERFinalityNumberOfBlocks=64 ``` -#### 10.25.6. `Sequencer.Finalizer.ClosingSignalsManagerWaitForCheckingL1Timeout` +#### 10.6.6. `Sequencer.Finalizer.ClosingSignalsManagerWaitForCheckingL1Timeout` **Title:** Duration @@ -1506,7 +1221,7 @@ GERFinalityNumberOfBlocks=64 ClosingSignalsManagerWaitForCheckingL1Timeout="10s" ``` -#### 10.25.7. `Sequencer.Finalizer.ClosingSignalsManagerWaitForCheckingGER` +#### 10.6.7. `Sequencer.Finalizer.ClosingSignalsManagerWaitForCheckingGER` **Title:** Duration @@ -1532,7 +1247,7 @@ ClosingSignalsManagerWaitForCheckingL1Timeout="10s" ClosingSignalsManagerWaitForCheckingGER="10s" ``` -#### 10.25.8. `Sequencer.Finalizer.ClosingSignalsManagerWaitForCheckingForcedBatches` +#### 10.6.8. `Sequencer.Finalizer.ClosingSignalsManagerWaitForCheckingForcedBatches` **Title:** Duration @@ -1558,7 +1273,7 @@ ClosingSignalsManagerWaitForCheckingGER="10s" ClosingSignalsManagerWaitForCheckingForcedBatches="10s" ``` -#### 10.25.9. `Sequencer.Finalizer.ForcedBatchesFinalityNumberOfBlocks` +#### 10.6.9. `Sequencer.Finalizer.ForcedBatchesFinalityNumberOfBlocks` **Type:** : `integer` @@ -1572,7 +1287,7 @@ ClosingSignalsManagerWaitForCheckingForcedBatches="10s" ForcedBatchesFinalityNumberOfBlocks=64 ``` -#### 10.25.10. `Sequencer.Finalizer.TimestampResolution` +#### 10.6.10. `Sequencer.Finalizer.TimestampResolution` **Title:** Duration @@ -1598,7 +1313,7 @@ ForcedBatchesFinalityNumberOfBlocks=64 TimestampResolution="10s" ``` -#### 10.25.11. `Sequencer.Finalizer.StopSequencerOnBatchNum` +#### 10.6.11. `Sequencer.Finalizer.StopSequencerOnBatchNum` **Type:** : `integer` @@ -1612,7 +1327,7 @@ TimestampResolution="10s" StopSequencerOnBatchNum=0 ``` -### 10.26. `[Sequencer.DBManager]` +### 10.7. `[Sequencer.DBManager]` **Type:** : `object` **Description:** DBManager's specific config properties @@ -1622,7 +1337,7 @@ StopSequencerOnBatchNum=0 | - [PoolRetrievalInterval](#Sequencer_DBManager_PoolRetrievalInterval ) | No | string | No | - | Duration | | - [L2ReorgRetrievalInterval](#Sequencer_DBManager_L2ReorgRetrievalInterval ) | No | string | No | - | Duration | -#### 10.26.1. `Sequencer.DBManager.PoolRetrievalInterval` +#### 10.7.1. `Sequencer.DBManager.PoolRetrievalInterval` **Title:** Duration @@ -1646,7 +1361,7 @@ StopSequencerOnBatchNum=0 PoolRetrievalInterval="500ms" ``` -#### 10.26.2. `Sequencer.DBManager.L2ReorgRetrievalInterval` +#### 10.7.2. `Sequencer.DBManager.L2ReorgRetrievalInterval` **Title:** Duration @@ -1670,7 +1385,7 @@ PoolRetrievalInterval="500ms" L2ReorgRetrievalInterval="5s" ``` -### 10.27. `[Sequencer.Worker]` +### 10.8. `[Sequencer.Worker]` **Type:** : `object` **Description:** Worker's specific config properties @@ -1679,7 +1394,7 @@ L2ReorgRetrievalInterval="5s" | --------------------------------------------------------------------- | ------- | ------ | ---------- | ---------- | -------------------------------------------------------------- | | - [ResourceCostMultiplier](#Sequencer_Worker_ResourceCostMultiplier ) | No | number | No | - | ResourceCostMultiplier is the multiplier for the resource cost | -#### 10.27.1. `Sequencer.Worker.ResourceCostMultiplier` +#### 10.8.1. `Sequencer.Worker.ResourceCostMultiplier` **Type:** : `number` @@ -1693,7 +1408,7 @@ L2ReorgRetrievalInterval="5s" ResourceCostMultiplier=1000 ``` -### 10.28. `[Sequencer.EffectiveGasPrice]` +### 10.9. `[Sequencer.EffectiveGasPrice]` **Type:** : `object` **Description:** EffectiveGasPrice is the config for the gas price @@ -1707,7 +1422,7 @@ ResourceCostMultiplier=1000 | - [Enabled](#Sequencer_EffectiveGasPrice_Enabled ) | No | boolean | No | - | Enabled is a flag to enable/disable the effective gas price | | - [DefaultMinGasPriceAllowed](#Sequencer_EffectiveGasPrice_DefaultMinGasPriceAllowed ) | No | integer | No | - | DefaultMinGasPriceAllowed is the default min gas price to suggest
This value is assigned from [Pool].DefaultMinGasPriceAllowed | -#### 10.28.1. `Sequencer.EffectiveGasPrice.MaxBreakEvenGasPriceDeviationPercentage` +#### 10.9.1. `Sequencer.EffectiveGasPrice.MaxBreakEvenGasPriceDeviationPercentage` **Type:** : `integer` @@ -1721,7 +1436,7 @@ ResourceCostMultiplier=1000 MaxBreakEvenGasPriceDeviationPercentage=10 ``` -#### 10.28.2. `Sequencer.EffectiveGasPrice.L1GasPriceFactor` +#### 10.9.2. `Sequencer.EffectiveGasPrice.L1GasPriceFactor` **Type:** : `number` @@ -1735,7 +1450,7 @@ MaxBreakEvenGasPriceDeviationPercentage=10 L1GasPriceFactor=0.25 ``` -#### 10.28.3. `Sequencer.EffectiveGasPrice.ByteGasCost` +#### 10.9.3. `Sequencer.EffectiveGasPrice.ByteGasCost` **Type:** : `integer` @@ -1749,7 +1464,7 @@ L1GasPriceFactor=0.25 ByteGasCost=16 ``` -#### 10.28.4. `Sequencer.EffectiveGasPrice.MarginFactor` +#### 10.9.4. `Sequencer.EffectiveGasPrice.MarginFactor` **Type:** : `number` @@ -1763,7 +1478,7 @@ ByteGasCost=16 MarginFactor=1 ``` -#### 10.28.5. `Sequencer.EffectiveGasPrice.Enabled` +#### 10.9.5. `Sequencer.EffectiveGasPrice.Enabled` **Type:** : `boolean` @@ -1777,7 +1492,7 @@ MarginFactor=1 Enabled=false ``` -#### 10.28.6. `Sequencer.EffectiveGasPrice.DefaultMinGasPriceAllowed` +#### 10.9.6. `Sequencer.EffectiveGasPrice.DefaultMinGasPriceAllowed` **Type:** : `integer` @@ -3085,5 +2800,276 @@ EnableLog=false MaxConns=200 ``` +## 21. `[Batch]` + +**Type:** : `object` +**Description:** Configuration of the batch service + +| Property | Pattern | Type | Deprecated | Definition | Title/Description | +| -------------------------------------------- | ------- | ------ | ---------- | ---------- | ----------------- | +| - [Constraints](#Batch_Constraints ) | No | object | No | - | - | +| - [ResourceWeights](#Batch_ResourceWeights ) | No | object | No | - | - | + +### 21.1. `[Batch.Constraints]` + +**Type:** : `object` + +| Property | Pattern | Type | Deprecated | Definition | Title/Description | +| ------------------------------------------------------------------ | ------- | ------- | ---------- | ---------- | ----------------- | +| - [MaxTxsPerBatch](#Batch_Constraints_MaxTxsPerBatch ) | No | integer | No | - | - | +| - [MaxBatchBytesSize](#Batch_Constraints_MaxBatchBytesSize ) | No | integer | No | - | - | +| - [MaxCumulativeGasUsed](#Batch_Constraints_MaxCumulativeGasUsed ) | No | integer | No | - | - | +| - [MaxKeccakHashes](#Batch_Constraints_MaxKeccakHashes ) | No | integer | No | - | - | +| - [MaxPoseidonHashes](#Batch_Constraints_MaxPoseidonHashes ) | No | integer | No | - | - | +| - [MaxPoseidonPaddings](#Batch_Constraints_MaxPoseidonPaddings ) | No | integer | No | - | - | +| - [MaxMemAligns](#Batch_Constraints_MaxMemAligns ) | No | integer | No | - | - | +| - [MaxArithmetics](#Batch_Constraints_MaxArithmetics ) | No | integer | No | - | - | +| - [MaxBinaries](#Batch_Constraints_MaxBinaries ) | No | integer | No | - | - | +| - [MaxSteps](#Batch_Constraints_MaxSteps ) | No | integer | No | - | - | + +#### 21.1.1. `Batch.Constraints.MaxTxsPerBatch` + +**Type:** : `integer` + +**Default:** `300` + +**Example setting the default value** (300): +``` +[Batch.Constraints] +MaxTxsPerBatch=300 +``` + +#### 21.1.2. `Batch.Constraints.MaxBatchBytesSize` + +**Type:** : `integer` + +**Default:** `120000` + +**Example setting the default value** (120000): +``` +[Batch.Constraints] +MaxBatchBytesSize=120000 +``` + +#### 21.1.3. `Batch.Constraints.MaxCumulativeGasUsed` + +**Type:** : `integer` + +**Default:** `30000000` + +**Example setting the default value** (30000000): +``` +[Batch.Constraints] +MaxCumulativeGasUsed=30000000 +``` + +#### 21.1.4. `Batch.Constraints.MaxKeccakHashes` + +**Type:** : `integer` + +**Default:** `2145` + +**Example setting the default value** (2145): +``` +[Batch.Constraints] +MaxKeccakHashes=2145 +``` + +#### 21.1.5. `Batch.Constraints.MaxPoseidonHashes` + +**Type:** : `integer` + +**Default:** `252357` + +**Example setting the default value** (252357): +``` +[Batch.Constraints] +MaxPoseidonHashes=252357 +``` + +#### 21.1.6. `Batch.Constraints.MaxPoseidonPaddings` + +**Type:** : `integer` + +**Default:** `135191` + +**Example setting the default value** (135191): +``` +[Batch.Constraints] +MaxPoseidonPaddings=135191 +``` + +#### 21.1.7. `Batch.Constraints.MaxMemAligns` + +**Type:** : `integer` + +**Default:** `236585` + +**Example setting the default value** (236585): +``` +[Batch.Constraints] +MaxMemAligns=236585 +``` + +#### 21.1.8. `Batch.Constraints.MaxArithmetics` + +**Type:** : `integer` + +**Default:** `236585` + +**Example setting the default value** (236585): +``` +[Batch.Constraints] +MaxArithmetics=236585 +``` + +#### 21.1.9. `Batch.Constraints.MaxBinaries` + +**Type:** : `integer` + +**Default:** `473170` + +**Example setting the default value** (473170): +``` +[Batch.Constraints] +MaxBinaries=473170 +``` + +#### 21.1.10. `Batch.Constraints.MaxSteps` + +**Type:** : `integer` + +**Default:** `7570538` + +**Example setting the default value** (7570538): +``` +[Batch.Constraints] +MaxSteps=7570538 +``` + +### 21.2. `[Batch.ResourceWeights]` + +**Type:** : `object` + +| Property | Pattern | Type | Deprecated | Definition | Title/Description | +| ---------------------------------------------------------------------------- | ------- | ------- | ---------- | ---------- | ----------------- | +| - [WeightBatchBytesSize](#Batch_ResourceWeights_WeightBatchBytesSize ) | No | integer | No | - | - | +| - [WeightCumulativeGasUsed](#Batch_ResourceWeights_WeightCumulativeGasUsed ) | No | integer | No | - | - | +| - [WeightKeccakHashes](#Batch_ResourceWeights_WeightKeccakHashes ) | No | integer | No | - | - | +| - [WeightPoseidonHashes](#Batch_ResourceWeights_WeightPoseidonHashes ) | No | integer | No | - | - | +| - [WeightPoseidonPaddings](#Batch_ResourceWeights_WeightPoseidonPaddings ) | No | integer | No | - | - | +| - [WeightMemAligns](#Batch_ResourceWeights_WeightMemAligns ) | No | integer | No | - | - | +| - [WeightArithmetics](#Batch_ResourceWeights_WeightArithmetics ) | No | integer | No | - | - | +| - [WeightBinaries](#Batch_ResourceWeights_WeightBinaries ) | No | integer | No | - | - | +| - [WeightSteps](#Batch_ResourceWeights_WeightSteps ) | No | integer | No | - | - | + +#### 21.2.1. `Batch.ResourceWeights.WeightBatchBytesSize` + +**Type:** : `integer` + +**Default:** `1` + +**Example setting the default value** (1): +``` +[Batch.ResourceWeights] +WeightBatchBytesSize=1 +``` + +#### 21.2.2. `Batch.ResourceWeights.WeightCumulativeGasUsed` + +**Type:** : `integer` + +**Default:** `1` + +**Example setting the default value** (1): +``` +[Batch.ResourceWeights] +WeightCumulativeGasUsed=1 +``` + +#### 21.2.3. `Batch.ResourceWeights.WeightKeccakHashes` + +**Type:** : `integer` + +**Default:** `1` + +**Example setting the default value** (1): +``` +[Batch.ResourceWeights] +WeightKeccakHashes=1 +``` + +#### 21.2.4. `Batch.ResourceWeights.WeightPoseidonHashes` + +**Type:** : `integer` + +**Default:** `1` + +**Example setting the default value** (1): +``` +[Batch.ResourceWeights] +WeightPoseidonHashes=1 +``` + +#### 21.2.5. `Batch.ResourceWeights.WeightPoseidonPaddings` + +**Type:** : `integer` + +**Default:** `1` + +**Example setting the default value** (1): +``` +[Batch.ResourceWeights] +WeightPoseidonPaddings=1 +``` + +#### 21.2.6. `Batch.ResourceWeights.WeightMemAligns` + +**Type:** : `integer` + +**Default:** `1` + +**Example setting the default value** (1): +``` +[Batch.ResourceWeights] +WeightMemAligns=1 +``` + +#### 21.2.7. `Batch.ResourceWeights.WeightArithmetics` + +**Type:** : `integer` + +**Default:** `1` + +**Example setting the default value** (1): +``` +[Batch.ResourceWeights] +WeightArithmetics=1 +``` + +#### 21.2.8. `Batch.ResourceWeights.WeightBinaries` + +**Type:** : `integer` + +**Default:** `1` + +**Example setting the default value** (1): +``` +[Batch.ResourceWeights] +WeightBinaries=1 +``` + +#### 21.2.9. `Batch.ResourceWeights.WeightSteps` + +**Type:** : `integer` + +**Default:** `1` + +**Example setting the default value** (1): +``` +[Batch.ResourceWeights] +WeightSteps=1 +``` + ---------------------------------------------------------------------------------------------------------------------------- Generated using [json-schema-for-humans](https://github.com/coveooss/json-schema-for-humans) diff --git a/docs/config-file/node-config-schema.json b/docs/config-file/node-config-schema.json index bed2336c99..a52aaadb1a 100644 --- a/docs/config-file/node-config-schema.json +++ b/docs/config-file/node-config-schema.json @@ -394,101 +394,6 @@ "300ms" ] }, - "MaxTxsPerBatch": { - "type": "integer", - "description": "MaxTxsPerBatch is the maximum amount of transactions in the batch", - "default": 300 - }, - "MaxBatchBytesSize": { - "type": "integer", - "description": "MaxBatchBytesSize is the maximum batch size in bytes\n(subtracted bits of all types.Sequence fields excluding BatchL2Data from MaxTxSizeForL1)", - "default": 120000 - }, - "MaxCumulativeGasUsed": { - "type": "integer", - "description": "MaxCumulativeGasUsed is max gas amount used by batch", - "default": 30000000 - }, - "MaxKeccakHashes": { - "type": "integer", - "description": "MaxKeccakHashes is max keccak hashes used by batch", - "default": 2145 - }, - "MaxPoseidonHashes": { - "type": "integer", - "description": "MaxPoseidonHashes is max poseidon hashes batch can handle", - "default": 252357 - }, - "MaxPoseidonPaddings": { - "type": "integer", - "description": "MaxPoseidonPaddings is max poseidon paddings batch can handle", - "default": 135191 - }, - "MaxMemAligns": { - "type": "integer", - "description": "MaxMemAligns is max mem aligns batch can handle", - "default": 236585 - }, - "MaxArithmetics": { - "type": "integer", - "description": "MaxArithmetics is max arithmetics batch can handle", - "default": 236585 - }, - "MaxBinaries": { - "type": "integer", - "description": "MaxBinaries is max binaries batch can handle", - "default": 473170 - }, - "MaxSteps": { - "type": "integer", - "description": "MaxSteps is max steps batch can handle", - "default": 7570538 - }, - "WeightBatchBytesSize": { - "type": "integer", - "description": "WeightBatchBytesSize is the cost weight for the BatchBytesSize batch resource", - "default": 1 - }, - "WeightCumulativeGasUsed": { - "type": "integer", - "description": "WeightCumulativeGasUsed is the cost weight for the CumulativeGasUsed batch resource", - "default": 1 - }, - "WeightKeccakHashes": { - "type": "integer", - "description": "WeightKeccakHashes is the cost weight for the KeccakHashes batch resource", - "default": 1 - }, - "WeightPoseidonHashes": { - "type": "integer", - "description": "WeightPoseidonHashes is the cost weight for the PoseidonHashes batch resource", - "default": 1 - }, - "WeightPoseidonPaddings": { - "type": "integer", - "description": "WeightPoseidonPaddings is the cost weight for the PoseidonPaddings batch resource", - "default": 1 - }, - "WeightMemAligns": { - "type": "integer", - "description": "WeightMemAligns is the cost weight for the MemAligns batch resource", - "default": 1 - }, - "WeightArithmetics": { - "type": "integer", - "description": "WeightArithmetics is the cost weight for the Arithmetics batch resource", - "default": 1 - }, - "WeightBinaries": { - "type": "integer", - "description": "WeightBinaries is the cost weight for the Binaries batch resource", - "default": 1 - }, - "WeightSteps": { - "type": "integer", - "description": "WeightSteps is the cost weight for the Steps batch resource", - "default": 1 - }, "TxLifetimeCheckTimeout": { "type": "string", "title": "Duration", @@ -1248,6 +1153,101 @@ "additionalProperties": false, "type": "object", "description": "Configuration of the hash database connection" + }, + "Batch": { + "properties": { + "Constraints": { + "properties": { + "MaxTxsPerBatch": { + "type": "integer", + "default": 300 + }, + "MaxBatchBytesSize": { + "type": "integer", + "default": 120000 + }, + "MaxCumulativeGasUsed": { + "type": "integer", + "default": 30000000 + }, + "MaxKeccakHashes": { + "type": "integer", + "default": 2145 + }, + "MaxPoseidonHashes": { + "type": "integer", + "default": 252357 + }, + "MaxPoseidonPaddings": { + "type": "integer", + "default": 135191 + }, + "MaxMemAligns": { + "type": "integer", + "default": 236585 + }, + "MaxArithmetics": { + "type": "integer", + "default": 236585 + }, + "MaxBinaries": { + "type": "integer", + "default": 473170 + }, + "MaxSteps": { + "type": "integer", + "default": 7570538 + } + }, + "additionalProperties": false, + "type": "object" + }, + "ResourceWeights": { + "properties": { + "WeightBatchBytesSize": { + "type": "integer", + "default": 1 + }, + "WeightCumulativeGasUsed": { + "type": "integer", + "default": 1 + }, + "WeightKeccakHashes": { + "type": "integer", + "default": 1 + }, + "WeightPoseidonHashes": { + "type": "integer", + "default": 1 + }, + "WeightPoseidonPaddings": { + "type": "integer", + "default": 1 + }, + "WeightMemAligns": { + "type": "integer", + "default": 1 + }, + "WeightArithmetics": { + "type": "integer", + "default": 1 + }, + "WeightBinaries": { + "type": "integer", + "default": 1 + }, + "WeightSteps": { + "type": "integer", + "default": 1 + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "description": "Configuration of the batch service" } }, "additionalProperties": false, diff --git a/sequencer/worker.go b/sequencer/worker.go index a8ddce001d..9ec10d560c 100644 --- a/sequencer/worker.go +++ b/sequencer/worker.go @@ -54,13 +54,13 @@ func (w *Worker) AddTxTracker(ctx context.Context, tx *TxTracker) (replacedTx *T // Make sure the IP is valid. if tx.IP != "" && !pool.IsValidIP(tx.IP) { - return pool.ErrInvalidIP, false + return nil, pool.ErrInvalidIP } // Make sure the transaction's batch resources are within the constraints. if !w.batchConstraints.IsWithinConstraints(tx.BatchResources.ZKCounters) { log.Errorf("OutOfCounters Error (Node level) for tx: %s", tx.Hash.String()) - return pool.ErrOutOfCounters, false + return nil, pool.ErrOutOfCounters } addr, found := w.pool[tx.FromStr] From 7d1b67222d19d31f3e36616bcc342a9aa4e51b13 Mon Sep 17 00:00:00 2001 From: Nikolay Nedkov Date: Thu, 27 Jul 2023 15:34:29 +0300 Subject: [PATCH 4/6] improve: moving BatchConfig to state package Signed-off-by: Nikolay Nedkov --- cmd/dumpstate.go | 2 +- cmd/restore.go | 14 +- cmd/run.go | 26 +- cmd/snapshot.go | 10 +- config/config.go | 7 +- config/config_test.go | 52 +- config/default.go | 62 +- .../environments/local/local.node.config.toml | 9 - docs/config-file/node-config-doc.html | 4 +- docs/config-file/node-config-doc.md | 569 +++++++++++------- docs/config-file/node-config-schema.json | 293 +++++---- pool/config.go | 46 -- pool/config_test.go | 2 +- pool/pool.go | 4 +- pool/pool_test.go | 4 +- sequencer/addrqueue.go | 3 +- sequencer/closingsignalsmanager_test.go | 3 +- sequencer/dbmanager.go | 4 +- sequencer/dbmanager_test.go | 3 +- sequencer/finalizer.go | 6 +- sequencer/finalizer_test.go | 2 +- sequencer/sequencer.go | 6 +- sequencer/txtracker.go | 10 +- sequencer/txtracker_test.go | 3 +- sequencer/worker.go | 8 +- sequencer/worker_test.go | 6 +- state/config.go | 56 +- .../sequencer/common/setup/setup.go | 3 +- test/config/debug.node.config.toml | 17 +- test/config/test.node.config.toml | 9 - test/e2e/uniswap_test.go | 2 +- 31 files changed, 727 insertions(+), 518 deletions(-) diff --git a/cmd/dumpstate.go b/cmd/dumpstate.go index 05b0bbea4e..6fc3b3156c 100644 --- a/cmd/dumpstate.go +++ b/cmd/dumpstate.go @@ -109,7 +109,7 @@ func dumpState(ctx *cli.Context) error { } // Connect to SQL - stateSqlDB, err := db.NewSQLDB(c.StateDB) + stateSqlDB, err := db.NewSQLDB(c.State.DB) if err != nil { return err } diff --git a/cmd/restore.go b/cmd/restore.go index 10e364338c..b31abbdf9a 100644 --- a/cmd/restore.go +++ b/cmd/restore.go @@ -46,25 +46,25 @@ func restore(ctx *cli.Context) error { } // Run migrations to create schemas and tables - runStateMigrations(c.StateDB) + runStateMigrations(c.State.DB) - port, err := strconv.Atoi(c.StateDB.Port) + port, err := strconv.Atoi(c.State.DB.Port) if err != nil { log.Error("error converting port to int. Error: ", err) return err } restore, err := pg.NewRestore(&pg.Postgres{ - Host: c.StateDB.Host, + Host: c.State.DB.Host, Port: port, - DB: c.StateDB.Name, - Username: c.StateDB.User, - Password: c.StateDB.Password, + DB: c.State.DB.Name, + Username: c.State.DB.User, + Password: c.State.DB.Password, }) if err != nil { log.Error("error: ", err) return err } - restore.Role = c.StateDB.User + restore.Role = c.State.DB.User restore.Schemas = append(restore.Schemas, "state") log.Info("Restore stateDB snapshot started, please wait...") restoreExec := restore.Exec(inputFileStateDB, pg.ExecOptions{StreamPrint: false}) diff --git a/cmd/run.go b/cmd/run.go index f09dc41663..a544785d5e 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -61,11 +61,11 @@ func start(cliCtx *cli.Context) error { if !cliCtx.Bool(config.FlagMigrations) { for _, comp := range components { if comp == SYNCHRONIZER { - runStateMigrations(c.StateDB) + runStateMigrations(c.State.DB) } } } - checkStateMigrations(c.StateDB) + checkStateMigrations(c.State.DB) // Decide if this node instance needs an executor and/or a state tree var needsExecutor, needsStateTree bool @@ -96,7 +96,7 @@ func start(cliCtx *cli.Context) error { eventLog = event.NewEventLog(c.EventLog, eventStorage) // Core State DB - stateSqlDB, err := db.NewSQLDB(c.StateDB) + stateSqlDB, err := db.NewSQLDB(c.State.DB) if err != nil { log.Fatal(err) } @@ -133,7 +133,7 @@ func start(cliCtx *cli.Context) error { ctx := context.Background() st := newState(ctx, c, l2ChainID, forkIDIntervals, stateSqlDB, eventLog, needsExecutor, needsStateTree) - ethTxManagerStorage, err := ethtxmanager.NewPostgresStorage(c.StateDB) + ethTxManagerStorage, err := ethtxmanager.NewPostgresStorage(c.State.DB) if err != nil { log.Fatal(err) } @@ -170,7 +170,7 @@ func start(cliCtx *cli.Context) error { log.Fatal(err) } if poolInstance == nil { - poolInstance = createPool(c.Pool, c.Batch.Constraints, l2ChainID, st, eventLog) + poolInstance = createPool(c.Pool, c.State.Batch.Constraints, l2ChainID, st, eventLog) } seq := createSequencer(*c, poolInstance, ethTxManagerStorage, st, eventLog) go seq.Start(ctx) @@ -182,7 +182,7 @@ func start(cliCtx *cli.Context) error { log.Fatal(err) } if poolInstance == nil { - poolInstance = createPool(c.Pool, c.Batch.Constraints, l2ChainID, st, eventLog) + poolInstance = createPool(c.Pool, c.State.Batch.Constraints, l2ChainID, st, eventLog) } seqSender := createSequenceSender(*c, poolInstance, ethTxManagerStorage, st, eventLog) go seqSender.Start(ctx) @@ -194,7 +194,7 @@ func start(cliCtx *cli.Context) error { log.Fatal(err) } if poolInstance == nil { - poolInstance = createPool(c.Pool, c.Batch.Constraints, l2ChainID, st, eventLog) + poolInstance = createPool(c.Pool, c.State.Batch.Constraints, l2ChainID, st, eventLog) } if c.RPC.EnableL2SuggestedGasPricePolling { // Needed for rejecting transactions with too low gas price @@ -213,7 +213,7 @@ func start(cliCtx *cli.Context) error { log.Fatal(err) } if poolInstance == nil { - poolInstance = createPool(c.Pool, c.Batch.Constraints, l2ChainID, st, eventLog) + poolInstance = createPool(c.Pool, c.State.Batch.Constraints, l2ChainID, st, eventLog) } go runSynchronizer(*c, etherman, etm, st, poolInstance, eventLog) case ETHTXMANAGER: @@ -233,7 +233,7 @@ func start(cliCtx *cli.Context) error { log.Fatal(err) } if poolInstance == nil { - poolInstance = createPool(c.Pool, c.Batch.Constraints, l2ChainID, st, eventLog) + poolInstance = createPool(c.Pool, c.State.Batch.Constraints, l2ChainID, st, eventLog) } go runL2GasPriceSuggester(c.L2GasPriceSuggester, st, poolInstance, etherman) } @@ -315,7 +315,7 @@ func runSynchronizer(cfg config.Config, etherman *etherman.Client, ethTxManager func runJSONRPCServer(c config.Config, etherman *etherman.Client, chainID uint64, pool *pool.Pool, st *state.State, apis map[string]bool) { var err error storage := jsonrpc.NewStorage() - c.RPC.MaxCumulativeGasUsed = c.Batch.Constraints.MaxCumulativeGasUsed + c.RPC.MaxCumulativeGasUsed = c.State.Batch.Constraints.MaxCumulativeGasUsed if !c.IsTrustedSequencer { if c.RPC.SequencerNodeURI == "" { log.Debug("getting trusted sequencer URL from smc") @@ -383,7 +383,7 @@ func createSequencer(cfg config.Config, pool *pool.Pool, etmStorage *ethtxmanage ethTxManager := ethtxmanager.New(cfg.EthTxManager, etherman, etmStorage, st) - seq, err := sequencer.New(cfg.Sequencer, cfg.Batch, pool, st, etherman, ethTxManager, eventLog) + seq, err := sequencer.New(cfg.Sequencer, cfg.State.Batch, pool, st, etherman, ethTxManager, eventLog) if err != nil { log.Fatal(err) } @@ -467,7 +467,7 @@ func newState(ctx context.Context, c *config.Config, l2ChainID uint64, forkIDInt } stateCfg := state.Config{ - MaxCumulativeGasUsed: c.Batch.Constraints.MaxCumulativeGasUsed, + MaxCumulativeGasUsed: c.State.Batch.Constraints.MaxCumulativeGasUsed, ChainID: l2ChainID, ForkIDIntervals: forkIDIntervals, MaxResourceExhaustedAttempts: c.Executor.MaxResourceExhaustedAttempts, @@ -480,7 +480,7 @@ func newState(ctx context.Context, c *config.Config, l2ChainID uint64, forkIDInt return st } -func createPool(cfgPool pool.Config, constraintsCfg pool.BatchConstraintsCfg, l2ChainID uint64, st *state.State, eventLog *event.EventLog) *pool.Pool { +func createPool(cfgPool pool.Config, constraintsCfg state.BatchConstraintsCfg, l2ChainID uint64, st *state.State, eventLog *event.EventLog) *pool.Pool { runPoolMigrations(cfgPool.DB) poolStorage, err := pgpoolstorage.NewPostgresPoolStorage(cfgPool.DB) if err != nil { diff --git a/cmd/snapshot.go b/cmd/snapshot.go index 4605772e12..01d7562654 100644 --- a/cmd/snapshot.go +++ b/cmd/snapshot.go @@ -25,17 +25,17 @@ func snapshot(ctx *cli.Context) error { } setupLog(c.Log) - port, err := strconv.Atoi(c.StateDB.Port) + port, err := strconv.Atoi(c.State.DB.Port) if err != nil { log.Error("error converting port to int. Error: ", err) return err } dump, err := pg.NewDump(&pg.Postgres{ - Host: c.StateDB.Host, + Host: c.State.DB.Host, Port: port, - DB: c.StateDB.Name, - Username: c.StateDB.User, - Password: c.StateDB.Password, + DB: c.State.DB.Name, + Username: c.State.DB.User, + Password: c.State.DB.Password, }) if err != nil { log.Error("error: ", err) diff --git a/config/config.go b/config/config.go index b83cfd6d20..b0baee6cfd 100644 --- a/config/config.go +++ b/config/config.go @@ -18,6 +18,7 @@ import ( "github.com/0xPolygonHermez/zkevm-node/pool" "github.com/0xPolygonHermez/zkevm-node/sequencer" "github.com/0xPolygonHermez/zkevm-node/sequencesender" + "github.com/0xPolygonHermez/zkevm-node/state" "github.com/0xPolygonHermez/zkevm-node/state/runtime/executor" "github.com/0xPolygonHermez/zkevm-node/synchronizer" "github.com/mitchellh/mapstructure" @@ -108,16 +109,14 @@ type Config struct { Executor executor.Config // Configuration of the merkle tree client service. Not use in the node, only for testing MTClient merkletree.Config - // Configuration of the state database connection - StateDB db.Config // Configuration of the metrics service, basically is where is going to publish the metrics Metrics metrics.Config // Configuration of the event database connection EventLog event.Config // Configuration of the hash database connection HashDB db.Config - // Configuration of the batch service - Batch pool.BatchConfig + // Configuration of the state + State state.Config } // Default parses the default configuration values. diff --git a/config/config_test.go b/config/config_test.go index ed580d22e7..78537ef9c3 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -201,31 +201,31 @@ func Test_Defaults(t *testing.T) { expectedValue: "zkevm-prover:50061", }, { - path: "StateDB.User", + path: "State.DB.User", expectedValue: "state_user", }, { - path: "StateDB.Password", + path: "State.DB.Password", expectedValue: "state_password", }, { - path: "StateDB.Name", + path: "State.DB.Name", expectedValue: "state_db", }, { - path: "StateDB.Host", + path: "State.DB.Host", expectedValue: "zkevm-state-db", }, { - path: "StateDB.Port", + path: "State.DB.Port", expectedValue: "5432", }, { - path: "StateDB.EnableLog", + path: "State.DB.EnableLog", expectedValue: false, }, { - path: "StateDB.MaxConns", + path: "State.DB.MaxConns", expectedValue: 200, }, { @@ -395,79 +395,79 @@ func Test_Defaults(t *testing.T) { }, { - path: "Batch.Constraints.MaxTxsPerBatch", + path: "State.Batch.Constraints.MaxTxsPerBatch", expectedValue: uint64(300), }, { - path: "Batch.Constraints.MaxBatchBytesSize", + path: "State.Batch.Constraints.MaxBatchBytesSize", expectedValue: uint64(120000), }, { - path: "Batch.Constraints.MaxCumulativeGasUsed", + path: "State.Batch.Constraints.MaxCumulativeGasUsed", expectedValue: uint64(30000000), }, { - path: "Batch.Constraints.MaxKeccakHashes", + path: "State.Batch.Constraints.MaxKeccakHashes", expectedValue: uint32(2145), }, { - path: "Batch.Constraints.MaxPoseidonHashes", + path: "State.Batch.Constraints.MaxPoseidonHashes", expectedValue: uint32(252357), }, { - path: "Batch.Constraints.MaxPoseidonPaddings", + path: "State.Batch.Constraints.MaxPoseidonPaddings", expectedValue: uint32(135191), }, { - path: "Batch.Constraints.MaxMemAligns", + path: "State.Batch.Constraints.MaxMemAligns", expectedValue: uint32(236585), }, { - path: "Batch.Constraints.MaxArithmetics", + path: "State.Batch.Constraints.MaxArithmetics", expectedValue: uint32(236585), }, { - path: "Batch.Constraints.MaxBinaries", + path: "State.Batch.Constraints.MaxBinaries", expectedValue: uint32(473170), }, { - path: "Batch.Constraints.MaxSteps", + path: "State.Batch.Constraints.MaxSteps", expectedValue: uint32(7570538), }, { - path: "Batch.ResourceWeights.WeightBatchBytesSize", + path: "State.Batch.ResourceWeights.WeightBatchBytesSize", expectedValue: 1, }, { - path: "Batch.ResourceWeights.WeightCumulativeGasUsed", + path: "State.Batch.ResourceWeights.WeightCumulativeGasUsed", expectedValue: 1, }, { - path: "Batch.ResourceWeights.WeightKeccakHashes", + path: "State.Batch.ResourceWeights.WeightKeccakHashes", expectedValue: 1, }, { - path: "Batch.ResourceWeights.WeightPoseidonHashes", + path: "State.Batch.ResourceWeights.WeightPoseidonHashes", expectedValue: 1, }, { - path: "Batch.ResourceWeights.WeightPoseidonPaddings", + path: "State.Batch.ResourceWeights.WeightPoseidonPaddings", expectedValue: 1, }, { - path: "Batch.ResourceWeights.WeightMemAligns", + path: "State.Batch.ResourceWeights.WeightMemAligns", expectedValue: 1, }, { - path: "Batch.ResourceWeights.WeightArithmetics", + path: "State.Batch.ResourceWeights.WeightArithmetics", expectedValue: 1, }, { - path: "Batch.ResourceWeights.WeightBinaries", + path: "State.Batch.ResourceWeights.WeightBinaries", expectedValue: 1, }, { - path: "Batch.ResourceWeights.WeightSteps", + path: "State.Batch.ResourceWeights.WeightSteps", expectedValue: 1, }, } diff --git a/config/default.go b/config/default.go index 30d4961181..1cc539fd62 100644 --- a/config/default.go +++ b/config/default.go @@ -11,14 +11,37 @@ Environment = "development" # "production" or "development" Level = "info" Outputs = ["stderr"] -[StateDB] -User = "state_user" -Password = "state_password" -Name = "state_db" -Host = "zkevm-state-db" -Port = "5432" -EnableLog = false -MaxConns = 200 +[State] + [State.DB] + User = "state_user" + Password = "state_password" + Name = "state_db" + Host = "zkevm-state-db" + Port = "5432" + EnableLog = false + MaxConns = 200 + [State.Batch] + [State.Batch.Constraints] + MaxTxsPerBatch = 300 + MaxBatchBytesSize = 120000 + MaxCumulativeGasUsed = 30000000 + MaxKeccakHashes = 2145 + MaxPoseidonHashes = 252357 + MaxPoseidonPaddings = 135191 + MaxMemAligns = 236585 + MaxArithmetics = 236585 + MaxBinaries = 473170 + MaxSteps = 7570538 + [State.Batch.ResourceWeights] + WeightBatchBytesSize = 1 + WeightCumulativeGasUsed = 1 + WeightKeccakHashes = 1 + WeightPoseidonHashes = 1 + WeightPoseidonPaddings = 1 + WeightMemAligns = 1 + WeightArithmetics = 1 + WeightBinaries = 1 + WeightSteps = 1 [Pool] IntervalToRefreshBlockedAddresses = "5m" @@ -148,27 +171,4 @@ Host = "zkevm-state-db" Port = "5432" EnableLog = false MaxConns = 200 - -[Batch] - [Batch.Constraints] - MaxTxsPerBatch = 300 - MaxBatchBytesSize = 120000 - MaxCumulativeGasUsed = 30000000 - MaxKeccakHashes = 2145 - MaxPoseidonHashes = 252357 - MaxPoseidonPaddings = 135191 - MaxMemAligns = 236585 - MaxArithmetics = 236585 - MaxBinaries = 473170 - MaxSteps = 7570538 - [Batch.ResourceWeights] - WeightBatchBytesSize = 1 - WeightCumulativeGasUsed = 1 - WeightKeccakHashes = 1 - WeightPoseidonHashes = 1 - WeightPoseidonPaddings = 1 - WeightMemAligns = 1 - WeightArithmetics = 1 - WeightBinaries = 1 - WeightSteps = 1 ` diff --git a/config/environments/local/local.node.config.toml b/config/environments/local/local.node.config.toml index 6092455beb..521e3697eb 100644 --- a/config/environments/local/local.node.config.toml +++ b/config/environments/local/local.node.config.toml @@ -6,15 +6,6 @@ Environment = "development" # "production" or "development" Level = "debug" Outputs = ["stderr"] -[StateDB] -User = "state_user" -Password = "state_password" -Name = "state_db" -Host = "zkevm-state-db" -Port = "5432" -EnableLog = false -MaxConns = 200 - [Pool] IntervalToRefreshBlockedAddresses = "5m" IntervalToRefreshGasPrices = "5s" diff --git a/docs/config-file/node-config-doc.html b/docs/config-file/node-config-doc.html index 022afdbe81..19d533c1f1 100644 --- a/docs/config-file/node-config-doc.html +++ b/docs/config-file/node-config-doc.html @@ -64,4 +64,6 @@
"300ms"
 

Default: 0.15Type: number

Configuration of the executor service
Default: "zkevm-prover:50071"Type: string

Default: 3Type: integer

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


Default: "1s"Type: string

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


Examples:

"1m"
 
"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 state database connection
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 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.


Configuration of the batch service
Default: 300Type: integer

Default: 120000Type: integer

Default: 30000000Type: integer

Default: 2145Type: integer

Default: 252357Type: integer

Default: 135191Type: integer

Default: 236585Type: integer

Default: 236585Type: integer

Default: 473170Type: integer

Default: 7570538Type: integer

\ No newline at end of file +
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.


Configuration of the state
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)


Configuration of the state database connection
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
\ 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 00135944fb..34de4c172f 100644 --- a/docs/config-file/node-config-doc.md +++ b/docs/config-file/node-config-doc.md @@ -23,11 +23,10 @@ | - [L2GasPriceSuggester](#L2GasPriceSuggester ) | No | object | No | - | Configuration of the gas price suggester service | | - [Executor](#Executor ) | No | object | No | - | Configuration of the executor service | | - [MTClient](#MTClient ) | No | object | No | - | Configuration of the merkle tree client service. Not use in the node, only for testing | -| - [StateDB](#StateDB ) | No | object | No | - | Configuration of the state database connection | | - [Metrics](#Metrics ) | No | object | No | - | Configuration of the metrics service, basically is where is going to publish the metrics | | - [EventLog](#EventLog ) | No | object | No | - | Configuration of the event database connection | | - [HashDB](#HashDB ) | No | object | No | - | Configuration of the hash database connection | -| - [Batch](#Batch ) | No | object | No | - | Configuration of the batch service | +| - [State](#State ) | No | object | No | - | Configuration of the state | ## 1. `IsTrustedSequencer` @@ -2354,120 +2353,7 @@ MaxGRPCMessageSize=100000000 URI="zkevm-prover:50061" ``` -## 17. `[StateDB]` - -**Type:** : `object` -**Description:** Configuration of the state database connection - -| Property | Pattern | Type | Deprecated | Definition | Title/Description | -| ---------------------------------- | ------- | ------- | ---------- | ---------- | ---------------------------------------------------------- | -| - [Name](#StateDB_Name ) | No | string | No | - | Database name | -| - [User](#StateDB_User ) | No | string | No | - | Database User name | -| - [Password](#StateDB_Password ) | No | string | No | - | Database Password of the user | -| - [Host](#StateDB_Host ) | No | string | No | - | Host address of database | -| - [Port](#StateDB_Port ) | No | string | No | - | Port Number of database | -| - [EnableLog](#StateDB_EnableLog ) | No | boolean | No | - | EnableLog | -| - [MaxConns](#StateDB_MaxConns ) | No | integer | No | - | MaxConns is the maximum number of connections in the pool. | - -### 17.1. `StateDB.Name` - -**Type:** : `string` - -**Default:** `"state_db"` - -**Description:** Database name - -**Example setting the default value** ("state_db"): -``` -[StateDB] -Name="state_db" -``` - -### 17.2. `StateDB.User` - -**Type:** : `string` - -**Default:** `"state_user"` - -**Description:** Database User name - -**Example setting the default value** ("state_user"): -``` -[StateDB] -User="state_user" -``` - -### 17.3. `StateDB.Password` - -**Type:** : `string` - -**Default:** `"state_password"` - -**Description:** Database Password of the user - -**Example setting the default value** ("state_password"): -``` -[StateDB] -Password="state_password" -``` - -### 17.4. `StateDB.Host` - -**Type:** : `string` - -**Default:** `"zkevm-state-db"` - -**Description:** Host address of database - -**Example setting the default value** ("zkevm-state-db"): -``` -[StateDB] -Host="zkevm-state-db" -``` - -### 17.5. `StateDB.Port` - -**Type:** : `string` - -**Default:** `"5432"` - -**Description:** Port Number of database - -**Example setting the default value** ("5432"): -``` -[StateDB] -Port="5432" -``` - -### 17.6. `StateDB.EnableLog` - -**Type:** : `boolean` - -**Default:** `false` - -**Description:** EnableLog - -**Example setting the default value** (false): -``` -[StateDB] -EnableLog=false -``` - -### 17.7. `StateDB.MaxConns` - -**Type:** : `integer` - -**Default:** `200` - -**Description:** MaxConns is the maximum number of connections in the pool. - -**Example setting the default value** (200): -``` -[StateDB] -MaxConns=200 -``` - -## 18. `[Metrics]` +## 17. `[Metrics]` **Type:** : `object` **Description:** Configuration of the metrics service, basically is where is going to publish the metrics @@ -2481,7 +2367,7 @@ MaxConns=200 | - [ProfilingPort](#Metrics_ProfilingPort ) | No | integer | No | - | ProfilingPort is the port to bind the profiling server | | - [ProfilingEnabled](#Metrics_ProfilingEnabled ) | No | boolean | No | - | ProfilingEnabled is the flag to enable/disable the profiling server | -### 18.1. `Metrics.Host` +### 17.1. `Metrics.Host` **Type:** : `string` @@ -2495,7 +2381,7 @@ MaxConns=200 Host="0.0.0.0" ``` -### 18.2. `Metrics.Port` +### 17.2. `Metrics.Port` **Type:** : `integer` @@ -2509,7 +2395,7 @@ Host="0.0.0.0" Port=9091 ``` -### 18.3. `Metrics.Enabled` +### 17.3. `Metrics.Enabled` **Type:** : `boolean` @@ -2523,7 +2409,7 @@ Port=9091 Enabled=false ``` -### 18.4. `Metrics.ProfilingHost` +### 17.4. `Metrics.ProfilingHost` **Type:** : `string` @@ -2537,7 +2423,7 @@ Enabled=false ProfilingHost="" ``` -### 18.5. `Metrics.ProfilingPort` +### 17.5. `Metrics.ProfilingPort` **Type:** : `integer` @@ -2551,7 +2437,7 @@ ProfilingHost="" ProfilingPort=0 ``` -### 18.6. `Metrics.ProfilingEnabled` +### 17.6. `Metrics.ProfilingEnabled` **Type:** : `boolean` @@ -2565,7 +2451,7 @@ ProfilingPort=0 ProfilingEnabled=false ``` -## 19. `[EventLog]` +## 18. `[EventLog]` **Type:** : `object` **Description:** Configuration of the event database connection @@ -2574,7 +2460,7 @@ ProfilingEnabled=false | --------------------- | ------- | ------ | ---------- | ---------- | -------------------------------- | | - [DB](#EventLog_DB ) | No | object | No | - | DB is the database configuration | -### 19.1. `[EventLog.DB]` +### 18.1. `[EventLog.DB]` **Type:** : `object` **Description:** DB is the database configuration @@ -2589,7 +2475,7 @@ ProfilingEnabled=false | - [EnableLog](#EventLog_DB_EnableLog ) | No | boolean | No | - | EnableLog | | - [MaxConns](#EventLog_DB_MaxConns ) | No | integer | No | - | MaxConns is the maximum number of connections in the pool. | -#### 19.1.1. `EventLog.DB.Name` +#### 18.1.1. `EventLog.DB.Name` **Type:** : `string` @@ -2603,7 +2489,7 @@ ProfilingEnabled=false Name="" ``` -#### 19.1.2. `EventLog.DB.User` +#### 18.1.2. `EventLog.DB.User` **Type:** : `string` @@ -2617,7 +2503,7 @@ Name="" User="" ``` -#### 19.1.3. `EventLog.DB.Password` +#### 18.1.3. `EventLog.DB.Password` **Type:** : `string` @@ -2631,7 +2517,7 @@ User="" Password="" ``` -#### 19.1.4. `EventLog.DB.Host` +#### 18.1.4. `EventLog.DB.Host` **Type:** : `string` @@ -2645,7 +2531,7 @@ Password="" Host="" ``` -#### 19.1.5. `EventLog.DB.Port` +#### 18.1.5. `EventLog.DB.Port` **Type:** : `string` @@ -2659,7 +2545,7 @@ Host="" Port="" ``` -#### 19.1.6. `EventLog.DB.EnableLog` +#### 18.1.6. `EventLog.DB.EnableLog` **Type:** : `boolean` @@ -2673,7 +2559,7 @@ Port="" EnableLog=false ``` -#### 19.1.7. `EventLog.DB.MaxConns` +#### 18.1.7. `EventLog.DB.MaxConns` **Type:** : `integer` @@ -2687,7 +2573,7 @@ EnableLog=false MaxConns=0 ``` -## 20. `[HashDB]` +## 19. `[HashDB]` **Type:** : `object` **Description:** Configuration of the hash database connection @@ -2702,7 +2588,7 @@ MaxConns=0 | - [EnableLog](#HashDB_EnableLog ) | No | boolean | No | - | EnableLog | | - [MaxConns](#HashDB_MaxConns ) | No | integer | No | - | MaxConns is the maximum number of connections in the pool. | -### 20.1. `HashDB.Name` +### 19.1. `HashDB.Name` **Type:** : `string` @@ -2716,7 +2602,7 @@ MaxConns=0 Name="prover_db" ``` -### 20.2. `HashDB.User` +### 19.2. `HashDB.User` **Type:** : `string` @@ -2730,7 +2616,7 @@ Name="prover_db" User="prover_user" ``` -### 20.3. `HashDB.Password` +### 19.3. `HashDB.Password` **Type:** : `string` @@ -2744,7 +2630,7 @@ User="prover_user" Password="prover_pass" ``` -### 20.4. `HashDB.Host` +### 19.4. `HashDB.Host` **Type:** : `string` @@ -2758,7 +2644,7 @@ Password="prover_pass" Host="zkevm-state-db" ``` -### 20.5. `HashDB.Port` +### 19.5. `HashDB.Port` **Type:** : `string` @@ -2772,7 +2658,7 @@ Host="zkevm-state-db" Port="5432" ``` -### 20.6. `HashDB.EnableLog` +### 19.6. `HashDB.EnableLog` **Type:** : `boolean` @@ -2786,7 +2672,7 @@ Port="5432" EnableLog=false ``` -### 20.7. `HashDB.MaxConns` +### 19.7. `HashDB.MaxConns` **Type:** : `integer` @@ -2800,34 +2686,305 @@ EnableLog=false MaxConns=200 ``` -## 21. `[Batch]` +## 20. `[State]` **Type:** : `object` -**Description:** Configuration of the batch service +**Description:** Configuration of the state + +| Property | Pattern | Type | Deprecated | Definition | Title/Description | +| ---------------------------------------------------------------------- | ------- | --------------- | ---------- | ---------- | ----------------------------------------------------------------------------------------------------------------------- | +| - [MaxCumulativeGasUsed](#State_MaxCumulativeGasUsed ) | No | integer | No | - | MaxCumulativeGasUsed is the max gas allowed per batch | +| - [ChainID](#State_ChainID ) | No | integer | No | - | ChainID is the L2 ChainID provided by the Network Config | +| - [ForkIDIntervals](#State_ForkIDIntervals ) | No | array of object | No | - | ForkIdIntervals is the list of fork id intervals | +| - [MaxResourceExhaustedAttempts](#State_MaxResourceExhaustedAttempts ) | No | integer | No | - | MaxResourceExhaustedAttempts is the max number of attempts to make a transaction succeed because of resource exhaustion | +| - [WaitOnResourceExhaustion](#State_WaitOnResourceExhaustion ) | No | string | No | - | Duration | +| - [ForkUpgradeBatchNumber](#State_ForkUpgradeBatchNumber ) | No | integer | No | - | Batch number from which there is a forkid change (fork upgrade) | +| - [ForkUpgradeNewForkId](#State_ForkUpgradeNewForkId ) | No | integer | No | - | New fork id to be used for batches greaters than ForkUpgradeBatchNumber (fork upgrade) | +| - [DB](#State_DB ) | No | object | No | - | Configuration of the state database connection | +| - [Batch](#State_Batch ) | No | object | No | - | Configuration for the batch constraints | + +### 20.1. `State.MaxCumulativeGasUsed` + +**Type:** : `integer` + +**Default:** `0` + +**Description:** MaxCumulativeGasUsed is the max gas allowed per batch + +**Example setting the default value** (0): +``` +[State] +MaxCumulativeGasUsed=0 +``` + +### 20.2. `State.ChainID` + +**Type:** : `integer` + +**Default:** `0` + +**Description:** ChainID is the L2 ChainID provided by the Network Config -| Property | Pattern | Type | Deprecated | Definition | Title/Description | -| -------------------------------------------- | ------- | ------ | ---------- | ---------- | ----------------- | -| - [Constraints](#Batch_Constraints ) | No | object | No | - | - | -| - [ResourceWeights](#Batch_ResourceWeights ) | No | object | No | - | - | +**Example setting the default value** (0): +``` +[State] +ChainID=0 +``` + +### 20.3. `State.ForkIDIntervals` + +**Type:** : `array of object` +**Description:** ForkIdIntervals is the list of fork id intervals + +| | Array restrictions | +| -------------------- | ------------------ | +| **Min items** | N/A | +| **Max items** | N/A | +| **Items unicity** | False | +| **Additional items** | False | +| **Tuple validation** | See below | + +| Each item of this array must be | Description | +| ----------------------------------------------------- | ------------------------------------ | +| [ForkIDIntervals items](#State_ForkIDIntervals_items) | ForkIDInterval is a fork id interval | -### 21.1. `[Batch.Constraints]` +#### 20.3.1. [State.ForkIDIntervals.ForkIDIntervals items] **Type:** : `object` +**Description:** ForkIDInterval is a fork id interval | Property | Pattern | Type | Deprecated | Definition | Title/Description | | ------------------------------------------------------------------ | ------- | ------- | ---------- | ---------- | ----------------- | -| - [MaxTxsPerBatch](#Batch_Constraints_MaxTxsPerBatch ) | No | integer | No | - | - | -| - [MaxBatchBytesSize](#Batch_Constraints_MaxBatchBytesSize ) | No | integer | No | - | - | -| - [MaxCumulativeGasUsed](#Batch_Constraints_MaxCumulativeGasUsed ) | No | integer | No | - | - | -| - [MaxKeccakHashes](#Batch_Constraints_MaxKeccakHashes ) | No | integer | No | - | - | -| - [MaxPoseidonHashes](#Batch_Constraints_MaxPoseidonHashes ) | No | integer | No | - | - | -| - [MaxPoseidonPaddings](#Batch_Constraints_MaxPoseidonPaddings ) | No | integer | No | - | - | -| - [MaxMemAligns](#Batch_Constraints_MaxMemAligns ) | No | integer | No | - | - | -| - [MaxArithmetics](#Batch_Constraints_MaxArithmetics ) | No | integer | No | - | - | -| - [MaxBinaries](#Batch_Constraints_MaxBinaries ) | No | integer | No | - | - | -| - [MaxSteps](#Batch_Constraints_MaxSteps ) | No | integer | No | - | - | +| - [FromBatchNumber](#State_ForkIDIntervals_items_FromBatchNumber ) | No | integer | No | - | - | +| - [ToBatchNumber](#State_ForkIDIntervals_items_ToBatchNumber ) | No | integer | No | - | - | +| - [ForkId](#State_ForkIDIntervals_items_ForkId ) | No | integer | No | - | - | +| - [Version](#State_ForkIDIntervals_items_Version ) | No | string | No | - | - | + +##### 20.3.1.1. `State.ForkIDIntervals.ForkIDIntervals items.FromBatchNumber` + +**Type:** : `integer` + +##### 20.3.1.2. `State.ForkIDIntervals.ForkIDIntervals items.ToBatchNumber` + +**Type:** : `integer` + +##### 20.3.1.3. `State.ForkIDIntervals.ForkIDIntervals items.ForkId` + +**Type:** : `integer` + +##### 20.3.1.4. `State.ForkIDIntervals.ForkIDIntervals items.Version` + +**Type:** : `string` + +### 20.4. `State.MaxResourceExhaustedAttempts` + +**Type:** : `integer` + +**Default:** `0` + +**Description:** MaxResourceExhaustedAttempts is the max number of attempts to make a transaction succeed because of resource exhaustion + +**Example setting the default value** (0): +``` +[State] +MaxResourceExhaustedAttempts=0 +``` + +### 20.5. `State.WaitOnResourceExhaustion` + +**Title:** Duration + +**Type:** : `string` + +**Default:** `"0s"` + +**Description:** WaitOnResourceExhaustion is the time to wait before retrying a transaction because of resource exhaustion + +**Examples:** + +```json +"1m" +``` + +```json +"300ms" +``` + +**Example setting the default value** ("0s"): +``` +[State] +WaitOnResourceExhaustion="0s" +``` + +### 20.6. `State.ForkUpgradeBatchNumber` + +**Type:** : `integer` + +**Default:** `0` + +**Description:** Batch number from which there is a forkid change (fork upgrade) + +**Example setting the default value** (0): +``` +[State] +ForkUpgradeBatchNumber=0 +``` + +### 20.7. `State.ForkUpgradeNewForkId` + +**Type:** : `integer` + +**Default:** `0` + +**Description:** New fork id to be used for batches greaters than ForkUpgradeBatchNumber (fork upgrade) + +**Example setting the default value** (0): +``` +[State] +ForkUpgradeNewForkId=0 +``` + +### 20.8. `[State.DB]` + +**Type:** : `object` +**Description:** Configuration of the state database connection + +| Property | Pattern | Type | Deprecated | Definition | Title/Description | +| ----------------------------------- | ------- | ------- | ---------- | ---------- | ---------------------------------------------------------- | +| - [Name](#State_DB_Name ) | No | string | No | - | Database name | +| - [User](#State_DB_User ) | No | string | No | - | Database User name | +| - [Password](#State_DB_Password ) | No | string | No | - | Database Password of the user | +| - [Host](#State_DB_Host ) | No | string | No | - | Host address of database | +| - [Port](#State_DB_Port ) | No | string | No | - | Port Number of database | +| - [EnableLog](#State_DB_EnableLog ) | No | boolean | No | - | EnableLog | +| - [MaxConns](#State_DB_MaxConns ) | No | integer | No | - | MaxConns is the maximum number of connections in the pool. | + +#### 20.8.1. `State.DB.Name` + +**Type:** : `string` + +**Default:** `"state_db"` + +**Description:** Database name + +**Example setting the default value** ("state_db"): +``` +[State.DB] +Name="state_db" +``` + +#### 20.8.2. `State.DB.User` + +**Type:** : `string` + +**Default:** `"state_user"` + +**Description:** Database User name + +**Example setting the default value** ("state_user"): +``` +[State.DB] +User="state_user" +``` + +#### 20.8.3. `State.DB.Password` + +**Type:** : `string` + +**Default:** `"state_password"` + +**Description:** Database Password of the user + +**Example setting the default value** ("state_password"): +``` +[State.DB] +Password="state_password" +``` + +#### 20.8.4. `State.DB.Host` + +**Type:** : `string` + +**Default:** `"zkevm-state-db"` + +**Description:** Host address of database + +**Example setting the default value** ("zkevm-state-db"): +``` +[State.DB] +Host="zkevm-state-db" +``` + +#### 20.8.5. `State.DB.Port` + +**Type:** : `string` + +**Default:** `"5432"` + +**Description:** Port Number of database + +**Example setting the default value** ("5432"): +``` +[State.DB] +Port="5432" +``` + +#### 20.8.6. `State.DB.EnableLog` + +**Type:** : `boolean` + +**Default:** `false` + +**Description:** EnableLog + +**Example setting the default value** (false): +``` +[State.DB] +EnableLog=false +``` + +#### 20.8.7. `State.DB.MaxConns` + +**Type:** : `integer` + +**Default:** `200` + +**Description:** MaxConns is the maximum number of connections in the pool. + +**Example setting the default value** (200): +``` +[State.DB] +MaxConns=200 +``` + +### 20.9. `[State.Batch]` + +**Type:** : `object` +**Description:** Configuration for the batch constraints + +| Property | Pattern | Type | Deprecated | Definition | Title/Description | +| -------------------------------------------------- | ------- | ------ | ---------- | ---------- | ----------------- | +| - [Constraints](#State_Batch_Constraints ) | No | object | No | - | - | +| - [ResourceWeights](#State_Batch_ResourceWeights ) | No | object | No | - | - | + +#### 20.9.1. `[State.Batch.Constraints]` + +**Type:** : `object` -#### 21.1.1. `Batch.Constraints.MaxTxsPerBatch` +| Property | Pattern | Type | Deprecated | Definition | Title/Description | +| ------------------------------------------------------------------------ | ------- | ------- | ---------- | ---------- | ----------------- | +| - [MaxTxsPerBatch](#State_Batch_Constraints_MaxTxsPerBatch ) | No | integer | No | - | - | +| - [MaxBatchBytesSize](#State_Batch_Constraints_MaxBatchBytesSize ) | No | integer | No | - | - | +| - [MaxCumulativeGasUsed](#State_Batch_Constraints_MaxCumulativeGasUsed ) | No | integer | No | - | - | +| - [MaxKeccakHashes](#State_Batch_Constraints_MaxKeccakHashes ) | No | integer | No | - | - | +| - [MaxPoseidonHashes](#State_Batch_Constraints_MaxPoseidonHashes ) | No | integer | No | - | - | +| - [MaxPoseidonPaddings](#State_Batch_Constraints_MaxPoseidonPaddings ) | No | integer | No | - | - | +| - [MaxMemAligns](#State_Batch_Constraints_MaxMemAligns ) | No | integer | No | - | - | +| - [MaxArithmetics](#State_Batch_Constraints_MaxArithmetics ) | No | integer | No | - | - | +| - [MaxBinaries](#State_Batch_Constraints_MaxBinaries ) | No | integer | No | - | - | +| - [MaxSteps](#State_Batch_Constraints_MaxSteps ) | No | integer | No | - | - | + +##### 20.9.1.1. `State.Batch.Constraints.MaxTxsPerBatch` **Type:** : `integer` @@ -2835,11 +2992,11 @@ MaxConns=200 **Example setting the default value** (300): ``` -[Batch.Constraints] +[State.Batch.Constraints] MaxTxsPerBatch=300 ``` -#### 21.1.2. `Batch.Constraints.MaxBatchBytesSize` +##### 20.9.1.2. `State.Batch.Constraints.MaxBatchBytesSize` **Type:** : `integer` @@ -2847,11 +3004,11 @@ MaxTxsPerBatch=300 **Example setting the default value** (120000): ``` -[Batch.Constraints] +[State.Batch.Constraints] MaxBatchBytesSize=120000 ``` -#### 21.1.3. `Batch.Constraints.MaxCumulativeGasUsed` +##### 20.9.1.3. `State.Batch.Constraints.MaxCumulativeGasUsed` **Type:** : `integer` @@ -2859,11 +3016,11 @@ MaxBatchBytesSize=120000 **Example setting the default value** (30000000): ``` -[Batch.Constraints] +[State.Batch.Constraints] MaxCumulativeGasUsed=30000000 ``` -#### 21.1.4. `Batch.Constraints.MaxKeccakHashes` +##### 20.9.1.4. `State.Batch.Constraints.MaxKeccakHashes` **Type:** : `integer` @@ -2871,11 +3028,11 @@ MaxCumulativeGasUsed=30000000 **Example setting the default value** (2145): ``` -[Batch.Constraints] +[State.Batch.Constraints] MaxKeccakHashes=2145 ``` -#### 21.1.5. `Batch.Constraints.MaxPoseidonHashes` +##### 20.9.1.5. `State.Batch.Constraints.MaxPoseidonHashes` **Type:** : `integer` @@ -2883,11 +3040,11 @@ MaxKeccakHashes=2145 **Example setting the default value** (252357): ``` -[Batch.Constraints] +[State.Batch.Constraints] MaxPoseidonHashes=252357 ``` -#### 21.1.6. `Batch.Constraints.MaxPoseidonPaddings` +##### 20.9.1.6. `State.Batch.Constraints.MaxPoseidonPaddings` **Type:** : `integer` @@ -2895,11 +3052,11 @@ MaxPoseidonHashes=252357 **Example setting the default value** (135191): ``` -[Batch.Constraints] +[State.Batch.Constraints] MaxPoseidonPaddings=135191 ``` -#### 21.1.7. `Batch.Constraints.MaxMemAligns` +##### 20.9.1.7. `State.Batch.Constraints.MaxMemAligns` **Type:** : `integer` @@ -2907,11 +3064,11 @@ MaxPoseidonPaddings=135191 **Example setting the default value** (236585): ``` -[Batch.Constraints] +[State.Batch.Constraints] MaxMemAligns=236585 ``` -#### 21.1.8. `Batch.Constraints.MaxArithmetics` +##### 20.9.1.8. `State.Batch.Constraints.MaxArithmetics` **Type:** : `integer` @@ -2919,11 +3076,11 @@ MaxMemAligns=236585 **Example setting the default value** (236585): ``` -[Batch.Constraints] +[State.Batch.Constraints] MaxArithmetics=236585 ``` -#### 21.1.9. `Batch.Constraints.MaxBinaries` +##### 20.9.1.9. `State.Batch.Constraints.MaxBinaries` **Type:** : `integer` @@ -2931,11 +3088,11 @@ MaxArithmetics=236585 **Example setting the default value** (473170): ``` -[Batch.Constraints] +[State.Batch.Constraints] MaxBinaries=473170 ``` -#### 21.1.10. `Batch.Constraints.MaxSteps` +##### 20.9.1.10. `State.Batch.Constraints.MaxSteps` **Type:** : `integer` @@ -2943,27 +3100,27 @@ MaxBinaries=473170 **Example setting the default value** (7570538): ``` -[Batch.Constraints] +[State.Batch.Constraints] MaxSteps=7570538 ``` -### 21.2. `[Batch.ResourceWeights]` +#### 20.9.2. `[State.Batch.ResourceWeights]` **Type:** : `object` -| Property | Pattern | Type | Deprecated | Definition | Title/Description | -| ---------------------------------------------------------------------------- | ------- | ------- | ---------- | ---------- | ----------------- | -| - [WeightBatchBytesSize](#Batch_ResourceWeights_WeightBatchBytesSize ) | No | integer | No | - | - | -| - [WeightCumulativeGasUsed](#Batch_ResourceWeights_WeightCumulativeGasUsed ) | No | integer | No | - | - | -| - [WeightKeccakHashes](#Batch_ResourceWeights_WeightKeccakHashes ) | No | integer | No | - | - | -| - [WeightPoseidonHashes](#Batch_ResourceWeights_WeightPoseidonHashes ) | No | integer | No | - | - | -| - [WeightPoseidonPaddings](#Batch_ResourceWeights_WeightPoseidonPaddings ) | No | integer | No | - | - | -| - [WeightMemAligns](#Batch_ResourceWeights_WeightMemAligns ) | No | integer | No | - | - | -| - [WeightArithmetics](#Batch_ResourceWeights_WeightArithmetics ) | No | integer | No | - | - | -| - [WeightBinaries](#Batch_ResourceWeights_WeightBinaries ) | No | integer | No | - | - | -| - [WeightSteps](#Batch_ResourceWeights_WeightSteps ) | No | integer | No | - | - | +| Property | Pattern | Type | Deprecated | Definition | Title/Description | +| ---------------------------------------------------------------------------------- | ------- | ------- | ---------- | ---------- | ----------------- | +| - [WeightBatchBytesSize](#State_Batch_ResourceWeights_WeightBatchBytesSize ) | No | integer | No | - | - | +| - [WeightCumulativeGasUsed](#State_Batch_ResourceWeights_WeightCumulativeGasUsed ) | No | integer | No | - | - | +| - [WeightKeccakHashes](#State_Batch_ResourceWeights_WeightKeccakHashes ) | No | integer | No | - | - | +| - [WeightPoseidonHashes](#State_Batch_ResourceWeights_WeightPoseidonHashes ) | No | integer | No | - | - | +| - [WeightPoseidonPaddings](#State_Batch_ResourceWeights_WeightPoseidonPaddings ) | No | integer | No | - | - | +| - [WeightMemAligns](#State_Batch_ResourceWeights_WeightMemAligns ) | No | integer | No | - | - | +| - [WeightArithmetics](#State_Batch_ResourceWeights_WeightArithmetics ) | No | integer | No | - | - | +| - [WeightBinaries](#State_Batch_ResourceWeights_WeightBinaries ) | No | integer | No | - | - | +| - [WeightSteps](#State_Batch_ResourceWeights_WeightSteps ) | No | integer | No | - | - | -#### 21.2.1. `Batch.ResourceWeights.WeightBatchBytesSize` +##### 20.9.2.1. `State.Batch.ResourceWeights.WeightBatchBytesSize` **Type:** : `integer` @@ -2971,11 +3128,11 @@ MaxSteps=7570538 **Example setting the default value** (1): ``` -[Batch.ResourceWeights] +[State.Batch.ResourceWeights] WeightBatchBytesSize=1 ``` -#### 21.2.2. `Batch.ResourceWeights.WeightCumulativeGasUsed` +##### 20.9.2.2. `State.Batch.ResourceWeights.WeightCumulativeGasUsed` **Type:** : `integer` @@ -2983,11 +3140,11 @@ WeightBatchBytesSize=1 **Example setting the default value** (1): ``` -[Batch.ResourceWeights] +[State.Batch.ResourceWeights] WeightCumulativeGasUsed=1 ``` -#### 21.2.3. `Batch.ResourceWeights.WeightKeccakHashes` +##### 20.9.2.3. `State.Batch.ResourceWeights.WeightKeccakHashes` **Type:** : `integer` @@ -2995,11 +3152,11 @@ WeightCumulativeGasUsed=1 **Example setting the default value** (1): ``` -[Batch.ResourceWeights] +[State.Batch.ResourceWeights] WeightKeccakHashes=1 ``` -#### 21.2.4. `Batch.ResourceWeights.WeightPoseidonHashes` +##### 20.9.2.4. `State.Batch.ResourceWeights.WeightPoseidonHashes` **Type:** : `integer` @@ -3007,11 +3164,11 @@ WeightKeccakHashes=1 **Example setting the default value** (1): ``` -[Batch.ResourceWeights] +[State.Batch.ResourceWeights] WeightPoseidonHashes=1 ``` -#### 21.2.5. `Batch.ResourceWeights.WeightPoseidonPaddings` +##### 20.9.2.5. `State.Batch.ResourceWeights.WeightPoseidonPaddings` **Type:** : `integer` @@ -3019,11 +3176,11 @@ WeightPoseidonHashes=1 **Example setting the default value** (1): ``` -[Batch.ResourceWeights] +[State.Batch.ResourceWeights] WeightPoseidonPaddings=1 ``` -#### 21.2.6. `Batch.ResourceWeights.WeightMemAligns` +##### 20.9.2.6. `State.Batch.ResourceWeights.WeightMemAligns` **Type:** : `integer` @@ -3031,11 +3188,11 @@ WeightPoseidonPaddings=1 **Example setting the default value** (1): ``` -[Batch.ResourceWeights] +[State.Batch.ResourceWeights] WeightMemAligns=1 ``` -#### 21.2.7. `Batch.ResourceWeights.WeightArithmetics` +##### 20.9.2.7. `State.Batch.ResourceWeights.WeightArithmetics` **Type:** : `integer` @@ -3043,11 +3200,11 @@ WeightMemAligns=1 **Example setting the default value** (1): ``` -[Batch.ResourceWeights] +[State.Batch.ResourceWeights] WeightArithmetics=1 ``` -#### 21.2.8. `Batch.ResourceWeights.WeightBinaries` +##### 20.9.2.8. `State.Batch.ResourceWeights.WeightBinaries` **Type:** : `integer` @@ -3055,11 +3212,11 @@ WeightArithmetics=1 **Example setting the default value** (1): ``` -[Batch.ResourceWeights] +[State.Batch.ResourceWeights] WeightBinaries=1 ``` -#### 21.2.9. `Batch.ResourceWeights.WeightSteps` +##### 20.9.2.9. `State.Batch.ResourceWeights.WeightSteps` **Type:** : `integer` @@ -3067,7 +3224,7 @@ WeightBinaries=1 **Example setting the default value** (1): ``` -[Batch.ResourceWeights] +[State.Batch.ResourceWeights] WeightSteps=1 ``` diff --git a/docs/config-file/node-config-schema.json b/docs/config-file/node-config-schema.json index a52aaadb1a..3f78e635a5 100644 --- a/docs/config-file/node-config-schema.json +++ b/docs/config-file/node-config-schema.json @@ -984,48 +984,6 @@ "type": "object", "description": "Configuration of the merkle tree client service. Not use in the node, only for testing" }, - "StateDB": { - "properties": { - "Name": { - "type": "string", - "description": "Database name", - "default": "state_db" - }, - "User": { - "type": "string", - "description": "Database User name", - "default": "state_user" - }, - "Password": { - "type": "string", - "description": "Database Password of the user", - "default": "state_password" - }, - "Host": { - "type": "string", - "description": "Host address of database", - "default": "zkevm-state-db" - }, - "Port": { - "type": "string", - "description": "Port Number of database", - "default": "5432" - }, - "EnableLog": { - "type": "boolean", - "description": "EnableLog", - "default": false - }, - "MaxConns": { - "type": "integer", - "description": "MaxConns is the maximum number of connections in the pool.", - "default": 200 - } - }, - "additionalProperties": false, - "type": "object", - "description": "Configuration of the state database connection" - }, "Metrics": { "properties": { "Host": { @@ -1154,100 +1112,207 @@ "type": "object", "description": "Configuration of the hash database connection" }, - "Batch": { + "State": { "properties": { - "Constraints": { - "properties": { - "MaxTxsPerBatch": { - "type": "integer", - "default": 300 - }, - "MaxBatchBytesSize": { - "type": "integer", - "default": 120000 - }, - "MaxCumulativeGasUsed": { - "type": "integer", - "default": 30000000 + "MaxCumulativeGasUsed": { + "type": "integer", + "description": "MaxCumulativeGasUsed is the max gas allowed per batch", + "default": 0 + }, + "ChainID": { + "type": "integer", + "description": "ChainID is the L2 ChainID provided by the Network Config", + "default": 0 + }, + "ForkIDIntervals": { + "items": { + "properties": { + "FromBatchNumber": { + "type": "integer" + }, + "ToBatchNumber": { + "type": "integer" + }, + "ForkId": { + "type": "integer" + }, + "Version": { + "type": "string" + } }, - "MaxKeccakHashes": { - "type": "integer", - "default": 2145 + "additionalProperties": false, + "type": "object", + "description": "ForkIDInterval is a fork id interval" + }, + "type": "array", + "description": "ForkIdIntervals is the list of fork id intervals" + }, + "MaxResourceExhaustedAttempts": { + "type": "integer", + "description": "MaxResourceExhaustedAttempts is the max number of attempts to make a transaction succeed because of resource exhaustion", + "default": 0 + }, + "WaitOnResourceExhaustion": { + "type": "string", + "title": "Duration", + "description": "WaitOnResourceExhaustion is the time to wait before retrying a transaction because of resource exhaustion", + "default": "0s", + "examples": [ + "1m", + "300ms" + ] + }, + "ForkUpgradeBatchNumber": { + "type": "integer", + "description": "Batch number from which there is a forkid change (fork upgrade)", + "default": 0 + }, + "ForkUpgradeNewForkId": { + "type": "integer", + "description": "New fork id to be used for batches greaters than ForkUpgradeBatchNumber (fork upgrade)", + "default": 0 + }, + "DB": { + "properties": { + "Name": { + "type": "string", + "description": "Database name", + "default": "state_db" }, - "MaxPoseidonHashes": { - "type": "integer", - "default": 252357 + "User": { + "type": "string", + "description": "Database User name", + "default": "state_user" }, - "MaxPoseidonPaddings": { - "type": "integer", - "default": 135191 + "Password": { + "type": "string", + "description": "Database Password of the user", + "default": "state_password" }, - "MaxMemAligns": { - "type": "integer", - "default": 236585 + "Host": { + "type": "string", + "description": "Host address of database", + "default": "zkevm-state-db" }, - "MaxArithmetics": { - "type": "integer", - "default": 236585 + "Port": { + "type": "string", + "description": "Port Number of database", + "default": "5432" }, - "MaxBinaries": { - "type": "integer", - "default": 473170 + "EnableLog": { + "type": "boolean", + "description": "EnableLog", + "default": false }, - "MaxSteps": { + "MaxConns": { "type": "integer", - "default": 7570538 + "description": "MaxConns is the maximum number of connections in the pool.", + "default": 200 } }, "additionalProperties": false, - "type": "object" + "type": "object", + "description": "Configuration of the state database connection" }, - "ResourceWeights": { + "Batch": { "properties": { - "WeightBatchBytesSize": { - "type": "integer", - "default": 1 - }, - "WeightCumulativeGasUsed": { - "type": "integer", - "default": 1 - }, - "WeightKeccakHashes": { - "type": "integer", - "default": 1 - }, - "WeightPoseidonHashes": { - "type": "integer", - "default": 1 - }, - "WeightPoseidonPaddings": { - "type": "integer", - "default": 1 - }, - "WeightMemAligns": { - "type": "integer", - "default": 1 - }, - "WeightArithmetics": { - "type": "integer", - "default": 1 - }, - "WeightBinaries": { - "type": "integer", - "default": 1 + "Constraints": { + "properties": { + "MaxTxsPerBatch": { + "type": "integer", + "default": 300 + }, + "MaxBatchBytesSize": { + "type": "integer", + "default": 120000 + }, + "MaxCumulativeGasUsed": { + "type": "integer", + "default": 30000000 + }, + "MaxKeccakHashes": { + "type": "integer", + "default": 2145 + }, + "MaxPoseidonHashes": { + "type": "integer", + "default": 252357 + }, + "MaxPoseidonPaddings": { + "type": "integer", + "default": 135191 + }, + "MaxMemAligns": { + "type": "integer", + "default": 236585 + }, + "MaxArithmetics": { + "type": "integer", + "default": 236585 + }, + "MaxBinaries": { + "type": "integer", + "default": 473170 + }, + "MaxSteps": { + "type": "integer", + "default": 7570538 + } + }, + "additionalProperties": false, + "type": "object" }, - "WeightSteps": { - "type": "integer", - "default": 1 + "ResourceWeights": { + "properties": { + "WeightBatchBytesSize": { + "type": "integer", + "default": 1 + }, + "WeightCumulativeGasUsed": { + "type": "integer", + "default": 1 + }, + "WeightKeccakHashes": { + "type": "integer", + "default": 1 + }, + "WeightPoseidonHashes": { + "type": "integer", + "default": 1 + }, + "WeightPoseidonPaddings": { + "type": "integer", + "default": 1 + }, + "WeightMemAligns": { + "type": "integer", + "default": 1 + }, + "WeightArithmetics": { + "type": "integer", + "default": 1 + }, + "WeightBinaries": { + "type": "integer", + "default": 1 + }, + "WeightSteps": { + "type": "integer", + "default": 1 + } + }, + "additionalProperties": false, + "type": "object" } }, "additionalProperties": false, - "type": "object" + "type": "object", + "description": "Configuration for the batch constraints" } }, "additionalProperties": false, "type": "object", - "description": "Configuration of the batch service" + "description": "Configuration of the state" } }, "additionalProperties": false, diff --git a/pool/config.go b/pool/config.go index d7fc598c45..ed7e22c401 100644 --- a/pool/config.go +++ b/pool/config.go @@ -3,7 +3,6 @@ package pool import ( "github.com/0xPolygonHermez/zkevm-node/config/types" "github.com/0xPolygonHermez/zkevm-node/db" - "github.com/0xPolygonHermez/zkevm-node/state" ) // Config is the pool configuration @@ -51,48 +50,3 @@ type EffectiveGasPrice struct { // MarginFactor is the margin factor percentage to be added to the L2 min gas price MarginFactor float64 `mapstructure:"MarginFactor"` } - -// BatchConfig represents the configuration of the batch constraints -type BatchConfig struct { - Constraints BatchConstraintsCfg `mapstructure:"Constraints"` - ResourceWeights BatchResourceWeights `mapstructure:"ResourceWeights"` -} - -// BatchConstraintsCfg represents the configuration of the batch constraints -type BatchConstraintsCfg struct { - MaxTxsPerBatch uint64 `mapstructure:"MaxTxsPerBatch"` - MaxBatchBytesSize uint64 `mapstructure:"MaxBatchBytesSize"` - MaxCumulativeGasUsed uint64 `mapstructure:"MaxCumulativeGasUsed"` - MaxKeccakHashes uint32 `mapstructure:"MaxKeccakHashes"` - MaxPoseidonHashes uint32 `mapstructure:"MaxPoseidonHashes"` - MaxPoseidonPaddings uint32 `mapstructure:"MaxPoseidonPaddings"` - MaxMemAligns uint32 `mapstructure:"MaxMemAligns"` - MaxArithmetics uint32 `mapstructure:"MaxArithmetics"` - MaxBinaries uint32 `mapstructure:"MaxBinaries"` - MaxSteps uint32 `mapstructure:"MaxSteps"` -} - -// IsWithinConstraints checks if the counters are within the batch constraints -func (c BatchConstraintsCfg) IsWithinConstraints(counters state.ZKCounters) bool { - return counters.CumulativeGasUsed <= c.MaxCumulativeGasUsed && - counters.UsedKeccakHashes <= c.MaxKeccakHashes && - counters.UsedPoseidonHashes <= c.MaxPoseidonHashes && - counters.UsedPoseidonPaddings <= c.MaxPoseidonPaddings && - counters.UsedMemAligns <= c.MaxMemAligns && - counters.UsedArithmetics <= c.MaxArithmetics && - counters.UsedBinaries <= c.MaxBinaries && - counters.UsedSteps <= c.MaxSteps -} - -// BatchResourceWeights represents the configuration of the batch resource weights -type BatchResourceWeights struct { - WeightBatchBytesSize int `mapstructure:"WeightBatchBytesSize"` - WeightCumulativeGasUsed int `mapstructure:"WeightCumulativeGasUsed"` - WeightKeccakHashes int `mapstructure:"WeightKeccakHashes"` - WeightPoseidonHashes int `mapstructure:"WeightPoseidonHashes"` - WeightPoseidonPaddings int `mapstructure:"WeightPoseidonPaddings"` - WeightMemAligns int `mapstructure:"WeightMemAligns"` - WeightArithmetics int `mapstructure:"WeightArithmetics"` - WeightBinaries int `mapstructure:"WeightBinaries"` - WeightSteps int `mapstructure:"WeightSteps"` -} diff --git a/pool/config_test.go b/pool/config_test.go index d73d694328..c37eb483fd 100644 --- a/pool/config_test.go +++ b/pool/config_test.go @@ -7,7 +7,7 @@ import ( ) func TestIsWithinConstraints(t *testing.T) { - cfg := BatchConstraintsCfg{ + cfg := state.BatchConstraintsCfg{ MaxCumulativeGasUsed: 500, MaxKeccakHashes: 100, MaxPoseidonHashes: 200, diff --git a/pool/pool.go b/pool/pool.go index b8718b9ade..2e3209c424 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -38,7 +38,7 @@ type Pool struct { state stateInterface chainID uint64 cfg Config - batchConstraintsCfg BatchConstraintsCfg + batchConstraintsCfg state.BatchConstraintsCfg blockedAddresses sync.Map minSuggestedGasPrice *big.Int minSuggestedGasPriceMux *sync.RWMutex @@ -64,7 +64,7 @@ type GasPrices struct { } // NewPool creates and initializes an instance of Pool -func NewPool(cfg Config, batchConstraintsCfg BatchConstraintsCfg, s storage, st stateInterface, chainID uint64, eventLog *event.EventLog) *Pool { +func NewPool(cfg Config, batchConstraintsCfg state.BatchConstraintsCfg, s storage, st stateInterface, chainID uint64, eventLog *event.EventLog) *Pool { startTimestamp := time.Now() p := &Pool{ cfg: cfg, diff --git a/pool/pool_test.go b/pool/pool_test.go index 7eadbed00d..dee3adf68b 100644 --- a/pool/pool_test.go +++ b/pool/pool_test.go @@ -70,7 +70,7 @@ var ( l1GasPrice = big.NewInt(1000000000000) gasLimit = uint64(21000) chainID = big.NewInt(1337) - bc = pool.BatchConstraintsCfg{ + bc = state.BatchConstraintsCfg{ MaxTxsPerBatch: 300, MaxBatchBytesSize: 120000, MaxCumulativeGasUsed: 30000000, @@ -1868,7 +1868,7 @@ func Test_AddTx_IPValidation(t *testing.T) { } } -func setupPool(t *testing.T, cfg pool.Config, constraintsCfg pool.BatchConstraintsCfg, s *pgpoolstorage.PostgresPoolStorage, st *state.State, chainID uint64, ctx context.Context, eventLog *event.EventLog) *pool.Pool { +func setupPool(t *testing.T, cfg pool.Config, constraintsCfg state.BatchConstraintsCfg, s *pgpoolstorage.PostgresPoolStorage, st *state.State, chainID uint64, ctx context.Context, eventLog *event.EventLog) *pool.Pool { p := pool.NewPool(cfg, constraintsCfg, s, st, chainID, eventLog) err := p.SetGasPrices(ctx, gasPrice.Uint64(), l1GasPrice.Uint64()) diff --git a/sequencer/addrqueue.go b/sequencer/addrqueue.go index c5a97c128c..a3aeb9f653 100644 --- a/sequencer/addrqueue.go +++ b/sequencer/addrqueue.go @@ -5,7 +5,6 @@ import ( "time" "github.com/0xPolygonHermez/zkevm-node/log" - "github.com/0xPolygonHermez/zkevm-node/pool" "github.com/0xPolygonHermez/zkevm-node/state" "github.com/0xPolygonHermez/zkevm-node/state/runtime" "github.com/ethereum/go-ethereum/common" @@ -187,7 +186,7 @@ func (a *addrQueue) updateCurrentNonceBalance(nonce *uint64, balance *big.Int) ( // UpdateTxZKCounters updates the ZKCounters for the given tx (txHash) // If the updated tx is the readyTx it returns a copy of the previous readyTx, nil otherwise -func (a *addrQueue) UpdateTxZKCounters(txHash common.Hash, counters state.ZKCounters, constraints batchConstraintsFloat64, weights pool.BatchResourceWeights) (newReadyTx, prevReadyTx *TxTracker) { +func (a *addrQueue) UpdateTxZKCounters(txHash common.Hash, counters state.ZKCounters, constraints batchConstraintsFloat64, weights state.BatchResourceWeights) (newReadyTx, prevReadyTx *TxTracker) { txHashStr := txHash.String() if (a.readyTx != nil) && (a.readyTx.HashStr == txHashStr) { diff --git a/sequencer/closingsignalsmanager_test.go b/sequencer/closingsignalsmanager_test.go index 8f805c292a..a6a374a84b 100644 --- a/sequencer/closingsignalsmanager_test.go +++ b/sequencer/closingsignalsmanager_test.go @@ -12,7 +12,6 @@ import ( "github.com/0xPolygonHermez/zkevm-node/log" "github.com/0xPolygonHermez/zkevm-node/merkletree" mtDBclientpb "github.com/0xPolygonHermez/zkevm-node/merkletree/pb" - "github.com/0xPolygonHermez/zkevm-node/pool" "github.com/0xPolygonHermez/zkevm-node/state" "github.com/0xPolygonHermez/zkevm-node/state/runtime/executor" "github.com/0xPolygonHermez/zkevm-node/test/dbutils" @@ -75,7 +74,7 @@ func setupTest(t *testing.T) { localStateTree := merkletree.NewStateTree(localMtDBServiceClient) localState = state.NewState(stateCfg, state.NewPostgresStorage(localStateDb), localExecutorClient, localStateTree, eventLog) - batchConstraints := pool.BatchConstraintsCfg{ + batchConstraints := state.BatchConstraintsCfg{ MaxTxsPerBatch: 300, MaxBatchBytesSize: 120000, MaxCumulativeGasUsed: 30000000, diff --git a/sequencer/dbmanager.go b/sequencer/dbmanager.go index 815f5a4892..1af2f80420 100644 --- a/sequencer/dbmanager.go +++ b/sequencer/dbmanager.go @@ -21,7 +21,7 @@ type dbManager struct { worker workerInterface l2ReorgCh chan L2ReorgEvent ctx context.Context - batchConstraints pool.BatchConstraintsCfg + batchConstraints state.BatchConstraintsCfg numberOfReorgs uint64 } @@ -41,7 +41,7 @@ type ClosingBatchParameters struct { EffectivePercentages []uint8 } -func newDBManager(ctx context.Context, config DBManagerCfg, txPool txPool, state stateInterface, worker *Worker, closingSignalCh ClosingSignalCh, batchConstraints pool.BatchConstraintsCfg) *dbManager { +func newDBManager(ctx context.Context, config DBManagerCfg, txPool txPool, state stateInterface, worker *Worker, closingSignalCh ClosingSignalCh, batchConstraints state.BatchConstraintsCfg) *dbManager { numberOfReorgs, err := state.CountReorgs(ctx, nil) if err != nil { log.Error("failed to get number of reorgs: %v", err) diff --git a/sequencer/dbmanager_test.go b/sequencer/dbmanager_test.go index 2b4b66558d..312305bd7a 100644 --- a/sequencer/dbmanager_test.go +++ b/sequencer/dbmanager_test.go @@ -13,7 +13,6 @@ import ( "github.com/0xPolygonHermez/zkevm-node/log" "github.com/0xPolygonHermez/zkevm-node/merkletree" mtDBclientpb "github.com/0xPolygonHermez/zkevm-node/merkletree/pb" - "github.com/0xPolygonHermez/zkevm-node/pool" "github.com/0xPolygonHermez/zkevm-node/state" "github.com/0xPolygonHermez/zkevm-node/state/runtime/executor" "github.com/0xPolygonHermez/zkevm-node/test/dbutils" @@ -74,7 +73,7 @@ func setupDBManager() { GERCh: make(chan common.Hash), L2ReorgCh: make(chan L2ReorgEvent), } - batchConstraints := pool.BatchConstraintsCfg{ + batchConstraints := state.BatchConstraintsCfg{ MaxTxsPerBatch: 300, MaxBatchBytesSize: 120000, MaxCumulativeGasUsed: 30000000, diff --git a/sequencer/finalizer.go b/sequencer/finalizer.go index d6df7226bb..3a00dcfcb4 100644 --- a/sequencer/finalizer.go +++ b/sequencer/finalizer.go @@ -42,7 +42,7 @@ type finalizer struct { dbManager dbManagerInterface executor stateInterface batch *WipBatch - batchConstraints pool.BatchConstraintsCfg + batchConstraints state.BatchConstraintsCfg processRequest state.ProcessRequest sharedResourcesMux *sync.RWMutex lastGERHash common.Hash @@ -111,7 +111,7 @@ func newFinalizer( sequencerAddr common.Address, isSynced func(ctx context.Context) bool, closingSignalCh ClosingSignalCh, - batchConstraints pool.BatchConstraintsCfg, + batchConstraints state.BatchConstraintsCfg, eventLog *event.EventLog, ) *finalizer { return &finalizer{ @@ -1246,7 +1246,7 @@ func (f *finalizer) getConstraintThresholdUint32(input uint32) uint32 { } // getUsedBatchResources returns the used resources in the batch -func getUsedBatchResources(constraints pool.BatchConstraintsCfg, remainingResources state.BatchResources) state.BatchResources { +func getUsedBatchResources(constraints state.BatchConstraintsCfg, remainingResources state.BatchResources) state.BatchResources { return state.BatchResources{ ZKCounters: state.ZKCounters{ CumulativeGasUsed: constraints.MaxCumulativeGasUsed - remainingResources.ZKCounters.CumulativeGasUsed, diff --git a/sequencer/finalizer_test.go b/sequencer/finalizer_test.go index dd2dcce454..0b55b52a86 100644 --- a/sequencer/finalizer_test.go +++ b/sequencer/finalizer_test.go @@ -33,7 +33,7 @@ var ( executorMock = new(StateMock) workerMock = new(WorkerMock) dbTxMock = new(DbTxMock) - bc = pool.BatchConstraintsCfg{ + bc = state.BatchConstraintsCfg{ MaxTxsPerBatch: 300, MaxBatchBytesSize: 120000, MaxCumulativeGasUsed: 30000000, diff --git a/sequencer/sequencer.go b/sequencer/sequencer.go index 20ed62045a..2d9dada0c1 100644 --- a/sequencer/sequencer.go +++ b/sequencer/sequencer.go @@ -18,7 +18,7 @@ import ( // Sequencer represents a sequencer type Sequencer struct { cfg Config - batchCfg pool.BatchConfig + batchCfg state.BatchConfig pool txPool state stateInterface @@ -42,7 +42,7 @@ type ClosingSignalCh struct { } // New init sequencer -func New(cfg Config, batchCfg pool.BatchConfig, txPool txPool, state stateInterface, etherman etherman, manager ethTxManager, eventLog *event.EventLog) (*Sequencer, error) { +func New(cfg Config, batchCfg state.BatchConfig, txPool txPool, state stateInterface, etherman etherman, manager ethTxManager, eventLog *event.EventLog) (*Sequencer, error) { addr, err := etherman.TrustedSequencer() if err != nil { return nil, fmt.Errorf("failed to get trusted sequencer address, err: %v", err) @@ -224,7 +224,7 @@ func (s *Sequencer) isSynced(ctx context.Context) bool { return true } -func getMaxRemainingResources(constraints pool.BatchConstraintsCfg) state.BatchResources { +func getMaxRemainingResources(constraints state.BatchConstraintsCfg) state.BatchResources { return state.BatchResources{ ZKCounters: state.ZKCounters{ CumulativeGasUsed: constraints.MaxCumulativeGasUsed, diff --git a/sequencer/txtracker.go b/sequencer/txtracker.go index 4870c3e8f3..2502bbebed 100644 --- a/sequencer/txtracker.go +++ b/sequencer/txtracker.go @@ -5,7 +5,6 @@ import ( "time" "github.com/0xPolygonHermez/zkevm-node/log" - "github.com/0xPolygonHermez/zkevm-node/pool" "github.com/0xPolygonHermez/zkevm-node/state" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" @@ -67,7 +66,7 @@ type batchConstraintsFloat64 struct { } // newTxTracker creates and inti a TxTracker -func newTxTracker(tx types.Transaction, counters state.ZKCounters, constraints batchConstraintsFloat64, weights pool.BatchResourceWeights, resourceCostMultiplier float64, ip string) (*TxTracker, error) { +func newTxTracker(tx types.Transaction, counters state.ZKCounters, constraints batchConstraintsFloat64, weights state.BatchResourceWeights, resourceCostMultiplier float64, ip string) (*TxTracker, error) { addr, err := state.GetSender(tx) if err != nil { return nil, err @@ -112,14 +111,13 @@ func newTxTracker(tx types.Transaction, counters state.ZKCounters, constraints b } // updateZKCounters updates the counters of the tx and recalculates the tx efficiency - -func (tx *TxTracker) updateZKCounters(counters state.ZKCounters, constraints batchConstraintsFloat64, weights pool.BatchResourceWeights) { +func (tx *TxTracker) updateZKCounters(counters state.ZKCounters, constraints batchConstraintsFloat64, weights state.BatchResourceWeights) { tx.BatchResources.ZKCounters = counters tx.calculateEfficiency(constraints, weights) } // calculateEfficiency calculates the tx efficiency -func (tx *TxTracker) calculateEfficiency(constraints batchConstraintsFloat64, weights pool.BatchResourceWeights) { +func (tx *TxTracker) calculateEfficiency(constraints batchConstraintsFloat64, weights state.BatchResourceWeights) { totalWeight := float64(weights.WeightArithmetics + weights.WeightBatchBytesSize + weights.WeightBinaries + weights.WeightCumulativeGasUsed + weights.WeightKeccakHashes + weights.WeightMemAligns + weights.WeightPoseidonHashes + weights.WeightPoseidonPaddings + weights.WeightSteps) @@ -152,7 +150,7 @@ func (tx *TxTracker) calculateEfficiency(constraints batchConstraintsFloat64, we } // calculateWeightMultipliers calculates the weight multipliers for each resource -func calculateWeightMultipliers(weights pool.BatchResourceWeights, totalWeight float64) batchResourceWeightMultipliers { +func calculateWeightMultipliers(weights state.BatchResourceWeights, totalWeight float64) batchResourceWeightMultipliers { return batchResourceWeightMultipliers{ cumulativeGasUsed: float64(weights.WeightCumulativeGasUsed) / totalWeight, arithmetics: float64(weights.WeightArithmetics) / totalWeight, diff --git a/sequencer/txtracker_test.go b/sequencer/txtracker_test.go index 313a26ef74..f996ac6094 100644 --- a/sequencer/txtracker_test.go +++ b/sequencer/txtracker_test.go @@ -5,7 +5,6 @@ import ( "math/big" "testing" - "github.com/0xPolygonHermez/zkevm-node/pool" "github.com/0xPolygonHermez/zkevm-node/state" "github.com/stretchr/testify/assert" ) @@ -20,7 +19,7 @@ type efficiencyCalcTestCase struct { func TestTxTrackerEfficiencyCalculation(t *testing.T) { // Init ZKEVM resourceCostWeight values - rcWeigth := pool.BatchResourceWeights{ + rcWeigth := state.BatchResourceWeights{ WeightBatchBytesSize: 2, WeightCumulativeGasUsed: 1, WeightArithmetics: 1, diff --git a/sequencer/worker.go b/sequencer/worker.go index 9ec10d560c..8d3a2bcb07 100644 --- a/sequencer/worker.go +++ b/sequencer/worker.go @@ -22,13 +22,13 @@ type Worker struct { efficiencyList *efficiencyList workerMutex sync.Mutex state stateInterface - batchConstraints pool.BatchConstraintsCfg + batchConstraints state.BatchConstraintsCfg batchConstraintsFloat64 batchConstraintsFloat64 - batchResourceWeights pool.BatchResourceWeights + batchResourceWeights state.BatchResourceWeights } // NewWorker creates an init a worker -func NewWorker(cfg WorkerCfg, state stateInterface, constraints pool.BatchConstraintsCfg, weights pool.BatchResourceWeights) *Worker { +func NewWorker(cfg WorkerCfg, state stateInterface, constraints state.BatchConstraintsCfg, weights state.BatchResourceWeights) *Worker { w := Worker{ cfg: cfg, pool: make(map[string]*addrQueue), @@ -334,7 +334,7 @@ func (w *Worker) HandleL2Reorg(txHashes []common.Hash) { } // convertBatchConstraintsToFloat64 converts the batch Constraints to float64 -func convertBatchConstraintsToFloat64(constraints pool.BatchConstraintsCfg) batchConstraintsFloat64 { +func convertBatchConstraintsToFloat64(constraints state.BatchConstraintsCfg) batchConstraintsFloat64 { return batchConstraintsFloat64{ maxTxsPerBatch: float64(constraints.MaxTxsPerBatch), maxBatchBytesSize: float64(constraints.MaxBatchBytesSize), diff --git a/sequencer/worker_test.go b/sequencer/worker_test.go index b81b136f40..5f78bcc188 100644 --- a/sequencer/worker_test.go +++ b/sequencer/worker_test.go @@ -21,7 +21,7 @@ var ( ResourceCostMultiplier: 1000, } // Init ZKEVM resourceCostWeight values - rcWeight = pool.BatchResourceWeights{ + rcWeight = state.BatchResourceWeights{ WeightBatchBytesSize: 2, WeightCumulativeGasUsed: 1, WeightArithmetics: 1, @@ -34,7 +34,7 @@ var ( } // Init ZKEVM resourceCostMax values - rcMax = pool.BatchConstraintsCfg{ + rcMax = state.BatchConstraintsCfg{ MaxCumulativeGasUsed: 10, MaxArithmetics: 10, MaxBinaries: 10, @@ -330,7 +330,7 @@ func TestWorkerGetBestTx(t *testing.T) { } } -func initWorker(stateMock *StateMock, rcMax pool.BatchConstraintsCfg, rcWeigth pool.BatchResourceWeights) *Worker { +func initWorker(stateMock *StateMock, rcMax state.BatchConstraintsCfg, rcWeigth state.BatchResourceWeights) *Worker { worker := NewWorker(workerCfg, stateMock, rcMax, rcWeigth) return worker } diff --git a/state/config.go b/state/config.go index 62cae08c93..0b54bf69a6 100644 --- a/state/config.go +++ b/state/config.go @@ -1,6 +1,9 @@ package state -import "github.com/0xPolygonHermez/zkevm-node/config/types" +import ( + "github.com/0xPolygonHermez/zkevm-node/config/types" + "github.com/0xPolygonHermez/zkevm-node/db" +) // Config is state config type Config struct { @@ -24,4 +27,55 @@ type Config struct { // New fork id to be used for batches greaters than ForkUpgradeBatchNumber (fork upgrade) ForkUpgradeNewForkId uint64 + + // Configuration of the state database connection + DB db.Config `mapstructure:"DB"` + + // Configuration for the batch constraints + Batch BatchConfig `mapstructure:"Batch"` +} + +// BatchConfig represents the configuration of the batch constraints +type BatchConfig struct { + Constraints BatchConstraintsCfg `mapstructure:"Constraints"` + ResourceWeights BatchResourceWeights `mapstructure:"ResourceWeights"` +} + +// BatchConstraintsCfg represents the configuration of the batch constraints +type BatchConstraintsCfg struct { + MaxTxsPerBatch uint64 `mapstructure:"MaxTxsPerBatch"` + MaxBatchBytesSize uint64 `mapstructure:"MaxBatchBytesSize"` + MaxCumulativeGasUsed uint64 `mapstructure:"MaxCumulativeGasUsed"` + MaxKeccakHashes uint32 `mapstructure:"MaxKeccakHashes"` + MaxPoseidonHashes uint32 `mapstructure:"MaxPoseidonHashes"` + MaxPoseidonPaddings uint32 `mapstructure:"MaxPoseidonPaddings"` + MaxMemAligns uint32 `mapstructure:"MaxMemAligns"` + MaxArithmetics uint32 `mapstructure:"MaxArithmetics"` + MaxBinaries uint32 `mapstructure:"MaxBinaries"` + MaxSteps uint32 `mapstructure:"MaxSteps"` +} + +// IsWithinConstraints checks if the counters are within the batch constraints +func (c BatchConstraintsCfg) IsWithinConstraints(counters ZKCounters) bool { + return counters.CumulativeGasUsed <= c.MaxCumulativeGasUsed && + counters.UsedKeccakHashes <= c.MaxKeccakHashes && + counters.UsedPoseidonHashes <= c.MaxPoseidonHashes && + counters.UsedPoseidonPaddings <= c.MaxPoseidonPaddings && + counters.UsedMemAligns <= c.MaxMemAligns && + counters.UsedArithmetics <= c.MaxArithmetics && + counters.UsedBinaries <= c.MaxBinaries && + counters.UsedSteps <= c.MaxSteps +} + +// BatchResourceWeights represents the configuration of the batch resource weights +type BatchResourceWeights struct { + WeightBatchBytesSize int `mapstructure:"WeightBatchBytesSize"` + WeightCumulativeGasUsed int `mapstructure:"WeightCumulativeGasUsed"` + WeightKeccakHashes int `mapstructure:"WeightKeccakHashes"` + WeightPoseidonHashes int `mapstructure:"WeightPoseidonHashes"` + WeightPoseidonPaddings int `mapstructure:"WeightPoseidonPaddings"` + WeightMemAligns int `mapstructure:"WeightMemAligns"` + WeightArithmetics int `mapstructure:"WeightArithmetics"` + WeightBinaries int `mapstructure:"WeightBinaries"` + WeightSteps int `mapstructure:"WeightSteps"` } diff --git a/test/benchmarks/sequencer/common/setup/setup.go b/test/benchmarks/sequencer/common/setup/setup.go index 28bcb96201..a36c4021d0 100644 --- a/test/benchmarks/sequencer/common/setup/setup.go +++ b/test/benchmarks/sequencer/common/setup/setup.go @@ -12,6 +12,7 @@ import ( "github.com/0xPolygonHermez/zkevm-node/log" "github.com/0xPolygonHermez/zkevm-node/pool" "github.com/0xPolygonHermez/zkevm-node/pool/pgpoolstorage" + "github.com/0xPolygonHermez/zkevm-node/state" "github.com/0xPolygonHermez/zkevm-node/test/benchmarks/sequencer/common/params" "github.com/0xPolygonHermez/zkevm-node/test/operations" "github.com/ethereum/go-ethereum/accounts/abi/bind" @@ -27,7 +28,7 @@ const ( ) var ( - bc = pool.BatchConstraintsCfg{ + bc = state.BatchConstraintsCfg{ MaxTxsPerBatch: 300, MaxBatchBytesSize: 120000, MaxCumulativeGasUsed: 30000000, diff --git a/test/config/debug.node.config.toml b/test/config/debug.node.config.toml index ab71c2740f..58ff8a9095 100644 --- a/test/config/debug.node.config.toml +++ b/test/config/debug.node.config.toml @@ -5,14 +5,15 @@ Environment = "development" # "production" or "development" Level = "debug" Outputs = ["stderr"] -[StateDB] -User = "state_user" -Password = "state_password" -Name = "state_db" -Host = "localhost" -Port = "5432" -EnableLog = true -MaxConns = 10 +[State] + [State.DB] + User = "state_user" + Password = "state_password" + Name = "state_db" + Host = "localhost" + Port = "5432" + EnableLog = true + MaxConns = 10 [Pool] FreeClaimGasLimit = 1500000 diff --git a/test/config/test.node.config.toml b/test/config/test.node.config.toml index 3db4f5d84f..1b8a48ea27 100644 --- a/test/config/test.node.config.toml +++ b/test/config/test.node.config.toml @@ -5,15 +5,6 @@ Environment = "development" # "production" or "development" Level = "debug" Outputs = ["stderr"] -[StateDB] -User = "state_user" -Password = "state_password" -Name = "state_db" -Host = "zkevm-state-db" -Port = "5432" -EnableLog = false -MaxConns = 200 - [Pool] FreeClaimGasLimit = 1500000 IntervalToRefreshBlockedAddresses = "5m" diff --git a/test/e2e/uniswap_test.go b/test/e2e/uniswap_test.go index 9ea1980b00..4abc6febfe 100644 --- a/test/e2e/uniswap_test.go +++ b/test/e2e/uniswap_test.go @@ -36,7 +36,7 @@ func TestUniswap(t *testing.T) { opsCfg := &operations.Config{ State: &state.Config{ - MaxCumulativeGasUsed: cfg.Batch.Constraints.MaxCumulativeGasUsed, + MaxCumulativeGasUsed: cfg.State.Batch.Constraints.MaxCumulativeGasUsed, }, SequenceSender: &operations.SequenceSenderConfig{ SenderAddress: "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", From 82589a1a78dea6a080a5d181f73dd7ccc9c04ad2 Mon Sep 17 00:00:00 2001 From: Nikolay Nedkov Date: Tue, 1 Aug 2023 18:08:35 +0300 Subject: [PATCH 5/6] fixing state_db env vars Signed-off-by: Nikolay Nedkov --- config/config.go | 2 +- config/default.go | 1 + config/environments/mainnet/example.env | 2 +- .../mainnet/public.node.config.toml | 9 ------- config/environments/testnet/example.env | 2 +- .../testnet/testnet.node.config.toml | 9 ------- docker-compose.yml | 2 +- docs/components/aggregator.md | 2 +- docs/components/rpc.md | 2 +- docs/components/sequencer.md | 2 +- docs/components/synchronizer.md | 2 +- docs/config-file/node-config-doc.html | 4 +-- docs/config-file/node-config-doc.md | 8 +++--- docs/config-file/node-config-schema.json | 4 +-- docs/configuration.md | 2 +- state/config.go | 2 +- test/docker-compose.yml | 26 +++++++++---------- 17 files changed, 32 insertions(+), 49 deletions(-) diff --git a/config/config.go b/config/config.go index b0baee6cfd..c6ee7ab2c1 100644 --- a/config/config.go +++ b/config/config.go @@ -115,7 +115,7 @@ type Config struct { EventLog event.Config // Configuration of the hash database connection HashDB db.Config - // Configuration of the state + // State service configuration State state.Config } diff --git a/config/default.go b/config/default.go index 1cc539fd62..07daf9942b 100644 --- a/config/default.go +++ b/config/default.go @@ -12,6 +12,7 @@ Level = "info" Outputs = ["stderr"] [State] +AccountQueue = 64 [State.DB] User = "state_user" Password = "state_password" diff --git a/config/environments/mainnet/example.env b/config/environments/mainnet/example.env index 95557a442c..05b13e5e79 100644 --- a/config/environments/mainnet/example.env +++ b/config/environments/mainnet/example.env @@ -2,7 +2,7 @@ ZKEVM_NETWORK = "mainnet" # URL of a JSON RPC for Ethereum mainnet ZKEVM_NODE_ETHERMAN_URL = "http://your.L1node.url" # PATH WHERE THE STATEDB POSTGRES CONTAINER WILL STORE PERSISTENT DATA -ZKEVM_NODE_STATEDB_DATA_DIR = "/path/to/persistent/data/statedb" +ZKEVM_NODE_STATE_DB_DATA_DIR = "/path/to/persistent/data/statedb" # PATH WHERE THE POOLDB POSTGRES CONTAINER WILL STORE PERSISTENT DATA ZKEVM_NODE_POOLDB_DATA_DIR = "/path/to/persistent/data/pooldb" # OPTIONAL, UNCOMENT IF YOU WANT TO DO ADVANCED CONFIG diff --git a/config/environments/mainnet/public.node.config.toml b/config/environments/mainnet/public.node.config.toml index 145a433ecb..ab12e064ac 100644 --- a/config/environments/mainnet/public.node.config.toml +++ b/config/environments/mainnet/public.node.config.toml @@ -3,15 +3,6 @@ Environment = "development" # "production" or "development" Level = "info" Outputs = ["stderr"] -[StateDB] -User = "state_user" -Password = "state_password" -Name = "state_db" -Host = "zkevm-state-db" -Port = "5432" -EnableLog = false -MaxConns = 200 - [Pool] MaxTxBytesSize=100132 MaxTxDataBytesSize=100000 diff --git a/config/environments/testnet/example.env b/config/environments/testnet/example.env index bf0db2e035..fe13decc82 100644 --- a/config/environments/testnet/example.env +++ b/config/environments/testnet/example.env @@ -2,7 +2,7 @@ ZKEVM_NETWORK = "testnet" # URL of a JSON RPC for Goerli ZKEVM_NODE_ETHERMAN_URL = "http://your.L1node.url" # PATH WHERE THE STATEDB POSTGRES CONTAINER WILL STORE PERSISTENT DATA -ZKEVM_NODE_STATEDB_DATA_DIR = "/path/to/persistent/data/statedb" +ZKEVM_NODE_STATE_DB_DATA_DIR = "/path/to/persistent/data/statedb" # PATH WHERE THE POOLDB POSTGRES CONTAINER WILL STORE PERSISTENT DATA ZKEVM_NODE_POOLDB_DATA_DIR = "/path/to/persistent/data/pooldb" # OPTIONAL, UNCOMENT IF YOU WANT TO DO ADVANCED CONFIG diff --git a/config/environments/testnet/testnet.node.config.toml b/config/environments/testnet/testnet.node.config.toml index 4566baa5f6..25c2028b4a 100644 --- a/config/environments/testnet/testnet.node.config.toml +++ b/config/environments/testnet/testnet.node.config.toml @@ -3,15 +3,6 @@ Environment = "development" # "production" or "development" Level = "info" Outputs = ["stderr"] -[StateDB] -User = "state_user" -Password = "state_password" -Name = "state_db" -Host = "zkevm-state-db" -Port = "5432" -EnableLog = false -MaxConns = 200 - [Pool] IntervalToRefreshBlockedAddresses = "5m" IntervalToRefreshGasPrices = "5s" diff --git a/docker-compose.yml b/docker-compose.yml index 27a64e0780..53de98f64b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -69,7 +69,7 @@ services: - 5432:5432 volumes: - ./db/scripts/init_prover_db.sql:/docker-entrypoint-initdb.d/init.sql - - ${ZKEVM_NODE_STATEDB_DATA_DIR}:/var/lib/postgresql/data + - ${ZKEVM_NODE_STATE_DB_DATA_DIR}:/var/lib/postgresql/data - ${ZKEVM_ADVANCED_CONFIG_DIR:-./config/environments/testnet}/postgresql.conf:/etc/postgresql.conf environment: - POSTGRES_USER=state_user diff --git a/docs/components/aggregator.md b/docs/components/aggregator.md index a1c314a22e..35b4031c49 100644 --- a/docs/components/aggregator.md +++ b/docs/components/aggregator.md @@ -38,7 +38,7 @@ The container alone needs some parameters configured, access to certain configur - `your genesis.json file`: /app/genesis.json - environment: Env variables that supersede the config file - - `ZKEVM_NODE_STATEDB_HOST`: Name of StateDB Database Host + - `ZKEVM_NODE_STATE_DB_HOST`: Name of StateDB Database Host ### The Account Keystore file: diff --git a/docs/components/rpc.md b/docs/components/rpc.md index 3725ed0436..60e2f2aac7 100644 --- a/docs/components/rpc.md +++ b/docs/components/rpc.md @@ -37,7 +37,7 @@ The container alone needs some parameters configured, access to certain configur - `8545:8545`: RPC Port - `9091:9091`: Needed if Prometheus metrics are enabled - environment: Env variables that supersede the config file - - `ZKEVM_NODE_STATEDB_HOST`: Name of StateDB Database Host + - `ZKEVM_NODE_STATE_DB_HOST`: Name of StateDB Database Host - `ZKEVM_NODE_POOL_HOST`: Name of PoolDB Database Host - `ZKEVM_NODE_RPC_DB_HOST`: Name of RPCDB Database Host - volumes: diff --git a/docs/components/sequencer.md b/docs/components/sequencer.md index 3490494de7..4a434a591c 100644 --- a/docs/components/sequencer.md +++ b/docs/components/sequencer.md @@ -28,7 +28,7 @@ The container alone needs some parameters configured, access to certain configur - environment: Env variables that supersede the config file - `ZKEVM_NODE_POOLDB_HOST`: Name of PoolDB Database Host - - `ZKEVM_NODE_STATEDB_HOST`: Name of StateDB Database Host + - `ZKEVM_NODE_STATE_DB_HOST`: Name of StateDB Database Host - volumes: - `your Account Keystore file`: /pk/keystore (note, this `/pk/keystore` value is the default path that's written in the Public Configuration files on this repo, meant to expedite deployments, it can be superseded via an env flag `ZKEVM_NODE_ETHERMAN_PRIVATEKEYPATH`.) - `your config.toml file`: /app/config.toml diff --git a/docs/components/synchronizer.md b/docs/components/synchronizer.md index 0e79e52a37..1f289c208b 100644 --- a/docs/components/synchronizer.md +++ b/docs/components/synchronizer.md @@ -31,7 +31,7 @@ To orchestrate multiple deployments of the different ZKEVM Node components, a `d The container alone needs some parameters configured, access to certain configuration files and the appropriate ports exposed. - environment: Env variables that supersede the config file - - `ZKEVM_NODE_STATEDB_HOST`: Name of StateDB Database Host + - `ZKEVM_NODE_STATE_DB_HOST`: Name of StateDB Database Host - volumes: - `your config.toml file`: /app/config.toml - `your genesis.json file`: /app/genesis.json diff --git a/docs/config-file/node-config-doc.html b/docs/config-file/node-config-doc.html index 19d533c1f1..56611eca3f 100644 --- a/docs/config-file/node-config-doc.html +++ b/docs/config-file/node-config-doc.html @@ -64,6 +64,6 @@
"300ms"
 

Default: 0.15Type: number

Configuration of the executor service
Default: "zkevm-prover:50071"Type: string

Default: 3Type: integer

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


Default: "1s"Type: string

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


Examples:

"1m"
 
"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.


Configuration of the state
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"
+

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)


Configuration of the state database connection
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
\ 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
\ 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 34de4c172f..3a7e15f485 100644 --- a/docs/config-file/node-config-doc.md +++ b/docs/config-file/node-config-doc.md @@ -26,7 +26,7 @@ | - [Metrics](#Metrics ) | No | object | No | - | Configuration of the metrics service, basically is where is going to publish the metrics | | - [EventLog](#EventLog ) | No | object | No | - | Configuration of the event database connection | | - [HashDB](#HashDB ) | No | object | No | - | Configuration of the hash database connection | -| - [State](#State ) | No | object | No | - | Configuration of the state | +| - [State](#State ) | No | object | No | - | State service configuration | ## 1. `IsTrustedSequencer` @@ -2689,7 +2689,7 @@ MaxConns=200 ## 20. `[State]` **Type:** : `object` -**Description:** Configuration of the state +**Description:** State service configuration | Property | Pattern | Type | Deprecated | Definition | Title/Description | | ---------------------------------------------------------------------- | ------- | --------------- | ---------- | ---------- | ----------------------------------------------------------------------------------------------------------------------- | @@ -2700,7 +2700,7 @@ MaxConns=200 | - [WaitOnResourceExhaustion](#State_WaitOnResourceExhaustion ) | No | string | No | - | Duration | | - [ForkUpgradeBatchNumber](#State_ForkUpgradeBatchNumber ) | No | integer | No | - | Batch number from which there is a forkid change (fork upgrade) | | - [ForkUpgradeNewForkId](#State_ForkUpgradeNewForkId ) | No | integer | No | - | New fork id to be used for batches greaters than ForkUpgradeBatchNumber (fork upgrade) | -| - [DB](#State_DB ) | No | object | No | - | Configuration of the state database connection | +| - [DB](#State_DB ) | No | object | No | - | DB is the database configuration | | - [Batch](#State_Batch ) | No | object | No | - | Configuration for the batch constraints | ### 20.1. `State.MaxCumulativeGasUsed` @@ -2847,7 +2847,7 @@ ForkUpgradeNewForkId=0 ### 20.8. `[State.DB]` **Type:** : `object` -**Description:** Configuration of the state database connection +**Description:** DB is the database configuration | Property | Pattern | Type | Deprecated | Definition | Title/Description | | ----------------------------------- | ------- | ------- | ---------- | ---------- | ---------------------------------------------------------- | diff --git a/docs/config-file/node-config-schema.json b/docs/config-file/node-config-schema.json index 3f78e635a5..f8d5ea15c4 100644 --- a/docs/config-file/node-config-schema.json +++ b/docs/config-file/node-config-schema.json @@ -1212,7 +1212,7 @@ }, "additionalProperties": false, "type": "object", - "description": "Configuration of the state database connection" + "description": "DB is the database configuration" }, "Batch": { "properties": { @@ -1312,7 +1312,7 @@ }, "additionalProperties": false, "type": "object", - "description": "Configuration of the state" + "description": "State service configuration" } }, "additionalProperties": false, diff --git a/docs/configuration.md b/docs/configuration.md index f38df7dfb1..e472bb9fd9 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -21,7 +21,7 @@ This file is used for trusted and for permisionless nodes. In the case of permis `ZKEVM_NODE_`[
`_`]*` For example: -`ZKEVM_NODE_STATEDB_HOST="localhost"` override value of section `[StateDB]` key `Host` +`ZKEVM_NODE_STATE_DB_HOST="localhost"` override value of section `[StateDB]` key `Host` ### Network Genesis Config This file is a [JSON](https://en.wikipedia.org/wiki/JSON) formatted file. diff --git a/state/config.go b/state/config.go index 0b54bf69a6..12a6d7ba71 100644 --- a/state/config.go +++ b/state/config.go @@ -28,7 +28,7 @@ type Config struct { // New fork id to be used for batches greaters than ForkUpgradeBatchNumber (fork upgrade) ForkUpgradeNewForkId uint64 - // Configuration of the state database connection + // DB is the database configuration DB db.Config `mapstructure:"DB"` // Configuration for the batch constraints diff --git a/test/docker-compose.yml b/test/docker-compose.yml index 3abb33ed0c..83eded5bc5 100644 --- a/test/docker-compose.yml +++ b/test/docker-compose.yml @@ -53,7 +53,7 @@ services: - 9092:9091 # needed if metrics enabled - 6060:6060 environment: - - ZKEVM_NODE_STATEDB_HOST=zkevm-state-db + - ZKEVM_NODE_STATE_DB_HOST=zkevm-state-db - ZKEVM_NODE_POOL_DB_HOST=zkevm-pool-db volumes: - ./config/test.node.config.toml:/app/config.toml @@ -67,7 +67,7 @@ services: container_name: zkevm-sequence-sender image: zkevm-node environment: - - ZKEVM_NODE_STATEDB_HOST=zkevm-state-db + - ZKEVM_NODE_STATE_DB_HOST=zkevm-state-db - ZKEVM_NODE_POOL_DB_HOST=zkevm-pool-db - ZKEVM_NODE_SEQUENCER_SENDER_ADDRESS=0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266 volumes: @@ -87,7 +87,7 @@ services: - 8133:8133 # needed if WebSockets enabled - 9091:9091 # needed if metrics enabled environment: - - ZKEVM_NODE_STATEDB_HOST=zkevm-state-db + - ZKEVM_NODE_STATE_DB_HOST=zkevm-state-db - ZKEVM_NODE_POOL_DB_HOST=zkevm-pool-db volumes: - ./config/test.node.config.toml:/app/config.toml @@ -104,7 +104,7 @@ services: - 50081:50081 - 9093:9091 # needed if metrics enabled environment: - - ZKEVM_NODE_STATEDB_HOST=zkevm-state-db + - ZKEVM_NODE_STATE_DB_HOST=zkevm-state-db - ZKEVM_NODE_AGGREGATOR_SENDER_ADDRESS=0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266 volumes: - ./config/test.node.config.toml:/app/config.toml @@ -120,7 +120,7 @@ services: ports: - 9095:9091 # needed if metrics enabled environment: - - ZKEVM_NODE_STATEDB_HOST=zkevm-state-db + - ZKEVM_NODE_STATE_DB_HOST=zkevm-state-db volumes: - ./config/test.node.config.toml:/app/config.toml - ./config/test.genesis.config.json:/app/genesis.json @@ -135,7 +135,7 @@ services: ports: - 9094:9091 # needed if metrics enabled environment: - - ZKEVM_NODE_STATEDB_HOST=zkevm-state-db + - ZKEVM_NODE_STATE_DB_HOST=zkevm-state-db volumes: - ./sequencer.keystore:/pk/sequencer.keystore - ./aggregator.keystore:/pk/aggregator.keystore @@ -285,7 +285,7 @@ services: - 8124:8124 - 8134:8134 # needed if WebSockets enabled environment: - - ZKEVM_NODE_STATEDB_HOST=zkevm-state-db + - ZKEVM_NODE_STATE_DB_HOST=zkevm-state-db - ZKEVM_NODE_POOL_DB_HOST=zkevm-pool-db - ZKEVM_NODE_RPC_PORT=8124 - ZKEVM_NODE_RPC_WEBSOCKETS_PORT=8134 @@ -364,7 +364,7 @@ services: container_name: zkevm-approve image: zkevm-node environment: - - ZKEVM_NODE_STATEDB_HOST=zkevm-state-db + - ZKEVM_NODE_STATE_DB_HOST=zkevm-state-db volumes: - ./sequencer.keystore:/pk/keystore - ./config/test.node.config.toml:/app/config.toml @@ -403,10 +403,10 @@ services: - 8125:8125 environment: - ZKEVM_NODE_ISTRUSTEDSEQUENCER=false - - ZKEVM_NODE_STATEDB_USER=test_user - - ZKEVM_NODE_STATEDB_PASSWORD=test_password - - ZKEVM_NODE_STATEDB_NAME=state_db - - ZKEVM_NODE_STATEDB_HOST=zkevm-permissionless-db + - ZKEVM_NODE_STATE_DB_USER=test_user + - ZKEVM_NODE_STATE_DB_PASSWORD=test_password + - ZKEVM_NODE_STATE_DB_NAME=state_db + - ZKEVM_NODE_STATE_DB_HOST=zkevm-permissionless-db - ZKEVM_NODE_POOL_DB_USER=test_user - ZKEVM_NODE_POOL_DB_PASSWORD=test_password - ZKEVM_NODE_POOL_DB_NAME=pool_db @@ -454,7 +454,7 @@ services: stdin_open: true tty: true environment: - - ZKEVM_NODE_STATEDB_HOST=zkevm-state-db + - ZKEVM_NODE_STATE_DB_HOST=zkevm-state-db - ZKEVM_NODE_POOL_DB_HOST=zkevm-pool-db volumes: - ./config/test.node.config.toml:/app/config.toml From 4166e3fa3a11a4d5803330ad2fd3e7a14097d293 Mon Sep 17 00:00:00 2001 From: Nikolay Nedkov Date: Wed, 16 Aug 2023 12:31:48 +0300 Subject: [PATCH 6/6] bugfix: adding back the 'State' section in test.node.config.toml to fix env vars resolving for 'permisionless-node'. Signed-off-by: Nikolay Nedkov --- test/config/test.node.config.toml | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test/config/test.node.config.toml b/test/config/test.node.config.toml index 1b8a48ea27..933866b31c 100644 --- a/test/config/test.node.config.toml +++ b/test/config/test.node.config.toml @@ -143,3 +143,36 @@ Host = "zkevm-state-db" Port = "5432" EnableLog = false MaxConns = 200 + +[State] + AccountQueue = 64 + [State.DB] + User = "state_user" + Password = "state_password" + Name = "state_db" + Host = "zkevm-state-db" + Port = "5432" + EnableLog = false + MaxConns = 200 + [State.Batch] + [State.Batch.Constraints] + MaxTxsPerBatch = 300 + MaxBatchBytesSize = 120000 + MaxCumulativeGasUsed = 30000000 + MaxKeccakHashes = 2145 + MaxPoseidonHashes = 252357 + MaxPoseidonPaddings = 135191 + MaxMemAligns = 236585 + MaxArithmetics = 236585 + MaxBinaries = 473170 + MaxSteps = 7570538 + [State.Batch.ResourceWeights] + WeightBatchBytesSize = 1 + WeightCumulativeGasUsed = 1 + WeightKeccakHashes = 1 + WeightPoseidonHashes = 1 + WeightPoseidonPaddings = 1 + WeightMemAligns = 1 + WeightArithmetics = 1 + WeightBinaries = 1 + WeightSteps = 1 \ No newline at end of file