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

[Utility] Foundational bugs, tests, code cleanup and improvements (1 / 2) #503

Merged
merged 66 commits into from
Feb 14, 2023

Conversation

Olshansk
Copy link
Member

@Olshansk Olshansk commented Feb 9, 2023

Description

This is the first of several changes necessary to refactor and improve the utility module to enable implementation of future, more complex, interfaces.

Issue

Fixes #475

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

Changes

Utility

  • Add a Validatable type for basic validation
  • Split business logic specific to certain actors (e.g. validator reward, app relays, message handling) into separate files
  • Reduce the scope of functions and types that shouldn’t be exposed
  • Upgraded the actors tests - a lot went here to help with understanding what’s going on but it’s still just a start
  • Remove the Context struct; unnecessary abstraction
  • Added comments and guidance on message, transaction and signature validation
  • Added ITransaction, an interface for the Transaction protocol to help capture the functionality it adds to the core type

Code Confusion

  • Remove IUnstakingActor and use UnstakingActor directly. Guideline for removing future unnecessary types (e.g. TxResult)
  • Delineate between unstaking & unbonding in a few places throughout the codebase

Bugs

  • Avoid unstaking all actors when intending to UnstakeMsg paused actors only (major bug in persistence sql query)
  • tx.Equals was comparing the same transaction against itself (major bug)
  • Staking status enums in utility did not reflect the same protocol as in persistence (needs to be consolidated)

Code optimization

  • Avoid redundant byte <-> string conversions in several places
  • Avoid redundant bigInt <-> string conversions in several places

Code health

  • Add comments explaining the use/responsibility of various types
  • Consolidate BigInt/String converters used in other parts of the codebase
  • Consolidate some types used everywhere (e.g. actorTypes)
  • Reduce the code footprint of the codec package & add some TODOs
  • Removed unused double sign code (moved to [Consensus] Penalize validators for double signing #432 for reference)

Files focused on

utility

  • ├── account.go
  • ├── account_test.go
  • ├── actor.go
  • ├── actor_test.go
  • ├── application.go
  • ├── application_test.go
  • ├── block.go
  • ├── block_test.go
  • ├── context.go
  • ├── doc
  • │   ├── CHANGELOG.md
  • │   ├── PROTOCOL_RELAY.md
  • │   ├── PROTOCOL_SESSION.md
  • │   └── README.md
  • ├── gov.go
  • ├── gov_test.go
  • ├── message_handler.go
  • ├── message_test.go
  • ├── module.go
  • ├── module_test.go
  • ├── service
  • │   └── service.go
  • ├── session.go
  • ├── transaction.go
  • ├── transaction_test.go
  • ├── types
  • │   ├── constants.go
  • │   ├── error.go
  • │   ├── gov.go
  • │   ├── message.go
  • │   ├── message_staking.go
  • │   ├── message_test.go
  • │   ├── proto
  • │   │   ├── message.proto
  • │   │   ├── stake_status.proto
  • │   │   ├── transaction.proto
  • │   │   ├── tx_result.proto
  • │   │   └── utility_messages.proto
  • │   ├── relay_chain.go
  • │   ├── relay_chain_test.go
  • │   ├── signature.go
  • │   ├── transaction.go
  • │   ├── transaction_test.go
  • │   ├── tx_fifo_mempool.go
  • │   ├── tx_fifo_mempool_test.go
  • │   ├── tx_result.go
  • │   └── validatable.go
  • └── validator.go

Testing

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

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 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)

Copy link
Member Author

@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.

@deblasis I'm still thinking through a couple of your comments and will follow up if I have a better idea. In the meantime, left some responses and addressed some of the changes.

}

var _ Codec = &ProtoCodec{}
type ICodec proto.Message
Copy link
Member Author

Choose a reason for hiding this comment

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

I added it, but then actually did not end up using it as intended.

The idea was to show that some of our interfaces add functionality to serializable types based on the codec we're using.

	_ codec.ICodec = &Transaction{}

I'm removing it for now (since it is extra code that doesn't provide much benefit), but we should discuss that this is a very implicit design pattern others might not understand.

Adding the following in codec.go in the meantime:

// DOCUMENT: Some of the types through the code based (e.g. Transaction) are defined via serializable
// files (e.g. .proto files) and add functionality defined in go on top of it (e.g. ITransaction). This
// a very implicit design pattern that may be non-obvious to new developers.

shared/modules/types/README.md Outdated Show resolved Hide resolved
utility/context.go Outdated Show resolved Hide resolved
utility/context.go Outdated Show resolved Hide resolved
utility/types/message_staking.go Show resolved Hide resolved
utility/types/message_test.go Show resolved Hide resolved
shared/core/types/actor.go Outdated Show resolved Hide resolved
}

var _ Codec = &ProtoCodec{}
type ICodec proto.Message
Copy link
Member Author

Choose a reason for hiding this comment

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

After doing the above and running tests, I got the following errors:

utility/types/message.go:179:20: msg.ProtoReflect undefined (type Message has no field or method ProtoReflect)
utility/types/message.go:183:38: cannot use msg (variable of type Message) as type protoreflect.ProtoMessage in argument to codec.GetCodec().Marshal:

For now, I've renamed ICodec to CodecType so I can embed it in message but going to keep thinking.

Screenshot 2023-02-11 at 5 46 26 PM

persistence/block.go Outdated Show resolved Hide resolved
@jessicadaugherty jessicadaugherty changed the title [Utility] Foundational bugs, tests, code cleanup and improvements (1 / N) [Utility] Foundational bugs, tests, code cleanup and improvements (1 / 2) Feb 13, 2023
@Olshansk Olshansk requested a review from deblasis February 13, 2023 23:23
Copy link
Member Author

@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.

@deblasis PTAL (please take another look).

Left some replies in the resolved comments as well as kept a few ones open. Will also update the chanelogs.

@deblasis deblasis self-requested a review February 14, 2023 18:51
Copy link
Contributor

@deblasis deblasis left a comment

Choose a reason for hiding this comment

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

@Olshansk Olshansk merged commit c167ad4 into main Feb 14, 2023
@Olshansk Olshansk deleted the issues/475/utility_module_foundation branch February 14, 2023 23:24
bryanchriswhite added a commit that referenced this pull request Feb 20, 2023
* pokt/main:
  [Infra] KISS 3 - Cluster Manager [Merge me after #521] - (Issues: #490) (#522)
  Refactor/fix state sync logs (#515)
  [P2P] KISS 2 - Peer discovery [Merge me after #520] - (Issues: #416, #429) (#521)
  [Core] KISS 1 - Finite State Machine [Merge me first] - (Issue: #499) (#520)
  [CLI] Stake command bugfix (#518)
  [CLI] Cannot run make localnet_client_debug: Cannot initialise the keybase with the validator keys: Unable to find YAML file (#517)
  Fix the link shown by `make go_doc`
  Fixed duplicate GITHUB_WIKI tag
  [Documentation] Update Devlog Formatting (#512)
  [Docs & Bugs] Minor fixes post keybase changes (#513)
  [Utility] Foundational bugs, tests, code cleanup and improvements (1 / 2) (#503)
  [Tooling] Integrate Keybase w/ CLI (Issue #484 ) (#501)
  update devlog2.md
  update devlog2.md
  Update devlog1.md
bryanchriswhite added a commit that referenced this pull request Feb 20, 2023
* pokt/main:
  [Infra] KISS 3 - Cluster Manager [Merge me after #521] - (Issues: #490) (#522)
  Refactor/fix state sync logs (#515)
  [P2P] KISS 2 - Peer discovery [Merge me after #520] - (Issues: #416, #429) (#521)
  [Core] KISS 1 - Finite State Machine [Merge me first] - (Issue: #499) (#520)
  [CLI] Stake command bugfix (#518)
  [CLI] Cannot run make localnet_client_debug: Cannot initialise the keybase with the validator keys: Unable to find YAML file (#517)
  Fix the link shown by `make go_doc`
  Fixed duplicate GITHUB_WIKI tag
  [Documentation] Update Devlog Formatting (#512)
  [Docs & Bugs] Minor fixes post keybase changes (#513)
  [Utility] Foundational bugs, tests, code cleanup and improvements (1 / 2) (#503)
  [Tooling] Integrate Keybase w/ CLI (Issue #484 ) (#501)
  update devlog2.md
  update devlog2.md
  Update devlog1.md
Olshansk added a commit that referenced this pull request Feb 28, 2023
…3) (#550)

## Description

The second of three changes necessary to refactor and improve the utility module to enable implementation of future, more complex, interfaces.

While the list of changes in #503 was more bug & testing focused, this PR was more readability & documentation focused in preparation for M3.

## Issue

Fixes #504

## Type of change

Please mark the relevant option(s):

- [ ] New feature, functionality or library
- [x] Bug fix
- [x] Code health or cleanup
- [x] Major breaking change
- [ ] Documentation
- [ ] Other <!-- add details here if it a different type of change -->

## List of changes

- Fixed bug where we were not removing txs from the mempool of replicas
- Improved the readability of the `Block` lifecycle and `Message` validation
- Replace unnecessary functions in such as `Store()`, `getStoreAndHeight()` and a few otherwise
- Moved the `Transaction` proto to the shared module
- Added documentation to `TxResult` result and removed `DefaultTxResult` and 
- Added extensive documentation to functions involved in the Block lifecycle
- Removed unnecessary fields from the `BlockHeader`
- Renamed `GenericParam` to `ServiceURL`
- Consolidated `StakeStatus` in the shared package
- Renamed governance parametesr related to rate limitting Applications
- Renamed `applyTx` to `hydrateTx` and added documentation on its functionality

## Testing

- [x] `make develop_test`
- [x] [LocalNet](https://github.com/pokt-network/pocket/blob/main/docs/development/README.md) w/ all of the steps outlined in the `README`

## Required 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] 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](https://mermaid-js.github.io) diagrams in the corresponding README(s)
- [ ] I have added, or updated, documentation and [mermaid.js](https://mermaid-js.github.io) diagrams in `shared/docs/*` if I updated `shared/*`README(s)

---

Co-authored-by: Alessandro De Blasis <alex@deblasis.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working - expected behaviour is incorrect core Core infrastructure - protocol related documentation Improvements or additions to documentation utility Utility specific changes
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[Utility] Utility Module Foundation - Part 1 / 2
2 participants