Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Split up server functions a bit #16152

Merged
merged 12 commits into from
May 17, 2023
Merged

refactor: Split up server functions a bit #16152

merged 12 commits into from
May 17, 2023

Conversation

ValarDragon
Copy link
Contributor

@ValarDragon ValarDragon commented May 15, 2023

Description

Very minor PR, should hopefully be a straightforward review/merge.

The startup server function was 207 lines long, and requires some careful attention to whats going on. I find myself having to look at it semi-occasionally. This PR moves things to sub-functions in a fully compatible manner, and it now takes 109 lines. With minor changes in some follow-ups, this can significantly reduce further.

This PR does some basic splitting up of components of the function, into smaller functions. It surely can be done better, but I essentially did this just to look at it better, so thought this incremental progress would be useful to PR. This area of the code definitely deserves more attention / better refactoring in the future though!

Its fully compatible as far as I can tell. Comments are left in the code to indicate directions for further improvement (and potential existing bugs), but they should be addressed in subsequent PR's.

Let me know if PR's like this aren't helpful.


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

@ValarDragon ValarDragon requested a review from a team as a code owner May 15, 2023 11:07
server/start.go Outdated Show resolved Hide resolved
// Add the tx service to the gRPC router. We only need to register this
// service if API or gRPC is enabled, and avoid doing so in the general
// case, because it spawns a new local CometBFT RPC client.
if svrCfg.API.Enable || svrCfg.GRPC.Enable {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Notice that its equivalent to move this here, as tmNode != nil implies its not GRPC only.

Comment on lines +287 to +288
// TODO: Move this to only be done if were launching the node. (So not in GRPC-only mode)
nodeKey, err := p2p.LoadOrGenNodeKey(cmtCfg.NodeKeyFile())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should be changed, but would technically change the behavior for Grpc-Only nodes, so would want it to be in its own PR.

server/start.go Outdated
Comment on lines 341 to 343
// TODO: Why do we reload and unmarshal the entire genesis doc in order to get the chain ID.
// surely theres a better way. This is likely a serious node start time overhead.
genDocProvider := getGenDocProvider(cmtCfg)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixing this (in another PR) would be really helpful!

Maybe should become a follow-up issue?

@ValarDragon
Copy link
Contributor Author

This PR is already really large, so going to stop adding any other fn moves. Let me know if its too big or generally unhelpful

I think this can really help us simplify the startup sequence though, as its a frequent source of problem / investigation area

@julienrbrt
Copy link
Member

This PR is already really large, so going to stop adding any other fn moves. Let me know if its too big or generally unhelpful

I think this can really help us simplify the startup sequence though, as its a frequent source of problem / investigation area

Personally, I really like smaller and more contained functions. imho decreasing cognitive complexity is def. helpful.

@ValarDragon
Copy link
Contributor Author

Failing test is code analysis, asking for more test coverage. But I think that should be another PR's role, given that this one is purely refactoring

Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

lgtm!

server/start.go Outdated Show resolved Hide resolved
@tac0turtle tac0turtle enabled auto-merge May 17, 2023 12:32
@tac0turtle tac0turtle added this pull request to the merge queue May 17, 2023
Merged via the queue into main with commit 9329a00 May 17, 2023
@tac0turtle tac0turtle deleted the dev/splitup_server branch May 17, 2023 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants