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

[Persistence] Followup on PrePersistence deprecation & Block lifecycle #165

Merged
merged 77 commits into from
Aug 18, 2022

Conversation

Olshansk
Copy link
Member

@Olshansk Olshansk commented Aug 14, 2022

Objective

Follow up on both critical and non-critical fixes to #140.

Origin Document

#140 deprecated PrePersistence and implemented multiple contexts. This PR is a follow with some stylistic changes, improvements in the readability of the tests, the addition of unit tests, bug fixes in some SQL business logic, and implementation of the read context.

Followup work is being tracked in #149.

Learnings to streamline workflow in the future

  • Do not conflate non-critical stylistic changes as it leads to more conflicts down the road
  • Implemented an automated "LocalNet" for easier testing
  • Try to plan work ahead of time so we can work in smaller PRs / iterations

Changelog / changes

Main persistence module changes:

  • Split ConnectAndInitializeDatabase into connectToDatabase and initializeDatabase
    • This enables creating multiple contexts in parallel without re-initializing the DB connection
  • Fix the SQL query used in SelectActors, SelectAccounts & SelectPools
    • Add a generalized unit test for all actors
  • Remove NewPersistenceModule and an injected Config + Create
    • This improves isolation a a “injection-like” paradigm for unit testing
  • Change SetupPostgresDocker to SetupPostgresDockerPersistenceMod
    • This enables more “functional” like testing by returning a persistence module and avoiding global testing variables
    • Only return once a connection to the DB has been initialized reducing the likelihood of test race conditions
  • Implemented NewReadContext with a proper read-only context

Secondary persistence module changes

  • Improve return values in Commit and Release (return error, add logging, etc…)
  • Add pgx.Conn pointer to PostgresDB
  • s/db/conn/g and s/conn/tx/g in some (not all) places where appropriate
  • Make some exported variables / functions unexported for readability & access purposes
  • Add a few helpers for persistence related unit testing
  • Added unit tests and TODOs for handling multiple read/write contexts

General milestone checklist

  • Update all the relevant CHANGELOGs
  • Update all the relevant READMEs
  • Update the source code tree explanation
  • Add or update a state, sequence or flowchart diagram using mermaid
  • Create followup milestones + issues
  • Document small TODO along the way

Follow-up Work

All follow-up work is being tracked in #149


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 or global README
  • If applicable, I have added added new diagrams using memaid.js
  • If applicable, I have added tests that prove my fix is effective or that my feature works

Andrew Nguyen and others added 30 commits July 6, 2022 16:49
#73)

## Objective

Foundational iteration of PostgreSQL based persistence module implementation.

## Origin Document

#68

## Type of change

New major module implementation.

### Persistence-related core changes:
- List of actors / interfaces with MVP implementation:
    - Applications
    - Fisherman
    - ServiceNode
    - Accounts
    - Pools
- List of actors / interfaces with partial MVP implementation:
    - Validator
    - Gov params
- List of actors / interfaces with minorimplementation:
    - Block
- SQL Schema definition of the actors above
- SQL Query implementation for common actor persistence functionality
- PostgresContext implementation of the actors actors above
- Base infrastructure for fuzz testing

Non-persistence “fly-by” changes
- Updates to the PrePersistence module and utility module with breaking changes
- A few minor improvements/additions to the Makefile
- TODOs & comment cleanups throughout the codebase

## How Has This Been Tested?

### Unit Tests

```
make test_persistence
make test_all
```

### LocalNet
Ran a basic LocalNet following the instructions in the [development README](docs/development/README.md).


Co-authored-by: Daniel Olshansky <olshansky.daniel@gmail.com>
Co-authored-by: Andrew Nguyen <andrewnguyen@Andrews-MacBook-Pro-2.local>
Co-authored-by: Andrew Nguyen <andrewnguyen@Andrews-MBP-2.lan>
Co-authored-by: Daniel Olshansky <olshansky@pokt.network>
@Olshansk Olshansk marked this pull request as ready for review August 17, 2022 00:03
@Olshansk Olshansk requested a review from a team as a code owner August 17, 2022 00:03
@Olshansk Olshansk changed the title Issue #128 fixes [Persistence] Followup on PrePersistence deprecation & Block lifecycle Aug 17, 2022
@Olshansk
Copy link
Member Author

@andrewnguyen22 Please take a look at this PR and lmk if there any additional changes you'd like for me to make.

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.

All looks good. 99% there. Just two comments

persistence/test/module_test.go Outdated Show resolved Hide resolved
persistence/gov.go Outdated Show resolved Hide resolved
@Olshansk
Copy link
Member Author

@andrewnguyen22 Please take a close look at the commits between HEAD and f9ddc0954de45f09559d7812de6e8b8857e9dc2d. All the unit tests are passing but I also had to make several block lifecycle modifications for LocalNet to succeed.

@Olshansk Olshansk removed the do not merge Prevent merging even with sufficient approvals label Aug 17, 2022
@andrewnguyen22
Copy link
Contributor

Utility context not nil when preparing a new block? Releasing for now but should not happen

consensus/module.go Outdated Show resolved Hide resolved
persistence/genesis.go Outdated Show resolved Hide resolved
persistence/gov.go Outdated Show resolved Hide resolved
persistence/module.go Show resolved Hide resolved
shared/modules/persistence_module.go Show resolved Hide resolved
@Olshansk
Copy link
Member Author

Olshansk commented Aug 18, 2022

EDIT: I'm thinking that even though we're going to remove it in https://github.com/pokt-network/pocket/pulls?q=is%3Apr+is%3Aopen+sort%3Aupdated-desc, I'll add back the previous block lifecycle / should hydrate genesis logic so we have a more stable main with less bugs.


@andrewnguyen22 comment regarding the genesis / lifecycle piece.

When we added the blockstore in #121 , we also added a shouldHydrateGenesis function so that:

  1. We don't run populateGenesis if there is already a previous state
  2. Pick up the previous state if we already had one (hence the logic around loading the previous hash and height which I'm just logging)

https://github.com/pokt-network/pocket/pull/140/files?file-filters%5B%5D=.go&file-filters%5B%5D=.json&file-filters%5B%5D=.md&file-filters%5B%5D=.mod&file-filters%5B%5D=.sum&file-filters%5B%5D=No+extension&show-viewed-files=true&show-deleted-files=false

Screen Shot 2022-08-18 at 6 45 18 AM

My understanding is that per the other comments / discussions (screenshot below), we didn't want to bring it back in favor of the future configs changes happening, but I had to add a couple stop-gap hacks in the meantime so that we load up the genesis correctly every time.

I'd personally prefer to add it back in this PR so there are less hacks / confusion, but also unsure per you your other comments. Lmk how you think I should proceed.

Screen Shot 2022-08-18 at 6 46 21 AM

@Olshansk
Copy link
Member Author

@andrewnguyen22 I removed the hacks, added the TODOs and replied to some of the outstanding comments.

Even though we'll make it more real in the next config change and delete some of this, it'll avoid us having more hacks, and a better baseline we can reference or revert to on mainline.

I added a small gif showing the state being loaded when we restart local net and some of the tooling we can use to investigate it manually.

The quality is low because github messages is limited to 10MB but a full video is available here.

vid2

@Olshansk Olshansk merged commit 77ea699 into main Aug 18, 2022
@Olshansk Olshansk deleted the issue-#128-fixes branch August 18, 2022 16:24
Olshansk added a commit that referenced this pull request Aug 24, 2022
#### Intention
Currently merge ready with #128 but not considering #165 since it's under active development.

## Description
- Deprecated old placeholder genesis_state and genesis_config
- Added utility_genesis_state to genesis_state
- Added consensus_genesis_state to genesis_state
- Added genesis_time to consensus_genesis_state
- Added chainID to consensus_genesis_state
- Added max_block_bytes to consensus_genesis_state
- Added accounts and pools to utility_genesis_state
- Added validators to utility_genesis_state
- Added applications to utility_genesis_state
- Added service_nodes to utility_genesis_state
- Added fishermen to utility_genesis_state
- Deprecated shared/config/
- Added new shared config proto3 structure
- Added base_config to config
- Added utility_config to config
- Added consensus_config to config
- Added persistence_config to config
- Added p2p_config to config
- Added telemetry_config to config
- Opened followup issue #163
- Added config and genesis generator to build package
- Deprecated old build files
- Use new config and genesis files for make compose_and_watch 
- Use new config and genesis files for make client_start && make client_connect

closes #154

## Type of change
Please mark the options that are relevant.

- [x] New feature (non-breaking change which adds functionality)
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Documentation
- [ ] Other (<_REPLACE_ME_WITH_DETAILS_>)

## How Has This Been Tested?
make test_all
&&
make compose_and_watch

- [x] `make test_all`
- [x] [LocalNet](https://github.com/pokt-network/pocket/blob/main/docs/development/README.md)

## Checklist
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have tested my changes using the available tooling
- [x] If applicable, I have made corresponding changes to related or global README
- [ ] If applicable, I have added added new diagrams using [mermaid.js](https://mermaid-js.github.io)
- [ ] If applicable, I have added tests that prove my fix is effective or that my feature works


--- 

Co-authored-by: Daniel Olshansky <olshansky.daniel@gmail.com>
Co-authored-by: Andrew Nguyen <andrewnguyen@Andrews-MacBook-Pro-2.local>
Co-authored-by: Andrew Nguyen <andrewnguyen@Andrews-MBP-2.lan>
Co-authored-by: Daniel Olshansky <olshansky@pokt.network>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core infrastructure - protocol related persistence Persistence specific changes
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants