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] KISS 4 - Basic nodes bootstrapping [Merge me after #522] - (Issue: #498) #523

Merged
merged 262 commits into from
Feb 20, 2023

Conversation

deblasis
Copy link
Contributor

Description

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

This simply adds entrypoints and basic logic for node bootstrapping leveraging the finite state machine

Issue

Fixes #498

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

  • Ability to fetch an addressbook from a bootstrap node(s) (by convention the first validator in LocalNet)
  • It's possible to override bootstrap nodes via CLI flag

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 self-assigned this Feb 17, 2023
@deblasis deblasis linked an issue Feb 17, 2023 that may be closed by this pull request
13 tasks
p2p/event_handler.go Outdated Show resolved Hide resolved
}
}
if !isSelfInAddrBook(m.address, addrBook) {
m.logger.Warn().Msg("Self address not found in addresbook, advertising")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

https://github.com/pokt-network/pocket/pull/491/files#r1108018541

WHy do we only advertise if we're not in the address book?

Good question. It's because the nodes are created with a genesis and if you are node 005+ you have the first 4 but not self. It's something we need to figure out.

Copy link
Member

Choose a reason for hiding this comment

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

  1. We might end up moving the addr book bootstrapping to a config file rather than genesis.
  2. Unrelated to (1), there's no harm to advertise even if some part of the network is already aware of your existence

p.logger.Info().Bool("TODO", true).Msg("Advertise self to network")

cc @bryanchriswhite

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed

p2p/event_handler.go Show resolved Hide resolved
runtime/defaults/defaults.go Outdated Show resolved Hide resolved
p2p/module.go Outdated Show resolved Hide resolved
p2p/module.go Outdated
func isValidHostnamePort(str string) bool {
pattern := regexp.MustCompile(`^(https?)://([a-zA-Z0-9.-]+):(\d{1,5})$`)
matches := pattern.FindStringSubmatch(str)
if len(matches) != 4 {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if len(matches) != 4 {
if matches != nil || len(matches) != 4 {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's redundant since the nil case in included in "not len(4)"

nill := []string(nil)
if len(nill) != 4 {
    fmt.Println("not 4")
}

Prints not 4

p2p/module.go Outdated
if len(matches) != 4 {
return false
}
protocol := matches[1]
Copy link
Member

Choose a reason for hiding this comment

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

It's not zero indexisble?

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 0th index is the (outermost) group that matches the whole regex

Copy link
Contributor Author

Choose a reason for hiding this comment

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

More context:

https://pkg.go.dev/regexp#Regexp.FindStringSubmatch

If 'Submatch' is present, the return value is a slice identifying the successive submatches of the expression. Submatches are matches of parenthesized subexpressions (also known as capturing groups) within the regular expression, numbered from left to right in order of opening parenthesis. Submatch 0 is the match of the entire expression, submatch 1 is the match of the first parenthesized subexpression, and so on.

p2p/module.go Outdated Show resolved Hide resolved
p2p/module.go Outdated Show resolved Hide resolved
p2p/module.go Outdated Show resolved Hide resolved
p2p/module_test.go Outdated Show resolved Hide resolved
p2p/module_test.go Outdated Show resolved Hide resolved
Base automatically changed from issue/490-cluster-manager to main February 17, 2023 22:27
@deblasis deblasis requested a review from Olshansk February 20, 2023 19:17
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.

A few minor comments (see them as optional), but otherwise, lgtm. A good way to end off a Monday after Valentine's week ;)

p2p/utils_test.go Outdated Show resolved Hide resolved
p2p/bootstrap.go Outdated Show resolved Hide resolved
p2p/bootstrap.go Outdated Show resolved Hide resolved
@deblasis deblasis merged commit b3ed290 into main Feb 20, 2023
@Olshansk Olshansk deleted the issue/498-kiss-bootstrapping branch February 20, 2023 23:40
bryanchriswhite added a commit that referenced this pull request Feb 21, 2023
* pokt/main:
  [P2P] KISS 4 - Basic nodes bootstrapping [Merge me after #522] - (Issue: #498) (#523)
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] KISS Node bootstrapping
3 participants