ava-labs / awm-relayer

Service for relaying Avalanche Warp Messages between Subnets
Other
24 stars 19 forks source link

Fetch peers over P2P #534

Open cam-schultz opened 3 weeks ago

cam-schultz commented 3 weeks ago

Context and scope With Etna, primary network API nodes will no longer be expected to be connected to all L1 validators. info.Peers will return peers only for tracked subnets. Rather than requiring Info API nodes for all tracked subnets, we can instead fetch the global peer list over p2p. https://github.com/ava-labs/avalanchego/pull/3491 relaxes the p2p.GetPeers constraints such that any primary network validator will return the list of peers across all L1s to non-primary network validator nodes. We can use this in the signature aggregator to fetch the global list of peers, and manually connect to each.

Discussion and alternatives Peers can be fetched over p2p using the p2p.GetPeerList message type. We need to ensure that we are requesting this from a primary network validator. We can do this by calling info.Peers on a primary network API node, which matches the current API requirements.

Open questions Is manually connecting to each of the peers the preferred approach? Currently, we connect to peers like so:

Instead, we should be able to transitively connect to all L1 peers by manually connecting to a subset of the L1's validators. See the example here. We may be able to instead maintain an in-memory list of connected/tracked subnets that we bootstrap connections to only once. This would likely be a larger change, but could simplify peer discovery overall. Some additional research is required here, especially given potential changes to subnet tracking semantics in the Avalanchego networking code.

perfilev-faraway commented 2 days ago

We're waiting for this feature. Current our workaround is using manuallyTrackedPeers, but it doesn't work with PoS chains when new validators can be added permissionless.

The patch below allows us to connect only to this bootstrap validator. The signature aggregator observes new validators correctly but unable to connect to them.

diff --git a/signature-aggregator/main/main.go b/signature-aggregator/main/main.go
index 829f860..3416aa9 100644
--- a/signature-aggregator/main/main.go
+++ b/signature-aggregator/main/main.go
@@ -4,12 +4,14 @@
 package main

 import (
+   "encoding/json"
    "errors"
    "fmt"
    "log"
    "net/http"
    "os"

+   "github.com/ava-labs/avalanchego/api/info"
    "github.com/ava-labs/avalanchego/message"
    "github.com/ava-labs/avalanchego/utils/constants"
    "github.com/ava-labs/avalanchego/utils/logging"
@@ -73,6 +75,24 @@ func main() {
        ),
    )

+   var peer info.Peer
+
+   err = json.Unmarshal([]byte(`{
+       "ip": "44.218.255.99:9651",
+       "publicIP": "44.218.255.99:9651",
+       "nodeID": "NodeID-KQi8kBX1xZFanG7n9aWkiN16mrQARGs4P",
+       "version": "v1.2.3",
+       "lastSent": "2024-11-07T15:04:05Z",
+       "lastReceived": "2024-11-07T15:04:05Z",
+       "observedUptime": 95,
+       "trackedSubnets": [],
+       "supportedACPs": [],
+       "objectedACPs": []
+   }`), &peer)
+   if err != nil {
+       log.Fatalf("Error unmarshalling JSON: %v", err)
+   }
+
    logger.Info("Initializing signature-aggregator")

    // Initialize the global app request network
@@ -88,7 +108,7 @@ func main() {
        networkLogLevel,
        prometheus.DefaultRegisterer,
        nil,
-       nil,
+       []info.Peer{peer},
        &cfg,
    )
    if err != nil {