-
Notifications
You must be signed in to change notification settings - Fork 33
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] chore: concurrent bootstrapping #694
Draft
bryanchriswhite
wants to merge
15
commits into
main
Choose a base branch
from
chore/concurrent-p2p-bootstrap
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+304
−66
Draft
Changes from 2 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
2bea8a2
chore: concurrent p2p bootstrapping
bryanchriswhite af6189a
chore: update changelog
bryanchriswhite bc6a38e
Merge remote-tracking branch 'pokt/main' into HEAD
bryanchriswhite ebd7231
chore: fix "boostrap" typo
bryanchriswhite ad695f9
fix: invalid zerolog #Fields() arg type`
bryanchriswhite 96fac17
chore: fix comment typo
bryanchriswhite f9ca955
refactor: update import alias
bryanchriswhite 778dfc5
chore: copy limiter from storj/common
bryanchriswhite 28b49a8
fixup: rename bootstrapFromRPC
bryanchriswhite 8dba296
fixup: use limiter instead of waitgroup
bryanchriswhite a6b424a
fixup: always bootstrap
bryanchriswhite c2a4049
chore: add `MaxBootstrapConcurrency`
bryanchriswhite 0eee237
chore: update changelog
bryanchriswhite b41153e
fix: runtime manager test
bryanchriswhite f4fa61e
fix: linter
bryanchriswhite File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -8,10 +8,10 @@ import ( | |||||
"regexp" | ||||||
"strconv" | ||||||
"strings" | ||||||
"sync" | ||||||
|
||||||
rpcCHP "github.com/pokt-network/pocket/p2p/providers/current_height_provider/rpc" | ||||||
rpcABP "github.com/pokt-network/pocket/p2p/providers/peerstore_provider/rpc" | ||||||
typesP2P "github.com/pokt-network/pocket/p2p/types" | ||||||
"github.com/pokt-network/pocket/rpc" | ||||||
"github.com/pokt-network/pocket/runtime/defaults" | ||||||
) | ||||||
|
@@ -43,37 +43,57 @@ func (m *p2pModule) configureBootstrapNodes() error { | |||||
|
||||||
// bootstrap attempts to bootstrap from a bootstrap node | ||||||
func (m *p2pModule) bootstrap() error { | ||||||
var pstore typesP2P.Peerstore | ||||||
var wg sync.WaitGroup | ||||||
|
||||||
for _, bootstrapNode := range m.bootstrapNodes { | ||||||
m.logger.Info().Str("endpoint", bootstrapNode).Msg("Attempting to bootstrap from bootstrap node") | ||||||
for _, serviceURL := range m.bootstrapNodes { | ||||||
wg.Add(1) | ||||||
bryanchriswhite marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
client, err := rpc.NewClientWithResponses(bootstrapNode) | ||||||
if err != nil { | ||||||
continue | ||||||
} | ||||||
healthCheck, err := client.GetV1Health(context.TODO()) | ||||||
if err != nil || healthCheck == nil || healthCheck.StatusCode != http.StatusOK { | ||||||
m.logger.Warn().Str("bootstrapNode", bootstrapNode).Msg("Error getting a green health check from bootstrap node") | ||||||
continue | ||||||
} | ||||||
// concurrent bootstrapping | ||||||
// TECHDEBT: add maximum bootstrapping concurrency to P2P config | ||||||
go m.bootstrapFromServiceURL(serviceURL) | ||||||
} | ||||||
wg.Wait() | ||||||
|
||||||
pstoreProvider := rpcABP.NewRPCPeerstoreProvider( | ||||||
rpcABP.WithP2PConfig( | ||||||
m.GetBus().GetRuntimeMgr().GetConfig().P2P, | ||||||
), | ||||||
rpcABP.WithCustomRPCURL(bootstrapNode), | ||||||
) | ||||||
if m.network.GetPeerstore().Size() == 0 { | ||||||
return fmt.Errorf("bootstrap failed") | ||||||
} | ||||||
return nil | ||||||
} | ||||||
|
||||||
currentHeightProvider := rpcCHP.NewRPCCurrentHeightProvider(rpcCHP.WithCustomRPCURL(bootstrapNode)) | ||||||
// boostrapFromServiceURL fetches the peerstore of the peer at `serviceURL and | ||||||
// adds it to this host's peerstore after performing a health check. | ||||||
// TECHDEBT(SOLID): refactor; this method has more than one reason to change | ||||||
func (m *p2pModule) bootstrapFromServiceURL(serviceURL string) { | ||||||
// NB: no need closure `serviceURL` as long as it remains a value type | ||||||
m.logger.Info().Str("endpoint", serviceURL).Msg("Attempting to bootstrap from bootstrap node") | ||||||
|
||||||
pstore, err = pstoreProvider.GetStakedPeerstoreAtHeight(currentHeightProvider.CurrentHeight()) | ||||||
if err != nil { | ||||||
m.logger.Warn().Err(err).Str("endpoint", bootstrapNode).Msg("Error getting address book from bootstrap node") | ||||||
continue | ||||||
} | ||||||
client, err := rpc.NewClientWithResponses(serviceURL) | ||||||
if err != nil { | ||||||
return | ||||||
} | ||||||
healthCheck, err := client.GetV1Health(context.TODO()) | ||||||
if err != nil || healthCheck == nil || healthCheck.StatusCode != http.StatusOK { | ||||||
m.logger.Warn().Str("serviceURL", serviceURL).Msg("Error getting a green health check from bootstrap node") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
return | ||||||
} | ||||||
|
||||||
// fetch `serviceURL`'s peerstore | ||||||
pstoreProvider := rpcABP.NewRPCPeerstoreProvider( | ||||||
rpcABP.WithP2PConfig( | ||||||
m.GetBus().GetRuntimeMgr().GetConfig().P2P, | ||||||
), | ||||||
rpcABP.WithCustomRPCURL(serviceURL), | ||||||
) | ||||||
|
||||||
currentHeightProvider := rpcCHP.NewRPCCurrentHeightProvider(rpcCHP.WithCustomRPCURL(serviceURL)) | ||||||
|
||||||
pstore, err := pstoreProvider.GetStakedPeerstoreAtHeight(currentHeightProvider.CurrentHeight()) | ||||||
if err != nil { | ||||||
m.logger.Warn().Err(err).Str("endpoint", serviceURL).Msg("Error getting address book from bootstrap node") | ||||||
return | ||||||
} | ||||||
|
||||||
// add `serviceURL`'s peers to this node's peerstore | ||||||
for _, peer := range pstore.GetPeerList() { | ||||||
m.logger.Debug().Str("address", peer.GetAddress().String()).Msg("Adding peer to network") | ||||||
if err := m.network.AddPeer(peer); err != nil { | ||||||
|
@@ -82,11 +102,6 @@ func (m *p2pModule) bootstrap() error { | |||||
Msg("adding peer") | ||||||
} | ||||||
} | ||||||
|
||||||
if m.network.GetPeerstore().Size() == 0 { | ||||||
return fmt.Errorf("bootstrap failed") | ||||||
} | ||||||
return nil | ||||||
} | ||||||
|
||||||
func isValidHostnamePort(str string) bool { | ||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀