Skip to content

Commit

Permalink
Merge pull request #521 from ava-labs/manually-tracked-peers
Browse files Browse the repository at this point in the history
Manually tracked peers
  • Loading branch information
michaelkaplan13 authored Oct 31, 2024
2 parents 16fde09 + 77fefc7 commit 9f3254b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
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...)

// 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

0 comments on commit 9f3254b

Please # to comment.