Skip to content

Commit

Permalink
improve: Add IP and ZKCounter Validation, Refactor Batch Configs
Browse files Browse the repository at this point in the history
Signed-off-by: Nikolay Nedkov <nikolai_nedkov@yahoo.com>
  • Loading branch information
Psykepro committed Jul 18, 2023
1 parent d9920f7 commit e60b3f4
Show file tree
Hide file tree
Showing 30 changed files with 665 additions and 389 deletions.
16 changes: 8 additions & 8 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,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)
Expand All @@ -185,7 +185,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)
Expand All @@ -197,7 +197,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
Expand All @@ -216,7 +216,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)
case ETHTXMANAGER:
Expand All @@ -236,7 +236,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)
}
Expand Down Expand Up @@ -386,7 +386,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)
}
Expand Down Expand Up @@ -483,13 +483,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
}

Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ type Config struct {
Metrics metrics.Config
EventLog event.Config
HashDB db.Config
Batch pool.BatchConfig
}

// Default parses the default configuration values.
Expand Down
153 changes: 77 additions & 76 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand Down Expand Up @@ -461,6 +385,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)
Expand Down
42 changes: 23 additions & 19 deletions config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,25 +77,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]
Expand Down Expand Up @@ -166,4 +147,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
`
42 changes: 23 additions & 19 deletions config/environments/local/local.node.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,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]
Expand Down Expand Up @@ -158,3 +139,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
Loading

0 comments on commit e60b3f4

Please sign in to comment.