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] chore: concurrent bootstrapping #694

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft
Prev Previous commit
Next Next commit
fixup: use limiter instead of waitgroup
  • Loading branch information
bryanchriswhite committed Apr 24, 2023
commit 8dba296c0daca9e7c8e236538e751d1e6a045884
18 changes: 8 additions & 10 deletions p2p/bootstrap.go
Original file line number Diff line number Diff line change
@@ -8,12 +8,12 @@ import (
"regexp"
"strconv"
"strings"
"sync"

rpcCHP "github.com/pokt-network/pocket/p2p/providers/current_height_provider/rpc"
rpcPSP "github.com/pokt-network/pocket/p2p/providers/peerstore_provider/rpc"
"github.com/pokt-network/pocket/rpc"
"github.com/pokt-network/pocket/runtime/defaults"
"github.com/pokt-network/pocket/shared/utils"
)

// configureBootstrapNodes parses the bootstrap nodes from the config and validates them
@@ -43,20 +43,18 @@ func (m *p2pModule) configureBootstrapNodes() error {

// bootstrap attempts to bootstrap from a bootstrap node
func (m *p2pModule) bootstrap() error {
var wg sync.WaitGroup
limiter := utils.NewLimiter(int(m.cfg.MaxBootstrapConcurrency))

for _, serviceURL := range m.bootstrapNodes {
wg.Add(1)

// concurrent bootstrapping
// TECHDEBT: add maximum bootstrapping concurrency to P2P config
go m.bootstrapFromServiceURL(serviceURL)
// TECHDEBT(#595): add ctx to interface methods and propagate down.
limiter.Go(context.TODO(), func() {
m.bootstrapFromRPC(strings.Clone(serviceURL))
})
}
wg.Wait()

if m.network.GetPeerstore().Size() == 0 {
return fmt.Errorf("bootstrap failed")
}
limiter.Close()

return nil
}