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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module github.com/ava-labs/awm-relayer

go 1.22.7
go 1.22.8

require (
github.com/ava-labs/avalanchego v1.11.11
github.com/ava-labs/avalanchego v1.12.0-initial-poc.5
github.com/ava-labs/coreth v0.13.8
github.com/ava-labs/subnet-evm v0.6.10
github.com/ava-labs/teleporter v1.0.7
Expand Down Expand Up @@ -85,7 +85,7 @@ require (
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/gorilla/rpc v1.2.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
github.com/hashicorp/go-bexpr v0.1.10 // indirect
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ github.com/alexliesenfeld/health v0.8.0/go.mod h1:TfNP0f+9WQVWMQRzvMUjlws4ceXKEL
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah4HI848JfFxHt+iPb26b4zyfspmqY0/8=
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/ava-labs/avalanchego v1.11.11 h1:MIQq8xRavRj4ZXHA4G+aMiymig7SOScGOG1SApmMvBc=
github.com/ava-labs/avalanchego v1.11.11/go.mod h1:yFx3V31Jy9NFa8GZlgGnwiVf8KGjeF2+Uc99l9Scd/8=
github.com/ava-labs/avalanchego v1.12.0-initial-poc.5 h1:gW4xAqZNvkA4gP8M9yDyd7YUzuwfQbbCR+hgd1ztOto=
github.com/ava-labs/avalanchego v1.12.0-initial-poc.5/go.mod h1:qSHmog3wMVjo/ruIAQo0ppXAilyni07NIu5K88RyhWE=
github.com/ava-labs/coreth v0.13.8 h1:f14X3KgwHl9LwzfxlN6S4bbn5VA2rhEsNnHaRLSTo/8=
github.com/ava-labs/coreth v0.13.8/go.mod h1:t3BSv/eQv0AlDPMfEDCMMoD/jq1RkUsbFzQAFg5qBcE=
github.com/ava-labs/subnet-evm v0.6.10 h1:uIh6bFMA4GCMVMQ3agBPxTMlYHL8FBR5FrhMR+drfKI=
Expand Down Expand Up @@ -355,8 +355,8 @@ github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB7
github.com/gorilla/rpc v1.2.0 h1:WvvdC2lNeT1SP32zrIce5l0ECBfbAlmrmSBsuc57wfk=
github.com/gorilla/rpc v1.2.0/go.mod h1:V4h9r+4sF5HnzqbwIez0fKSpANP0zlYd3qR7p36jkTQ=
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho=
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 h1:RtRsiaGvWxcwd8y3BiRZxsylPT8hLWZ5SPcfI+3IDNk=
Expand Down
29 changes: 20 additions & 9 deletions peers/app_request_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,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 @@ -58,13 +59,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 @@ -121,13 +128,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 @@ -154,7 +162,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 @@ -165,6 +173,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).


// Attempt to connect to each peer
var trackedNodes set.Set[ids.NodeID]
for _, peer := range peers {
Expand Down
4 changes: 2 additions & 2 deletions peers/info_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ func (i *InfoAPI) Peers(ctx context.Context) ([]info.Peer, error) {
return i.client.Peers(ctx, i.options...)
}

func (i *InfoAPI) Uptime(ctx context.Context, subnetID ids.ID) (*info.UptimeResponse, error) {
return i.client.Uptime(ctx, subnetID, i.options...)
func (i *InfoAPI) Uptime(ctx context.Context) (*info.UptimeResponse, error) {
return i.client.Uptime(ctx, i.options...)
}
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