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

[P2P] refactor: peerstore provider (part 1) #804

Merged
merged 42 commits into from
Jun 13, 2023

Conversation

bryanchriswhite
Copy link
Contributor

@bryanchriswhite bryanchriswhite commented Jun 5, 2023

Description

  1. Simplify PeerstoreProvider interface
  2. Extend it to support retrieval of the unstaked actor peerstore
  3. Implement the extended interface in persistencePeerstoreProvider

Before

classDiagram 

class InterruptableModule {
    <<interface>>
    Start() error
    Stop() error
}
class IntegratableModule {
    <<interface>>
    +SetBus(bus Bus)
    +GetBus() Bus
}
class InitializableModule {
    <<interface>>
    +GetModuleName() string
    +Create(bus Bus, opts ...Option) (Module, error)
}
class Module {
    <<interface>>
}

Module --|> InitializableModule
Module --|> IntegratableModule
Module --|> InterruptableModule


class PeerstoreProvider {
    <<interface>>
    +GetStakedPeerstoreAtHeight(height int) (Peerstore, error)
    +GetP2PConfig() *P2PConfig
}

class persistencePeerstoreProvider

class rpcPeerstoreProvider

persistencePeerstoreProvider --|> PeerstoreProvider

rpcPeerstoreProvider --|> PeerstoreProvider
PeerstoreProvider --|> Module
Loading

After

classDiagram 

class IntegratableModule {
    <<interface>>
    +GetBus() Bus
    +SetBus(bus Bus)
}

class PeerstoreProvider {
    <<interface>>
    +GetStakedPeerstoreAtHeight(height int) (Peerstore, error)
    +GetUnstakedPeerstore() (Peerstore, error)
}

class persistencePeerstoreProvider
class rpcPeerstoreProvider
class p2pModule

class unstakedPeerstoreProvider {
    <<interface>>
    +GetUnstakedPeerstore() (Peerstore, error)
}

persistencePeerstoreProvider --|> PeerstoreProvider
persistencePeerstoreProvider --> p2pModule : from Bus
rpcPeerstoreProvider --> p2pModule : from Bus
p2pModule --|> unstakedPeerstoreProvider

rpcPeerstoreProvider --|> PeerstoreProvider
rpcPeerstoreProvider --|> Module
PeerstoreProvider --|> IntegratableModule

class Module {
    <<interface>>
}

Module --|> InitializableModule
Module --|> IntegratableModule
Module --|> InterruptableModule
Loading

Issue

Realted:

Dependants:

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

  • Replaced embedded modules.Module with simpler modules.IntegratableModule in PeerstoreProvider interface
  • Removed unused PeerstoreProvider#GetP2PConfig() method
  • Added PeerstoreProvider#GetUnstakedPeerstore() method
  • Added p2pPeerstoreProvider implementation of PeerstoreProvider interface
  • Added Factory generic type

Testing

  • make develop_test; if any code changes were made
  • make test_e2e on k8s LocalNet; if any code changes were made
  • e2e-devnet-test passes tests on DevNet; if any code was changed
  • 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)

@bryanchriswhite bryanchriswhite added the p2p P2P specific changes label Jun 5, 2023
@bryanchriswhite bryanchriswhite self-assigned this Jun 5, 2023
@reviewpad reviewpad bot added the small Pull request is small label Jun 5, 2023
@codecov

This comment was marked as off-topic.

@bryanchriswhite
Copy link
Contributor Author

bryanchriswhite commented Jun 5, 2023

I threw together a mindmap of my initial thinking, which was mainly focusd on whether this new API should be a debug-only thing (as it's being used in a "debug CLI" scenario). TLDR; I think "no" is the answer I landed on (plus some additional thinking):

mindmap
Q: should p2p peerstore provider be debug only?
    NO
        REASONING
            Will likely fit better with future versions / refactors
                r1(**Perhaps it would and/or already does make sense to split PeerstoreProvider into StakedPeerstoreProvider and UnstakedPeerstoreProvider)
        CONSEQUENCES
            c1[MUST design a non-debug way to access p2p module's peerstores]
                eg[e.g.: add GetUnstakedPeerstore method to modules.P2PModule]
                    Does this fight against peerstore provider / modular design?
                        YES because...
                            p[provides multiple ways to access the same thing: un/staked-actor-router peerstore]
                        NO because...
                            allows any module to get either peerstore without having to know anything about p2p module
                            no other single module can support this interface
                                justified by the need in the CLI
                    Alternatives
                        ?
            Makes Peerstore interface type "module shared"; i.e. it must be moved to another package avoid potential import cycles
            w[WORKAROUND: in #804, I'm working around the need for this change by defining a consumer-side interface which I assert that the P2P module implements, in addition to its module interface]

    YES
        REASONING
            r1[Only currently needed in a low-level / debug scenarios]
        CONSEQUENCES
            c1[Simpler implementation; no need for PeerstoreProvider interface refactor #804]
            c2[Harder to maintain and more complex to reason about; would likely rely on build tags]
Loading

** Here's what splitting PeerstoreProvider into StakedPeerstoreProvider and UnstakedPeerstoreProvider would look like:

classDiagram 

class IntegratableModule {
    <<interface>>
    +SetBus(bus Bus)
    +GetBus() Bus
}

class PeerstoreProvider {
    <<interface>>
    
}

class StakedPeerstoreProvider {
    <<interface>>
    +GetStakedPeerstoreAtHeight(height int) (Peerstore, error)
}

class UnstakedPeerstoreProvider {
    <<interface>>
    +GetUnstakedPeerstore() (Peerstore, error)
}

class persistencePeerstoreProvider
class rpcPeerstoreProvider
class p2pPeerstoreProvider {
  -persistencePeerstoreProvider
  -p2pModule P2PModule
}
class p2pModule

p2pPeerstoreProvider --o p2pModule
p2pPeerstoreProvider --* persistencePeerstoreProvider
p2pPeerstoreProvider --|> PeerstoreProvider

rpcPeerstoreProvider --|> StakedPeerstoreProvider
persistencePeerstoreProvider --|> StakedPeerstoreProvider

PeerstoreProvider --* StakedPeerstoreProvider
PeerstoreProvider --* UnstakedPeerstoreProvider

PeerstoreProvider --|> IntegratableModule
StakedPeerstoreProvider --|> IntegratableModule
UnstakedPeerstoreProvider --|> IntegratableModule
Loading

@bryanchriswhite bryanchriswhite force-pushed the refactor/peerstore-provider branch from 9209358 to 968be5f Compare June 5, 2023 11:01
@reviewpad reviewpad bot added medium Pull request is medium and removed small Pull request is small labels Jun 5, 2023
@bryanchriswhite bryanchriswhite force-pushed the refactor/peerstore-provider branch from 968be5f to 4bc605a Compare June 5, 2023 11:23
@bryanchriswhite bryanchriswhite changed the base branch from feat/kad-peer-discovery to main June 5, 2023 11:23
@reviewpad reviewpad bot added large Pull request is large medium Pull request is medium and removed medium Pull request is medium large Pull request is large labels Jun 5, 2023
@bryanchriswhite bryanchriswhite marked this pull request as ready for review June 5, 2023 12:03
Copy link
Contributor

@dylanlott dylanlott left a comment

Choose a reason for hiding this comment

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

First round feedback, waiting for E2E test results 👍


p2pModule := bus.GetP2PModule()
if p2pModule == nil {
return nil, fmt.Errorf("p2p module is not registered to bus and is required")
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: consider passing the bus to the Errrof for debugging purposes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The bus doesn't implement Stringer, what do you expect/want the DX to look/feel like?

Copy link
Member

Choose a reason for hiding this comment

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

☝️ The bus is just a point to our "DI framework" and "pubsub" so curious what you had in mind for this @dylanlott?

shared/modules/factory.go Outdated Show resolved Hide resolved
shared/CHANGELOG.md Show resolved Hide resolved
shared/modules/factory.go Outdated Show resolved Hide resolved
…ider

* pokt/main:
  Consensus/readme (#777)
  chore: add `--build-tags` flag to `go_lint` make target (#807)
  [Core] Deploying all-the-protocol-actors (#710)
  Add github wiki tag to devlog8
  Add README for Devlog8 for iteration17 (#805)
@bryanchriswhite bryanchriswhite force-pushed the refactor/peerstore-provider branch from b802e1e to 2489b92 Compare June 8, 2023 15:37
@bryanchriswhite bryanchriswhite requested a review from Olshansk June 8, 2023 15:46
p2p/providers/peerstore_provider/rpc/provider.go Outdated Show resolved Hide resolved
p2p/providers/peerstore_provider/persistence/provider.go Outdated Show resolved Hide resolved
p2p/providers/peerstore_provider/persistence/provider.go Outdated Show resolved Hide resolved
p2p/providers/peerstore_provider/rpc/provider.go Outdated Show resolved Hide resolved
shared/modules/factory.go Show resolved Hide resolved
@bryanchriswhite bryanchriswhite force-pushed the refactor/peerstore-provider branch 4 times, most recently from 0749b80 to 4589585 Compare June 12, 2023 12:37
@bryanchriswhite bryanchriswhite force-pushed the refactor/peerstore-provider branch from 4589585 to 22ff0fd Compare June 12, 2023 12:55
@bryanchriswhite bryanchriswhite requested a review from Olshansk June 12, 2023 13:08
_ persistencePStoreProviderFactory = &persistencePeerstoreProvider{}
)

type persistencePStoreProviderOption func(*persistencePeerstoreProvider)
Copy link
Member

Choose a reason for hiding this comment

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

On the topic of "not being afraid to change everything", take into consideration that maybe "providers" aren't the best approach with our bus based system.

Not making a comment on removing/extending them, but just sharing that it is not set in stone so don't feel constrained.

(cherry picked from commit 5254967bbe067e30c02fb63d40bc263f3d6def22)
@bryanchriswhite bryanchriswhite merged commit 9cb0ee9 into main Jun 13, 2023
bryanchriswhite added a commit that referenced this pull request Jun 13, 2023
* pokt/main:
  [P2P] refactor: peerstore provider (part 1) (#804)
@bryanchriswhite bryanchriswhite deleted the refactor/peerstore-provider branch June 13, 2023 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
e2e-devnet-test Runs E2E tests on devnet medium Pull request is medium p2p P2P specific changes push-image Build and push a container image on non-main builds waiting-for-review
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants