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

Simplify info client usage #68

Merged
merged 2 commits into from
Oct 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 20 additions & 31 deletions peers/app_request_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package peers
import (
"context"
"fmt"
"math/rand"
"sync"
"time"

Expand All @@ -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"
Expand Down Expand Up @@ -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 {

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?

Copy link
Collaborator Author

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.

logger.Warn(
"Failed to find a full set of peers to connect to on startup",
zap.Int("connectedPeers", len(beaconIPs)),
zap.Int("expectedConnectedPeers", numInitialTestPeers),
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we abort if the number of connectedPeers is 0?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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 {
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's a good question. As Matt mentioned above, ManuallyTrack will continuously attempt to connect. We should look into what the failure modes for that function call are, and consider how to handle them. Right now if we are unable to connect to any peers on initialization, we will attempt to connect to the subnet validators when relaying a message. So there is some form of redundancy, but an explicit resampling on startup would be more robust.

Expand Down
Loading