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

Manually tracked peers #521

Merged
merged 7 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
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
29 changes: 20 additions & 9 deletions peers/app_request_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"sync"
"time"

"github.com/ava-labs/avalanchego/api/info"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/message"
"github.com/ava-labs/avalanchego/network"
Expand Down Expand Up @@ -59,13 +60,19 @@ type appRequestNetwork struct {
lock *sync.Mutex
validatorClient *validators.CanonicalValidatorClient
metrics *AppRequestNetworkMetrics

// Nodes that we should connect to that are not publicly discoverable.
// Should only be used for local or custom blockchains where validators are not
// publicly discoverable by primary network nodes.
manuallyTrackedPeers []info.Peer
}

// NewNetwork creates a p2p network client for interacting with validators
// NewNetwork creates a P2P network client for interacting with validators
func NewNetwork(
logLevel logging.Level,
registerer prometheus.Registerer,
trackedSubnets set.Set[ids.ID],
manuallyTrackedPeers []info.Peer,
cfg Config,
) (AppRequestNetwork, error) {
logger := logging.NewLogger(
Expand Down Expand Up @@ -122,13 +129,14 @@ func NewNetwork(
validatorClient := validators.NewCanonicalValidatorClient(logger, cfg.GetPChainAPI())

arNetwork := &appRequestNetwork{
network: testNetwork,
handler: handler,
infoAPI: infoAPI,
logger: logger,
lock: new(sync.Mutex),
validatorClient: validatorClient,
metrics: metrics,
network: testNetwork,
handler: handler,
infoAPI: infoAPI,
logger: logger,
lock: new(sync.Mutex),
validatorClient: validatorClient,
metrics: metrics,
manuallyTrackedPeers: manuallyTrackedPeers,
}
go logger.RecoverAndPanic(func() {
testNetwork.Dispatch()
Expand All @@ -155,7 +163,7 @@ func (n *appRequestNetwork) ConnectPeers(nodeIDs set.Set[ids.NodeID]) set.Set[id
// re-adding connections to already tracked peers.

startInfoAPICall := time.Now()
// Get the list of peers
// Get the list of publicly discoverable peers
peers, err := n.infoAPI.Peers(context.Background())
n.setInfoAPICallLatencyMS(float64(time.Since(startInfoAPICall).Milliseconds()))
if err != nil {
Expand All @@ -166,6 +174,9 @@ func (n *appRequestNetwork) ConnectPeers(nodeIDs set.Set[ids.NodeID]) set.Set[id
return nil
}

// Add manually tracked peers
peers = append(peers, n.manuallyTrackedPeers...)
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume the system will behave correctly even if a peer appears more than once in the peers list (i.e., both returned by infoAPI.peers and is a member of the manuallyTrackedPeers).

Copy link
Contributor

Choose a reason for hiding this comment

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

yes it will since we are using sets below and ManuallyTrack is idempotent.


// Attempt to connect to each peer
var trackedNodes set.Set[ids.NodeID]
for _, peer := range peers {
Expand Down
1 change: 1 addition & 0 deletions relayer/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ func main() {
networkLogLevel,
registerer,
trackedSubnets,
nil,
&cfg,
)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions signature-aggregator/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func main() {
networkLogLevel,
prometheus.DefaultRegisterer,
nil,
nil,
&cfg,
)
if err != nil {
Expand Down