From 7281e5da29db004198e931a13c69b759de9cc6a0 Mon Sep 17 00:00:00 2001 From: Sulejman Sarajlija <3107367+Sulejman@users.noreply.github.com> Date: Sat, 27 Jul 2024 03:09:46 +0200 Subject: [PATCH 01/14] feat: trusted relayers [WIP] --- config/settings.example.json | 3 +- config/settings.go | 2 + go.mod | 1 + go.sum | 2 + pkgs/service/discovery.go | 84 +++++++++++++++----- pkgs/service/discovery_test.go | 136 +++++++++++++++++++++++++++++++++ pkgs/service/relay.go | 19 +++++ pkgs/service/relay_test.go | 48 ++++++++++++ 8 files changed, 274 insertions(+), 21 deletions(-) create mode 100644 pkgs/service/discovery_test.go create mode 100644 pkgs/service/relay_test.go diff --git a/config/settings.example.json b/config/settings.example.json index 7acf167..39347dc 100644 --- a/config/settings.example.json +++ b/config/settings.example.json @@ -5,5 +5,6 @@ "RelayerPrivateKey": "RELAYER_PRIVATE_KEY", "PowerloomReportingUrl": "POWERLOOM_REPORTING_URL", "SignerAccountAddress": "SIGNER_ACCOUNT_ADDRESS", - "LocalCollectorPort": "LOCAL_COLLECTOR_PORT" + "LocalCollectorPort": "LOCAL_COLLECTOR_PORT", + "TrustedRelayersListUrl" : "TRUSTED_RELAYERS_LIST_URL", } diff --git a/config/settings.go b/config/settings.go index f1412a6..ce29345 100644 --- a/config/settings.go +++ b/config/settings.go @@ -17,6 +17,8 @@ type Settings struct { PowerloomReportingUrl string `json:"PowerloomReportingUrl"` SignerAccountAddress string `json:"SignerAccountAddress"` PortNumber string `json:"LocalCollectorPort"` + TrustedRelayersListUrl string `json:"TrustedRelayersListUrl"` + SequencerNetworkPath string `json:"SequencerNetworkPath"` } func LoadConfig() { diff --git a/go.mod b/go.mod index b2e9a16..cf56dfa 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/cenkalti/backoff/v4 v4.2.0 github.com/google/uuid v1.6.0 github.com/libp2p/go-libp2p v0.32.2 + github.com/libp2p/go-libp2p-core v0.20.1 github.com/libp2p/go-libp2p-kad-dht v0.25.2 github.com/multiformats/go-multiaddr v0.12.2 github.com/sethvargo/go-retry v0.2.4 diff --git a/go.sum b/go.sum index 9ba638d..378b22e 100644 --- a/go.sum +++ b/go.sum @@ -192,6 +192,8 @@ github.com/libp2p/go-libp2p v0.32.2 h1:s8GYN4YJzgUoyeYNPdW7JZeZ5Ee31iNaIBfGYMAY4 github.com/libp2p/go-libp2p v0.32.2/go.mod h1:E0LKe+diV/ZVJVnOJby8VC5xzHF0660osg71skcxJvk= github.com/libp2p/go-libp2p-asn-util v0.3.0 h1:gMDcMyYiZKkocGXDQ5nsUQyquC9+H+iLEQHwOCZ7s8s= github.com/libp2p/go-libp2p-asn-util v0.3.0/go.mod h1:B1mcOrKUE35Xq/ASTmQ4tN3LNzVVaMNmq2NACuqyB9w= +github.com/libp2p/go-libp2p-core v0.20.1 h1:fQz4BJyIFmSZAiTbKV8qoYhEH5Dtv/cVhZbG3Ib/+Cw= +github.com/libp2p/go-libp2p-core v0.20.1/go.mod h1:6zR8H7CvQWgYLsbG4on6oLNSGcyKaYFSEYyDt51+bIY= github.com/libp2p/go-libp2p-kad-dht v0.25.2 h1:FOIk9gHoe4YRWXTu8SY9Z1d0RILol0TrtApsMDPjAVQ= github.com/libp2p/go-libp2p-kad-dht v0.25.2/go.mod h1:6za56ncRHYXX4Nc2vn8z7CZK0P4QiMcrn77acKLM2Oo= github.com/libp2p/go-libp2p-kbucket v0.6.3 h1:p507271wWzpy2f1XxPzCQG9NiN6R6lHL9GiSErbQQo0= diff --git a/pkgs/service/discovery.go b/pkgs/service/discovery.go index 58978b7..2ca7954 100644 --- a/pkgs/service/discovery.go +++ b/pkgs/service/discovery.go @@ -2,7 +2,10 @@ package service import ( "context" - "fmt" + "encoding/json" + "io" + "net/http" + "proto-snapshot-server/config" "sync" "github.com/cenkalti/backoff/v4" @@ -16,6 +19,38 @@ import ( log "github.com/sirupsen/logrus" ) +type Relayer struct { + ID string `json:"id"` + Name string `json:"name"` + RendezvousPoint string `json:"rendezvousPoint"` + Maddr string `json:"maddr"` +} + +func fetchTrustedRelayers(url string) []Relayer { + resp, err := http.Get(url) + if err != nil { + log.Fatalf("Failed to fetch JSON: %v", err) + } + defer resp.Body.Close() + + body, err := io.ReadAll(resp.Body) + if err != nil { + log.Debugf("Failed to read response body: %v", err) + } + + var relayers []Relayer + err = json.Unmarshal(body, &relayers) + if err != nil { + log.Debugln("Failed to unmarshal JSON:", err) + } + + for _, relayer := range relayers { + log.Debugf("ID: %s, Name: %s, Rendezvous Point: %s, Maddr: %s\n", relayer.ID, relayer.Name, relayer.RendezvousPoint, relayer.Maddr) + } + + return relayers +} + func isVisited(id peer.ID, visited []peer.ID) bool { for _, v := range visited { if v == id { @@ -25,43 +60,52 @@ func isVisited(id peer.ID, visited []peer.ID) bool { return false } -func connectToStableRelayer(ctx context.Context, host host.Host, relayerAddr string) peer.ID { - stableRelayerMA, err := ma.NewMultiaddr("/ip4/104.248.63.86/tcp/5001/p2p/QmQSEao6C3SuPZ8cWiYccPqsd7LtWBTzNgXQZiAjeGTQpm") +func AddPeerConnection(ctx context.Context, host host.Host, relayerAddr string) bool { + stableRelayerMA, err := ma.NewMultiaddr(relayerAddr) if err != nil { log.Debugln("Failed to parse stable peer multiaddress: ", err) } peerInfo, err := peer.AddrInfoFromP2pAddr(stableRelayerMA) if err != nil { - log.Debugln("Failed to extract peer info from multiaddress: %v", err) + log.Debugln("Failed to extract peer info from multiaddress:", err) + } + + if host.Network().Connectedness(peerInfo.ID) != network.Connected { + log.Debugln("Skipping connected relayer: ", peerInfo.ID) + return true } // Add the peer to the peerstore host.Peerstore().AddAddrs(peerInfo.ID, peerInfo.Addrs, peerstore.PermanentAddrTTL) - if err := host.Connect(ctx, *peerInfo); err != nil { - log.Debugln("Failed to connect to stable relayer: %v", err) + if err := backoff.Retry(func() error { return host.Connect(ctx, *peerInfo) }, backoff.WithMaxRetries(backoff.NewExponentialBackOff(), 1)); err != nil { + log.Errorf("Failed to connect to relayer %s: %s", peerInfo.ID, err) + } else { + log.Infof("Connected to new relayer: %s", peerInfo.ID) + return true } - fmt.Println("Connected to stable relayer:", peerInfo.ID) - return peerInfo.ID + return false } -func ConnectToPeer(ctx context.Context, routingDiscovery *routing.RoutingDiscovery, rendezvousString string, host host.Host, visited []peer.ID) peer.ID { - stableRelayer1 := "/ip4/104.248.63.86/tcp/5001/p2p/QmQSEao6C3SuPZ8cWiYccPqsd7LtWBTzNgXQZiAjeGTQpm" - stableRelayer2 := "/ip4/137.184.132.196/tcp/5001/p2p/QmU3xwsjRqQR4pjJQ7Cxhcb2tiPvaJ6Z5AHDULq7hHWvvj" - - // Connect to stable relayers - peerID1 := connectToStableRelayer(ctx, host, stableRelayer1) - peerID2 := connectToStableRelayer(ctx, host, stableRelayer2) +func ConnectToTrustedRelayers(ctx context.Context, host host.Host) []Relayer { + relayers := fetchTrustedRelayers(config.SettingsObj.TrustedRelayersListUrl) + var connectedRelayers []Relayer - if peerID1 != "" { - return peerID1 - } - if peerID2 != "" { - return peerID2 + for _, relayer := range relayers { + if AddPeerConnection(ctx, host, relayer.Maddr) { + connectedRelayers = append(connectedRelayers, relayer) + } } + return connectedRelayers +} + +func ConnectToPeer(ctx context.Context, routingDiscovery *routing.RoutingDiscovery, rendezvousString string, host host.Host, visited []peer.ID) peer.ID { + //stableRelayer1 := "/ip4/104.248.63.86/tcp/5001/p2p/QmQSEao6C3SuPZ8cWiYccPqsd7LtWBTzNgXQZiAjeGTQpm" + //stableRelayer2 := "/ip4/137.184.132.196/tcp/5001/p2p/QmU3xwsjRqQR4pjJQ7Cxhcb2tiPvaJ6Z5AHDULq7hHWvvj" + peerChan, err := routingDiscovery.FindPeers(ctx, rendezvousString) if err != nil { diff --git a/pkgs/service/discovery_test.go b/pkgs/service/discovery_test.go new file mode 100644 index 0000000..dadc653 --- /dev/null +++ b/pkgs/service/discovery_test.go @@ -0,0 +1,136 @@ +package service + +import ( + "context" + "github.com/libp2p/go-libp2p" + "github.com/libp2p/go-libp2p/core/peer" + ma "github.com/multiformats/go-multiaddr" + log "github.com/sirupsen/logrus" + "io" + "net/http" + "net/http/httptest" + "proto-snapshot-server/config" + "testing" + "time" +) + +type Settings struct { + TrustedRelayersListUrl string +} + +var SettingsObj *Settings + +func TestFetchTrustedRelayers(t *testing.T) { + // Sample JSON response + mockResponse := `[{ + "id": "QmQSEao6C3SuPZ8cWiYccPqsd7LtWBTzNgXQZiAjeGTQpm", + "name": "Relayer1", + "rendezvousPoint": "Relayer_POP_test_simulation_phase_1", + "maddr": "/ip4/104.248.63.86/tcp/5001/p2p/QmQSEao6C3SuPZ8cWiYccPqsd7LtWBTzNgXQZiAjeGTQpm" + }, { + "id": "QmU3xwsjRqQR4pjJQ7Cxhcb2tiPvaJ6Z5AHDULq7hHWvvj", + "name": "Relayer2", + "rendezvousPoint": "Relayer_POP_test_simulation_phase_1", + "maddr": "/ip4/137.184.132.196/tcp/5001/p2p/QmU3xwsjRqQR4pjJQ7Cxhcb2tiPvaJ6Z5AHDULq7hHWvvj" + }]` + + // Create a test server that returns the mock JSON response + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + io.WriteString(w, mockResponse) + })) + defer ts.Close() + + // Call the function to test + relayers := fetchTrustedRelayers(ts.URL) + + // Expected result + expected := []Relayer{ + { + ID: "QmQSEao6C3SuPZ8cWiYccPqsd7LtWBTzNgXQZiAjeGTQpm", + Name: "Relayer1", + RendezvousPoint: "Relayer_POP_test_simulation_phase_1", + Maddr: "/ip4/104.248.63.86/tcp/5001/p2p/QmQSEao6C3SuPZ8cWiYccPqsd7LtWBTzNgXQZiAjeGTQpm", + }, + { + ID: "QmU3xwsjRqQR4pjJQ7Cxhcb2tiPvaJ6Z5AHDULq7hHWvvj", + Name: "Relayer2", + RendezvousPoint: "Relayer_POP_test_simulation_phase_1", + Maddr: "/ip4/137.184.132.196/tcp/5001/p2p/QmU3xwsjRqQR4pjJQ7Cxhcb2tiPvaJ6Z5AHDULq7hHWvvj", + }, + } + + if len(relayers) != len(expected) { + t.Fatalf("expected %d relayers, got %d", len(expected), len(relayers)) + } + + for i, r := range relayers { + if r != expected[i] { + t.Errorf("expected relayer %v, got %v", expected[i], r) + } + } +} + +func TestAddPeerConnection(t *testing.T) { + host, err := libp2p.New() + if err != nil { + t.Fatalf("Failed to create host: %v", err) + } + defer host.Close() + ctx := context.Background() + relayerAddr := "/ip4/104.248.63.86/tcp/5001/p2p/QmQSEao6C3SuPZ8cWiYccPqsd7LtWBTzNgXQZiAjeGTQpm" + + result := AddPeerConnection(ctx, host, relayerAddr) + + if !result { + t.Error("expected true, got false") + } +} + +func TestConnectToTrustedRelayers(t *testing.T) { + mockResponse := `[{ + "id": "QmQSEao6C3SuPZ8cWiYccPqsd7LtWBTzNgXQZiAjeGTQpm", + "name": "Relayer1", + "rendezvousPoint": "Relayer_POP_test_simulation_phase_1", + "maddr": "/ip4/104.248.63.86/tcp/5001/p2p/QmQSEao6C3SuPZ8cWiYccPqsd7LtWBTzNgXQZiAjeGTQpm" + }, { + "id": "QmU3xwsjRqQR4pjJQ7Cxhcb2tiPvaJ6Z5AHDULq7hHWvvj", + "name": "Relayer2", + "rendezvousPoint": "Relayer_POP_test_simulation_phase_1", + "maddr": "/ip4/137.184.132.196/tcp/5001/p2p/QmU3xwsjRqQR4pjJQ7Cxhcb2tiPvaJ6Z5AHDULq7hHWvvj" + }]` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + io.WriteString(w, mockResponse) + })) + + defer ts.Close() + + config.SettingsObj = &config.Settings{ + TrustedRelayersListUrl: ts.URL, + } + + host, err := libp2p.New() + if err != nil { + t.Fatalf("Failed to create host: %v", err) + } + defer host.Close() + + relayers := ConnectToTrustedRelayers(context.Background(), host) + + time.Sleep(3 * time.Second) + + log.Println(host.Network().Connectedness(peer.ID(relayers[0].ID))) + log.Println(host.Network().Connectedness(peer.ID(relayers[1].ID))) + + host.Connect(context.Background(), peer.AddrInfo{ + ID: peer.ID("QmdJbNsbHpFseUPKC9vLt4vMsfdxA4dyHPzsAWuzYz3Yxx"), + Addrs: []ma.Multiaddr{ma.StringCast("/ip4/159.223.164.169/tcp/9100/p2p/QmdJbNsbHpFseUPKC9vLt4vMsfdxA4dyHPzsAWuzYz3Yxx")}, + }) + + time.Sleep(3 * time.Second) + + log.Println(host.Network().Connectedness(peer.ID("QmdJbNsbHpFseUPKC9vLt4vMsfdxA4dyHPzsAWuzYz3Yxx"))) + // TODO: FINISH THIS TEST +} diff --git a/pkgs/service/relay.go b/pkgs/service/relay.go index 2e5b3f1..2c1ac81 100644 --- a/pkgs/service/relay.go +++ b/pkgs/service/relay.go @@ -2,6 +2,7 @@ package service import ( "context" + "fmt" "proto-snapshot-server/config" "time" @@ -107,9 +108,27 @@ func ConfigureRelayer() { // return // } // ConnectToSequencer(peerId) + + ConnectToTrustedRelayers(context.Background(), rpctorelay) + ConnectToSequencer() } +func ConnectToSequencerP2P(relayers []Relayer, p2pHost host.Host) bool { + for _, relayer := range relayers { + sequencerAddr, err := ma.NewMultiaddr(fmt.Sprintf("/p2p/%s/p2p-circuit/p2p/%s", relayer.ID, config.SettingsObj.SequencerId)) + if err != nil { + log.Debugln(err.Error()) + } + log.Debugln("Connecting to Sequencer: ", sequencerAddr.String()) + isConnected := AddPeerConnection(context.Background(), p2pHost, sequencerAddr.String()) + if isConnected { + return true + } + } + return false +} + func ConnectToSequencer() { // if peerId == "" { // log.Debugln("Not connected to a relayer") diff --git a/pkgs/service/relay_test.go b/pkgs/service/relay_test.go new file mode 100644 index 0000000..dfe38f8 --- /dev/null +++ b/pkgs/service/relay_test.go @@ -0,0 +1,48 @@ +package service + +import ( + "github.com/libp2p/go-libp2p" + "github.com/libp2p/go-libp2p/core/peer" + "log" + "proto-snapshot-server/config" + "testing" +) + +func TestConnectToSequencerP2P(t *testing.T) { + // Mock relayers data + relayers := []Relayer{ + { + ID: "QmQSEao6C3SuPZ8cWiYccPqsd7LtWBTzNgXQZiAjeGTQpm", + Name: "Relayer1", + RendezvousPoint: "Relayer_POP_test_simulation_phase_1", + Maddr: "/ip4/104.248.63.86/tcp/5001/p2p/QmQSEao6C3SuPZ8cWiYccPqsd7LtWBTzNgXQZiAjeGTQpm", + }, + { + ID: "QmU3xwsjRqQR4pjJQ7Cxhcb2tiPvaJ6Z5AHDULq7hHWvvj", + Name: "Relayer2", + RendezvousPoint: "Relayer_POP_test_simulation_phase_1", + Maddr: "/ip4/137.184.132.196/tcp/5001/p2p/QmU3xwsjRqQR4pjJQ7Cxhcb2tiPvaJ6Z5AHDULq7hHWvvj", + }, + } + + // Initialize the configuration settings + config.SettingsObj = &config.Settings{ + SequencerId: "QmdJbNsbHpFseUPKC9vLt4vMsfdxA4dyHPzsAWuzYz3Yxx", + } + + host, err := libp2p.New() + if err != nil { + t.Fatalf("Failed to create host: %v", err) + } + defer host.Close() + // Test the function + result := ConnectToSequencerP2P(relayers, host) + + if !result { + t.Error("expected true, got false") + } + + log.Println("Connected to peer 1: ", host.Network().ConnsToPeer(peer.ID(relayers[0].ID))) + log.Println("Connected to peer 2: ", host.Network().ConnsToPeer(peer.ID(relayers[0].ID))) + log.Println("Connected to peer 3: ", host.Network().ConnsToPeer(peer.ID(config.SettingsObj.SequencerId))) +} From b78af47e85f99a35a508fe6cf68f75baef4a94ea Mon Sep 17 00:00:00 2001 From: Sulejman Sarajlija <3107367+Sulejman@users.noreply.github.com> Date: Sun, 28 Jul 2024 14:32:53 +0200 Subject: [PATCH 02/14] Updated test and relay connection logic --- pkgs/service/discovery.go | 16 +++++++++---- pkgs/service/discovery_test.go | 13 +++++----- pkgs/service/relay.go | 19 ++++++++------- pkgs/service/relay_test.go | 43 ++++++++++++++++++++++------------ relayers.json | 11 +++++++++ 5 files changed, 68 insertions(+), 34 deletions(-) create mode 100644 relayers.json diff --git a/pkgs/service/discovery.go b/pkgs/service/discovery.go index 2ca7954..b0e01d0 100644 --- a/pkgs/service/discovery.go +++ b/pkgs/service/discovery.go @@ -13,7 +13,6 @@ import ( "github.com/libp2p/go-libp2p/core/host" "github.com/libp2p/go-libp2p/core/network" "github.com/libp2p/go-libp2p/core/peer" - "github.com/libp2p/go-libp2p/core/peerstore" "github.com/libp2p/go-libp2p/p2p/discovery/routing" ma "github.com/multiformats/go-multiaddr" log "github.com/sirupsen/logrus" @@ -71,18 +70,27 @@ func AddPeerConnection(ctx context.Context, host host.Host, relayerAddr string) log.Debugln("Failed to extract peer info from multiaddress:", err) } - if host.Network().Connectedness(peerInfo.ID) != network.Connected { + if host.Network().Connectedness(peerInfo.ID) == network.Connected { log.Debugln("Skipping connected relayer: ", peerInfo.ID) return true } // Add the peer to the peerstore - host.Peerstore().AddAddrs(peerInfo.ID, peerInfo.Addrs, peerstore.PermanentAddrTTL) + //host.Peerstore().AddAddrs(peerInfo.ID, peerInfo.Addrs, peerstore.PermanentAddrTTL) - if err := backoff.Retry(func() error { return host.Connect(ctx, *peerInfo) }, backoff.WithMaxRetries(backoff.NewExponentialBackOff(), 1)); err != nil { + err = host.Connect(ctx, *peerInfo) + if err != nil { log.Errorf("Failed to connect to relayer %s: %s", peerInfo.ID, err) + return false + if err := backoff.Retry(func() error { return host.Connect(ctx, *peerInfo) }, backoff.WithMaxRetries(backoff.NewExponentialBackOff(), 1)); err != nil { + log.Errorf("Failed to connect to relayer %s: %s", peerInfo.ID, err) + } else { + log.Infof("Connected to new relayer: %s", peerInfo.ID) + return true + } } else { log.Infof("Connected to new relayer: %s", peerInfo.ID) + log.Infoln("Connected: ", host.Network().ConnsToPeer(peerInfo.ID)) return true } diff --git a/pkgs/service/discovery_test.go b/pkgs/service/discovery_test.go index dadc653..19d2310 100644 --- a/pkgs/service/discovery_test.go +++ b/pkgs/service/discovery_test.go @@ -11,7 +11,6 @@ import ( "net/http/httptest" "proto-snapshot-server/config" "testing" - "time" ) type Settings struct { @@ -50,13 +49,13 @@ func TestFetchTrustedRelayers(t *testing.T) { ID: "QmQSEao6C3SuPZ8cWiYccPqsd7LtWBTzNgXQZiAjeGTQpm", Name: "Relayer1", RendezvousPoint: "Relayer_POP_test_simulation_phase_1", - Maddr: "/ip4/104.248.63.86/tcp/5001/p2p/QmQSEao6C3SuPZ8cWiYccPqsd7LtWBTzNgXQZiAjeGTQpm", + Maddr: "/ip4/104.248.63.86/tcp/9100/p2p/QmQSEao6C3SuPZ8cWiYccPqsd7LtWBTzNgXQZiAjeGTQpm", }, { ID: "QmU3xwsjRqQR4pjJQ7Cxhcb2tiPvaJ6Z5AHDULq7hHWvvj", Name: "Relayer2", RendezvousPoint: "Relayer_POP_test_simulation_phase_1", - Maddr: "/ip4/137.184.132.196/tcp/5001/p2p/QmU3xwsjRqQR4pjJQ7Cxhcb2tiPvaJ6Z5AHDULq7hHWvvj", + Maddr: "/ip4/137.184.132.196/tcp/9100/p2p/QmU3xwsjRqQR4pjJQ7Cxhcb2tiPvaJ6Z5AHDULq7hHWvvj", }, } @@ -92,12 +91,12 @@ func TestConnectToTrustedRelayers(t *testing.T) { "id": "QmQSEao6C3SuPZ8cWiYccPqsd7LtWBTzNgXQZiAjeGTQpm", "name": "Relayer1", "rendezvousPoint": "Relayer_POP_test_simulation_phase_1", - "maddr": "/ip4/104.248.63.86/tcp/5001/p2p/QmQSEao6C3SuPZ8cWiYccPqsd7LtWBTzNgXQZiAjeGTQpm" + "maddr": "/ip4/104.248.63.86/tcp/9100/p2p/QmQSEao6C3SuPZ8cWiYccPqsd7LtWBTzNgXQZiAjeGTQpm" }, { "id": "QmU3xwsjRqQR4pjJQ7Cxhcb2tiPvaJ6Z5AHDULq7hHWvvj", "name": "Relayer2", "rendezvousPoint": "Relayer_POP_test_simulation_phase_1", - "maddr": "/ip4/137.184.132.196/tcp/5001/p2p/QmU3xwsjRqQR4pjJQ7Cxhcb2tiPvaJ6Z5AHDULq7hHWvvj" + "maddr": "/ip4/137.184.132.196/tcp/9100/p2p/QmU3xwsjRqQR4pjJQ7Cxhcb2tiPvaJ6Z5AHDULq7hHWvvj" }]` ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -119,7 +118,7 @@ func TestConnectToTrustedRelayers(t *testing.T) { relayers := ConnectToTrustedRelayers(context.Background(), host) - time.Sleep(3 * time.Second) + //time.Sleep(3 * time.Second) log.Println(host.Network().Connectedness(peer.ID(relayers[0].ID))) log.Println(host.Network().Connectedness(peer.ID(relayers[1].ID))) @@ -129,7 +128,7 @@ func TestConnectToTrustedRelayers(t *testing.T) { Addrs: []ma.Multiaddr{ma.StringCast("/ip4/159.223.164.169/tcp/9100/p2p/QmdJbNsbHpFseUPKC9vLt4vMsfdxA4dyHPzsAWuzYz3Yxx")}, }) - time.Sleep(3 * time.Second) + //time.Sleep(3 * time.Second) log.Println(host.Network().Connectedness(peer.ID("QmdJbNsbHpFseUPKC9vLt4vMsfdxA4dyHPzsAWuzYz3Yxx"))) // TODO: FINISH THIS TEST diff --git a/pkgs/service/relay.go b/pkgs/service/relay.go index 2c1ac81..76a734c 100644 --- a/pkgs/service/relay.go +++ b/pkgs/service/relay.go @@ -109,14 +109,13 @@ func ConfigureRelayer() { // } // ConnectToSequencer(peerId) - ConnectToTrustedRelayers(context.Background(), rpctorelay) - ConnectToSequencer() } func ConnectToSequencerP2P(relayers []Relayer, p2pHost host.Host) bool { for _, relayer := range relayers { - sequencerAddr, err := ma.NewMultiaddr(fmt.Sprintf("/p2p/%s/p2p-circuit/p2p/%s", relayer.ID, config.SettingsObj.SequencerId)) + sequencerAddr, err := ma.NewMultiaddr(fmt.Sprintf("%s/p2p/%s", relayer.Maddr, config.SettingsObj.SequencerId)) + if err != nil { log.Debugln(err.Error()) } @@ -130,11 +129,15 @@ func ConnectToSequencerP2P(relayers []Relayer, p2pHost host.Host) bool { } func ConnectToSequencer() { - // if peerId == "" { - // log.Debugln("Not connected to a relayer") - // return - // } - // sequencerAddr, err := ma.NewMultiaddr(fmt.Sprintf("/p2p/%s/p2p-circuit/p2p/%s", peerId, config.SettingsObj.SequencerId)) + trustedRelayers := ConnectToTrustedRelayers(context.Background(), rpctorelay) + isConnectedP2P := ConnectToSequencerP2P(trustedRelayers, rpctorelay) + if isConnectedP2P { + log.Debugln("Successfully connected to the Sequencer: ", rpctorelay.Network().Connectedness(SequencerId)) + return + } else { + log.Debugln("Failed to connect to the Sequencer") + } + sequencerAddr, err := ma.NewMultiaddr("/ip4/159.223.164.169/tcp/9100/p2p/QmdJbNsbHpFseUPKC9vLt4vMsfdxA4dyHPzsAWuzYz3Yxx") if err != nil { log.Debugln(err.Error()) diff --git a/pkgs/service/relay_test.go b/pkgs/service/relay_test.go index dfe38f8..b876899 100644 --- a/pkgs/service/relay_test.go +++ b/pkgs/service/relay_test.go @@ -1,33 +1,42 @@ package service import ( + "context" "github.com/libp2p/go-libp2p" "github.com/libp2p/go-libp2p/core/peer" + "io" "log" + "net/http" + "net/http/httptest" "proto-snapshot-server/config" "testing" ) func TestConnectToSequencerP2P(t *testing.T) { // Mock relayers data - relayers := []Relayer{ - { - ID: "QmQSEao6C3SuPZ8cWiYccPqsd7LtWBTzNgXQZiAjeGTQpm", - Name: "Relayer1", - RendezvousPoint: "Relayer_POP_test_simulation_phase_1", - Maddr: "/ip4/104.248.63.86/tcp/5001/p2p/QmQSEao6C3SuPZ8cWiYccPqsd7LtWBTzNgXQZiAjeGTQpm", - }, - { - ID: "QmU3xwsjRqQR4pjJQ7Cxhcb2tiPvaJ6Z5AHDULq7hHWvvj", - Name: "Relayer2", - RendezvousPoint: "Relayer_POP_test_simulation_phase_1", - Maddr: "/ip4/137.184.132.196/tcp/5001/p2p/QmU3xwsjRqQR4pjJQ7Cxhcb2tiPvaJ6Z5AHDULq7hHWvvj", - }, - } + mockResponse := `[{ + "id": "QmQSEao6C3SuPZ8cWiYccPqsd7LtWBTzNgXQZiAjeGTQpm", + "name": "Relayer1", + "rendezvousPoint": "Relayer_POP_test_simulation_phase_1", + "maddr": "/ip4/104.248.63.86/tcp/9100/p2p/QmQSEao6C3SuPZ8cWiYccPqsd7LtWBTzNgXQZiAjeGTQpm" + }, { + "id": "QmU3xwsjRqQR4pjJQ7Cxhcb2tiPvaJ6Z5AHDULq7hHWvvj", + "name": "Relayer2", + "rendezvousPoint": "Relayer_POP_test_simulation_phase_1", + "maddr": "/ip4/137.184.132.196/tcp/9100/p2p/QmU3xwsjRqQR4pjJQ7Cxhcb2tiPvaJ6Z5AHDULq7hHWvvj" + }]` + + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + io.WriteString(w, mockResponse) + })) + + defer ts.Close() // Initialize the configuration settings config.SettingsObj = &config.Settings{ - SequencerId: "QmdJbNsbHpFseUPKC9vLt4vMsfdxA4dyHPzsAWuzYz3Yxx", + TrustedRelayersListUrl: ts.URL, + SequencerId: "QmdJbNsbHpFseUPKC9vLt4vMsfdxA4dyHPzsAWuzYz3Yxx", } host, err := libp2p.New() @@ -35,6 +44,10 @@ func TestConnectToSequencerP2P(t *testing.T) { t.Fatalf("Failed to create host: %v", err) } defer host.Close() + + // Fetch the relayers + relayers := ConnectToTrustedRelayers(context.Background(), host) + // Test the function result := ConnectToSequencerP2P(relayers, host) diff --git a/relayers.json b/relayers.json new file mode 100644 index 0000000..2794d8c --- /dev/null +++ b/relayers.json @@ -0,0 +1,11 @@ +[{ + "id": "QmQSEao6C3SuPZ8cWiYccPqsd7LtWBTzNgXQZiAjeGTQpm", + "name": "Relayer1", + "rendezvousPoint": "Relayer_POP_test_simulation_phase_1", + "maddr": "/ip4/104.248.63.86/tcp/9100/p2p/QmQSEao6C3SuPZ8cWiYccPqsd7LtWBTzNgXQZiAjeGTQpm" +}, { + "id": "QmU3xwsjRqQR4pjJQ7Cxhcb2tiPvaJ6Z5AHDULq7hHWvvj", + "name": "Relayer2", + "rendezvousPoint": "Relayer_POP_test_simulation_phase_1", + "maddr": "/ip4/137.184.132.196/tcp/9100/p2p/QmU3xwsjRqQR4pjJQ7Cxhcb2tiPvaJ6Z5AHDULq7hHWvvj" +}] \ No newline at end of file From 3ead618414e5ce4939f7fb6eb4d42bfc65f88684 Mon Sep 17 00:00:00 2001 From: Sulejman Sarajlija <3107367+Sulejman@users.noreply.github.com> Date: Sun, 28 Jul 2024 14:46:07 +0200 Subject: [PATCH 03/14] Updated link for testing fetchRelays to permalink --- pkgs/service/discovery_test.go | 2 +- pkgs/service/relay.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/service/discovery_test.go b/pkgs/service/discovery_test.go index 19d2310..d19a51e 100644 --- a/pkgs/service/discovery_test.go +++ b/pkgs/service/discovery_test.go @@ -41,7 +41,7 @@ func TestFetchTrustedRelayers(t *testing.T) { defer ts.Close() // Call the function to test - relayers := fetchTrustedRelayers(ts.URL) + relayers := fetchTrustedRelayers("https://raw.githubusercontent.com/PowerLoom/snapshotter-lite-local-collector/feat/trusted-relayers/relayers.json") // Expected result expected := []Relayer{ diff --git a/pkgs/service/relay.go b/pkgs/service/relay.go index 76a734c..0b9f7ac 100644 --- a/pkgs/service/relay.go +++ b/pkgs/service/relay.go @@ -132,7 +132,7 @@ func ConnectToSequencer() { trustedRelayers := ConnectToTrustedRelayers(context.Background(), rpctorelay) isConnectedP2P := ConnectToSequencerP2P(trustedRelayers, rpctorelay) if isConnectedP2P { - log.Debugln("Successfully connected to the Sequencer: ", rpctorelay.Network().Connectedness(SequencerId)) + log.Debugln("Successfully connected to the Sequencer: ", rpctorelay.Network().Connectedness(peer.ID(config.SettingsObj.SequencerId)), isConnectedP2P) return } else { log.Debugln("Failed to connect to the Sequencer") From 642d5a268538cfcbade9d9185f56a58bdd7c79a1 Mon Sep 17 00:00:00 2001 From: Sulejman Sarajlija <3107367+Sulejman@users.noreply.github.com> Date: Mon, 5 Aug 2024 13:34:36 +0200 Subject: [PATCH 04/14] Latest Deployment --- config/settings.go | 4 ++-- config/settings.json | 10 ++++++++ pkgs/service/discovery.go | 48 --------------------------------------- pkgs/service/relay.go | 11 ++++++++- 4 files changed, 22 insertions(+), 51 deletions(-) create mode 100644 config/settings.json diff --git a/config/settings.go b/config/settings.go index ce29345..5ff293c 100644 --- a/config/settings.go +++ b/config/settings.go @@ -4,7 +4,6 @@ import ( "encoding/json" log "github.com/sirupsen/logrus" "os" - "strings" ) var SettingsObj *Settings @@ -22,7 +21,8 @@ type Settings struct { } func LoadConfig() { - file, err := os.Open(strings.TrimSuffix(os.Getenv("CONFIG_PATH"), "/") + "/config/settings.json") + //file, err := os.Open(strings.TrimSuffix(os.Getenv("CONFIG_PATH"), "/") + "/config/settings.json") + file, err := os.Open("/Users/sulejmansarajlija/IdeaProjects/powerloom/snapshotter-lite-local-collector/config/settings.json") if err != nil { log.Fatalf("Failed to open config file: %v", err) } diff --git a/config/settings.json b/config/settings.json new file mode 100644 index 0000000..b06d3f7 --- /dev/null +++ b/config/settings.json @@ -0,0 +1,10 @@ +{ + "SequencerId": "QmdJbNsbHpFseUPKC9vLt4vMsfdxA4dyHPzsAWuzYz3Yxx", + "RelayerRendezvousPoint": "RELAYER_RENDEZVOUS_POINT", + "ClientRendezvousPoint": "CLIENT_RENDEZVOUS_POINT", + "RelayerPrivateKey": "RELAYER_PRIVATE_KEY", + "PowerloomReportingUrl": "POWERLOOM_REPORTING_URL", + "SignerAccountAddress": "SIGNER_ACCOUNT_ADDRESS", + "LocalCollectorPort": "LOCAL_COLLECTOR_PORT", + "TrustedRelayersListUrl" : "https://raw.githubusercontent.com/PowerLoom/snapshotter-lite-local-collector/feat/trusted-relayers/relayers.json" +} diff --git a/pkgs/service/discovery.go b/pkgs/service/discovery.go index b0e01d0..79a911e 100644 --- a/pkgs/service/discovery.go +++ b/pkgs/service/discovery.go @@ -13,7 +13,6 @@ import ( "github.com/libp2p/go-libp2p/core/host" "github.com/libp2p/go-libp2p/core/network" "github.com/libp2p/go-libp2p/core/peer" - "github.com/libp2p/go-libp2p/p2p/discovery/routing" ma "github.com/multiformats/go-multiaddr" log "github.com/sirupsen/logrus" ) @@ -50,15 +49,6 @@ func fetchTrustedRelayers(url string) []Relayer { return relayers } -func isVisited(id peer.ID, visited []peer.ID) bool { - for _, v := range visited { - if v == id { - return true - } - } - return false -} - func AddPeerConnection(ctx context.Context, host host.Host, relayerAddr string) bool { stableRelayerMA, err := ma.NewMultiaddr(relayerAddr) if err != nil { @@ -75,9 +65,6 @@ func AddPeerConnection(ctx context.Context, host host.Host, relayerAddr string) return true } - // Add the peer to the peerstore - //host.Peerstore().AddAddrs(peerInfo.ID, peerInfo.Addrs, peerstore.PermanentAddrTTL) - err = host.Connect(ctx, *peerInfo) if err != nil { log.Errorf("Failed to connect to relayer %s: %s", peerInfo.ID, err) @@ -110,41 +97,6 @@ func ConnectToTrustedRelayers(ctx context.Context, host host.Host) []Relayer { return connectedRelayers } -func ConnectToPeer(ctx context.Context, routingDiscovery *routing.RoutingDiscovery, rendezvousString string, host host.Host, visited []peer.ID) peer.ID { - //stableRelayer1 := "/ip4/104.248.63.86/tcp/5001/p2p/QmQSEao6C3SuPZ8cWiYccPqsd7LtWBTzNgXQZiAjeGTQpm" - //stableRelayer2 := "/ip4/137.184.132.196/tcp/5001/p2p/QmU3xwsjRqQR4pjJQ7Cxhcb2tiPvaJ6Z5AHDULq7hHWvvj" - - peerChan, err := routingDiscovery.FindPeers(ctx, rendezvousString) - - if err != nil { - log.Fatalf("Failed to find peers: %s", err) - } - log.Debugln("Triggering peer discovery") - - log.Debugln("Skipping visited peers: ", visited) - - for relayer := range peerChan { - if relayer.ID == host.ID() { - continue // Skip self or peers with no addresses - } - - if host.Network().Connectedness(relayer.ID) != network.Connected { - // Connect to the relayer if not already connected - if err = backoff.Retry(func() error { return host.Connect(ctx, relayer) }, backoff.WithMaxRetries(backoff.NewExponentialBackOff(), 1)); err != nil { - log.Errorf("Failed to connect to relayer %s: %s", relayer.ID, err) - } else { - log.Infof("Connected to new relayer: %s", relayer.ID) - return relayer.ID - } - } else { - log.Debugln("Already connected to: ", relayer.ID) - // return relayer.ID - } - } - log.Debugln("Active connections: ", activeConnections) - return "" -} - func ConfigureDHT(ctx context.Context, host host.Host) *dht.IpfsDHT { // Set up a Kademlia DHT for the service host kademliaDHT, err := dht.New(ctx, host) diff --git a/pkgs/service/relay.go b/pkgs/service/relay.go index 0b9f7ac..c2f2790 100644 --- a/pkgs/service/relay.go +++ b/pkgs/service/relay.go @@ -3,6 +3,7 @@ package service import ( "context" "fmt" + circuitv2 "github.com/libp2p/go-libp2p/p2p/protocol/circuitv2/client" "proto-snapshot-server/config" "time" @@ -114,11 +115,19 @@ func ConfigureRelayer() { func ConnectToSequencerP2P(relayers []Relayer, p2pHost host.Host) bool { for _, relayer := range relayers { - sequencerAddr, err := ma.NewMultiaddr(fmt.Sprintf("%s/p2p/%s", relayer.Maddr, config.SettingsObj.SequencerId)) + relayerMA, err := ma.NewMultiaddr(relayer.Maddr) + relayerInfo, err := peer.AddrInfoFromP2pAddr(relayerMA) + if reservation, err := circuitv2.Reserve(context.Background(), p2pHost, *relayerInfo); err != nil { + log.Fatalf("Failed to request reservation with relay: %v", err) + } else { + fmt.Println("Reservation with relay successful", reservation.Expiration, reservation.LimitDuration) + } + sequencerAddr, err := ma.NewMultiaddr(fmt.Sprintf("%s/p2p-circuit/p2p/%s", relayer.Maddr, config.SettingsObj.SequencerId)) if err != nil { log.Debugln(err.Error()) } + log.Debugln("Connecting to Sequencer: ", sequencerAddr.String()) isConnected := AddPeerConnection(context.Background(), p2pHost, sequencerAddr.String()) if isConnected { From 5fef84157d16525b17ef5d0c0a726fd6306d0b5a Mon Sep 17 00:00:00 2001 From: Sulejman Sarajlija <3107367+Sulejman@users.noreply.github.com> Date: Mon, 5 Aug 2024 15:15:31 +0200 Subject: [PATCH 05/14] Direct sequencer connection --- cmd/main.go | 9 ++++----- config/settings.example.json | 1 + config/settings.go | 5 +++++ config/settings.json | 3 ++- pkgs/service/relay.go | 20 ++++++++++---------- server_autofill.sh | 12 +++++++++++- 6 files changed, 33 insertions(+), 17 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 2dcd3ec..2aa0f4b 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -4,17 +4,16 @@ import ( "proto-snapshot-server/config" "proto-snapshot-server/pkgs/helpers" "proto-snapshot-server/pkgs/service" - "sync" "time" ) func main() { - var wg sync.WaitGroup + //var wg sync.WaitGroup helpers.InitLogger() config.LoadConfig() service.InitializeReportingService(config.SettingsObj.PowerloomReportingUrl, 5*time.Second) service.ConfigureRelayer() - wg.Add(1) - go service.StartSubmissionServer(service.NewMsgServerImpl()) - wg.Wait() + //wg.Add(1) + //go service.StartSubmissionServer(service.NewMsgServerImpl()) + //wg.Wait() } diff --git a/config/settings.example.json b/config/settings.example.json index 39347dc..c4c904f 100644 --- a/config/settings.example.json +++ b/config/settings.example.json @@ -7,4 +7,5 @@ "SignerAccountAddress": "SIGNER_ACCOUNT_ADDRESS", "LocalCollectorPort": "LOCAL_COLLECTOR_PORT", "TrustedRelayersListUrl" : "TRUSTED_RELAYERS_LIST_URL", + "SequencerNetworkPath" : "SEQUENCER_MULTIADDR" } diff --git a/config/settings.go b/config/settings.go index 5ff293c..f13487a 100644 --- a/config/settings.go +++ b/config/settings.go @@ -39,5 +39,10 @@ func LoadConfig() { if err != nil { log.Fatalf("Failed to decode config file: %v", err) } + + if config.TrustedRelayersListUrl == "" { + config.TrustedRelayersListUrl = "https://raw.githubusercontent.com/PowerLoom/snapshotter-lite-local-collector/feat/trusted-relayers/relayers.json" + } + SettingsObj = &config } diff --git a/config/settings.json b/config/settings.json index b06d3f7..612f4de 100644 --- a/config/settings.json +++ b/config/settings.json @@ -6,5 +6,6 @@ "PowerloomReportingUrl": "POWERLOOM_REPORTING_URL", "SignerAccountAddress": "SIGNER_ACCOUNT_ADDRESS", "LocalCollectorPort": "LOCAL_COLLECTOR_PORT", - "TrustedRelayersListUrl" : "https://raw.githubusercontent.com/PowerLoom/snapshotter-lite-local-collector/feat/trusted-relayers/relayers.json" + "TrustedRelayersListUrl" : "https://raw.githubusercontent.com/PowerLoom/snapshotter-lite-local-collector/feat/trusted-relayers/relayers.json", + "SequencerNetworkPath": "/dns/proto-snapshot-listener.aws2.powerloom.io/tcp/9100/p2p/QmTK9e9QNEotPkjWAdZT5bbYKV7PEJVu7iXzdVn3VZDEk9" } diff --git a/pkgs/service/relay.go b/pkgs/service/relay.go index c2f2790..2ed4bb0 100644 --- a/pkgs/service/relay.go +++ b/pkgs/service/relay.go @@ -138,16 +138,16 @@ func ConnectToSequencerP2P(relayers []Relayer, p2pHost host.Host) bool { } func ConnectToSequencer() { - trustedRelayers := ConnectToTrustedRelayers(context.Background(), rpctorelay) - isConnectedP2P := ConnectToSequencerP2P(trustedRelayers, rpctorelay) - if isConnectedP2P { - log.Debugln("Successfully connected to the Sequencer: ", rpctorelay.Network().Connectedness(peer.ID(config.SettingsObj.SequencerId)), isConnectedP2P) - return - } else { - log.Debugln("Failed to connect to the Sequencer") - } - - sequencerAddr, err := ma.NewMultiaddr("/ip4/159.223.164.169/tcp/9100/p2p/QmdJbNsbHpFseUPKC9vLt4vMsfdxA4dyHPzsAWuzYz3Yxx") + //trustedRelayers := ConnectToTrustedRelayers(context.Background(), rpctorelay) + //isConnectedP2P := ConnectToSequencerP2P(trustedRelayers, rpctorelay) + //if isConnectedP2P { + // log.Debugln("Successfully connected to the Sequencer: ", rpctorelay.Network().Connectedness(peer.ID(config.SettingsObj.SequencerId)), isConnectedP2P) + // return + //} else { + // log.Debugln("Failed to connect to the Sequencer") + //} + + sequencerAddr, err := ma.NewMultiaddr(config.SettingsObj.SequencerNetworkPath) if err != nil { log.Debugln(err.Error()) return diff --git a/server_autofill.sh b/server_autofill.sh index 5a716a2..1701c12 100755 --- a/server_autofill.sh +++ b/server_autofill.sh @@ -21,6 +21,14 @@ if [ -z "$LOCAL_COLLECTOR_PORT" ]; then echo "LOCAL_COLLECTOR_PORT not found, please set this in your .env!"; exit 1; fi +if [ -z "$SEQUENCER_MULTIADDR" ]; then + echo "SEQUENCER_MULTIADDR not found, please set this in your .env!"; + exit 1; +fi +if [ -z "$TRUSTED_RELAYERS_LIST_URL" ]; then + echo "TRUSTED_RELAYERS_LIST_URL not found, please set this in your .env!"; + exit 1; +fi cd config # Template to actual settings.json manipulation @@ -43,7 +51,9 @@ sed -i'.backup' -e "s#SEQUENCER_ID#$SEQUENCER_ID#" \ -e "s#POWERLOOM_REPORTING_URL#$POWERLOOM_REPORTING_URL#" \ -e "s#SIGNER_ACCOUNT_ADDRESS#$SIGNER_ACCOUNT_ADDRESS#" \ -e "s#LOCAL_COLLECTOR_PORT#$LOCAL_COLLECTOR_PORT#" \ - -e "s#RELAYER_PRIVATE_KEY#$RELAYER_PRIVATE_KEY#" settings.json + -e "s#RELAYER_PRIVATE_KEY#$RELAYER_PRIVATE_KEY#" settings.json \ + -e "s#SEQUENCER_MULTIADDR#$SEQUENCER_MULTIADDR#" \ + -e "s#TRUSTED_RELAYERS_LIST_URL#$TRUSTED_RELAYERS_LIST_URL#" settings.json # Cleanup backup file rm settings.json.backup From fcff0435aa550d1c02d284b37e469e515275a603 Mon Sep 17 00:00:00 2001 From: Sulejman Sarajlija <3107367+Sulejman@users.noreply.github.com> Date: Mon, 5 Aug 2024 15:18:09 +0200 Subject: [PATCH 06/14] clean up --- cmd/main.go | 9 +++++---- config/settings.go | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 2aa0f4b..2dcd3ec 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -4,16 +4,17 @@ import ( "proto-snapshot-server/config" "proto-snapshot-server/pkgs/helpers" "proto-snapshot-server/pkgs/service" + "sync" "time" ) func main() { - //var wg sync.WaitGroup + var wg sync.WaitGroup helpers.InitLogger() config.LoadConfig() service.InitializeReportingService(config.SettingsObj.PowerloomReportingUrl, 5*time.Second) service.ConfigureRelayer() - //wg.Add(1) - //go service.StartSubmissionServer(service.NewMsgServerImpl()) - //wg.Wait() + wg.Add(1) + go service.StartSubmissionServer(service.NewMsgServerImpl()) + wg.Wait() } diff --git a/config/settings.go b/config/settings.go index f13487a..0c33a84 100644 --- a/config/settings.go +++ b/config/settings.go @@ -4,6 +4,7 @@ import ( "encoding/json" log "github.com/sirupsen/logrus" "os" + "strings" ) var SettingsObj *Settings @@ -21,8 +22,7 @@ type Settings struct { } func LoadConfig() { - //file, err := os.Open(strings.TrimSuffix(os.Getenv("CONFIG_PATH"), "/") + "/config/settings.json") - file, err := os.Open("/Users/sulejmansarajlija/IdeaProjects/powerloom/snapshotter-lite-local-collector/config/settings.json") + file, err := os.Open(strings.TrimSuffix(os.Getenv("CONFIG_PATH"), "/") + "/config/settings.json") if err != nil { log.Fatalf("Failed to open config file: %v", err) } From dcea9aa4eebe565592eed1185946352b36705d50 Mon Sep 17 00:00:00 2001 From: Sulejman Sarajlija <3107367+Sulejman@users.noreply.github.com> Date: Wed, 14 Aug 2024 00:54:40 +0200 Subject: [PATCH 07/14] fetching sequencer from json in github repo --- go.mod | 7 ++- go.sum | 3 +- pkgs/service/discovery.go | 43 ++++++++++++++++++ pkgs/service/discovery_test.go | 79 ++++++++++++++++++++++++++++++++++ pkgs/service/relay.go | 24 +++++++++-- sequencers.json | 14 ++++++ 6 files changed, 162 insertions(+), 8 deletions(-) create mode 100644 sequencers.json diff --git a/go.mod b/go.mod index cf56dfa..ab4589a 100644 --- a/go.mod +++ b/go.mod @@ -6,11 +6,12 @@ require ( github.com/cenkalti/backoff/v4 v4.2.0 github.com/google/uuid v1.6.0 github.com/libp2p/go-libp2p v0.32.2 - github.com/libp2p/go-libp2p-core v0.20.1 github.com/libp2p/go-libp2p-kad-dht v0.25.2 github.com/multiformats/go-multiaddr v0.12.2 + github.com/pkg/errors v0.9.1 github.com/sethvargo/go-retry v0.2.4 github.com/sirupsen/logrus v1.9.3 + github.com/stretchr/testify v1.8.4 google.golang.org/grpc v1.62.0 google.golang.org/protobuf v1.32.0 ) @@ -21,6 +22,7 @@ require ( github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/containerd/cgroups v1.1.0 // indirect github.com/coreos/go-systemd/v22 v22.5.0 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect github.com/docker/go-units v0.5.0 // indirect @@ -85,7 +87,7 @@ require ( github.com/opencontainers/runtime-spec v1.1.0 // indirect github.com/opentracing/opentracing-go v1.2.0 // indirect github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect - github.com/pkg/errors v0.9.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect github.com/polydawn/refmt v0.89.0 // indirect github.com/prometheus/client_golang v1.16.0 // indirect github.com/prometheus/client_model v0.4.0 // indirect @@ -117,5 +119,6 @@ require ( golang.org/x/tools v0.18.0 // indirect gonum.org/v1/gonum v0.13.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect lukechampine.com/blake3 v1.2.1 // indirect ) diff --git a/go.sum b/go.sum index 378b22e..86160d3 100644 --- a/go.sum +++ b/go.sum @@ -192,8 +192,6 @@ github.com/libp2p/go-libp2p v0.32.2 h1:s8GYN4YJzgUoyeYNPdW7JZeZ5Ee31iNaIBfGYMAY4 github.com/libp2p/go-libp2p v0.32.2/go.mod h1:E0LKe+diV/ZVJVnOJby8VC5xzHF0660osg71skcxJvk= github.com/libp2p/go-libp2p-asn-util v0.3.0 h1:gMDcMyYiZKkocGXDQ5nsUQyquC9+H+iLEQHwOCZ7s8s= github.com/libp2p/go-libp2p-asn-util v0.3.0/go.mod h1:B1mcOrKUE35Xq/ASTmQ4tN3LNzVVaMNmq2NACuqyB9w= -github.com/libp2p/go-libp2p-core v0.20.1 h1:fQz4BJyIFmSZAiTbKV8qoYhEH5Dtv/cVhZbG3Ib/+Cw= -github.com/libp2p/go-libp2p-core v0.20.1/go.mod h1:6zR8H7CvQWgYLsbG4on6oLNSGcyKaYFSEYyDt51+bIY= github.com/libp2p/go-libp2p-kad-dht v0.25.2 h1:FOIk9gHoe4YRWXTu8SY9Z1d0RILol0TrtApsMDPjAVQ= github.com/libp2p/go-libp2p-kad-dht v0.25.2/go.mod h1:6za56ncRHYXX4Nc2vn8z7CZK0P4QiMcrn77acKLM2Oo= github.com/libp2p/go-libp2p-kbucket v0.6.3 h1:p507271wWzpy2f1XxPzCQG9NiN6R6lHL9GiSErbQQo0= @@ -362,6 +360,7 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA= github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/urfave/cli v1.22.10/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= diff --git a/pkgs/service/discovery.go b/pkgs/service/discovery.go index 79a911e..1aee952 100644 --- a/pkgs/service/discovery.go +++ b/pkgs/service/discovery.go @@ -3,6 +3,7 @@ package service import ( "context" "encoding/json" + "github.com/pkg/errors" "io" "net/http" "proto-snapshot-server/config" @@ -24,6 +25,48 @@ type Relayer struct { Maddr string `json:"maddr"` } +type Sequencer struct { + ID string `json:"id"` + Maddr string `json:"maddr"` + DataMarketAddress string `json:"dataMarketAddress"` + Environment string `json:"environment"` +} + +func fetchSequencer(url string, dataMarketAddress string) (Sequencer, error) { + resp, err := http.Get(url) + if err != nil { + log.Fatalf("Failed to fetch JSON: %v", err) + } + defer resp.Body.Close() + + body, err := io.ReadAll(resp.Body) + if err != nil { + log.Debugf("Failed to read response body: %v", err) + } + + var sequencers []Sequencer + err = json.Unmarshal(body, &sequencers) + if err != nil { + log.Debugln("Failed to unmarshal JSON:", err) + } + + for _, sequencer := range sequencers { + log.Debugf( + "ID: %s, Maddr: %s, Data Market Address: %s, Environment: %s\n", + sequencer.ID, + sequencer.Maddr, + sequencer.DataMarketAddress, + sequencer.Environment, + ) + + if sequencer.DataMarketAddress == dataMarketAddress { + return sequencer, nil + } + } + + return Sequencer{}, errors.New("Sequencer not found") +} + func fetchTrustedRelayers(url string) []Relayer { resp, err := http.Get(url) if err != nil { diff --git a/pkgs/service/discovery_test.go b/pkgs/service/discovery_test.go index d19a51e..77f2e31 100644 --- a/pkgs/service/discovery_test.go +++ b/pkgs/service/discovery_test.go @@ -2,10 +2,13 @@ package service import ( "context" + "encoding/json" + "errors" "github.com/libp2p/go-libp2p" "github.com/libp2p/go-libp2p/core/peer" ma "github.com/multiformats/go-multiaddr" log "github.com/sirupsen/logrus" + "github.com/stretchr/testify/assert" "io" "net/http" "net/http/httptest" @@ -133,3 +136,79 @@ func TestConnectToTrustedRelayers(t *testing.T) { log.Println(host.Network().Connectedness(peer.ID("QmdJbNsbHpFseUPKC9vLt4vMsfdxA4dyHPzsAWuzYz3Yxx"))) // TODO: FINISH THIS TEST } + +func TestFetchSequencer(t *testing.T) { + // Create mock data + sequencers := []Sequencer{ + { + ID: "QmTK9e9QNEotPkjWAdZT5bbYKV7PEJVu7iXzdVn3VZDEk9", + Maddr: "/dns/proto-snapshot-listener.aws2.powerloom.io/tcp/9100/p2p/QmTK9e9QNEotPkjWAdZT5bbYKV7PEJVu7iXzdVn3VZDEk9", + DataMarketAddress: "0xa8D4C62BD8831bca08C9a16b3e76C824c9658eA1", + Environment: "prod", + }, + { + ID: "QmbWC2TKXDWnYB1picmYwAMRUz7ACXLXDWyLibjHnaRyoN", + Maddr: "/dns/proto-snapshot-listener.aws2.powerloom.io/tcp/9100/p2p/QmbWC2TKXDWnYB1picmYwAMRUz7ACXLXDWyLibjHnaRyoN", + DataMarketAddress: "0x718b3f7B8ef6abA1D1440A26F92AC11EE167005a", + Environment: "staging", + }, + } + + // Convert mock data to JSON + jsonData, err := json.Marshal(sequencers) + assert.NoError(t, err) + + t.Log(string(jsonData)) + + // Create a test server with the mock JSON response + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + w.Write(jsonData) + })) + defer server.Close() + + tests := []struct { + name string + dataMarketAddr string + environment string + expectedID string + expectedError error + }{ + { + name: "Valid sequencer found (prod)", + dataMarketAddr: "0xa8D4C62BD8831bca08C9a16b3e76C824c9658eA1", + environment: "prod", + expectedID: "QmTK9e9QNEotPkjWAdZT5bbYKV7PEJVu7iXzdVn3VZDEk9", + expectedError: nil, + }, + { + name: "Valid sequencer found (staging)", + dataMarketAddr: "0x718b3f7B8ef6abA1D1440A26F92AC11EE167005a", + environment: "staging", + expectedID: "QmbWC2TKXDWnYB1picmYwAMRUz7ACXLXDWyLibjHnaRyoN", + expectedError: nil, + }, + { + name: "Sequencer not found", + dataMarketAddr: "0x9999", + environment: "prod", + expectedID: "", + expectedError: errors.New("Sequencer not found"), + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + sequencer, err := fetchSequencer(server.URL, tt.dataMarketAddr) + + if tt.expectedError != nil { + assert.Error(t, err) + assert.Equal(t, tt.expectedError.Error(), err.Error()) + } else { + assert.NoError(t, err) + assert.Equal(t, tt.expectedID, sequencer.ID) + } + }) + } +} diff --git a/pkgs/service/relay.go b/pkgs/service/relay.go index 2ed4bb0..894dfe2 100644 --- a/pkgs/service/relay.go +++ b/pkgs/service/relay.go @@ -147,10 +147,26 @@ func ConnectToSequencer() { // log.Debugln("Failed to connect to the Sequencer") //} - sequencerAddr, err := ma.NewMultiaddr(config.SettingsObj.SequencerNetworkPath) - if err != nil { - log.Debugln(err.Error()) - return + var sequencerAddr ma.Multiaddr + var err error + + if config.SettingsObj.SequencerNetworkPath != "" { + sequencerAddr, err = ma.NewMultiaddr(config.SettingsObj.SequencerNetworkPath) + if err != nil { + log.Debugln(err.Error()) + return + } + } else { + sequencer, err := fetchSequencer("https://raw.githubusercontent.com/PowerLoom/snapshotter-lite-local-collector/feat/trusted-relayers/sequencers.json", config.SettingsObj.DataMarketAddress) + if err != nil { + log.Debugln(err.Error()) + } + config.SettingsObj.SequencerNetworkPath = sequencer.Maddr + sequencerAddr, err = ma.NewMultiaddr(sequencer.Maddr) + if err != nil { + log.Debugln(err.Error()) + return + } } sequencerInfo, err := peer.AddrInfoFromP2pAddr(sequencerAddr) diff --git a/sequencers.json b/sequencers.json new file mode 100644 index 0000000..625a81b --- /dev/null +++ b/sequencers.json @@ -0,0 +1,14 @@ +[ + { + "id": "QmTK9e9QNEotPkjWAdZT5bbYKV7PEJVu7iXzdVn3VZDEk9", + "maddr": "/dns/proto-snapshot-listener.aws2.powerloom.io/tcp/9100/p2p/QmTK9e9QNEotPkjWAdZT5bbYKV7PEJVu7iXzdVn3VZDEk9", + "dataMarketAddress": "0xa8D4C62BD8831bca08C9a16b3e76C824c9658eA1", + "environment": "prod" + }, + { + "id": "QmbWC2TKXDWnYB1picmYwAMRUz7ACXLXDWyLibjHnaRyoN", + "maddr": "/dns/proto-snapshot-listener.aws2.powerloom.io/tcp/9100/p2p/QmbWC2TKXDWnYB1picmYwAMRUz7ACXLXDWyLibjHnaRyoN", + "dataMarketAddress": "0x718b3f7B8ef6abA1D1440A26F92AC11EE167005a", + "environment": "staging" + } +] \ No newline at end of file From cebc391aef3a234cebadbd758c47bd29bc07b440 Mon Sep 17 00:00:00 2001 From: Sulejman Sarajlija <3107367+Sulejman@users.noreply.github.com> Date: Wed, 14 Aug 2024 00:55:11 +0200 Subject: [PATCH 08/14] fetching sequencer from json in github repo --- config/settings.example.json | 3 ++- config/settings.go | 7 ++++--- config/settings.json | 3 ++- server_autofill.sh | 7 ++++++- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/config/settings.example.json b/config/settings.example.json index c4c904f..68a922d 100644 --- a/config/settings.example.json +++ b/config/settings.example.json @@ -7,5 +7,6 @@ "SignerAccountAddress": "SIGNER_ACCOUNT_ADDRESS", "LocalCollectorPort": "LOCAL_COLLECTOR_PORT", "TrustedRelayersListUrl" : "TRUSTED_RELAYERS_LIST_URL", - "SequencerNetworkPath" : "SEQUENCER_MULTIADDR" + "SequencerNetworkPath" : "SEQUENCER_MULTIADDR", + "DataMarketAddress" : "DATA_MARKET_ADDRESS" } diff --git a/config/settings.go b/config/settings.go index 0c33a84..8753786 100644 --- a/config/settings.go +++ b/config/settings.go @@ -4,7 +4,6 @@ import ( "encoding/json" log "github.com/sirupsen/logrus" "os" - "strings" ) var SettingsObj *Settings @@ -18,11 +17,13 @@ type Settings struct { SignerAccountAddress string `json:"SignerAccountAddress"` PortNumber string `json:"LocalCollectorPort"` TrustedRelayersListUrl string `json:"TrustedRelayersListUrl"` - SequencerNetworkPath string `json:"SequencerNetworkPath"` + SequencerNetworkPath string `json:"Sequencers"` + DataMarketAddress string `json:"DataMarketAddress"` } func LoadConfig() { - file, err := os.Open(strings.TrimSuffix(os.Getenv("CONFIG_PATH"), "/") + "/config/settings.json") + //file, err := os.Open(strings.TrimSuffix(os.Getenv("CONFIG_PATH"), "/") + "/config/settings.json") + file, err := os.Open("/Users/sulejmansarajlija/IdeaProjects/powerloom/snapshotter-lite-local-collector/config/settings.json") if err != nil { log.Fatalf("Failed to open config file: %v", err) } diff --git a/config/settings.json b/config/settings.json index 612f4de..e17dd5b 100644 --- a/config/settings.json +++ b/config/settings.json @@ -7,5 +7,6 @@ "SignerAccountAddress": "SIGNER_ACCOUNT_ADDRESS", "LocalCollectorPort": "LOCAL_COLLECTOR_PORT", "TrustedRelayersListUrl" : "https://raw.githubusercontent.com/PowerLoom/snapshotter-lite-local-collector/feat/trusted-relayers/relayers.json", - "SequencerNetworkPath": "/dns/proto-snapshot-listener.aws2.powerloom.io/tcp/9100/p2p/QmTK9e9QNEotPkjWAdZT5bbYKV7PEJVu7iXzdVn3VZDEk9" + "SequencerNetworkPath": "/dns/proto-snapshot-listener.aws2.powerloom.io/tcp/9100/p2p/QmTK9e9QNEotPkjWAdZT5bbYKV7PEJVu7iXzdVn3VZDEk9", + "DataMarketAddress" : "0xa8D4C62BD8831bca08C9a16b3e76C824c9658eA1" } diff --git a/server_autofill.sh b/server_autofill.sh index 1701c12..179a7d7 100755 --- a/server_autofill.sh +++ b/server_autofill.sh @@ -21,6 +21,10 @@ if [ -z "$LOCAL_COLLECTOR_PORT" ]; then echo "LOCAL_COLLECTOR_PORT not found, please set this in your .env!"; exit 1; fi +if [ -z "$DATA_MARKET_ADDRESS" ]; then + echo "DATA_MARKET_ADDRESS not found, please set this in your .env!"; + exit 1; +fi if [ -z "$SEQUENCER_MULTIADDR" ]; then echo "SEQUENCER_MULTIADDR not found, please set this in your .env!"; exit 1; @@ -53,7 +57,8 @@ sed -i'.backup' -e "s#SEQUENCER_ID#$SEQUENCER_ID#" \ -e "s#LOCAL_COLLECTOR_PORT#$LOCAL_COLLECTOR_PORT#" \ -e "s#RELAYER_PRIVATE_KEY#$RELAYER_PRIVATE_KEY#" settings.json \ -e "s#SEQUENCER_MULTIADDR#$SEQUENCER_MULTIADDR#" \ - -e "s#TRUSTED_RELAYERS_LIST_URL#$TRUSTED_RELAYERS_LIST_URL#" settings.json + -e "s#TRUSTED_RELAYERS_LIST_URL#$TRUSTED_RELAYERS_LIST_URL#" settings.json \ + -e "s#DATA_MARKET_ADDRESS#$DATA_MARKET_ADDRESS#" settings.json # Cleanup backup file rm settings.json.backup From 9192c170f412d13382df362a141845ff01dc37f6 Mon Sep 17 00:00:00 2001 From: Sulejman Sarajlija <3107367+Sulejman@users.noreply.github.com> Date: Wed, 14 Aug 2024 12:57:00 +0200 Subject: [PATCH 09/14] Removing local config --- config/settings.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/settings.go b/config/settings.go index 8753786..09e6b21 100644 --- a/config/settings.go +++ b/config/settings.go @@ -4,6 +4,7 @@ import ( "encoding/json" log "github.com/sirupsen/logrus" "os" + "strings" ) var SettingsObj *Settings @@ -22,8 +23,7 @@ type Settings struct { } func LoadConfig() { - //file, err := os.Open(strings.TrimSuffix(os.Getenv("CONFIG_PATH"), "/") + "/config/settings.json") - file, err := os.Open("/Users/sulejmansarajlija/IdeaProjects/powerloom/snapshotter-lite-local-collector/config/settings.json") + file, err := os.Open(strings.TrimSuffix(os.Getenv("CONFIG_PATH"), "/") + "/config/settings.json") if err != nil { log.Fatalf("Failed to open config file: %v", err) } From 72fca1d4c9c245f73cfe7cd61f453fc26ad75502 Mon Sep 17 00:00:00 2001 From: Sulejman Sarajlija <3107367+Sulejman@users.noreply.github.com> Date: Thu, 15 Aug 2024 13:10:03 +0200 Subject: [PATCH 10/14] Updating sequencer list --- sequencers.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sequencers.json b/sequencers.json index 625a81b..b00b95c 100644 --- a/sequencers.json +++ b/sequencers.json @@ -7,7 +7,7 @@ }, { "id": "QmbWC2TKXDWnYB1picmYwAMRUz7ACXLXDWyLibjHnaRyoN", - "maddr": "/dns/proto-snapshot-listener.aws2.powerloom.io/tcp/9100/p2p/QmbWC2TKXDWnYB1picmYwAMRUz7ACXLXDWyLibjHnaRyoN", + "maddr": "/dns/staging-proto-snapshot-listener.aws2.powerloom.io/tcp/9100/p2p/QmbWC2TKXDWnYB1picmYwAMRUz7ACXLXDWyLibjHnaRyoN", "dataMarketAddress": "0x718b3f7B8ef6abA1D1440A26F92AC11EE167005a", "environment": "staging" } From 4b3bf6b15467197c3a305f9de43c6d8bbebc8220 Mon Sep 17 00:00:00 2001 From: Sulejman Sarajlija <3107367+Sulejman@users.noreply.github.com> Date: Fri, 16 Aug 2024 14:04:01 +0200 Subject: [PATCH 11/14] Update sequencers.json New DataMarket on same sequencer: 0x7231806D5778e7f4b30f0CeaA4656416DDe5a57c --- sequencers.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sequencers.json b/sequencers.json index b00b95c..ff3ea9e 100644 --- a/sequencers.json +++ b/sequencers.json @@ -8,7 +8,7 @@ { "id": "QmbWC2TKXDWnYB1picmYwAMRUz7ACXLXDWyLibjHnaRyoN", "maddr": "/dns/staging-proto-snapshot-listener.aws2.powerloom.io/tcp/9100/p2p/QmbWC2TKXDWnYB1picmYwAMRUz7ACXLXDWyLibjHnaRyoN", - "dataMarketAddress": "0x718b3f7B8ef6abA1D1440A26F92AC11EE167005a", + "dataMarketAddress": "0x7231806D5778e7f4b30f0CeaA4656416DDe5a57c", "environment": "staging" } -] \ No newline at end of file +] From 65b4bb1950a3ac14124c1d2686bf1cdace2163a7 Mon Sep 17 00:00:00 2001 From: Sulejman Sarajlija <3107367+Sulejman@users.noreply.github.com> Date: Fri, 16 Aug 2024 16:27:57 +0200 Subject: [PATCH 12/14] Changing env variable to be compatible with --- config/settings.example.json | 2 +- server_autofill.sh | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/config/settings.example.json b/config/settings.example.json index 68a922d..2aa1239 100644 --- a/config/settings.example.json +++ b/config/settings.example.json @@ -8,5 +8,5 @@ "LocalCollectorPort": "LOCAL_COLLECTOR_PORT", "TrustedRelayersListUrl" : "TRUSTED_RELAYERS_LIST_URL", "SequencerNetworkPath" : "SEQUENCER_MULTIADDR", - "DataMarketAddress" : "DATA_MARKET_ADDRESS" + "DataMarketAddress" : "DATA_MARKET_CONTRACT" } diff --git a/server_autofill.sh b/server_autofill.sh index 179a7d7..dd652c2 100755 --- a/server_autofill.sh +++ b/server_autofill.sh @@ -21,8 +21,8 @@ if [ -z "$LOCAL_COLLECTOR_PORT" ]; then echo "LOCAL_COLLECTOR_PORT not found, please set this in your .env!"; exit 1; fi -if [ -z "$DATA_MARKET_ADDRESS" ]; then - echo "DATA_MARKET_ADDRESS not found, please set this in your .env!"; +if [ -z "$DATA_MARKET_CONTRACT" ]; then + echo "DATA_MARKET_CONTRACT not found, please set this in your .env!"; exit 1; fi if [ -z "$SEQUENCER_MULTIADDR" ]; then @@ -58,7 +58,7 @@ sed -i'.backup' -e "s#SEQUENCER_ID#$SEQUENCER_ID#" \ -e "s#RELAYER_PRIVATE_KEY#$RELAYER_PRIVATE_KEY#" settings.json \ -e "s#SEQUENCER_MULTIADDR#$SEQUENCER_MULTIADDR#" \ -e "s#TRUSTED_RELAYERS_LIST_URL#$TRUSTED_RELAYERS_LIST_URL#" settings.json \ - -e "s#DATA_MARKET_ADDRESS#$DATA_MARKET_ADDRESS#" settings.json + -e "s#DATA_MARKET_CONTRACT#$DATA_MARKET_CONTRACT#" settings.json # Cleanup backup file rm settings.json.backup From 933becd11a5eb56600c859c4dbea78809642bfd1 Mon Sep 17 00:00:00 2001 From: Sulejman Sarajlija <3107367+Sulejman@users.noreply.github.com> Date: Fri, 16 Aug 2024 20:26:19 +0200 Subject: [PATCH 13/14] Non-neccessary env values --- config/settings.example.json | 3 --- server_autofill.sh | 26 ++------------------------ 2 files changed, 2 insertions(+), 27 deletions(-) diff --git a/config/settings.example.json b/config/settings.example.json index 2aa1239..92d8bfe 100644 --- a/config/settings.example.json +++ b/config/settings.example.json @@ -1,7 +1,4 @@ { - "SequencerId": "SEQUENCER_ID", - "RelayerRendezvousPoint": "RELAYER_RENDEZVOUS_POINT", - "ClientRendezvousPoint": "CLIENT_RENDEZVOUS_POINT", "RelayerPrivateKey": "RELAYER_PRIVATE_KEY", "PowerloomReportingUrl": "POWERLOOM_REPORTING_URL", "SignerAccountAddress": "SIGNER_ACCOUNT_ADDRESS", diff --git a/server_autofill.sh b/server_autofill.sh index dd652c2..9376993 100755 --- a/server_autofill.sh +++ b/server_autofill.sh @@ -5,18 +5,6 @@ set -e echo 'populating server settings from environment values...'; export LOCAL_COLLECTOR_PORT="${LOCAL_COLLECTOR_PORT:-50051}" -if [ -z "$CLIENT_RENDEZVOUS_POINT" ]; then - echo "CLIENT_RENDEZVOUS_POINT not found, please set this in your .env!"; - exit 1; -fi -if [ -z "$RELAYER_RENDEZVOUS_POINT" ]; then - echo "RELAYER_RENDEZVOUS_POINT not found, please set this in your .env!"; - exit 1; -fi -if [ -z "$SEQUENCER_ID" ]; then - echo "SEQUENCER_ID not found, please set this in your .env!"; - exit 1; -fi if [ -z "$LOCAL_COLLECTOR_PORT" ]; then echo "LOCAL_COLLECTOR_PORT not found, please set this in your .env!"; exit 1; @@ -25,14 +13,7 @@ if [ -z "$DATA_MARKET_CONTRACT" ]; then echo "DATA_MARKET_CONTRACT not found, please set this in your .env!"; exit 1; fi -if [ -z "$SEQUENCER_MULTIADDR" ]; then - echo "SEQUENCER_MULTIADDR not found, please set this in your .env!"; - exit 1; -fi -if [ -z "$TRUSTED_RELAYERS_LIST_URL" ]; then - echo "TRUSTED_RELAYERS_LIST_URL not found, please set this in your .env!"; - exit 1; -fi + cd config # Template to actual settings.json manipulation @@ -49,10 +30,7 @@ fi export RELAYER_PRIVATE_KEY # Replace placeholders in settings.json with actual values from environment variables -sed -i'.backup' -e "s#SEQUENCER_ID#$SEQUENCER_ID#" \ - -e "s#RELAYER_RENDEZVOUS_POINT#$RELAYER_RENDEZVOUS_POINT#" \ - -e "s#CLIENT_RENDEZVOUS_POINT#$CLIENT_RENDEZVOUS_POINT#" \ - -e "s#POWERLOOM_REPORTING_URL#$POWERLOOM_REPORTING_URL#" \ +sed -i'.backup' -e "s#POWERLOOM_REPORTING_URL#$POWERLOOM_REPORTING_URL#" \ -e "s#SIGNER_ACCOUNT_ADDRESS#$SIGNER_ACCOUNT_ADDRESS#" \ -e "s#LOCAL_COLLECTOR_PORT#$LOCAL_COLLECTOR_PORT#" \ -e "s#RELAYER_PRIVATE_KEY#$RELAYER_PRIVATE_KEY#" settings.json \ From 5653c6728d9116bdeaea246c1e73a0b8e3ba29c2 Mon Sep 17 00:00:00 2001 From: Sulejman Sarajlija <3107367+Sulejman@users.noreply.github.com> Date: Tue, 20 Aug 2024 14:37:59 +0200 Subject: [PATCH 14/14] Update sequencers.json with new staging deployment --- sequencers.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sequencers.json b/sequencers.json index ff3ea9e..274015a 100644 --- a/sequencers.json +++ b/sequencers.json @@ -8,7 +8,7 @@ { "id": "QmbWC2TKXDWnYB1picmYwAMRUz7ACXLXDWyLibjHnaRyoN", "maddr": "/dns/staging-proto-snapshot-listener.aws2.powerloom.io/tcp/9100/p2p/QmbWC2TKXDWnYB1picmYwAMRUz7ACXLXDWyLibjHnaRyoN", - "dataMarketAddress": "0x7231806D5778e7f4b30f0CeaA4656416DDe5a57c", + "dataMarketAddress": "0xf46D4Dd56868371C0AF6Fe8DB1bD8F252B34b685", "environment": "staging" } ]