Skip to content

Commit

Permalink
improve: moving BatchConfig to state package
Browse files Browse the repository at this point in the history
Signed-off-by: Nikolay Nedkov <[email protected]>
  • Loading branch information
Psykepro committed Jul 27, 2023
1 parent 53eefdd commit 7d1b672
Show file tree
Hide file tree
Showing 31 changed files with 727 additions and 518 deletions.
2 changes: 1 addition & 1 deletion cmd/dumpstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
14 changes: 7 additions & 7 deletions cmd/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
26 changes: 13 additions & 13 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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)
}
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions cmd/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down
52 changes: 26 additions & 26 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
{
Expand Down Expand Up @@ -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,
},
}
Expand Down
Loading

0 comments on commit 7d1b672

Please sign in to comment.