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][Utility] Separate all CreateAndApply functions into more functional components - Issue #508 #652

Merged
merged 33 commits into from
Apr 7, 2023

Conversation

deblasis
Copy link
Contributor

@deblasis deblasis commented Apr 4, 2023

Description

This PR tends to the deliverables in the parent issue

Issue

Fixes #508

Type of change

Please mark the relevant option(s):

  • New feature, functionality or library
  • Bug fix
  • Code health or cleanup
  • Major breaking change
  • Documentation
  • Other

List of changes

Consensus

  • Updated to reflect the new ApplyBlock signature from utilityUnitOfWork
  • Updated to use utilityUnitOfWork.GetStateHash()
  • Removed duplicate import
  • Renamed CreateAndApplyProposalBlock to CreateProposalBlock

Shared

  • Renamed CreateAndApplyProposalBlock to CreateProposalBlock
  • Added GetStateHash to UtilityUnitOfWork

Utility

  • Renamed CreateAndApplyProposalBlock to CreateProposalBlock
  • Added GetPrevBlockByzantineValidators and ProposalBlockNotSet errors
  • Instrumented CreateProposalBlock and ApplyBlock with log statements
  • Refactored functions for block creation and application to be more readable/modular
  • Added TODOs for future refactoring
  • Renamed u to uow for consistency
  • Added stateHash validation against proposalBlock
  • Added feature flag for stateHash validation (for testing purposes)
  • Updated tests accordingly

Testing

  • make develop_test; if any code changes were made
  • Docker Compose LocalNet; if any major functionality was changed or introduced
  • k8s LocalNet; if any infrastructure or configuration changes were made

Required Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added, or updated, godoc format comments on touched members (see: tip.golang.org/doc/comment)
  • I have tested my changes using the available tooling
  • I have updated the corresponding CHANGELOG

If Applicable Checklist

  • I have updated the corresponding README(s); local and/or global
  • I have added tests that prove my fix is effective or that my feature works
  • I have added, or updated, mermaid.js diagrams in the corresponding README(s)
  • I have added, or updated, documentation and mermaid.js diagrams in shared/docs/* if I updated shared/*README(s)

@deblasis deblasis added core Core infrastructure - protocol related consensus Consensus specific changes utility Utility specific changes persistence Persistence specific changes code health Nice to have code improvement labels Apr 4, 2023
@cr-gpt
Copy link

cr-gpt bot commented Apr 4, 2023

Seems you are using me but didn't get OPENAI_API_KEY seted in Variables for this repo. you could follow readme for more information

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

The changelog validation failed with the following output:
Missing changelog in module: consensus/

Missing changelog in module: shared/

Missing changelog in module: utility/

Changelog verification failed. See error messages for more detail.

Please update the relevant CHANGELOG.md files and ensure they follow the correct format.

@reviewpad
Copy link

reviewpad bot commented Apr 4, 2023

AI-Generated Pull Request Summary: This pull request introduces various changes to improve code consistency, readability, error handling, and logging across multiple files. The primary modification is refactoring the CreateAndApplyProposalBlock function into a new function called CreateProposalBlock, along with separating the mempool reaping logic into another function called reapMempool. Additional changes include updating the block.go file to handle Byzantine validators, renaming several functions and method calls, updating comments and TODOs, and introducing new error codes, messages, and error creation functions. Furthermore, there are updates to flow diagrams, sequence diagrams, and documentation in the PROTOCOL_STATE_HASH.md file. Finally, test cases have been modified, and new test cases have been added to ensure proper error handling.

@reviewpad reviewpad bot added the large label Apr 4, 2023
@cr-gpt
Copy link

cr-gpt bot commented Apr 4, 2023

Seems you are using me but didn't get OPENAI_API_KEY seted in Variables for this repo. you could follow readme for more information

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

The changelog validation failed with the following output:
Missing changelog in module: consensus/

Missing changelog in module: shared/

Missing changelog in module: utility/

Changelog verification failed. See error messages for more detail.

Please update the relevant CHANGELOG.md files and ensure they follow the correct format.

@deblasis deblasis marked this pull request as ready for review April 4, 2023 22:27
@reviewpad reviewpad bot requested a review from Olshansk April 4, 2023 22:28
@deblasis deblasis requested a review from dylanlott April 4, 2023 22:29
@deblasis deblasis added the gpt review Triggers a code review from https://github.com/anc95/ChatGPT-CodeReview label Apr 4, 2023
@reviewpad
Copy link

reviewpad bot commented Apr 4, 2023

AI-Generated Pull Request Summary: This pull request introduces updates and improvements to several files, primarily focusing on renaming the CreateAndApplyProposalBlock function to CreateProposalBlock and improving the transaction processing and error handling involved in creating a proposal block. Key changes include:

  1. Documentation updates in PROTOCOL_STATE_HASH.md, making flowcharts and descriptions consistent with the updated naming.
  2. Modifications to block_test.go, utility_module.go, utility/types/error.go, consensus/hotstuff_leader.go, consensus/e2e_tests/utils_test.go, and uow_leader.go primarily to accommodate the renaming of CreateAndApplyProposalBlock to CreateProposalBlock and handle error cases more gracefully.
  3. Introduction of several new functions for better modularity and readability, such as processTransactionsFromProposalBlock, reapMempool, and prevBlockByzantineValidators.
  4. Refactoring and restructuring of the ApplyBlock function and the addition of a new helper function for better transaction processing.
  5. Improvements in readability and maintainability within the block.go file, including renaming variables, adding log statements, and handling error cases more gracefully.

These changes help improve transaction processing, error handling, and maintainability in the creation of a proposal block and contribute to the overall robustness and efficiency of the system.

@deblasis
Copy link
Contributor Author

deblasis commented Apr 4, 2023

Sweet

@cr-gpt
Copy link

cr-gpt bot commented Apr 6, 2023

Seems you are using me but didn't get OPENAI_API_KEY seted in Variables for this repo. you could follow readme for more information

@github-actions github-actions bot dismissed stale reviews from themself April 6, 2023 23:20

The check succeeded, dismissing the review comment.

- Added `stateHash` validation against `proposalBlock`
- Added feature flag for `stateHash` validation (for testing purposes)
- Updated tests accordingly

## [0.0.0.34] - 2023-04-06

- Updated to reflect pools address changes
Copy link

Choose a reason for hiding this comment

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

Here's a brief review of the provided code patch:

  1. It seems that you are updating the project's changelog with a new version (0.0.0.35) and its main changes.
  2. You have renamed a function CreateAndApplyProposalBlock to CreateProposalBlock, which is clearer if it only creates proposal blocks without applying them.
  3. Two new error types were added: GetPrevBlockByzantineValidators and ProposalBlockNotSet. Make sure they are caught and handled correctly.
  4. Several log statements were added for instrumentation, this will help in debugging and understanding the application flow.
  5. Refactoring was done to improve readability and modularity of the code. This suggests a cleaner codebase but requires proper testing to ensure functionality hasn't been compromised.
  6. TODOs were added indicating additional refactoring plans. Be sure to follow up on these to continue improving the codebase.
  7. A variable was renamed u to uow for consistency. Ensure all references to the old name have been updated.
  8. stateHash validation against proposalBlock has been added, which should improve security for the block. However, make sure that no incorrect validations throw unexpected errors.
  9. A feature flag was introduced for stateHash validation for testing purposes. Remember to remove this when appropriate or decide whether to toggle it in production.
  10. Lastly, tests have been updated accordingly. Confirm that all tests still pass after the above changes have been made.

Overall, the patch seems focused on increasing code readability and improving functionality. Testing the updated code thoroughly, both automatically and manually, is critical to ensure correctness and stability. Additionally, prompt action on the TODOs mentioned would be ideal for continuous improvement.

@reviewpad
Copy link

reviewpad bot commented Apr 6, 2023

AI-Generated Summary: This pull request includes changes across multiple files, refactoring and updating the codebase for better readability, maintainability, and functionality. Key updates include:

  1. Splitting the CreateAndApplyProposalBlock function into separate CreateProposalBlock and ApplyBlock functions.
  2. Introducing a new method GetStateHash in the UtilityUnitOfWork interface, and updating various functions and tests to use it.
  3. Adding new error codes, error messages, and error handling to the codebase.
  4. Improved logging and variable naming throughout.
  5. Updating CHANGELOG.md and other documentation files to reflect the changes made in this pull request.
  6. Changes in import paths and refactoring of some functions for better organization.

Overall, this pull request enhances the code clarity, error handling, and modularization in the codebase, making it more maintainable and better for future development.

@deblasis
Copy link
Contributor Author

deblasis commented Apr 6, 2023

@Olshansk I believe I tackled everything

@deblasis deblasis requested a review from Olshansk April 6, 2023 23:23
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.

Can you just rerun tests & localnet on your machine to make sure that the failure in consensus/e2e_tests/state_sync_test.go was a one-off flaky issue?

Otherwise, just see my suggestion and :shipit:

## [0.0.0.48] - 2023-04-06

- Renamed `CreateAndApplyProposalBlock` to `CreateProposalBlock`

## [0.0.0.47] - 2023-04-06

- Updated to reflect pools address changes
Copy link
Member

Choose a reason for hiding this comment

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

This actually isn't bad

utility/unit_of_work/module.go Outdated Show resolved Hide resolved
Co-authored-by: Daniel Olshansky <olshansky@pokt.network>
@cr-gpt
Copy link

cr-gpt bot commented Apr 6, 2023

Seems you are using me but didn't get OPENAI_API_KEY seted in Variables for this repo. you could follow readme for more information

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

The changelog validation failed with the following output:
Latest date in consensus/doc/CHANGELOG.md is incorrect.
Latest: 2023-04-07, Current: 2023-04-06

Latest date in shared/CHANGELOG.md is incorrect.
Latest: 2023-04-07, Current: 2023-04-06

Latest date in utility/doc/CHANGELOG.md is incorrect.
Latest: 2023-04-07, Current: 2023-04-06

Changelog verification failed. See error messages for more detail.

Please update the relevant CHANGELOG.md files and ensure they follow the correct format.

@reviewpad
Copy link

reviewpad bot commented Apr 6, 2023

AI-Generated Summary: This pull request includes changes in multiple files related to the refactoring of blockchain and consensus code, improving readability and consistency. Key changes involve renaming the function CreateAndApplyProposalBlock to CreateProposalBlock, updating error codes, implementing new functions like GetStateHash and processTransactionsFromProposalBlock, and modifying tests to adapt to these changes. Additional updates include changes to the CHANGELOG.md, logging improvements, import updates, and renaming of an imported package alias. Overall, these modifications aim to enhance the code structure, testing scenarios, and error handling, while ensuring better debugging and tracing execution.

@cr-gpt
Copy link

cr-gpt bot commented Apr 7, 2023

Seems you are using me but didn't get OPENAI_API_KEY seted in Variables for this repo. you could follow readme for more information

- Update state_sync module with additional function definitions
- Update state_sync module with additional function definitions

## [0.0.0.41] - 2023-03-30

- Improve & simplify `utilityUnitOfWork` management
Copy link

Choose a reason for hiding this comment

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

Based on the given code patch, here's a brief code review:

  1. The changes in versioning and release notes are well-documented and clear.

  2. Renaming CreateAndApplyProposalBlock to CreateProposalBlock potentially reflects better separation of concerns in your application.

  3. Updating to use the new ApplyBlock signature and GetStateHash() function from utilityUnitOfWork ensures consistency across the project.

  4. Removing the duplicate import means the code will be cleaner and more efficient.

  5. Formatting inconsistencies are fixed by adding line breaks before and after listing updates for [0.0.0.42].

Overall, the changes appear beneficial and I don't see any obvious bugs or risks. However, it's important to ensure these changes are covered by appropriate tests and don't introduce unintended behavior throughout the project.

@github-actions github-actions bot dismissed their stale review April 7, 2023 00:03

The check succeeded, dismissing the review comment.

@reviewpad
Copy link

reviewpad bot commented Apr 7, 2023

AI-Generated Summary: This pull request introduces various changes across multiple files, primarily focusing on refactoring the CreateAndApplyProposalBlock function into two separate functions, CreateProposalBlock and ApplyBlock, as well as adding a new method GetStateHash() to the UtilityUnitOfWork interface. Other changes include updating tests and error handling, renaming variables and functions for consistency, enhancing logging, and updating the documentation and CHANGELOG.md file accordingly. Additionally, the pull request improves code organization, readability, and maintainability in various areas of the codebase.

@deblasis
Copy link
Contributor Author

deblasis commented Apr 7, 2023

Can you just rerun tests & localnet on your machine to make sure that the failure in consensus/e2e_tests/state_sync_test.go was a one-off flaky issue?

Otherwise, just see my suggestion and :shipit:

test.mp4

👍

@Olshansk
Copy link
Member

Olshansk commented Apr 7, 2023

giphy (2)

@deblasis deblasis merged commit c9f18a3 into main Apr 7, 2023
bryanchriswhite added a commit that referenced this pull request Apr 10, 2023
* pokt/main:
  [Utility][RPC][CLI] Querying governance parameters (Issue #619) (#622)
  [Persistence][Utility] Separate all CreateAndApply functions into more functional components - Issue #508 (#652)
  [Persistence][Utility] Pools Address hack removal + state accessor fix for params and flags (#654)
  [PERSISTENCE] SavePoints and Rollbacks design document (Issue #493) (#533)
  Update reviewpad.yml
  Added ChatGPT-CodeReview workflow (#649)
  Update reviewpad.yml
  Added default reviewpad.yml file (#648)
  [DevNet] tweaks for remote environments (#601)
  [Documentation] Swap validator and non-validator triggers when finished synching (#646)
  [Consensus] Configuration entry point state sync (#528)
bryanchriswhite added a commit to bryanchriswhite/pocket that referenced this pull request Apr 10, 2023
…p-modules

* pokt/main:
  [Utility][RPC][CLI] Querying governance parameters (Issue pokt-network#619) (pokt-network#622)
  [Persistence][Utility] Separate all CreateAndApply functions into more functional components - Issue pokt-network#508 (pokt-network#652)
  [Persistence][Utility] Pools Address hack removal + state accessor fix for params and flags (pokt-network#654)
  [PERSISTENCE] SavePoints and Rollbacks design document (Issue pokt-network#493) (pokt-network#533)
  Update reviewpad.yml
  Added ChatGPT-CodeReview workflow (pokt-network#649)
  Update reviewpad.yml
  Added default reviewpad.yml file (pokt-network#648)
  [DevNet] tweaks for remote environments (pokt-network#601)
  [Documentation] Swap validator and non-validator triggers when finished synching (pokt-network#646)
  [Consensus] Configuration entry point state sync (pokt-network#528)
bryanchriswhite added a commit that referenced this pull request Apr 12, 2023
…p-modules

* pokt/main:
  update pocket repo read.me (#667)
  Update reviewpad.yml
  [KEYBASE] Add improve comment on keybase config (#665)
  [E2E] Chore: Doc updates (#663)
  [E2E] Adds staking, unstaking, and sending tests (#653)
  [Utility][RPC][CLI] Querying governance parameters (Issue #619) (#622)
  [Persistence][Utility] Separate all CreateAndApply functions into more functional components - Issue #508 (#652)
  [Persistence][Utility] Pools Address hack removal + state accessor fix for params and flags (#654)
  [PERSISTENCE] SavePoints and Rollbacks design document (Issue #493) (#533)
  Update reviewpad.yml
  Added ChatGPT-CodeReview workflow (#649)
  Update reviewpad.yml
  Added default reviewpad.yml file (#648)
  [DevNet] tweaks for remote environments (#601)
  [Documentation] Swap validator and non-validator triggers when finished synching (#646)
  [Consensus] Configuration entry point state sync (#528)
bryanchriswhite added a commit that referenced this pull request Apr 12, 2023
…p-modules

* pokt/main:
  update pocket repo read.me (#667)
  Update reviewpad.yml
  [KEYBASE] Add improve comment on keybase config (#665)
  [E2E] Chore: Doc updates (#663)
  [E2E] Adds staking, unstaking, and sending tests (#653)
  [Utility][RPC][CLI] Querying governance parameters (Issue #619) (#622)
  [Persistence][Utility] Separate all CreateAndApply functions into more functional components - Issue #508 (#652)
  [Persistence][Utility] Pools Address hack removal + state accessor fix for params and flags (#654)
  [PERSISTENCE] SavePoints and Rollbacks design document (Issue #493) (#533)
  Update reviewpad.yml
  Added ChatGPT-CodeReview workflow (#649)
  Update reviewpad.yml
  Added default reviewpad.yml file (#648)
  [DevNet] tweaks for remote environments (#601)
  [Documentation] Swap validator and non-validator triggers when finished synching (#646)
  [Consensus] Configuration entry point state sync (#528)
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 consensus Consensus specific changes core Core infrastructure - protocol related gpt review Triggers a code review from https://github.com/anc95/ChatGPT-CodeReview persistence Persistence specific changes utility Utility specific changes waiting-for-review
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[Persistence][Utility] Separate all CreateAndApply functions into more functional components
3 participants