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

[Shared] Config and genesis handling refactoring idea #235

Merged
merged 107 commits into from
Oct 13, 2022

Conversation

deblasis
Copy link
Contributor

@deblasis deblasis commented Sep 20, 2022

Description

This PR is a way to convey a design idea for the refactoring of the way we handle config and genesis as highlighted in a couple of Protocol Hours and also summarized, along with more context that should help us making the right decisions, into the discussion #234

Issue

There's no issue per-se, this is basically TECHDEBT handling I guess. Let me know if I should create one.

Type of change

Please mark the options that are relevant.

  • New feature, functionality or library
  • Code health or cleanup

List of changes

  • Abstracted config and genesis handling
  • Mockable runtime
  • Refactored all modules to use RuntimeMgr
  • Updated RuntimeMgr to manage clock as well
  • Modules now accept interfaces instead of paths.
  • Unmarshalling is done in a new runtime package (runtime because what we do in there affects the runtime of the application)
  • We are now able to accept configuration via environment variables (thanks to @okdas for inspiration and sp13 for Viper)

Testing

  • make test_all
  • LocalNet w/ all of the steps outlined in the README

Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have tested my changes using the available tooling
  • If applicable, I have made corresponding changes to related local or global README
  • If applicable, I have added new diagrams using mermaid.js
  • If applicable, I have added tests that prove my fix is effective or that my feature works

@deblasis deblasis added core Core infrastructure - protocol related code health Nice to have code improvement labels Sep 20, 2022
@deblasis deblasis self-assigned this Sep 20, 2022
@deblasis deblasis requested a review from a team as a code owner September 20, 2022 12:49
app/client/main.go Outdated Show resolved Hide resolved
p2p/module_raintree_test.go Outdated Show resolved Hide resolved
runtime/config.go Show resolved Hide resolved
shared/modules/module.go Show resolved Hide resolved
shared/node.go Outdated Show resolved Hide resolved
shared/test_artifacts/generator.go Outdated Show resolved Hide resolved
@@ -8,6 +8,7 @@ import (
"os"
"testing"

typesPers "github.com/pokt-network/pocket/persistence/types"
Copy link
Contributor

Choose a reason for hiding this comment

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

Utility mod added import from Persistence mod.

We're trying to get rid of this cross module sharing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps we could move module creation for testing purposes under test_artifacts to hide away the implementation details of the other modules when we are testing one

Copy link
Member

Choose a reason for hiding this comment

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

+1 This will enable the "composable testing blocks", so the testing framework will simply evolve over time.

Probably outside the scope of this one PR, but we could create a ticket just to remove this.

It would include doing greps like this:

grep --exclude-dir='./persistence' -r "github.com/pokt-network/pocket/persistence"
grep --exclude-dir='./consensus' -r "github.com/pokt-network/pocket/consensus"
...

@okdas Can even add this as a custom linter once #190 is done. Wdyt?

Copy link
Member

Choose a reason for hiding this comment

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

Created #239

Copy link
Member

Choose a reason for hiding this comment

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

@Olshansk that is likely going to be a somewhat sophisticated AST rule but should be doable! 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure how this was resolved. We just added an issue to automatically check

Copy link
Member

@Olshansk Olshansk left a comment

Choose a reason for hiding this comment

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

I think my review is a bit outdated but figured I'd publish the comments I have as an interim iteration. Looking great so far

app/client/main.go Outdated Show resolved Hide resolved
app/client/main.go Outdated Show resolved Hide resolved
app/client/main.go Outdated Show resolved Hide resolved
consensus/module.go Outdated Show resolved Hide resolved
consensus/module.go Outdated Show resolved Hide resolved
runtime/runtime.go Outdated Show resolved Hide resolved
runtime/runtime.go Outdated Show resolved Hide resolved
runtime/runtime.go Outdated Show resolved Hide resolved
runtime/runtime.go Outdated Show resolved Hide resolved
runtime/runtime.go Outdated Show resolved Hide resolved
@deblasis deblasis requested a review from Olshansk October 6, 2022 16:39
@Olshansk
Copy link
Member

Olshansk commented Oct 6, 2022

The only blocker from my end is fixing the unit tests. Some of it might be resolved after we merge in #282, so let's aim to get that in first.

Screen Shot 2022-10-06 at 10 02 35 AM


I took another look through the PR. With the goal of unblocking downstream work. the 3 biggest action items remaining IMO are (see screenshots below):

  1. Consider renaming NodeModules
  2. Figuring out how to implement ValidateConfig while allowing injection of mocks
  3. Renaming GetVals to GetValidators because Vals can be misinterpreted

@deblasis Can you create a "235 follow ups" to track it?

@andrewnguyen22 Assuming we merge in #282 and create the follow-up for that work, can we merge this in?


Screen Shot 2022-10-06 at 10 00 49 AM

Screen Shot 2022-10-06 at 10 00 35 AM

Screen Shot 2022-10-06 at 10 00 27 AM

@andrewnguyen22
Copy link
Contributor

I will review it again @Olshansk

@deblasis
Copy link
Contributor Author

deblasis commented Oct 6, 2022

I have created the issues to track the open items as requested. They are not assigned to me and I put them in QoL, please change that as you see fit.

The only blocker from my end is fixing the unit tests. Some of it might be resolved after we merge in #282, so let's aim to get that in first.

I have to point out that tests are not failing in this PR... what's failing is the CI because of the new linting:

image

and also for the build / push part:

image

Copy link
Member

@Olshansk Olshansk left a comment

Choose a reason for hiding this comment

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

Thanks for creating the follow up work.

👍 from my POV. Not perfect but I was to prevent the scope of the PR from increasing and it's already a big improvement over what we had.

Let's wait to hear if @andrewnguyen22 has any blockers though

Copy link
Contributor

@andrewnguyen22 andrewnguyen22 left a comment

Choose a reason for hiding this comment

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

Pretty much there, a few blockers and a few discussion items.

Resolve conflicts and blockers and I'll approve

consensus/module.go Outdated Show resolved Hide resolved
consensus/hotstuff_leader.go Outdated Show resolved Hide resolved
consensus/module.go Outdated Show resolved Hide resolved
consensus/module.go Outdated Show resolved Hide resolved
p2p/module.go Outdated Show resolved Hide resolved
@@ -21,6 +24,21 @@ type InterruptableModule interface {

type InitializableModule interface {
GetModuleName() string
InitConfig(pathToConfigJSON string) (IConfig, error)
InitGenesis(pathToGenesisJSON string) (IGenesis, error)
Create(runtime RuntimeMgr) (Module, error)
Copy link
Contributor

Choose a reason for hiding this comment

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

Non-Blocker:

The granularity here is getting a bit sticky for me. Consider mental load vs. verbosity

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see. If it sounds like over-optimization or premature optimization let's consider the fact that soon we'll have modules that are very simple and only implement a subset of the Module interface. Logging for example, which is coming soon. Keybase as well I guess.

Maybe my .Net background surfaces here. I am used to very small and targeted interfaces.

I am open to suggestions.

serviceNodes, snPrivateKeys := NewActors(types.ActorType_ServiceNode, numServiceNodes)
fish, fishPrivateKeys := NewActors(types.ActorType_Fisherman, numFisherman)

genesisState := runtime.NewGenesis(
Copy link
Contributor

Choose a reason for hiding this comment

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

Non-Blocker:

Is there no way to use runtime for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you mean to move test_artifacts under runtime. I have done it.

@@ -1,9 +1,11 @@
package test_artifacts
Copy link
Contributor

Choose a reason for hiding this comment

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

Non-Blocker:

Can we move this to the runtime package?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -62,6 +59,14 @@ func (m *NoopTelemetryModule) GetBus() modules.Bus {
return m.bus
}

func (*NoopTelemetryModule) ValidateConfig(cfg modules.Config) error {
// DISCUSS (team): we cannot cast if we want to use mocks and rely on interfaces
Copy link
Contributor

@andrewnguyen22 andrewnguyen22 Oct 12, 2022

Choose a reason for hiding this comment

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

Agree, see applicable comment above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe addressed with #235 (comment)

if u.bus == nil {
log.Fatalf("Bus is not initialized")
}
return u.bus
}

func (*utilityModule) ValidateConfig(cfg modules.Config) error {
// DISCUSS (team): we cannot cast if we want to use mocks and rely on interfaces
Copy link
Contributor

@andrewnguyen22 andrewnguyen22 Oct 12, 2022

Choose a reason for hiding this comment

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

Agree see applicable comment above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe addressed with #235 (comment)

return mgr
}

func NewManagerFromReaders(configReader, genesisReader io.Reader, options ...func(*Manager)) *Manager {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could potentially remove this. I have used during development and forgot to clean after myself

@deblasis
Copy link
Contributor Author

@andrewnguyen22 thank you for your time and feedback reviewing this :)

I have addressed all the comments that I have marked with a 👍 and left comments otherwise. There are a couple of questions from me but nothing major, I guess.

Regarding NodeModule I think that since both of you flagged it, its short life had to come to an end. I have axed it and replaced with the struct. Perhaps I was over-abstracting.

Copy link
Contributor

@andrewnguyen22 andrewnguyen22 left a comment

Choose a reason for hiding this comment

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

Great work @deblasis

@deblasis deblasis merged commit 87a6060 into pokt-network:main Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code health Nice to have code improvement core Core infrastructure - protocol related discussion It has a related Discussion
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants