Skip to content

Commit

Permalink
Refactor config value retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
matej committed Dec 12, 2023
1 parent d851a8b commit bff9c34
Show file tree
Hide file tree
Showing 2 changed files with 265 additions and 209 deletions.
229 changes: 129 additions & 100 deletions utils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,101 +102,105 @@ type Config struct {
AppName string
CommandName string

// user defined values by arguments
First uint64 // first block
Last uint64 // last block

AidaDb string // directory to profiling database containing substate, update, delete accounts data
ArchiveMaxQueryAge int // the maximum age for archive queries (in blocks)
ArchiveMode bool // enable archive mode
ArchiveQueryRate int // the queries per second send to the archive
ArchiveVariant string // selects the implementation variant of the archive
BalanceRange int64 // balance range for stochastic simulation/replay
BasicBlockProfiling bool // enable profiling of basic block
BlockLength uint64 // length of a block in number of transactions
CPUProfile string // pprof cpu profile output file name
CPUProfilePerInterval bool // a different CPU profile is taken per 100k block interval
Cache int // Cache for StateDb or Priming
CarmenSchema int // the current DB schema ID to use in Carmen
ChainID ChainID // Blockchain ID (mainnet: 250/testnet: 4002)
ChannelBufferSize int // set a buffer size for profiling channel
CompactDb bool // compact database after merging
ContinueOnFailure bool // continue validation when an error detected
ContractNumber int64 // number of contracts to create
DbComponent string // options for util-db info are 'all', 'substate', 'delete', 'update', 'state-hash'
DbImpl string // storage implementation
DbLogging string // set to true if all DB operations should be logged
DbTmp string // path to temporary database
DbVariant string // database variant
Debug bool // enable trace debug flag
DebugFrom uint64 // the first block to print trace debug
DeleteSourceDbs bool // delete source databases
DeletionDb string // directory of deleted account database
DiagnosticServer int64 // if not zero, the port used for hosting a HTTP server for performance diagnostics
ErrorLogging string // if defined, error logging to file is enabled
Genesis string // genesis file
IncludeStorage bool // represents a flag for contract storage inclusion in an operation
IsExistingStateDb bool // this is true if we are using an existing StateDb
KeepDb bool // set to true if db is kept after run
KeysNumber int64 // number of keys to generate
LogLevel string // level of the logging of the app action
MaxNumErrors int // maximum number of errors when ContinueOnFailure is enabled
MaxNumTransactions int // the maximum number of processed transactions
MemoryBreakdown bool // enable printing of memory breakdown
MemoryProfile string // capture the memory heap profile into the file
MicroProfiling bool // enable micro-profiling of EVM
NoHeartbeatLogging bool // disables heartbeat logging
NonceRange int // nonce range for stochastic simulation/replay
OnlySuccessful bool // only runs transactions that have been successful
OperaBinary string // path to opera binary
OperaDb string // path to opera database
Output string // output directory for aida-db patches or path to events.json file in stochastic generation
PathToStateDb string // Path to a working state-db directory
PrimeRandom bool // enable randomized priming
PrimeThreshold int // set account threshold before commit
Profile bool // enable micro profiling
ProfileBlocks bool // enables block profiler extension
ProfileDB string // profile db for parallel transaction execution
ProfileDepth int // 0 = Interval, 1 = Interval+Block, 2 = Interval+Block+Tx
ProfileEVMCall bool // enable profiling for EVM call
ProfileFile string // output file containing profiling result
ProfileInterval uint64 // interval of printing profile result
ProfileSqlite3 string // output profiling results to sqlite3 DB
ProfilingDbName string // set a database name for storing micro-profiling results
RandomSeed int64 // set random seed for stochastic testing
RpcRecordingFile string // path to source file with recorded RPC requests
ShadowDb bool // defines we want to open an existing db as shadow
ShadowImpl string // implementation of the shadow DB to use, empty if disabled
ShadowVariant string // database variant of the shadow DB to be used
SkipMetadata bool // skip metadata insert/getting into AidaDb
SkipPriming bool // skip priming of the state DB
SkipStateHashScrapping bool // if enabled, then state-hashes are not loaded from rpc
SnapshotDepth int // depth of snapshot history
SourceTableName string // represents the name of a source DB table
SrcDbReadonly bool // if false, make a copy the source statedb
StateDbSrc string // directory to load an existing State DB data
StateValidationMode ValidationMode // state validation mode
SubstateDb string // substate directory
SyncPeriodLength uint64 // length of a sync-period in number of blocks
TargetBlock uint64 // represents the ID of target block to be reached by state evolve process or in dump state
TargetDb string // represents the path of a target DB
TargetEpoch uint64 // represents the ID of target epoch to be reached by autogen patch generator
Trace bool // trace flag
TraceDirectory string // name of trace directory
TraceFile string // name of trace file
TrackProgress bool // enables track progress logging
TransactionLength uint64 // determines indirectly the length of a transaction
TrieRootHash string // represents a hash of a state trie root to be decoded
UpdateBufferSize uint64 // cache size in Bytes
UpdateDb string // update-set directory
UpdateOnFailure bool // if enabled and continue-on-failure is also enabled, this updates any error found in StateDb
UpdateType string // download datatype
Validate bool // validate validate aida-db
ValidateStateHashes bool // if this is true state hash validation is enabled in Executor
ValidateTxState bool // validate stateDB before and after transaction
ValuesNumber int64 // number of values to generate
VmImpl string // vm implementation (geth/lfvm)
Workers int // number of worker threads
WorldStateDb string // path to worldstate
// internal values
IsExistingStateDb bool // this is true if we are using an existing StateDb
PathToStateDb string // Path to a working state-db directory
SrcDbReadonly bool // if false, make a copy the source statedb
StateValidationMode ValidationMode // state validation mode

// user defined values by flags
AidaDb string // directory to profiling database containing substate, update, delete accounts data
ArchiveMaxQueryAge int // the maximum age for archive queries (in blocks)
ArchiveMode bool // enable archive mode
ArchiveQueryRate int // the queries per second send to the archive
ArchiveVariant string // selects the implementation variant of the archive
BalanceRange int64 // balance range for stochastic simulation/replay
BasicBlockProfiling bool // enable profiling of basic block
BlockLength uint64 // length of a block in number of transactions
Cache int // Cache for StateDb or Priming
CarmenSchema int // the current DB schema ID to use in Carmen
ChainID ChainID // Blockchain ID (mainnet: 250/testnet: 4002)
ChannelBufferSize int // set a buffer size for profiling channel
CompactDb bool // compact database after merging
ContinueOnFailure bool // continue validation when an error detected
ContractNumber int64 // number of contracts to create
CPUProfile string // pprof cpu profile output file name
CPUProfilePerInterval bool // a different CPU profile is taken per 100k block interval
DbComponent string // options for util-db info are 'all', 'substate', 'delete', 'update', 'state-hash'
DbImpl string // storage implementation
DbLogging string // set to true if all DB operations should be logged
DbTmp string // path to temporary database
DbVariant string // database variant
Debug bool // enable trace debug flag
DebugFrom uint64 // the first block to print trace debug
DeleteSourceDbs bool // delete source databases
DeletionDb string // directory of deleted account database
DiagnosticServer int64 // if not zero, the port used for hosting a HTTP server for performance diagnostics
ErrorLogging string // if defined, error logging to file is enabled
Genesis string // genesis file
IncludeStorage bool // represents a flag for contract storage inclusion in an operation
KeepDb bool // set to true if db is kept after run
KeysNumber int64 // number of keys to generate
LogLevel string // level of the logging of the app action
MaxNumErrors int // maximum number of errors when ContinueOnFailure is enabled
MaxNumTransactions int // the maximum number of processed transactions
MemoryBreakdown bool // enable printing of memory breakdown
MemoryProfile string // capture the memory heap profile into the file
MicroProfiling bool // enable micro-profiling of EVM
NoHeartbeatLogging bool // disables heartbeat logging
NonceRange int // nonce range for stochastic simulation/replay
OnlySuccessful bool // only runs transactions that have been successful
OperaBinary string // path to opera binary
OperaDb string // path to opera database
Output string // output directory for aida-db patches or path to events.json file in stochastic generation
PrimeRandom bool // enable randomized priming
PrimeThreshold int // set account threshold before commit
Profile bool // enable micro profiling
ProfileBlocks bool // enables block profiler extension
ProfileDB string // profile db for parallel transaction execution
ProfileDepth int // 0 = Interval, 1 = Interval+Block, 2 = Interval+Block+Tx
ProfileEVMCall bool // enable profiling for EVM call
ProfileFile string // output file containing profiling result
ProfileInterval uint64 // interval of printing profile result
ProfileSqlite3 string // output profiling results to sqlite3 DB
ProfilingDbName string // set a database name for storing micro-profiling results
RandomSeed int64 // set random seed for stochastic testing
RpcRecordingFile string // path to source file with recorded RPC requests
ShadowDb bool // defines we want to open an existing db as shadow
ShadowImpl string // implementation of the shadow DB to use, empty if disabled
ShadowVariant string // database variant of the shadow DB to be used
SkipMetadata bool // skip metadata insert/getting into AidaDb
SkipPriming bool // skip priming of the state DB
SkipStateHashScrapping bool // if enabled, then state-hashes are not loaded from rpc
SnapshotDepth int // depth of snapshot history
SourceTableName string // represents the name of a source DB table
StateDbSrc string // directory to load an existing State DB data
SubstateDb string // substate directory
SyncPeriodLength uint64 // length of a sync-period in number of blocks
TargetBlock uint64 // represents the ID of target block to be reached by state evolve process or in dump state
TargetDb string // represents the path of a target DB
TargetEpoch uint64 // represents the ID of target epoch to be reached by autogen patch generator
Trace bool // trace flag
TraceDirectory string // name of trace directory
TraceFile string // name of trace file
TrackProgress bool // enables track progress logging
TransactionLength uint64 // determines indirectly the length of a transaction
TrieRootHash string // represents a hash of a state trie root to be decoded
UpdateBufferSize uint64 // cache size in Bytes
UpdateDb string // update-set directory
UpdateOnFailure bool // if enabled and continue-on-failure is also enabled, this updates any error found in StateDb
UpdateType string // download datatype
Validate bool // validate validate aida-db
ValidateStateHashes bool // if this is true state hash validation is enabled in Executor
ValidateTxState bool // validate stateDB before and after transaction
ValuesNumber int64 // number of values to generate
VmImpl string // vm implementation (geth/lfvm)
Workers int // number of worker threads
WorldStateDb string // path to worldstate
}

type configContext struct {
Expand All @@ -218,7 +222,7 @@ func NewConfig(ctx *cli.Context, mode ArgumentMode) (*Config, error) {
var err error

// create config with user flag values, if not set default values are used
cfg := createConfigFromFlags(ctx)
cfg, specifiedFlags, err := createConfigFromFlags(ctx)

// create config context for sharing common arguments
cc := NewConfigContext(cfg)
Expand Down Expand Up @@ -249,7 +253,11 @@ func NewConfig(ctx *cli.Context, mode ArgumentMode) (*Config, error) {
return nil, fmt.Errorf("cannot adjust missing config values; %v", err)
}

cc.reportNewConfig()
err = cc.reportNewConfig(specifiedFlags)
if err != nil {
return nil, fmt.Errorf("cannot report new config; %v", err)

}

return cfg, nil
}
Expand Down Expand Up @@ -622,22 +630,41 @@ func OverwriteDbPathsByAidaDb(cfg *Config) {
}

// reportNewConfig logs out the state of config in current run
func (cc *configContext) reportNewConfig() {
func (cc *configContext) reportNewConfig(specifiedFlags map[string]bool) error {
cfg := cc.cfg
log := cc.log

log.Noticef("Run config:")
log.Infof("Block range: %v to %v", cfg.First, cfg.Last)

if cfg.MaxNumTransactions >= 0 {
log.Noticef("Transaction limit: %d", cfg.MaxNumTransactions)
}
log.Infof("Chain id: %v (record & run-vm only)", cfg.ChainID)
log.Infof("SyncPeriod length: %v", cfg.SyncPeriodLength)
log.Noticef("Used VM implementation: %v", cfg.VmImpl)
log.Infof("Aida DB directory: %v", cfg.AidaDb)
if specifiedFlags[ChainIDFlag.Name] {
log.Infof("Chain id: %v (record & run-vm only)", cfg.ChainID)
}

if specifiedFlags[SyncPeriodLengthFlag.Name] {
log.Infof("SyncPeriod length: %v", cfg.SyncPeriodLength)
}

if specifiedFlags[VmImplementation.Name] {
log.Noticef("Used VM implementation: %v", cfg.VmImpl)
}

if specifiedFlags[StateDbImplementationFlag.Name] {
log.Noticef("Used DB implementation: %v", cfg.DbImpl)
}

if specifiedFlags[AidaDbFlag.Name] {
log.Infof("Aida DB directory: %v", cfg.AidaDb)
}

// todo move to tx validator once finished
log.Infof("validate tx state: %v", cfg.ValidateTxState)
if specifiedFlags[ValidateTxStateFlag.Name] {
log.Infof("validate tx state: %v", cfg.ValidateTxState)
}

if cfg.Profile {
log.Infof("Profiling enabled - at depth: %d", cfg.ProfileDepth)
if cfg.ProfileFile != "" {
Expand All @@ -654,4 +681,6 @@ func (cc *configContext) reportNewConfig() {
if cfg.DbLogging != "" {
log.Warning("Db logging enabled, reducing Tx throughput")
}

return nil
}
Loading

0 comments on commit bff9c34

Please sign in to comment.