-
Notifications
You must be signed in to change notification settings - Fork 19
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
Simplify info client usage #68
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ package peers | |
import ( | ||
"context" | ||
"fmt" | ||
"math/rand" | ||
"sync" | ||
"time" | ||
|
||
|
@@ -17,7 +18,6 @@ import ( | |
"github.com/ava-labs/avalanchego/utils/constants" | ||
"github.com/ava-labs/avalanchego/utils/ips" | ||
"github.com/ava-labs/avalanchego/utils/logging" | ||
"github.com/ava-labs/avalanchego/utils/sampler" | ||
"github.com/ava-labs/avalanchego/utils/set" | ||
"github.com/prometheus/client_golang/prometheus" | ||
"go.uber.org/zap" | ||
|
@@ -103,44 +103,33 @@ func NewNetwork( | |
) | ||
return nil, nil, err | ||
} | ||
ip, err := infoClient.GetNodeIP(context.Background()) | ||
if err != nil { | ||
logger.Error( | ||
"Failed to get ip", | ||
zap.Error(err), | ||
) | ||
return nil, nil, err | ||
} | ||
id, _, err := infoClient.GetNodeID(context.Background()) | ||
if err != nil { | ||
logger.Error( | ||
"Failed to get node id", | ||
zap.Error(err), | ||
) | ||
return nil, nil, err | ||
} | ||
beaconIPs = append(beaconIPs, ip) | ||
beaconIDs = append(beaconIDs, id.String()) | ||
|
||
var indices []uint64 | ||
// If we have more peers than numInitialTestPeers, take a random sample of numInitialTestPeers peers | ||
if len(peers) > numInitialTestPeers { | ||
s := sampler.NewUniform() | ||
s.Initialize(uint64(len(peers))) | ||
indices, _ = s.Sample(numInitialTestPeers) | ||
} else { | ||
for i := range peers { | ||
indices = append(indices, uint64(i)) | ||
} | ||
} | ||
|
||
// Randomly select peers to connect to until we have numInitialTestPeers | ||
indices := rand.Perm(len(peers)) | ||
for _, index := range indices { | ||
// Do not attempt to connect to private peers | ||
if len(peers[index].PublicIP) == 0 { | ||
continue | ||
} | ||
beaconIPs = append(beaconIPs, peers[index].PublicIP) | ||
beaconIDs = append(beaconIDs, peers[index].ID.String()) | ||
if len(beaconIDs) == numInitialTestPeers { | ||
break | ||
} | ||
} | ||
if len(beaconIPs) == 0 { | ||
logger.Error( | ||
"Failed to find any peers to connect to", | ||
zap.Error(err), | ||
) | ||
return nil, nil, err | ||
} | ||
if len(beaconIPs) < numInitialTestPeers { | ||
logger.Warn( | ||
"Failed to find a full set of peers to connect to on startup", | ||
zap.Int("connectedPeers", len(beaconIPs)), | ||
zap.Int("expectedConnectedPeers", numInitialTestPeers), | ||
) | ||
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. Should we abort if the number of connectedPeers is 0? 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. In that case, we return an error a few lines above here. |
||
} | ||
|
||
for i, beaconIDStr := range beaconIDs { | ||
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. What if we are unable to connect to any of the initial test peers? Will we select another sample of peers? 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. That's a good question. As Matt mentioned above, |
||
|
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.
why do we need to limit the number of peers to 5 again? IIUC when we do the signature aggregation process it could take longer in terms of us sending out more signature requests, but would increase likelihood of having enough stake threshold in the peers. Are 5 peers generally enough for exceeding stake threshold?
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.
This is just the list of initial peers to manually connect to in order to initialize the app request network. When requesting signatures, we connect to all peers from which we are requesting signatures.