Skip to content

Commit

Permalink
Merge pull request #14 from PowerLoom/dockerify
Browse files Browse the repository at this point in the history
Merge setup for trusted sequencer list
  • Loading branch information
SwaroopH authored Aug 22, 2024
2 parents e7f587a + a76a2f5 commit 41c4a2c
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 45 deletions.
1 change: 0 additions & 1 deletion config/settings.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
"SignerAccountAddress": "SIGNER_ACCOUNT_ADDRESS",
"LocalCollectorPort": "LOCAL_COLLECTOR_PORT",
"TrustedRelayersListUrl" : "TRUSTED_RELAYERS_LIST_URL",
"SequencerNetworkPath" : "SEQUENCER_MULTIADDR",
"DataMarketAddress" : "DATA_MARKET_CONTRACT"
}
4 changes: 2 additions & 2 deletions config/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package config

import (
"encoding/json"
log "github.com/sirupsen/logrus"
"os"
"strings"

log "github.com/sirupsen/logrus"
)

var SettingsObj *Settings
Expand All @@ -18,7 +19,6 @@ type Settings struct {
SignerAccountAddress string `json:"SignerAccountAddress"`
PortNumber string `json:"LocalCollectorPort"`
TrustedRelayersListUrl string `json:"TrustedRelayersListUrl"`
SequencerNetworkPath string `json:"Sequencers"`
DataMarketAddress string `json:"DataMarketAddress"`
}

Expand Down
12 changes: 0 additions & 12 deletions config/settings.json

This file was deleted.

12 changes: 2 additions & 10 deletions pkgs/service/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package service
import (
"context"
"encoding/json"
"github.com/pkg/errors"
"io"
"net/http"
"proto-snapshot-server/config"
"sync"

"github.com/cenkalti/backoff/v4"
"github.com/pkg/errors"

dht "github.com/libp2p/go-libp2p-kad-dht"
"github.com/libp2p/go-libp2p/core/host"
"github.com/libp2p/go-libp2p/core/network"
Expand Down Expand Up @@ -112,19 +112,11 @@ func AddPeerConnection(ctx context.Context, host host.Host, relayerAddr string)
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
}

return false
}

func ConnectToTrustedRelayers(ctx context.Context, host host.Host) []Relayer {
Expand Down
2 changes: 1 addition & 1 deletion pkgs/service/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func mustSetStream(s *server) error {
}
return nil
}
return backoff.Retry(operation, backoff.WithMaxRetries(backoff.NewExponentialBackOff(), 3))
return backoff.Retry(operation, backoff.WithMaxRetries(backoff.NewExponentialBackOff(), 1))
}

func TryConnection(s *server) error {
Expand Down
28 changes: 10 additions & 18 deletions pkgs/service/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,25 +150,17 @@ func ConnectToSequencer() {
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
}

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())
}

sequencerAddr, err = ma.NewMultiaddr(sequencer.Maddr)
if err != nil {
log.Debugln(err.Error())
return
}

sequencerInfo, err := peer.AddrInfoFromP2pAddr(sequencerAddr)

if err != nil {
Expand Down
1 change: 0 additions & 1 deletion server_autofill.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ 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 \
-e "s#SEQUENCER_MULTIADDR#$SEQUENCER_MULTIADDR#" \
-e "s#TRUSTED_RELAYERS_LIST_URL#$TRUSTED_RELAYERS_LIST_URL#" settings.json \
-e "s#DATA_MARKET_CONTRACT#$DATA_MARKET_CONTRACT#" settings.json

Expand Down

0 comments on commit 41c4a2c

Please sign in to comment.