diff --git a/cmd/dumpstate.go b/cmd/dumpstate.go index 6fc3b3156c..350048a3eb 100644 --- a/cmd/dumpstate.go +++ b/cmd/dumpstate.go @@ -113,7 +113,7 @@ func dumpState(ctx *cli.Context) error { if err != nil { return err } - stateDB := state.NewPostgresStorage(stateSqlDB) + stateDB := state.NewPostgresStorage(state.Config{}, stateSqlDB) dump := dumpedState{ Description: description, diff --git a/cmd/run.go b/cmd/run.go index 66556ad6cd..683ba4bccc 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -464,7 +464,7 @@ func waitSignal(cancelFuncs []context.CancelFunc) { } func newState(ctx context.Context, c *config.Config, l2ChainID uint64, forkIDIntervals []state.ForkIDInterval, sqlDB *pgxpool.Pool, eventLog *event.EventLog, needsExecutor, needsStateTree bool) *state.State { - stateDb := state.NewPostgresStorage(sqlDB) + stateDb := state.NewPostgresStorage(c.State, sqlDB) // Executor var executorClient executor.ExecutorServiceClient @@ -487,6 +487,8 @@ func newState(ctx context.Context, c *config.Config, l2ChainID uint64, forkIDInt WaitOnResourceExhaustion: c.Executor.WaitOnResourceExhaustion, ForkUpgradeBatchNumber: c.ForkUpgradeBatchNumber, ForkUpgradeNewForkId: c.ForkUpgradeNewForkId, + MaxLogsCount: c.RPC.MaxLogsCount, + MaxLogsBlockRange: c.RPC.MaxLogsBlockRange, } st := state.NewState(stateCfg, stateDb, executorClient, stateTree, eventLog) diff --git a/config/config_test.go b/config/config_test.go index d3c5e5c11c..90f2373734 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -341,6 +341,14 @@ func Test_Defaults(t *testing.T) { path: "RPC.BatchRequestsLimit", expectedValue: uint(20), }, + { + path: "RPC.MaxLogsCount", + expectedValue: uint64(10000), + }, + { + path: "RPC.MaxLogsBlockRange", + expectedValue: uint64(10000), + }, { path: "RPC.WebSockets.Enabled", expectedValue: true, diff --git a/config/default.go b/config/default.go index 008195cea7..c1b54cd0d8 100644 --- a/config/default.go +++ b/config/default.go @@ -77,6 +77,8 @@ SequencerNodeURI = "" EnableL2SuggestedGasPricePolling = true BatchRequestsEnabled = false BatchRequestsLimit = 20 +MaxLogsCount = 10000 +MaxLogsBlockRange = 10000 [RPC.WebSockets] Enabled = true Host = "0.0.0.0" diff --git a/db/migrations/state/0011.sql b/db/migrations/state/0011.sql new file mode 100644 index 0000000000..ed40c997f5 --- /dev/null +++ b/db/migrations/state/0011.sql @@ -0,0 +1,17 @@ +-- +migrate Up +CREATE INDEX IF NOT EXISTS l2block_created_at_idx ON state.l2block (created_at); + +CREATE INDEX IF NOT EXISTS log_log_index_idx ON state.log (log_index); +CREATE INDEX IF NOT EXISTS log_topic0_idx ON state.log (topic0); +CREATE INDEX IF NOT EXISTS log_topic1_idx ON state.log (topic1); +CREATE INDEX IF NOT EXISTS log_topic2_idx ON state.log (topic2); +CREATE INDEX IF NOT EXISTS log_topic3_idx ON state.log (topic3); + +-- +migrate Down +DROP INDEX IF EXISTS state.l2block_created_at_idx; + +DROP INDEX IF EXISTS state.log_log_index_idx; +DROP INDEX IF EXISTS state.log_topic0_idx; +DROP INDEX IF EXISTS state.log_topic1_idx; +DROP INDEX IF EXISTS state.log_topic2_idx; +DROP INDEX IF EXISTS state.log_topic3_idx; \ No newline at end of file diff --git a/db/migrations/state/0011_test.go b/db/migrations/state/0011_test.go new file mode 100644 index 0000000000..2ec3072c1d --- /dev/null +++ b/db/migrations/state/0011_test.go @@ -0,0 +1,59 @@ +package migrations_test + +import ( + "database/sql" + "testing" + + "github.com/stretchr/testify/assert" +) + +// this migration changes length of the token name +type migrationTest0011 struct{} + +func (m migrationTest0011) InsertData(db *sql.DB) error { + return nil +} + +func (m migrationTest0011) RunAssertsAfterMigrationUp(t *testing.T, db *sql.DB) { + indexes := []string{ + "l2block_created_at_idx", + "log_log_index_idx", + "log_topic0_idx", + "log_topic1_idx", + "log_topic2_idx", + "log_topic3_idx", + } + // Check indexes adding + for _, idx := range indexes { + // getIndex + const getIndex = `SELECT count(*) FROM pg_indexes WHERE indexname = $1;` + row := db.QueryRow(getIndex, idx) + var result int + assert.NoError(t, row.Scan(&result)) + assert.Equal(t, 1, result) + } +} + +func (m migrationTest0011) RunAssertsAfterMigrationDown(t *testing.T, db *sql.DB) { + indexes := []string{ + "l2block_created_at_idx", + "log_log_index_idx", + "log_topic0_idx", + "log_topic1_idx", + "log_topic2_idx", + "log_topic3_idx", + } + // Check indexes removing + for _, idx := range indexes { + // getIndex + const getIndex = `SELECT count(*) FROM pg_indexes WHERE indexname = $1;` + row := db.QueryRow(getIndex, idx) + var result int + assert.NoError(t, row.Scan(&result)) + assert.Equal(t, 0, result) + } +} + +func TestMigration0011(t *testing.T) { + runMigrationTest(t, 11, migrationTest0011{}) +} diff --git a/docs/config-file/node-config-doc.html b/docs/config-file/node-config-doc.html index d16ff3b38e..f402dad247 100644 --- a/docs/config-file/node-config-doc.html +++ b/docs/config-file/node-config-doc.html @@ -14,7 +14,7 @@
"300ms"
WriteTimeout is the HTTP server write timeout
check net/http.server.WriteTimeout
"1m"
"300ms"
-
MaxRequestsPerIPAndSecond defines how much requests a single IP can
send within a single second
SequencerNodeURI is used allow Non-Sequencer nodes
to relay transactions to the Sequencer node
MaxCumulativeGasUsed is the max gas allowed per batch
Enabled defines if the WebSocket requests are enabled or disabled
Host defines the network adapter that will be used to serve the WS requests
Port defines the port to serve the endpoints via WS
ReadLimit defines the maximum size of a message read from the client (in bytes)
EnableL2SuggestedGasPricePolling enables polling of the L2 gas price to block tx in the RPC with lower gas price.
BatchRequestsEnabled defines if the Batch requests are enabled or disabled
BatchRequestsLimit defines the limit of requests that can be incorporated into each batch request
L2Coinbase defines which address is going to receive the fees
Must contain a minimum of 20
items
Must contain a maximum of 20
items
SyncInterval is the delay interval between reading new rollup information
"1m"
+
MaxRequestsPerIPAndSecond defines how much requests a single IP can
send within a single second
SequencerNodeURI is used allow Non-Sequencer nodes
to relay transactions to the Sequencer node
MaxCumulativeGasUsed is the max gas allowed per batch
Enabled defines if the WebSocket requests are enabled or disabled
Host defines the network adapter that will be used to serve the WS requests
Port defines the port to serve the endpoints via WS
ReadLimit defines the maximum size of a message read from the client (in bytes)
EnableL2SuggestedGasPricePolling enables polling of the L2 gas price to block tx in the RPC with lower gas price.
BatchRequestsEnabled defines if the Batch requests are enabled or disabled
BatchRequestsLimit defines the limit of requests that can be incorporated into each batch request
L2Coinbase defines which address is going to receive the fees
Must contain a minimum of 20
items
Must contain a maximum of 20
items
MaxLogsCount is a configuration to set the max number of logs that can be returned
in a single call to the state, if zero it means no limit
MaxLogsBlockRange is a configuration to set the max range for block number when querying TXs
logs in a single call to the state, if zero it means no limit
SyncInterval is the delay interval between reading new rollup information
"1m"
"300ms"
SyncChunkSize is the number of blocks to sync on each chunk
TrustedSequencerURL is the rpc url to connect and sync the trusted state
L1ParallelSynchronization Use new L1 synchronization that do in parallel request to L1 and process the data
If false use the legacy sequential mode
NumberOfParallelOfEthereumClients Number of clients used to synchronize with L1
(if UseParallelModeForL1Synchronization is true)
CapacityOfBufferingRollupInfoFromL1 Size of the buffer used to store rollup information from L1, must be >= to NumberOfEthereumClientsToSync
sugested twice of NumberOfParallelOfEthereumClients
(if UseParallelModeForL1Synchronization is true)
TimeForCheckLastBlockOnL1Time is the time to wait to request the
last block to L1 to known if we need to retrieve more data.
This value only apply when the system is synchronized
"1m"
"300ms"
@@ -78,4 +78,4 @@
"300ms"
URI is the server URI.
Host is the address to bind the metrics server
Port is the port to bind the metrics server
Enabled is the flag to enable/disable the metrics server
ProfilingHost is the address to bind the profiling server
ProfilingPort is the port to bind the profiling server
ProfilingEnabled is the flag to enable/disable the profiling server
Database name
Database User name
Database Password of the user
Host address of database
Port Number of database
EnableLog
MaxConns is the maximum number of connections in the pool.
Database name
Database User name
Database Password of the user
Host address of database
Port Number of database
EnableLog
MaxConns is the maximum number of connections in the pool.
MaxCumulativeGasUsed is the max gas allowed per batch
ChainID is the L2 ChainID provided by the Network Config
ForkIdIntervals is the list of fork id intervals
MaxResourceExhaustedAttempts is the max number of attempts to make a transaction succeed because of resource exhaustion
WaitOnResourceExhaustion is the time to wait before retrying a transaction because of resource exhaustion
"1m"
"300ms"
-
Batch number from which there is a forkid change (fork upgrade)
New fork id to be used for batches greaters than ForkUpgradeBatchNumber (fork upgrade)
Database name
Database User name
Database Password of the user
Host address of database
Port Number of database
EnableLog
MaxConns is the maximum number of connections in the pool.