Skip to content

Commit

Permalink
Revert "limit persistent peers to 20"
Browse files Browse the repository at this point in the history
This reverts commit d340f2b.
  • Loading branch information
Eric-Warehime committed Nov 5, 2024
1 parent bbaca50 commit afc76ac
Showing 1 changed file with 3 additions and 25 deletions.
28 changes: 3 additions & 25 deletions cosmos/node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@ import (
"bytes"
"context"
"fmt"
"math/rand"
"reflect"
"strings"
"time"

toml "github.com/pelletier/go-toml/v2"
petritypes "github.com/skip-mev/petri/core/v2/types"
"reflect"
"time"
)

type Toml map[string]any
Expand Down Expand Up @@ -167,12 +164,8 @@ func (n *Node) SetDefaultConfigs(ctx context.Context) error {
func (n *Node) SetPersistentPeers(ctx context.Context, peers string) error {
cometBftConfig := make(Toml)

allPeers := strings.Split(peers, ",")

p2pConfig := make(Toml)

// return the filtered peers
p2pConfig["persistent_peers"] = filterPeers(allPeers)
p2pConfig["persistent_peers"] = peers

cometBftConfig["p2p"] = p2pConfig

Expand All @@ -182,18 +175,3 @@ func (n *Node) SetPersistentPeers(ctx context.Context, peers string) error {
cometBftConfig,
)
}

// filter peers returns a random subset of the given peers. The subset is determined as follows:
// 1. If the number of peers is less than or equal to 20, return all peers.
// 2. If the number of peers is greater than 20, return a random subset of 20 peers.
func filterPeers(allPeers []string) string {
if len(allPeers) <= 20 {
return strings.Join(allPeers, ",")
}

rand.Shuffle(len(allPeers), func(i, j int) {
allPeers[i], allPeers[j] = allPeers[j], allPeers[i]
})

return strings.Join(allPeers[:20], ",")
}

0 comments on commit afc76ac

Please sign in to comment.