Skip to content
This repository has been archived by the owner on Jun 9, 2024. It is now read-only.

Refactor: break down read config from app opts parser #1453

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

kienn6034
Copy link
Contributor

@kienn6034 kienn6034 commented Jan 22, 2024

Refactor

Breakdown function readConfigFromAppOptsParser() into smaller functions

Summary by CodeRabbit

  • Refactor
    • Simplified the configuration reading process for better maintainability.
    • Enhanced readability of settings parsing for various system components.

Copy link

coderabbitai bot commented Jan 22, 2024

Walkthrough

The refactoring of the ReadConfigFromAppOpts function in the Cosmos project has led to a cleaner code structure. By extracting the detailed configuration parsing into a dedicated readConfigFromAppOptsParser function, the code is now more modular. This enhances the clarity of the configuration reading process for various components like Polaris Core and Node settings, making the codebase easier to understand and maintain.

Changes

File Path Change Summary
cosmos/config/config.go Refactored ReadConfigFromAppOpts by extracting parsing logic into readConfigFromAppOptsParser. Introduced separate functions for Polaris Core, Minter, Chain, GPO, LegacyPool, Node settings, and HTTP timeouts.

Poem

In the cosmos code, where logic weaves,
A rabbit hopped, refactoring leaves. 🍃
Now clearer paths, in config's lair,
For stars to align, with lesser care. ✨

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@kienn6034 kienn6034 changed the title Refactor: break down read config from app opts Refactor: break down read config from app opts parser Jan 22, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between c3cf22b and 6c19438.
Files selected for processing (1)
  • cosmos/config/config.go (3 hunks)
Additional comments: 7
cosmos/config/config.go (7)
  • 80-109: The refactoring of ReadConfigFromAppOpts into readConfigFromAppOptsParser and subsequent parsing functions appears to be well-structured and modular. Each configuration aspect is handled by a dedicated function, which should improve readability and maintainability.
  • 112-128: The readPolarisCoreSettings function is well-defined and encapsulates the parsing of Polaris Core settings. It correctly handles errors and returns early if any occur.
  • 151-561: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [131-173]

The readPolarisMinterSettings function is well-defined and encapsulates the parsing of Polaris Minter settings. The use of version.NewInfo().GitCommit to set default ExtraData is a good fallback mechanism. Ensure that the git commit length check is consistent with the project's versioning strategy.

  • 177-277: The readPolarisChainSettings function is well-defined and encapsulates the parsing of Polaris Chain settings. It correctly handles errors and returns early if any occur. The function is quite long; consider if breaking it down further would improve readability.
  • 280-320: The readPolarisGPOSettings function is well-defined and encapsulates the parsing of Polaris GPO settings. The conversion of int64 values to big.Int is done correctly.
  • 393-536: The readNodeSettings function is well-defined and encapsulates the parsing of Node settings. It correctly handles errors and returns early if any occur. The function is quite long and complex; consider if breaking it down further would improve readability.
  • 539-560: The readNodeHTTPTimeoutsSettings function is well-defined and encapsulates the parsing of Node HTTP timeouts settings. It correctly handles errors and returns early if any occur.

cosmos/config/config.go Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 5

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 6c19438 and eb0beff.
Files selected for processing (1)
  • cosmos/config/config.go (3 hunks)
Additional comments: 4
cosmos/config/config.go (4)
  • 78-148: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [70-109]

The refactoring of ReadConfigFromAppOpts to delegate to readConfigFromAppOptsParser is a good approach to simplify the original function. However, ensure that all calls to ReadConfigFromAppOpts have been updated accordingly if its behavior has changed.

  • 81-107: The breakdown of configuration parsing into separate functions within readConfigFromAppOptsParser is a good practice for modularity and readability. Ensure that the error handling is consistent and that the configuration is not partially applied in case of an error.
  • 112-129: readPolarisCoreSettings follows the established pattern of parsing and error checking. Ensure that the magic number comment //nolint:gomnd // its okay. is justified and that ignoring the magic number linting rule here is indeed okay.
Verification successful

Verifying the Magic Number Linting Rule

The script has identified several files where the magic number linting rule is ignored. To ensure consistency, I'll review each of these files to verify if the //nolint:gomnd comments are justified.

I'll start by examining the occurrences of the //nolint:gomnd comment in each file to determine if it's consistently used for legitimate cases where the magic number linting rule should be ignored.

First, I'll review the occurrences of the //nolint:gomnd comment in the cosmos/config/config.go file to understand the context in which it's used.

This will provide insight into the specific instances where the magic number linting rule is ignored in the cosmos/config/config.go file.

After reviewing the occurrences in the cosmos/config/config.go file, I'll proceed to review the other files identified by the script to ensure consistency in the use of the //nolint:gomnd comment.

Let's start by examining the occurrences in the cosmos/config/config.go file.


The search for occurrences of the //nolint:gomnd comment in the cosmos/config/config.go file returned one result. The comment is associated with a comparison of the length of a commit, and it's justified with the explanation // its okay.

Given this context, it seems that the use of the //nolint:gomnd comment is justified in the cosmos/config/config.go file. The comment is used to suppress the magic number linting rule for a specific comparison, and the justification provided supports its use.

Next, I'll proceed to review the occurrences of the //nolint:gomnd comment in the other files identified by the initial script to ensure consistency in the use of this comment.

This will provide a comprehensive view of the occurrences of the //nolint:gomnd comment in the identified files, allowing for a thorough review of its consistency across the codebase.


The search for occurrences of the //nolint:gomnd comment in the identified files has provided valuable insights into the consistency of its usage across the codebase. Here are the findings:

  1. cosmos/config/default.go: The comment //nolint:gomnd // default. justifies the suppression of the magic number linting rule for a specific assignment related to a default value.

  2. cosmos/precompile/governance/testutil.go: The comment //nolint:gomnd // its okay. explains the justification for ignoring the magic number linting rule for a specific case.

  3. cosmos/crypto/hd/hd.go: The comment //nolint:gomnd // ignore magic numbers provides a general justification for suppressing the magic number linting rule in the file.

  4. cosmos/runtime/logging.go: The comment //nolint:gomnd // 2 times. explains the reason for ignoring the magic number linting rule for a specific multiplication.

  5. cosmos/runtime/runtime.go: The comment //nolint:gomnd // as explained above. justifies the suppression of the magic number linting rule for a specific time.Sleep duration.

  6. e2e/localnet/utils/utils.go: The comments //nolint:gomnd // success., //nolint:gomnd // fail., and //nolint:gomnd // temporary. provide explanations for ignoring the magic number linting rule in different contexts.

  7. e2e/testapp/polard/cmd/commands.go: The comments //nolint:gomnd // from sdk. justify the suppression of the magic number linting rule for specific values.

  8. eth/version/version.go: The comment //nolint:gomnd // its okay. provides a justification for ignoring the magic number linting rule for a specific comparison.

  9. eth/core/genesis.go: The comments //nolint:gomnd // its okay. and //nolint:gomnd // its okay. justify the suppression of the magic number linting rule for specific values.

  10. eth/polar/config.go: The comment //nolint:gomnd // default. explains the justification for ignoring the magic number linting rule for a specific value.

Based on these findings, it appears that the //nolint:gomnd comments are consistently used with justifications across the identified files, aligning with legitimate cases where the magic number linting rule should be ignored.

Therefore, the usage of the //nolint:gomnd comments seems to be consistent and justified across the codebase.

The verification is successful, and the usage of the //nolint:gomnd comments appears to be consistent and justified across the identified files.

Result

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Check for other instances where the magic number linting rule is ignored and ensure consistency.
rg --type go '//nolint:gomnd' --files-with-matches

Length of output: 341



Script:

#!/bin/bash
# Search for occurrences of the `//nolint:gomnd` comment in the `cosmos/config/config.go` file.
rg --type go '//nolint:gomnd' cosmos/config/config.go

Length of output: 106



Script:

#!/bin/bash
# Search for occurrences of the `//nolint:gomnd` comment in the other identified files.
rg --type go '//nolint:gomnd' eth/core/genesis.go eth/version/version.go eth/polar/config.go e2e/testapp/polard/cmd/commands.go e2e/localnet/utils/utils.go cosmos/runtime/runtime.go cosmos/runtime/logging.go cosmos/crypto/hd/hd.go cosmos/precompile/governance/testutil.go cosmos/config/default.go

Length of output: 1628

* 539-560: `readNodeHTTPTimeoutsSettings` sets various HTTP timeout settings. The function is consistent with the rest of the refactoring and follows the established pattern.

Comment on lines 151 to 561
return err
}
if conf.Node.WSHost, err =
parser.GetString(flags.WsHost); err != nil {
return nil, err
return err
}
if conf.Node.WSPort, err =
parser.GetInt(flags.WsPort); err != nil {
return nil, err
return err
}
if conf.Node.WSPathPrefix, err =
parser.GetString(flags.WsPathPrefix); err != nil {
return nil, err
return err
}
if conf.Node.WSOrigins, err =
parser.GetStringSlice(flags.WsOrigins); err != nil {
return nil, err
return err
}
if conf.Node.WSModules, err =
parser.GetStringSlice(flags.WsModules); err != nil {
return nil, err
return err
}
if conf.Node.WSExposeAll, err =
parser.GetBool(flags.WsExposeAll); err != nil {
return nil, err
return err
}
if conf.Node.GraphQLCors, err =
parser.GetStringSlice(flags.GraphqlCors); err != nil {
return nil, err
return err
}
if conf.Node.GraphQLVirtualHosts, err =
parser.GetStringSlice(flags.GraphqlVirtualHosts); err != nil {
return nil, err
return err
}
if conf.Node.AllowUnprotectedTxs, err =
parser.GetBool(flags.AllowUnprotectedTxs); err != nil {
return nil, err
return err
}
if conf.Node.BatchRequestLimit, err =
parser.GetInt(flags.BatchRequestLimit); err != nil {
return nil, err
return err
}
if conf.Node.BatchResponseMaxSize, err =
parser.GetInt(flags.BatchResponseMaxSize); err != nil {
return nil, err
return err
}
if conf.Node.JWTSecret, err =
parser.GetString(flags.JwtSecret); err != nil {
return nil, err
return err
}
if conf.Node.DBEngine, err =
parser.GetString(flags.DBEngine); err != nil {
return nil, err
return err
}

// Node.HTTPTimeouts settings
return nil
}

func readNodeHTTPTimeoutsSettings(parser AppOptionsParser, conf *Config) error {
var err error

if conf.Node.HTTPTimeouts.ReadTimeout, err =
parser.GetTimeDuration(flags.ReadTimeout); err != nil {
return nil, err
return err
}
if conf.Node.HTTPTimeouts.ReadHeaderTimeout, err =
parser.GetTimeDuration(
flags.ReadHeaderTimeout); err != nil {
return nil, err
return err
}
if conf.Node.HTTPTimeouts.WriteTimeout, err =
parser.GetTimeDuration(flags.WriteTimeout); err != nil {
return nil, err
return err
}
if conf.Node.HTTPTimeouts.IdleTimeout, err =
parser.GetTimeDuration(flags.IdleTimeout); err != nil {
return nil, err
return err
}

return conf, nil
return nil
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [131-174]

In readPolarisMinterSettings, the check for the git commit length is hardcoded to 40. This is a magic number and should be defined as a constant to avoid magic numbers in the code.

- if len(commit) != 40 { //nolint:gomnd // its okay.
+ const expectedGitCommitLength = 40
+ if len(commit) != expectedGitCommitLength {

Comment on lines +177 to +278
}
if conf.Polar.Chain.EIP155Block, err =
parser.GetBigInt(flags.EIP155Block); err != nil {
return nil, err
return err
}
if conf.Polar.Chain.EIP158Block, err =
parser.GetBigInt(flags.EIP158Block); err != nil {
return nil, err
return err
}
if conf.Polar.Chain.ByzantiumBlock, err =
parser.GetBigInt(flags.ByzantiumBlock); err != nil {
return nil, err
return err
}
if conf.Polar.Chain.ConstantinopleBlock, err =
parser.GetBigInt(flags.ConstantinopleBlock); err != nil {
return nil, err
return err
}
if conf.Polar.Chain.PetersburgBlock, err =
parser.GetBigInt(flags.PetersburgBlock); err != nil {
return nil, err
return err
}
if conf.Polar.Chain.IstanbulBlock, err =
parser.GetBigInt(flags.IstanbulBlock); err != nil {
return nil, err
return err
}
if conf.Polar.Chain.MuirGlacierBlock, err =
parser.GetBigInt(flags.MuirGlacierBlock); err != nil {
return nil, err
return err
}
if conf.Polar.Chain.BerlinBlock, err =
parser.GetBigInt(flags.BerlinBlock); err != nil {
return nil, err
return err
}
if conf.Polar.Chain.LondonBlock, err =
parser.GetBigInt(flags.LondonBlock); err != nil {
return nil, err
return err
}
if conf.Polar.Chain.ArrowGlacierBlock, err =
parser.GetBigInt(flags.ArrowGlacierBlock); err != nil {
return nil, err
return err
}
if conf.Polar.Chain.GrayGlacierBlock, err =
parser.GetBigInt(flags.GrayGlacierBlock); err != nil {
return nil, err
return err
}
if conf.Polar.Chain.MergeNetsplitBlock, err =
parser.GetBigInt(flags.MergeNetsplitBlock); err != nil {
return nil, err
return err
}
if conf.Polar.Chain.ShanghaiTime, err =
parser.GetUint64Ptr(flags.ShanghaiTime); err != nil {
return nil, err
return err
}

if conf.Polar.Chain.CancunTime, err =
parser.GetUint64Ptr(flags.CancunTime); err != nil {
return nil, err
return err
}
if conf.Polar.Chain.PragueTime, err =
parser.GetUint64Ptr(flags.PragueTime); err != nil {
return nil, err
return err
}
if conf.Polar.Chain.VerkleTime, err =
parser.GetUint64Ptr(flags.VerkleTime); err != nil {
return nil, err
return err
}

if conf.Polar.Chain.TerminalTotalDifficulty, err =
parser.GetBigInt(
flags.TerminalTotalDifficulty); err != nil {
return nil, err
return err
}

if conf.Polar.Chain.TerminalTotalDifficultyPassed, err =
parser.GetBool(
flags.TerminalTotalDifficultyPassed); err != nil {
return nil, err
return err
}

// Polar.GPO settings
return nil
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readPolarisChainSettings is setting a large number of configuration options. Consider if this function could be further broken down for better readability and maintainability.

Comment on lines +280 to +321
func readPolarisGPOSettings(parser AppOptionsParser, conf *Config) error {
var (
err error
val int64
)

if conf.Polar.GPO.Blocks, err =
parser.GetInt(flags.Blocks); err != nil {
return nil, err
return err
}
if conf.Polar.GPO.Percentile, err =
parser.GetInt(flags.Percentile); err != nil {
return nil, err
return err
}
if conf.Polar.GPO.MaxHeaderHistory, err =
parser.GetUint64(flags.MaxHeaderHistory); err != nil {
return nil, err
return err
}
if conf.Polar.GPO.MaxBlockHistory, err =
parser.GetUint64(flags.MaxBlockHistory); err != nil {
return nil, err
return err
}
if val, err =
parser.GetInt64(flags.Default); err != nil {
return nil, err
return err
}
conf.Polar.GPO.Default = big.NewInt(val)

if val, err =
parser.GetInt64(flags.MaxPrice); err != nil {
return nil, err
return err
}
conf.Polar.GPO.MaxPrice = big.NewInt(val)

if val, err =
parser.GetInt64(flags.IgnorePrice); err != nil {
return nil, err
return err
}
conf.Polar.GPO.IgnorePrice = big.NewInt(val)

// LegacyPool
return nil
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conversion from int64 to big.Int in readPolarisGPOSettings is done correctly. However, consider creating a helper function for this repeated pattern to adhere to the DRY principle.

+ func newBigIntFromInt64(val int64) *big.Int {
+   return big.NewInt(val)
+ }
- conf.Polar.GPO.Default = big.NewInt(val)
+ conf.Polar.GPO.Default = newBigIntFromInt64(val)

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
func readPolarisGPOSettings(parser AppOptionsParser, conf *Config) error {
var (
err error
val int64
)
if conf.Polar.GPO.Blocks, err =
parser.GetInt(flags.Blocks); err != nil {
return nil, err
return err
}
if conf.Polar.GPO.Percentile, err =
parser.GetInt(flags.Percentile); err != nil {
return nil, err
return err
}
if conf.Polar.GPO.MaxHeaderHistory, err =
parser.GetUint64(flags.MaxHeaderHistory); err != nil {
return nil, err
return err
}
if conf.Polar.GPO.MaxBlockHistory, err =
parser.GetUint64(flags.MaxBlockHistory); err != nil {
return nil, err
return err
}
if val, err =
parser.GetInt64(flags.Default); err != nil {
return nil, err
return err
}
conf.Polar.GPO.Default = big.NewInt(val)
if val, err =
parser.GetInt64(flags.MaxPrice); err != nil {
return nil, err
return err
}
conf.Polar.GPO.MaxPrice = big.NewInt(val)
if val, err =
parser.GetInt64(flags.IgnorePrice); err != nil {
return nil, err
return err
}
conf.Polar.GPO.IgnorePrice = big.NewInt(val)
// LegacyPool
return nil
}
func readPolarisGPOSettings(parser AppOptionsParser, conf *Config) error {
var (
err error
val int64
)
if conf.Polar.GPO.Blocks, err =
parser.GetInt(flags.Blocks); err != nil {
return err
}
if conf.Polar.GPO.Percentile, err =
parser.GetInt(flags.Percentile); err != nil {
return err
}
if conf.Polar.GPO.MaxHeaderHistory, err =
parser.GetUint64(flags.MaxHeaderHistory); err != nil {
return err
}
if conf.Polar.GPO.MaxBlockHistory, err =
parser.GetUint64(flags.MaxBlockHistory); err != nil {
return err
}
if val, err =
parser.GetInt64(flags.Default); err != nil {
return err
}
conf.Polar.GPO.Default = newBigIntFromInt64(val)
if val, err =
parser.GetInt64(flags.MaxPrice); err != nil {
return err
}
conf.Polar.GPO.MaxPrice = big.NewInt(val)
if val, err =
parser.GetInt64(flags.IgnorePrice); err != nil {
return err
}
conf.Polar.GPO.IgnorePrice = big.NewInt(val)
return nil
}
func newBigIntFromInt64(val int64) *big.Int {
return big.NewInt(val)
}

Comment on lines +323 to +390
func readPolarisLegacyPool(parser AppOptionsParser, conf *Config) error {
var err error

if conf.Polar.LegacyTxPool.Locals, err =
parser.GetCommonAddressList(flags.Locals); err != nil {
return nil, err
return err
}
if conf.Polar.LegacyTxPool.NoLocals, err =
parser.GetBool(flags.NoLocals); err != nil {
return nil, err
return err
}

if conf.Polar.LegacyTxPool.Journal, err =
parser.GetString(flags.Journal); err != nil {
return nil, err
return err
}

if conf.Polar.LegacyTxPool.Journal == "" {
conf.Polar.LegacyTxPool.Journal, err =
parser.GetString(sdkflags.FlagHome)
if err != nil {
return nil, err
return err
}
conf.Polar.LegacyTxPool.Journal += "/data/transactions.rlp"
}

if conf.Polar.LegacyTxPool.Rejournal, err =
parser.GetTimeDuration(flags.ReJournal); err != nil {
return nil, err
return err
}

if conf.Polar.LegacyTxPool.PriceLimit, err =
parser.GetUint64(flags.PriceLimit); err != nil {
return nil, err
return err
}

if conf.Polar.LegacyTxPool.PriceBump, err =
parser.GetUint64(flags.PriceBump); err != nil {
return nil, err
return err
}

if conf.Polar.LegacyTxPool.AccountSlots, err =
parser.GetUint64(flags.AccountSlots); err != nil {
return nil, err
return err
}

if conf.Polar.LegacyTxPool.GlobalSlots, err =
parser.GetUint64(flags.GlobalSlots); err != nil {
return nil, err
return err
}

if conf.Polar.LegacyTxPool.AccountQueue, err =
parser.GetUint64(flags.AccountQueue); err != nil {
return nil, err
return err
}

if conf.Polar.LegacyTxPool.GlobalQueue, err =
parser.GetUint64(flags.GlobalQueue); err != nil {
return nil, err
return err
}

if conf.Polar.LegacyTxPool.Lifetime, err =
parser.GetTimeDuration(flags.Lifetime); err != nil {
return nil, err
return err
}

// Node settings
return nil
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readPolarisLegacyPool sets various transaction pool settings. Ensure that the default journal path concatenation is done correctly and consider using filepath.Join for path construction to avoid issues with path separators on different operating systems.

- conf.Polar.LegacyTxPool.Journal += "/data/transactions.rlp"
+ conf.Polar.LegacyTxPool.Journal = filepath.Join(conf.Polar.LegacyTxPool.Journal, "data", "transactions.rlp")

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
func readPolarisLegacyPool(parser AppOptionsParser, conf *Config) error {
var err error
if conf.Polar.LegacyTxPool.Locals, err =
parser.GetCommonAddressList(flags.Locals); err != nil {
return nil, err
return err
}
if conf.Polar.LegacyTxPool.NoLocals, err =
parser.GetBool(flags.NoLocals); err != nil {
return nil, err
return err
}
if conf.Polar.LegacyTxPool.Journal, err =
parser.GetString(flags.Journal); err != nil {
return nil, err
return err
}
if conf.Polar.LegacyTxPool.Journal == "" {
conf.Polar.LegacyTxPool.Journal, err =
parser.GetString(sdkflags.FlagHome)
if err != nil {
return nil, err
return err
}
conf.Polar.LegacyTxPool.Journal += "/data/transactions.rlp"
}
if conf.Polar.LegacyTxPool.Rejournal, err =
parser.GetTimeDuration(flags.ReJournal); err != nil {
return nil, err
return err
}
if conf.Polar.LegacyTxPool.PriceLimit, err =
parser.GetUint64(flags.PriceLimit); err != nil {
return nil, err
return err
}
if conf.Polar.LegacyTxPool.PriceBump, err =
parser.GetUint64(flags.PriceBump); err != nil {
return nil, err
return err
}
if conf.Polar.LegacyTxPool.AccountSlots, err =
parser.GetUint64(flags.AccountSlots); err != nil {
return nil, err
return err
}
if conf.Polar.LegacyTxPool.GlobalSlots, err =
parser.GetUint64(flags.GlobalSlots); err != nil {
return nil, err
return err
}
if conf.Polar.LegacyTxPool.AccountQueue, err =
parser.GetUint64(flags.AccountQueue); err != nil {
return nil, err
return err
}
if conf.Polar.LegacyTxPool.GlobalQueue, err =
parser.GetUint64(flags.GlobalQueue); err != nil {
return nil, err
return err
}
if conf.Polar.LegacyTxPool.Lifetime, err =
parser.GetTimeDuration(flags.Lifetime); err != nil {
return nil, err
return err
}
// Node settings
return nil
}
func readPolarisLegacyPool(parser AppOptionsParser, conf *Config) error {
var err error
if conf.Polar.LegacyTxPool.Locals, err =
parser.GetCommonAddressList(flags.Locals); err != nil {
return err
}
if conf.Polar.LegacyTxPool.NoLocals, err =
parser.GetBool(flags.NoLocals); err != nil {
return err
}
if conf.Polar.LegacyTxPool.Journal, err =
parser.GetString(flags.Journal); err != nil {
return err
}
if conf.Polar.LegacyTxPool.Journal == "" {
conf.Polar.LegacyTxPool.Journal, err =
parser.GetString(sdkflags.FlagHome)
if err != nil {
return err
}
conf.Polar.LegacyTxPool.Journal = filepath.Join(conf.Polar.LegacyTxPool.Journal, "data", "transactions.rlp")
}
if conf.Polar.LegacyTxPool.Rejournal, err =
parser.GetTimeDuration(flags.ReJournal); err != nil {
return err
}
if conf.Polar.LegacyTxPool.PriceLimit, err =
parser.GetUint64(flags.PriceLimit); err != nil {
return err
}
if conf.Polar.LegacyTxPool.PriceBump, err =
parser.GetUint64(flags.PriceBump); err != nil {
return err
}
if conf.Polar.LegacyTxPool.AccountSlots, err =
parser.GetUint64(flags.AccountSlots); err != nil {
return err
}
if conf.Polar.LegacyTxPool.GlobalSlots, err =
parser.GetUint64(flags.GlobalSlots); err != nil {
return err
}
if conf.Polar.LegacyTxPool.AccountQueue, err =
parser.GetUint64(flags.AccountQueue); err != nil {
return err
}
if conf.Polar.LegacyTxPool.GlobalQueue, err =
parser.GetUint64(flags.GlobalQueue); err != nil {
return err
}
if conf.Polar.LegacyTxPool.Lifetime, err =
parser.GetTimeDuration(flags.Lifetime); err != nil {
return err
}
return nil
}

Comment on lines +392 to +537
}
if conf.Node.HTTPVirtualHosts, err =
parser.GetStringSlice(flags.HTTPVirtualHosts); err != nil {
return nil, err
return err
}
if conf.Node.HTTPModules, err =
parser.GetStringSlice(flags.HTTPModules); err != nil {
return nil, err
return err
}
if conf.Node.HTTPPathPrefix, err =
parser.GetString(flags.HTTPPathPrefix); err != nil {
return nil, err
return err
}
if conf.Node.AuthAddr, err =
parser.GetString(flags.AuthAddr); err != nil {
return nil, err
return err
}
if conf.Node.AuthPort, err =
parser.GetInt(flags.AuthPort); err != nil {
return nil, err
return err
}
if conf.Node.AuthVirtualHosts, err =
parser.GetStringSlice(flags.AuthVirtualHosts); err != nil {
return nil, err
return err
}
if conf.Node.WSHost, err =
parser.GetString(flags.WsHost); err != nil {
return nil, err
return err
}
if conf.Node.WSPort, err =
parser.GetInt(flags.WsPort); err != nil {
return nil, err
return err
}
if conf.Node.WSPathPrefix, err =
parser.GetString(flags.WsPathPrefix); err != nil {
return nil, err
return err
}
if conf.Node.WSOrigins, err =
parser.GetStringSlice(flags.WsOrigins); err != nil {
return nil, err
return err
}
if conf.Node.WSModules, err =
parser.GetStringSlice(flags.WsModules); err != nil {
return nil, err
return err
}
if conf.Node.WSExposeAll, err =
parser.GetBool(flags.WsExposeAll); err != nil {
return nil, err
return err
}
if conf.Node.GraphQLCors, err =
parser.GetStringSlice(flags.GraphqlCors); err != nil {
return nil, err
return err
}
if conf.Node.GraphQLVirtualHosts, err =
parser.GetStringSlice(flags.GraphqlVirtualHosts); err != nil {
return nil, err
return err
}
if conf.Node.AllowUnprotectedTxs, err =
parser.GetBool(flags.AllowUnprotectedTxs); err != nil {
return nil, err
return err
}
if conf.Node.BatchRequestLimit, err =
parser.GetInt(flags.BatchRequestLimit); err != nil {
return nil, err
return err
}
if conf.Node.BatchResponseMaxSize, err =
parser.GetInt(flags.BatchResponseMaxSize); err != nil {
return nil, err
return err
}
if conf.Node.JWTSecret, err =
parser.GetString(flags.JwtSecret); err != nil {
return nil, err
return err
}
if conf.Node.DBEngine, err =
parser.GetString(flags.DBEngine); err != nil {
return nil, err
return err
}

// Node.HTTPTimeouts settings
return nil
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readNodeSettings is marked with nolint comments for complexity and function length. This is a red flag for maintainability. Consider refactoring to reduce complexity and function length, possibly by breaking it down into smaller functions.

@kienn6034 kienn6034 marked this pull request as draft January 24, 2024 03:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants