From 244bb176eb81ce76ed36f950ddd6778b1e73720d Mon Sep 17 00:00:00 2001 From: Prem Chaitanya Prathi Date: Tue, 1 Oct 2024 10:21:13 +0530 Subject: [PATCH 1/2] feat: add clusterID and shards config to c-bindings (#1228) --- library/c/README.md | 2 ++ library/config.go | 2 ++ library/node.go | 2 ++ waku/v2/node/wakuoptions.go | 17 +++++++++++++++++ 4 files changed, 23 insertions(+) diff --git a/library/c/README.md b/library/c/README.md index 30c2e0607..92dc08bbc 100644 --- a/library/c/README.md +++ b/library/c/README.md @@ -285,6 +285,8 @@ interface JsonConfig { storeRetentionTimeSeconds?: number; websocket?: Websocket; dns4DomainName?: string; + clusterID: int; + shards: Array; } ``` diff --git a/library/config.go b/library/config.go index 344d88a37..1574b9109 100644 --- a/library/config.go +++ b/library/config.go @@ -31,6 +31,8 @@ type WakuConfig struct { RetentionTimeSeconds *int `json:"storeRetentionTimeSeconds,omitempty"` DNS4DomainName string `json:"dns4DomainName,omitempty"` Websockets *WebsocketConfig `json:"websockets,omitempty"` + ClusterID int `json:"clusterID"` + Shards []uint16 `json:"shards"` } // WebsocketConfig contains all the settings required to setup websocket support in waku diff --git a/library/node.go b/library/node.go index f084b85a7..5232f4d92 100644 --- a/library/node.go +++ b/library/node.go @@ -164,6 +164,8 @@ func NewNode(instance *WakuInstance, configJSON string) error { node.WithPrivateKey(prvKey), node.WithHostAddress(hostAddr), node.WithKeepAlive(10*time.Second, time.Duration(*config.KeepAliveInterval)*time.Second), + node.WithClusterID(uint16(config.ClusterID)), + node.WithShards(config.Shards), } if *config.EnableRelay { diff --git a/waku/v2/node/wakuoptions.go b/waku/v2/node/wakuoptions.go index 112cafe61..7e7c5e103 100644 --- a/waku/v2/node/wakuoptions.go +++ b/waku/v2/node/wakuoptions.go @@ -319,6 +319,11 @@ func WithPrivateKey(privKey *ecdsa.PrivateKey) WakuNodeOption { func WithClusterID(clusterID uint16) WakuNodeOption { return func(params *WakuNodeParameters) error { params.clusterID = clusterID + if params.shards == nil { + var pshards protocol.RelayShards + pshards.ClusterID = params.clusterID + params.shards = &pshards + } return nil } } @@ -340,6 +345,18 @@ func WithPubSubTopics(topics []string) WakuNodeOption { } } +func WithShards(shards []uint16) WakuNodeOption { + return func(params *WakuNodeParameters) error { + if params.shards == nil { + var pshards protocol.RelayShards + pshards.ClusterID = params.clusterID + params.shards = &pshards + } + params.shards.ShardIDs = shards + return nil + } +} + // WithMaxConnectionsPerIP sets the max number of allowed peers from the same IP func WithMaxConnectionsPerIP(limit int) WakuNodeOption { return func(params *WakuNodeParameters) error { From ae423936ed811fd1cd3ee06447bd8730de2a4aea Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Tue, 1 Oct 2024 18:24:47 -0400 Subject: [PATCH 2/2] fix: remove bandwidth metrics that were commited to `master` by mistake --- waku/v2/node/metrics.go | 17 ----------------- waku/v2/node/wakunode2.go | 32 +++++--------------------------- 2 files changed, 5 insertions(+), 44 deletions(-) diff --git a/waku/v2/node/metrics.go b/waku/v2/node/metrics.go index e845e7452..7bcf51223 100644 --- a/waku/v2/node/metrics.go +++ b/waku/v2/node/metrics.go @@ -3,7 +3,6 @@ package node import ( "fmt" - "github.com/libp2p/go-libp2p/core/metrics" "github.com/libp2p/go-libp2p/p2p/metricshelper" "github.com/prometheus/client_golang/prometheus" ) @@ -34,20 +33,11 @@ var peerStoreSize = prometheus.NewGauge( Help: "Size of Peer Store", }) -var bandwidthTotal = prometheus.NewCounterVec( - prometheus.CounterOpts{ - Name: "libp2p_network_bytes_total", - Help: "Bandwidth usage total", - }, - []string{"direction"}, -) - var collectors = []prometheus.Collector{ gitVersion, peerDials, connectedPeers, peerStoreSize, - bandwidthTotal, } // Metrics exposes the functions required to update prometheus metrics for the waku node @@ -57,7 +47,6 @@ type Metrics interface { RecordPeerConnected() RecordPeerDisconnected() SetPeerStoreSize(int) - RecordBandwidth(metrics.Stats) } type metricsImpl struct { @@ -95,9 +84,3 @@ func (m *metricsImpl) RecordPeerDisconnected() { func (m *metricsImpl) SetPeerStoreSize(size int) { peerStoreSize.Set(float64(size)) } - -func (m *metricsImpl) RecordBandwidth(stats metrics.Stats) { - bandwidthTotal.WithLabelValues("in").Add(float64(stats.TotalIn)) - bandwidthTotal.WithLabelValues("out").Add(float64(stats.TotalOut)) - -} diff --git a/waku/v2/node/wakunode2.go b/waku/v2/node/wakunode2.go index d5890b011..2de62cc7e 100644 --- a/waku/v2/node/wakunode2.go +++ b/waku/v2/node/wakunode2.go @@ -18,7 +18,6 @@ import ( "github.com/libp2p/go-libp2p/core/event" "github.com/libp2p/go-libp2p/core/host" - "github.com/libp2p/go-libp2p/core/metrics" "github.com/libp2p/go-libp2p/core/network" "github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/core/peerstore" @@ -85,12 +84,11 @@ type RLNRelay interface { } type WakuNode struct { - host host.Host - opts *WakuNodeParameters - log *zap.Logger - timesource timesource.Timesource - metrics Metrics - bandwidthCounter *metrics.BandwidthCounter + host host.Host + opts *WakuNodeParameters + log *zap.Logger + timesource timesource.Timesource + metrics Metrics peerstore peerstore.Peerstore peerConnector *peermanager.PeerConnectionStrategy @@ -197,9 +195,6 @@ func New(opts ...WakuNodeOption) (*WakuNode, error) { w.metrics = newMetrics(params.prometheusReg) w.metrics.RecordVersion(Version, GitCommit) - w.bandwidthCounter = metrics.NewBandwidthCounter() - params.libP2POpts = append(params.libP2POpts, libp2p.BandwidthReporter(w.bandwidthCounter)) - // Setup peerstore wrapper if params.peerstore != nil { w.peerstore = wps.NewWakuPeerstore(params.peerstore) @@ -364,23 +359,6 @@ func (w *WakuNode) Start(ctx context.Context) error { w.host = host - // Bandwidth reporter created for comparing IDONTWANT performance - go func() { - ticker := time.NewTicker(time.Second) - defer ticker.Stop() - - for { - select { - case <-ctx.Done(): - return - case <-ticker.C: - totals := w.bandwidthCounter.GetBandwidthTotals() - w.bandwidthCounter.Reset() - w.metrics.RecordBandwidth(totals) - } - } - }() - if w.addressChangesSub, err = host.EventBus().Subscribe(new(event.EvtLocalAddressesUpdated)); err != nil { return err }