Skip to content

[Libp2p] Add libp2p module directories and helpers (part 1)#534

Merged
bryanchriswhite merged 38 commits intomainfrom
chore/libp2p-1
Mar 2, 2023
Merged

[Libp2p] Add libp2p module directories and helpers (part 1)#534
bryanchriswhite merged 38 commits intomainfrom
chore/libp2p-1

Conversation

@bryanchriswhite
Copy link
Copy Markdown
Collaborator

@bryanchriswhite bryanchriswhite commented Feb 22, 2023

Description

This is the first of a series of PRs split out from #500. Here we set up the new libp2p module directory structure and add crypto and identity / network helpers.

Issue

#347

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

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)

@bryanchriswhite bryanchriswhite added the p2p P2P specific changes label Feb 22, 2023
@bryanchriswhite bryanchriswhite self-assigned this Feb 22, 2023
@bryanchriswhite bryanchriswhite force-pushed the chore/libp2p-1 branch 3 times, most recently from 773daae to 2449b9f Compare February 22, 2023 12:45
@bryanchriswhite bryanchriswhite marked this pull request as ready for review February 22, 2023 12:46
@bryanchriswhite
Copy link
Copy Markdown
Collaborator Author

bryanchriswhite commented Feb 22, 2023

Changelog validation failure

I think this is a false positive caused by the changelog in question having no previous version (as it's new). To prove this locally:

  1. Apply the following diff by copy/pasting to a new file (e.g. ./patch):
diff --git i/libp2p/docs/CHANGELOG.md w/libp2p/docs/CHANGELOG.md
index fc69f1ad..8b10fe54 100644
--- i/libp2p/docs/CHANGELOG.md
+++ w/libp2p/docs/CHANGELOG.md
@@ -5,11 +5,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ## [Unreleased]
 
-## [0.0.0.0] - 2023-03-01
+## [0.0.0.1] - 2023-03-01
 
 - prepare pocket repo new libp2p module
 - add pocket / libp2p identity helpers
 - add url <--> multiaddr conversion helpers for use with libp2p (see: https://github.com/multiformats/go-multiaddr)
 - add `Multiaddr` field to `typesP2P.NetworkPeer`
 
+## [0.0.0.0] - 2023-03-01
+
 <!-- GITHUB_WIKI: changelog/libp2p -->
  1. Run the changelog validation hook to ensure it passes: bash ./.githooks/pre-receive $(git diff --stat --name-only pokt/main..HEAD)

@bryanchriswhite bryanchriswhite linked an issue Feb 22, 2023 that may be closed by this pull request
6 tasks
@bryanchriswhite

This comment was marked as outdated.

deblasis added a commit that referenced this pull request Feb 23, 2023
## Description

This PR updated our Github workflow to return the full output of failed
tests for easier debugging/troubleshooting.

It was raised by @bryanchriswhite here:
#534 (comment)


![image](https://user-images.githubusercontent.com/29378614/220946245-07865c91-f0eb-4564-a8e9-773926c11cd7.png)


And also probably related:


![image](https://user-images.githubusercontent.com/29378614/220948460-0f80797d-dff0-4823-bb43-fa12da59e968.png)


## Issue

N/A

## Type of change

Please mark the relevant option(s):

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

## List of changes

- updated `jq` 🪄 to return all the rows that match a failed test

## Testing

- [ ] `make develop_test`
- [ ]
[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

- [ ] 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](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)
Copy link
Copy Markdown
Collaborator

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

A few minor comments, but for the most part super clean and well compartmentalized as a separate PR. Appreciate making it easy for the reviewer

@bryanchriswhite

This comment was marked as outdated.

* pokt/main:
  [Tooling] Returning failed tests full output (#542)
  [Tooling] Update CLI to support key management (Issue #489) (#524)
strs []string
}

func (marshaler stringLogArrayMarshaler) MarshalZerologArray(arr *zerolog.Array) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Where is this being used?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is called by zerolog and is required by the zerolog.LogArrayMarshaler interface, which is the type of the second argument to zerolog.Evt#Array.

I don't have a strong opinions on doing it this way, this just seemed to me like the most appropriate way to convey the information available via our structured logging. I've simplified as you suggested and added comments so nobody else has to ask the same question. 😅

@Olshansk
Copy link
Copy Markdown
Collaborator

Olshansk commented Mar 1, 2023

@bryanchriswhite Going to take a look at this tomorrow, but I think it should be good to go after the next set of changes.

Copy link
Copy Markdown
Contributor

@okdas okdas left a comment

Choose a reason for hiding this comment

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

Thank you for leaving thorough comments in your code - that definitely helps me to understand what's going on! :)

return fmt.Errorf(errResolvePeerIPMsg, hostname, err)
}

func getPeerIP(hostname string) (net.IP, error) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Though having multiple A DNS records for the same hostname should not happen often in our case, I can see a scenario when nodes are provisioned behind a multi-zone LB, which is often a default for Kubernetes set up in clouds (I suppose they make more 🤑 that way).

Do you think there might be issues when the same node has a hostname that resolves to multiple IP addresses?

I assume PeerID has no correlation with Multiaddr. I suppose it should be fine if one PeerID has different addresses. Imagine a situation with multiple network interfaces, e.g. internet and local networks on one machine, both interfaces have different addresses in that case. But the same node can be exposed on both interfaces. In that case, (I assume) the PeerID stays the same, but other peers should be able to connect to it just fine even if IP addresses are different. Not sure if that makes sense, I'm just kind of fascinated by this topic and my guess is random address should work as long as packets flow correctly. :)

return fmt.Errorf(errResolvePeerIPMsg, hostname, err)
}

func getPeerIP(hostname string) (net.IP, error) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

puts us in the driver seat

Do you mean something like we could sort the IP addresses and always use the first one so all nodes in the network predictably connect to the same IP even if there are multiple A DNS records?

@gitguardian
Copy link
Copy Markdown

gitguardian bot commented Mar 1, 2023

⚠️ GitGuardian has uncovered 2 secrets following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secrets in your pull request
GitGuardian id Secret Commit Filename
5841025 Generic High Entropy Secret b694338 build/localnet/manifests/configs.yaml View secret
5841025 Generic High Entropy Secret b694338 build/config/genesis.json View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secrets safely. Learn here the best practices.
  3. Revoke and rotate these secrets.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

Our GitHub checks need improvements? Share your feedbacks!

@bryanchriswhite
Copy link
Copy Markdown
Collaborator Author

@Olshansk, @okdas thanks again for taking the time! 🙏

Apologies for changing things at the last minute, but as was surfaced in discussion with @okdas, we should be selecting a random record from the DNS response until we decide to support multiple IPs natively. As a result, There's a bit more code in getPeerIP than there was previously which collects the valid IPs before selecting one randomly.

I've added a test for the error case of getPeerIP where the resolution contained no records. I've also added a skipped test for the success cases of getPeerIP, skipped because to implement would require more time with net.Resolver and understanding how to get gomock to generate mocks for stdlib interfaces (e.g. net.Conn).

Copy link
Copy Markdown
Contributor

@okdas okdas left a comment

Choose a reason for hiding this comment

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

Thank you!

I am not 100% sure if you can merge the PR unless @Olshansk reviews again due to his prior review, maybe resolving all conversation can help? Otherwise, I should be able to bypass.

@bryanchriswhite bryanchriswhite dismissed Olshansk’s stale review March 2, 2023 20:10

Feedback resolved

@bryanchriswhite bryanchriswhite merged commit f03197f into main Mar 2, 2023
bryanchriswhite added a commit that referenced this pull request Mar 3, 2023
* main:
  [Libp2p] Add libp2p module directories and helpers (part 1) (#534)
  [P2P, Runtime] Update P2P & base config (part 2) (#535)
  [Utility] Foundational bugs, tests, code cleanup and improvements (2/3) (#550)
  [CONSENSUS] Find issue with sending metadata request (#548)
  [Tooling] SLIP-0010 HD Child Key Generation (#510)
bryanchriswhite added a commit that referenced this pull request Mar 3, 2023
## Description

This is another of a series of PRs split out from
#500. Here we add a new
implementation of `typesP2P.Network` in terms of libp2p abstractions,
utilizing the helpers which were added in #534.

## Issue

#347 

## Type of change

Please mark the relevant option(s):

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

## List of changes

- Added a new `typesP2P.Network` implementation to the `libp2p` module
directory
- Added embedded `modules.InitializableModule` to the P2P
`AddrBookProvider` interface so that it can be dependency injected as a
`modules.Module` via the bus registry.
- Added `PoktProtocolID` for use within the libp2p module or by public
API consumers

## 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
- [ ] 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
- [x] 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>
@bryanchriswhite bryanchriswhite deleted the chore/libp2p-1 branch March 3, 2023 12:39
func TestGetPeerIP_Success(t *testing.T) {
t.Skip("TODO: replace `net.DefaultResolver` with one which has a `Dial` function that returns a mocked `net.Conn` (see: https://pkg.go.dev/net#Resolver)")

//nolint:gocritic // commentedOutCode - Outlines the minimum requirements for disproving regression.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p2p P2P specific changes

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[P2P] Integrate LibP2P

4 participants