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

[TECHDEBT] [P2P] integration with persistence for addressBook management - (Issue #271) #374

Merged
merged 72 commits into from
Dec 15, 2022

Conversation

deblasis
Copy link
Contributor

@deblasis deblasis commented Dec 5, 2022

Description

This PR is a stepping stone for the removal of the ValidatorMap.
Specifically it allows us to use per-Height addressBook and lays the ground for churn management.
Right before a new height is reached, the addressBook is propagated via a message on the Bus so that other interested modules can handle it. This part is out-of-scope for this PR and will be covered later on in a specific issue, unless differently agreed during code-review.

Also, this PR tends to the TODO:

mempool map[uint64]struct{} // TODO (#278) replace map implementation (can grow unbounded)

Issue

Fixes #271

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
    • Consolidated number of validators in tests in a single constant: numValidators
    • Fixed typo in make test_consensus_concurrent_tests so that we can run the correct test matrix
    • Using GetBus() instead of bus wherever possible
  • P2P
    • mempool cap is now configurable via P2PConfig. Tests implement the mock accordingly.
    • Introduced the concept of a addrbookProvider that abstracts the fetching and the mapping from Actor to NetworkPeer
    • Temporary hack to allow access to the addrBook to the debug client (will be removed in an upcoming PR already in the works for issues #203 and #331)
    • Transport related functions are now in the transport package
    • Updated tests to source the addrBook from the addrbookProvider and therefore Persistence
    • Updated Raintree network constructur with dependency injection
    • Updated stdNetwork constructur with dependency injection
    • Improved documentation for the `peersManager
    • Raintree mempool cannot grow unbounded anymore. It's now bounded by a constant limit and when new nonces are inserted the oldest ones are removed.
      Olshansk marked this conversation as resolved.
      Show resolved
    • Raintree is now capable of fetching the address book for a previous height and to instantiate an ephemeral peersManager with it.
  • Persistence
    • Moved Actor related getters from genesis.go to actor.go
    • Added GetAllStakedActors() that returns all Actors
  • Shared
    • Added GetMaxMempoolCount

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 p2p P2P specific changes code health Nice to have code improvement labels Dec 5, 2022
@deblasis deblasis requested a review from Olshansk December 5, 2022 01:41
@deblasis deblasis self-assigned this Dec 5, 2022
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.

@deblasis Left a few comments, and the integration of consensus with persistence is great, but I think I may have led you down the wrong path.

  • When we're doing something like consensus, the proposer does a direct send (address forwarded to P2P and P2P resolves it).

  • When we're doing a structured gossip (where every staked actor has the same view of all the addresses on the network), the P2P module retrieves that list from persistence, and is then responsible for resolving addresses to IPs. When an address doesn't resolve is when we need to start looking at our redundancy/cleanup/adjust/resent layers

  • This is making me think that in the case of full nodes, there might also be a a need for random gossip (increase data availability, but still need to mull on it).


Overall, given the comments, do you see a need for the broadcast events introduced here?

consensus/consensus_tests/utils_test.go Outdated Show resolved Hide resolved
consensus/consensus_tests/utils_test.go Outdated Show resolved Hide resolved
consensus/leader_election/module.go Outdated Show resolved Hide resolved
consensus/leader_election/module.go Outdated Show resolved Hide resolved
consensus/pacemaker.go Outdated Show resolved Hide resolved
p2p/module.go Outdated Show resolved Hide resolved
p2p/module.go Outdated Show resolved Hide resolved
p2p/raintree/network.go Outdated Show resolved Hide resolved
shared/messaging/proto/addressbook_at_height.proto Outdated Show resolved Hide resolved
shared/node.go Outdated Show resolved Hide resolved
p2p/addrbook_provider/getter.go Outdated Show resolved Hide resolved
p2p/addrbook_provider/getter.go Outdated Show resolved Hide resolved
p2p/addrbook_provider/getter.go Outdated Show resolved Hide resolved
p2p/addrbook_provider/getter.go Outdated Show resolved Hide resolved
p2p/addrbook_provider/getter.go Outdated Show resolved Hide resolved
runtime/defaults/defaults.go Outdated Show resolved Hide resolved
p2p/module.go Outdated
return fmt.Errorf("failed to cast message to BeforeHeightChangedEvent")
}

// DISCUSS (https://github.com/pokt-network/pocket/pull/374#issuecomment-1341350786): decide if we want a pull or push model for integrating with persistence
Copy link
Member

Choose a reason for hiding this comment

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

To quote you previous message:

Where would this function be called currently? I would say that if it's not relevant to the scope of this issue we shouldn't do it here. Sounds like scope creep a little bit. No?

I'm personally not a huge fan because these events were out of scope and are not being used, though I can see where your head is at.

If I were to introduce a new event, I'd probably create a NewViewEvent(height, round) and/or NewHeight(height) because I can only speculate how we'd use BeforeNewHeightEvent right now and the cost to add it is low.

I don't want this to continue being a blocker, but not a fan. Let's do this:

  1. If you feel strongly that BeforeNewHeightEvent and HeightChangedEvent events will be useful, let's keep it as is.
  2. If you're not sure, let's do one of the following:
    2.1. Remove them altogether
    2.2 Just add a NewViewEvent (per my suggestions)

consensus/pacemaker.go Outdated Show resolved Hide resolved
p2p/types/addr_book.go Show resolved Hide resolved
persistence/genesis.go Outdated Show resolved Hide resolved

// IMPROVE: This is a proof of concept. Ideally we should have a single query that returns all actors.
func (p PostgresContext) GetAllStakedActors(height int64) (actors []modules.Actor, err error) {
actors = make([]modules.Actor, 0)
Copy link
Member

Choose a reason for hiding this comment

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

if we don't initialize this, does it break?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, well, good to know! Thanks @Olshansk 🙏

https://go.dev/play/p/GjBg0QuZEbB

image
image

Nice

Copy link
Member

Choose a reason for hiding this comment

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

200w

persistence/genesis.go Outdated Show resolved Hide resolved
persistence/genesis.go Outdated Show resolved Hide resolved
p2p/raintree/peers_manager.go Show resolved Hide resolved
p2p/addrbook_provider/persistence.go Show resolved Hide resolved
@Olshansk
Copy link
Member

@deblasis Sorry for hom many back & forths this one is taking, but it's looking better with every iteration, and thank you for bearing!

@deblasis
Copy link
Contributor Author

@deblasis Sorry for hom many back & forths this one is taking, but it's looking better with every iteration, and thank you for bearing!

It's all good @Olshansk ! It's all part of the process. I should be the one apologizing if you think about it.

I'll address your comments and re-request review later today. 🙏

@deblasis
Copy link
Contributor Author

I have removed the events, addressed comments and it's ready for another pass. Fewer things to look at I guess. We are getting there.

When you are happy I'll update the CHANGELOGs

@deblasis deblasis requested a review from Olshansk December 14, 2022 22:45
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.

LGTM, let's just update the CHANGELOG and we're good to go

p2p/raintree/utils_test.go Outdated Show resolved Hide resolved
p2p/addrbook_provider/persistence.go Outdated Show resolved Hide resolved
@deblasis deblasis requested a review from Olshansk December 15, 2022 01:28
@deblasis
Copy link
Contributor Author

@Olshansk CHANGELOGs updated

@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.0.1] - 2022-12-14

- Added `DefaultP2PMempoolMaxNonceCount`
Copy link
Member

Choose a reason for hiding this comment

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

Optional: Rename this to DefaultP2PMempoolMaxCount instead DefaultP2PMempoolMaxNonceCount to match the interface name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

I see your DefaultP2PMempoolMaxCount and I am going all-in with DefaultP2PMaxMempoolCount since the interface method is called GetMaxMempoolCount

MichaelCeraMollysGameGIF

Copy link
Member

Choose a reason for hiding this comment

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

monkey-call

@deblasis deblasis merged commit 1e83081 into main Dec 15, 2022
@Olshansk Olshansk deleted the issue/271-p2p-persistence-addrbook-management_l branch December 15, 2022 06:00
deblasis added a commit that referenced this pull request Dec 16, 2022
… - (Issue #270) (#378)

## Description

This PR builds on top of #374 (the base branch is not `main` in order to
highlight the delta of the changes) in order to tend to the TECHDEBT
TODOs listed in #270

## Issue

Fixes #270 

## Type of change

Please mark the relevant option(s):

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

## List of changes

- Consensus
- `LeaderElectionModule`'s `electNextLeaderDeterministicRoundRobin` now
uses `Persistence` to access the list of validators instead of the
static `ValidatorMap`.
  - Updated tests (mock configs) accounting for the updated logic
- P2P
  - `ValidatorMapToAddrBook` renamed to `ActorToAddrBook`
  - `ValidatorToNetworkPeer` renamed to `ActorToNetworkPeer`

## 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`
<!--
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: Daniel Olshansky <olshansky@pokt.network>
Olshansk added a commit that referenced this pull request Dec 16, 2022
… - (Issue #270) (#378)

This PR builds on top of #374 (the base branch is not `main` in order to
highlight the delta of the changes) in order to tend to the TECHDEBT
TODOs listed in #270

Fixes #270

Please mark the relevant option(s):

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

- Consensus
- `LeaderElectionModule`'s `electNextLeaderDeterministicRoundRobin` now
uses `Persistence` to access the list of validators instead of the
static `ValidatorMap`.
  - Updated tests (mock configs) accounting for the updated logic
- P2P
  - `ValidatorMapToAddrBook` renamed to `ActorToAddrBook`
  - `ValidatorToNetworkPeer` renamed to `ActorToNetworkPeer`

- [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`
<!--
If you added additional tests or infrastructure, describe it here.

Bonus points for images and videos or gifs.
-->

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

- [ ] 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: Daniel Olshansky <olshansky@pokt.network>
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 p2p P2P specific changes
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[TECHDEBT] [P2P] integration with persistence for addressBook management
2 participants