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

[Core] KISS 1 - Finite State Machine [Merge me first] - (Issue: #499) #520

Merged
merged 51 commits into from
Feb 17, 2023

Conversation

deblasis
Copy link
Contributor

@deblasis deblasis commented Feb 16, 2023

Description

This PR has been extracted from #491 and is, hopefully, more digestible from a code-review and scope point of view.

In a nutshell:

  • It introduces the a Finite State Machine that is meant to govern the internal state, transitions and events
  • It includes a refactoring of our module initialization pattern using functional options (https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis)
  • It improves the module registration with a first class... you might have guessed it: ModulesRegistry
  • It reduces boilerplate code making our modules more DRY with the introduction of base_modules that provide basic functionality (that can still be customized/extended when needed)

Issue

Fixes #499

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

In a nutshell:

  • It introduces the a Finite State Machine that is meant to govern the internal state, transitions and events
  • It includes a refactoring of our module initialization pattern using functional options (https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis)
  • It improves the module registration with a first class... you might have guessed it: ModulesRegistry
  • It reduces boilerplate code making our modules more DRY with the introduction of base_modules that provide basic functionality (that can still be customized/extended when needed)

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)

@deblasis deblasis added core Core infrastructure - protocol related p2p P2P specific changes consensus Consensus specific changes code health Nice to have code improvement labels Feb 16, 2023
@deblasis deblasis self-assigned this Feb 16, 2023
@deblasis deblasis marked this pull request as ready for review February 16, 2023 20:28
@deblasis deblasis requested a review from Olshansk February 16, 2023 20:55
@deblasis deblasis changed the title [Core] KISS - Finite State Machine [Core] KISS - Finite State Machine [Merge me first] - (Issue: #499) Feb 16, 2023
@deblasis deblasis changed the title [Core] KISS - Finite State Machine [Merge me first] - (Issue: #499) [Core] KISS 1 - Finite State Machine [Merge me first] - (Issue: #499) Feb 17, 2023
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.

Left a few comments/suggestions but nothing blocking. Approving so we can get the ⛵ moving.

This was VERY easy to read and review. I know it was painful, but truly appreciate it!!

consensus/e2e_tests/utils_test.go Outdated Show resolved Hide resolved
consensus/e2e_tests/utils_test.go Show resolved Hide resolved
func (m *consensusModule) SetBus(pocketBus modules.Bus) {
m.bus = pocketBus
m.IntegratableModule.SetBus(pocketBus)
Copy link
Member

Choose a reason for hiding this comment

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

Since we're embedding IntegradbleModule, you should be able to use pocketBus directly

Screenshot 2023-02-16 at 7 53 32 PM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Your example is not representative of the scenario.
In here we are overloading something that's handled already in the embedded struct.

If I did what you are suggesting I guess we would have this 🤔:
image

Let's play dumb and try it out...
Actually the behaviour is even weirder:

overloading.mp4

nothing happens!

If I try to "walk my way into the stack"... it stops there, suggesting that my solution seems to be the right approach.

overloading2.mp4

If you wanna play along:
https://go.dev/play/p/s8ncxTVMMp6

Copy link
Member

Choose a reason for hiding this comment

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

Okay, I understand what I was missing and why you're solution works.

However, now I'm trying to understand:

  1. We're not calling the parent's foo function (bey default)
  2. We're not entering an infinite recursion

I can understand why (1) is not happening, but without researching, this makes me feel that the playground abstracts (2) away for us.

Screenshot 2023-02-17 at 10 47 53 AM

runtime/bus.go Outdated Show resolved Hide resolved
shared/modules/doc/README.md Show resolved Hide resolved
shared/core/types/states.go Outdated Show resolved Hide resolved
shared/modules/module.go Show resolved Hide resolved
state_machine/module.go Show resolved Hide resolved
state_machine/docs/README.md Show resolved Hide resolved
state_machine/docs/README.md Outdated Show resolved Hide resolved
@deblasis deblasis merged commit d7060b1 into main Feb 17, 2023
@deblasis deblasis deleted the issue/499-fsm branch February 17, 2023 10:20
deblasis added a commit that referenced this pull request Feb 17, 2023
…429) (#521)

## Description

This PR has been extracted from
#491 and is, hopefully, more
digestible from a code-review and scope point of view.

The main goal is to remove hardcoded nodes and move towards a more
dynamic environment.

It's also highlighting the potential entry points for subsequent P2P
work

The code leverages the abstractions added recently
(`currentHeightProvider` and `addressBookProvider`) to fetch the data
from an RPC endpoint.

## Issue

Fixes #416
Fixes #429

## Type of change

Please mark the relevant option(s):

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

## List of changes

### CLI

- Updated CLI to use to source the address book and the current height
from the RPC server leveraging the `rpcAddressBookProvider` and
`rpcCurrentHeightProvider` respectively and the `bus` for dependency
injection

### P2P

- Modules embed `base_modules.IntegratableModule` and
`base_modules.InterruptableModule` for DRYness
- Deprecated `debugAddressBookProvider`
- Added `rpcAddressBookProvider` to source the address book from the RPC
server
- Leveraging `bus` for dependency injection of the `addressBookProvider`
and `currentHeightProvider`
- Deprecated `debugCurrentHeightProvider`
- Added `rpcCurrentHeightProvider` to source the current height from the
RPC server
- Fixed raintree to use the `currentHeightProvider` instead of consensus
(that was what we wanted to avoid in the first place)
- Added `getAddrBookDelta` to calculate changes to the address book
between heights and update the internal state and componentry
accordingly
- Reacting to `ConsensusNewHeightEventType` to update the address book 
- Updated tests

### RPC

- Updated RPC to expose the node's address book via GET
/v1/p2p/staked_actors_address_book


## 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`

<!-- REMOVE this comment block after following the instructions
 If you added additional tests or infrastructure, describe it here.
 Bonus points for images and videos or gifs.
-->

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

---------

Signed-off-by: Alessandro De Blasis <alex@deblasis.net>
Co-authored-by: Dmitry K <okdas@pm.me>
Co-authored-by: Dmitry Knyazev <okdas@users.noreply.github.com>
Co-authored-by: Daniel Olshansky <olshansky@pokt.network>
Co-authored-by: Daniel Olshansky <olshansky.daniel@gmail.com>
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
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 p2p P2P specific changes
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[Core] Node finite state machine
2 participants